my scripts wont work! they're supposed to fire a bullet out the tip (working), take off one ammo (kinda working) and wait (not working)
then load up again and wait. depending if youve ran out of ammo, reload the rack and wait.
by wait i mean use my own alarm (aka gun_stats[gt,3])
the problem is that it doesnt wait and fires a continuous stream of bullets, and when it gets to 1, it wont fire (rather than reload)
before you look at the scripts, some stuff you should know:
- gt represents gun type
- gs is an object which holds the array of gun_stone
- the rifle (gt 2) turns into sniper mode (gt 6) in a key press event. they have the same properties, exept for the z and the firing position.
script 1: step event of obj_player
CODE
//gun_stats array: 0=ammo, 1=racks, 2=have?, 3=time til next fire, 4=canfire
//gun_stone array: 0=name, 1=reload amt, 2=round time, 3=reload time 4=pie, 5=forc, 6=bur, 7=velocity, 8=size, 9=z
//rifle=sniper
if gt=2
gun_stats[6,0]=gun_stats[2,0]
gun_stats[6,1]=gun_stats[2,1]
gun_stats[6,2]=gun_stats[2,2]
gun_stats[6,3]=gun_stats[2,3]
gun_stats[6,4]=gun_stats[2,4]
if gt=6
gun_stats[2,0]=gun_stats[6,0]
gun_stats[2,1]=gun_stats[6,1]
gun_stats[2,2]=gun_stats[6,2]
gun_stats[2,3]=gun_stats[6,3]
gun_stats[2,4]=gun_stats[6,4]
//skipping guns i dont have them
while gun_stats[gt,2]=0
{
repeat (6)
{
if gt=1 or 2 or 3 or 4
{gt+=1}
if gt=5
{gt=0}
if gt=6
{gt=3}
}
}
//anti-below 0
if gun_stats[gt,0]<0 gun_stats[gt,0]=0;
if gun_stats[gt,1]<0 gun_stats[gt,1]=0;
if gun_stats[gt,2]<0 gun_stats[gt,2]=0;
if gun_stats[gt,3]<0 gun_stats[gt,3]=0;
if gun_stats[gt,4]<0 gun_stats[gt,4]=0;
//self-alarm for reload
if gun_stats[gt,3]>0
gun_stats[gt,3]-=1
//gun_stone array: 0=name, 1=reload amt, 2=round time, 3=reload time 4=pie, 5=forc, 6=bur, 7=velocity, 8=size, 9=z
//rifle=sniper
if gt=2
gun_stats[6,0]=gun_stats[2,0]
gun_stats[6,1]=gun_stats[2,1]
gun_stats[6,2]=gun_stats[2,2]
gun_stats[6,3]=gun_stats[2,3]
gun_stats[6,4]=gun_stats[2,4]
if gt=6
gun_stats[2,0]=gun_stats[6,0]
gun_stats[2,1]=gun_stats[6,1]
gun_stats[2,2]=gun_stats[6,2]
gun_stats[2,3]=gun_stats[6,3]
gun_stats[2,4]=gun_stats[6,4]
//skipping guns i dont have them
while gun_stats[gt,2]=0
{
repeat (6)
{
if gt=1 or 2 or 3 or 4
{gt+=1}
if gt=5
{gt=0}
if gt=6
{gt=3}
}
}
//anti-below 0
if gun_stats[gt,0]<0 gun_stats[gt,0]=0;
if gun_stats[gt,1]<0 gun_stats[gt,1]=0;
if gun_stats[gt,2]<0 gun_stats[gt,2]=0;
if gun_stats[gt,3]<0 gun_stats[gt,3]=0;
if gun_stats[gt,4]<0 gun_stats[gt,4]=0;
//self-alarm for reload
if gun_stats[gt,3]>0
gun_stats[gt,3]-=1
script 2: space bar (fire) for player 1
CODE
//gun_stone array: 0=name, 1=reload amt, 2=round time, 3=reload time 4=pie, 5=forc, 6=bur, 7=velocity, 8=size, 9=z
//gun_stats array: 0=ammo, 1=racks, 2=have?, 3=time til next fire, 4=canfire
if gun_stats[gt,0]>0 and gun_stats[gt,4]=1 and gun_stats[gt,3]=0
{
var nb; nb=0;
x1=x + lengthdir_x(26, direction)+ sin(direction*pi/180)*5; y1=y + lengthdir_y(26, direction)+ cos(direction*pi/180)*5;
x2=x + lengthdir_x(26, direction); y2=y + lengthdir_y(26, direction);
if gt =!6 //check if you are in sniper mode, therefore having the gun in front of you
{nb=instance_create(x1,y1,obj_bullet);}
else
{nb=instance_create(x2,y2,obj_bullet);}
//give the bullet the properties as stated in the create of gun_stone which is a array of object gs
nb.pie=gs.gun_stone[gt,4]; nb.forc=gs.gun_stone[gt,5]; nb.bur=gs.gun_stone[gt,6];
nb.velocity=gs.gun_stone[gt,7]; nb.size=gs.gun_stone[gt,8]; nb.z=gs.gun_stone[gt,9];
nb.direction=direction;;
//take off ammo and prevent shooting
gun_stats[gt,0]-=1
gun_stats[gt,4]=0
//reload bullet
if gun_stats[gt,0]>0
{gun_stats[gt,3]-=gs.gun_stone[gt,2]; gun_stats[gt,4]=1;}
//reload rack
if gun_stats[gt,0]=0 and gun_stats[gt,1]>0
{gun_stats[gt,3]-=gs.gun_stone[gt,3]; gun_stats[gt,0]=gs.gun_stone[gt,1]; gun_stats[gt,4]=1;}
}
//gun_stats array: 0=ammo, 1=racks, 2=have?, 3=time til next fire, 4=canfire
if gun_stats[gt,0]>0 and gun_stats[gt,4]=1 and gun_stats[gt,3]=0
{
var nb; nb=0;
x1=x + lengthdir_x(26, direction)+ sin(direction*pi/180)*5; y1=y + lengthdir_y(26, direction)+ cos(direction*pi/180)*5;
x2=x + lengthdir_x(26, direction); y2=y + lengthdir_y(26, direction);
if gt =!6 //check if you are in sniper mode, therefore having the gun in front of you
{nb=instance_create(x1,y1,obj_bullet);}
else
{nb=instance_create(x2,y2,obj_bullet);}
//give the bullet the properties as stated in the create of gun_stone which is a array of object gs
nb.pie=gs.gun_stone[gt,4]; nb.forc=gs.gun_stone[gt,5]; nb.bur=gs.gun_stone[gt,6];
nb.velocity=gs.gun_stone[gt,7]; nb.size=gs.gun_stone[gt,8]; nb.z=gs.gun_stone[gt,9];
nb.direction=direction;;
//take off ammo and prevent shooting
gun_stats[gt,0]-=1
gun_stats[gt,4]=0
//reload bullet
if gun_stats[gt,0]>0
{gun_stats[gt,3]-=gs.gun_stone[gt,2]; gun_stats[gt,4]=1;}
//reload rack
if gun_stats[gt,0]=0 and gun_stats[gt,1]>0
{gun_stats[gt,3]-=gs.gun_stone[gt,3]; gun_stats[gt,0]=gs.gun_stone[gt,1]; gun_stats[gt,4]=1;}
}
if you really need the arrays creation event scripts then tell me and i will post them
thanks very much
frank