So, i need make the SSG shoot 8 bulets instead of 3
The SSG code:
Spoiler 

-- Setup Tables
if cc==nil then cc={} end
cc.sshotty={}
cc.sshotty.bullet={}
-- Load & Prepare Ressources
cc.sshotty.gfx_wpn=loadgfx("weapons/SGN2A0.bmp") -- Weapon Image
setmidhandle(cc.sshotty.gfx_wpn)
cc.sshotty.gfx_pro=loadgfx("weapons/shot.bmp") -- Projectile Image
setmidhandle(cc.sshotty.gfx_pro)
cc.sshotty.sfx_attack=loadsfx("DSSSG.wav") -- Attack Sound
--------------------------------------------------------------------------------
-- Weapon: Shotgun
--------------------------------------------------------------------------------
cc.sshotty.id=addweapon("cc.sshotty","superhotgun",cc.sshotty.gfx_wpn, 5) -- Add Weapon
cc.sshotty.ammo=2 -- 2 Shots
function cc.sshotty.draw() -- Draw
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
drawinhand(cc.sshotty.gfx_wpn,6,0)
-- HUD ammobar
if cc.sshotty.ammo-weapon_shots>0 then
hudammobar(cc.sshotty.ammo-weapon_shots,cc.sshotty.ammo)
end
-- HUD Crosshair
if cc.sshotty.ammo-weapon_shots>0 then
hudcrosshair(7,3)
end
end
function cc.sshotty.attack(attack) -- Attack
-- Decrement timer
if weapon_timer>0 then
weapon_timer=weapon_timer-1
end
-- Attack
if weapon_shots<cc.sshotty.ammo and weapon_timer<=0 and attack==1 then
-- No more weapon switching!
useweapon(0)
-- Reset Timer
weapon_timer=20
-- Attack
playsound(cc.sshotty.sfx_attack)
weapon_shots=weapon_shots+1
for i=1,3,1 do
id=createprojectile(cc.sshotty.bullet.id)
projectiles[id]={}
rot=getplayerrotation(0)
if i==2 then
rot=rot-5
elseif i==3 then
rot=rot+5
end
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(rot))*5.0
projectiles[id].y=getplayery(0)+3+math.cos(math.rad(rot))*5.0
-- Set speed of projectile
projectiles[id].sx=math.sin(math.rad(rot))*15.0
projectiles[id].sy=-math.cos(math.rad(rot))*15.0
-- Initial movement
projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
for i=1,3,1 do
if cc.sshotty.bullet.move(id)==1 then
break
end
end
end
-- Effects
recoil(7)
particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
particlefadealpha(0.005)
-- End Turn
if (weapon_shots>=cc.sshotty.ammo) then
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: Bullet
--------------------------------------------------------------------------------
cc.sshotty.bullet.id=addprojectile("cc.sshotty.bullet") -- Add Projectile
function cc.sshotty.bullet.draw(id) -- Draw
-- Setup draw mode
setblend(blend_light)
setalpha(1)
setcolor(255,125,0)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
drawimage(cc.sshotty.gfx_pro,projectiles[id].x,projectiles[id].y)
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.sshotty.bullet.update(id) -- Update
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()*0.02
projectiles[id].sy=projectiles[id].sy+getgravity()*0.75
-- Move
cc.sshotty.bullet.move(id)
end
function cc.sshotty.bullet.move(id)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20,1,1)==1 then
if terraincollision()==1 or playercollision()~=projectiles[id].ignore then
-- Cause damage
if playercollision()~=0 then
playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
playerdamage(playercollision(),4)
blood(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)
end
-- Destroy terrain
terrainexplosion(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20,12,0)
-- Effects
particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
particlefadealpha(0.004)
particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
-- Free projectile
freeprojectile(id)
return 1
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
if math.random(1,2)==1 then
playsound(sfx_hitwater2)
else
playsound(sfx_hitwater3)
end
-- Free projectile
freeprojectile(id)
return 1
end
end
end
if cc==nil then cc={} end
cc.sshotty={}
cc.sshotty.bullet={}
-- Load & Prepare Ressources
cc.sshotty.gfx_wpn=loadgfx("weapons/SGN2A0.bmp") -- Weapon Image
setmidhandle(cc.sshotty.gfx_wpn)
cc.sshotty.gfx_pro=loadgfx("weapons/shot.bmp") -- Projectile Image
setmidhandle(cc.sshotty.gfx_pro)
cc.sshotty.sfx_attack=loadsfx("DSSSG.wav") -- Attack Sound
--------------------------------------------------------------------------------
-- Weapon: Shotgun
--------------------------------------------------------------------------------
cc.sshotty.id=addweapon("cc.sshotty","superhotgun",cc.sshotty.gfx_wpn, 5) -- Add Weapon
cc.sshotty.ammo=2 -- 2 Shots
function cc.sshotty.draw() -- Draw
setblend(blend_alpha)
setalpha(1)
setcolor(255,255,255)
drawinhand(cc.sshotty.gfx_wpn,6,0)
-- HUD ammobar
if cc.sshotty.ammo-weapon_shots>0 then
hudammobar(cc.sshotty.ammo-weapon_shots,cc.sshotty.ammo)
end
-- HUD Crosshair
if cc.sshotty.ammo-weapon_shots>0 then
hudcrosshair(7,3)
end
end
function cc.sshotty.attack(attack) -- Attack
-- Decrement timer
if weapon_timer>0 then
weapon_timer=weapon_timer-1
end
-- Attack
if weapon_shots<cc.sshotty.ammo and weapon_timer<=0 and attack==1 then
-- No more weapon switching!
useweapon(0)
-- Reset Timer
weapon_timer=20
-- Attack
playsound(cc.sshotty.sfx_attack)
weapon_shots=weapon_shots+1
for i=1,3,1 do
id=createprojectile(cc.sshotty.bullet.id)
projectiles[id]={}
rot=getplayerrotation(0)
if i==2 then
rot=rot-5
elseif i==3 then
rot=rot+5
end
-- Ignore collision with current player at beginning
projectiles[id].ignore=playercurrent()
-- Set initial position of projectile
projectiles[id].x=getplayerx(0)+(7*getplayerdirection(0))-math.sin(math.rad(rot))*5.0
projectiles[id].y=getplayery(0)+3+math.cos(math.rad(rot))*5.0
-- Set speed of projectile
projectiles[id].sx=math.sin(math.rad(rot))*15.0
projectiles[id].sy=-math.cos(math.rad(rot))*15.0
-- Initial movement
projectiles[id].x=projectiles[id].x-projectiles[id].sx*1.5
projectiles[id].y=projectiles[id].y-projectiles[id].sy*1.5
for i=1,3,1 do
if cc.sshotty.bullet.move(id)==1 then
break
end
end
end
-- Effects
recoil(7)
particle(p_muzzle,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
particle(p_smoke,getplayerx(0)+(getplayerdirection(0)*7)+math.sin(math.rad(getplayerrotation(0)))*16,getplayery(0)+3-math.cos(math.rad(getplayerrotation(0)))*16)
particlespeed(-0.2+math.random()*0.4+getwind()*10.0,-1.0+math.random()*0.6)
particlefadealpha(0.005)
-- End Turn
if (weapon_shots>=cc.sshotty.ammo) then
endturn()
end
end
end
--------------------------------------------------------------------------------
-- Projectile: Bullet
--------------------------------------------------------------------------------
cc.sshotty.bullet.id=addprojectile("cc.sshotty.bullet") -- Add Projectile
function cc.sshotty.bullet.draw(id) -- Draw
-- Setup draw mode
setblend(blend_light)
setalpha(1)
setcolor(255,125,0)
setscale(1,1)
-- Calculate projectile rotation
setrotation(math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy)))
-- Draw projectile
drawimage(cc.sshotty.gfx_pro,projectiles[id].x,projectiles[id].y)
-- Draw Arrow if out of Screen
outofscreenarrow(projectiles[id].x,projectiles[id].y)
end
function cc.sshotty.bullet.update(id) -- Update
-- Wind + Gravity influence on speed
projectiles[id].sx=projectiles[id].sx+getwind()*0.02
projectiles[id].sy=projectiles[id].sy+getgravity()*0.75
-- Move
cc.sshotty.bullet.move(id)
end
function cc.sshotty.bullet.move(id)
rot=math.deg(math.atan2(projectiles[id].sx,-projectiles[id].sy))
-- Move (in substep loop for optimal collision precision)
msubt=math.ceil(math.max(math.abs(projectiles[id].sx),math.abs(projectiles[id].sy))/3)
msubx=projectiles[id].sx/msubt
msuby=projectiles[id].sy/msubt
for i=1,msubt,1 do
projectiles[id].x=projectiles[id].x+msubx
projectiles[id].y=projectiles[id].y+msuby
-- Collision
if collision(col3x3,projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20,1,1)==1 then
if terraincollision()==1 or playercollision()~=projectiles[id].ignore then
-- Cause damage
if playercollision()~=0 then
playerpush(playercollision(),projectiles[id].sx/10.0,projectiles[id].sy/10.0)
playerdamage(playercollision(),4)
blood(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20)
end
-- Destroy terrain
terrainexplosion(projectiles[id].x+math.sin(math.rad(rot))*20,projectiles[id].y-math.cos(math.rad(rot))*20,12,0)
-- Effects
particle(p_smoke,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
particlefadealpha(0.004)
particle(p_muzzle,projectiles[id].x+math.sin(math.rad(rot))*21,projectiles[id].y-math.cos(math.rad(rot))*21)
-- Free projectile
freeprojectile(id)
return 1
end
else
projectiles[id].ignore=0
end
-- Water
if (projectiles[id].y)>getwatery()+5 then
-- Effects
particle(p_waterhit,projectiles[id].x,projectiles[id].y)
if math.random(1,2)==1 then
playsound(sfx_hitwater2)
else
playsound(sfx_hitwater3)
end
-- Free projectile
freeprojectile(id)
return 1
end
end
end
may anyone help me pls ?
edited 1×, last 16.09.10 03:07:07 pm
Lua Scripts/Questions/Help
1 
Offline
never use os.clock() for action related stuff in your Carnage Contest weapon scripts because os.clock() is different on each PC. it will make your scripts asynchronous (run different for all players) which CAN result in strange bugs. all CC weapon scripts have to be written in a way that guarantees that they run equally on all PCs every time they are executed.
use