Script to hurt a player when shot by a bullet/projectile

I need a script that makes it when i have a gani of a person shoting a gun the bullet shots out and if it hits another it hurts then 29 damage

tricxta please post a tutorial on how to use trigger actions. i want to learn too.

we’re not going to make you anything. Just learn the GS1 commands “triggeraction” and “shoot.”

Sure here’s my tutorial:

We set up the data to be sent with the projectile by using setshootparams and then we emit it using shoot.

For this demonstration we’ll keep things simple and ignore z and zangle, these add a 3rd dimension to your projectile and no one really uses them effectively.
Same applies with power, although if you want something more sophisticated you know where to go.

setshootparams gun,29;
shoot playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2,0,getangle(vecx(playerdir),vecy(playerdir)),0,0,a_bullet,aspritesheet.png;

I’ve given the project the data, gun,29(#p(0) and #p(1)). You can as many or as little projectiles as you like although…i’m not sure on the max amount of parameters a projectile can hold but I can get away with 6, just play with it and see what works.

See that the starting of the bullet is at the coordinates playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2.
I’ve then calculated my angle based off the players direction, getangle(vecx(playerdir),vecy(playerdir))
We can add spread to this like you would on a machine gun by simply adding or subtracting a random number, eg:getangle(vecx(playerdir),vecy(playerdir))+random(-0.1,0.1)

And finally I’ve decided to use an imaginary gani called a_bullet which uses the spreet sheet aspritesheet.png, these gani parameters can be defined using params1,params2,and so on.

On the receiving end we can tell if a player has been struck by using actionprojectile

if (actionprojectile){
  if (strequals(#p(0),gun)){
    health-=strtofloat(#p(1));
  }
}

What i’ve done here is say if the player has been struck and if the first parameter of the projectile is gun, the subtract the second parameter from health.
Notice: you could from 0 when dealing with parameters. Same case applies for most programming aspects.

For those too lazy to read here, have a gun using all the principles I just explained:

if (playerenters){
  if (!isweapon)toweapons a gun;
  this.spread = .2;
  this.fireFreeze = .1;
  this.bullets = 20;
  this.damage = 14;
}

if (weaponfired){
  if (this.bullets <= 0)return;
  this.angle = getangle(vecx(playerdir),vecy(playerdir))+random(this.spread*-1,this.spread);
  setshootparams gun,#v(this.damage);
  shoot playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2,0,this.angle,0,0,a_bullet,aspritesheet.png;
  this.bullets--;
  freezeplayer this.fireFreeze;
}

and here’s the weapon to detect it:

if (playerenters && !isweapon)toweapons -projectiledetect;

if (actionprojectile){
  if (strequals(#p(0),gun)){
    if (playerhearts <= 0)return;
    playerhearts-=strtofloat(#p(1));
  }
}

awesome. this.fireFreeze is the best part.

Riley if it’s possible, copy that post to a new thread and sticky it plx.

[QUOTE=tricxta;91248]
Sure here’s my tutorial:

We set up the data to be sent with the projectile by using setshootparams and then we emit it using shoot.

For this demonstration we’ll keep things simple and ignore z and zangle, these add a 3rd dimension to your projectile and no one really uses them effectively.
Same applies with power, although if you want something more sophisticated you know where to go.

setshootparams gun,29;
shoot playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2,0,getangle(vecx(playerdir),vecy(playerdir)),0,a_bullet,aspritesheet.png;

I’ve given the project the data, gun,29(#p(0) and #p(1)). You can as many or as little projectiles as you like although…i’m not sure on the max amount of parameters a projectile can hold but I can get away with 6, just play with it and see what works.

See that the starting of the bullet is at the coordinates playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2.
I’ve then calculated my angle based off the players direction, getangle(vecx(playerdir),vecy(playerdir))
We can add spread to this like you would on a machine gun by simply adding or subtracting a random number, eg:getangle(vecx(playerdir),vecy(playerdir))+random(-0.1,0.1)

And finally I’ve decided to use an imaginary gani called a_bullet which uses the spreet sheet aspritesheet.png, these gani parameters can be defined using params1,params2,and so on.

On the receiving end we can tell if a player has been struck by using actionprojectile

if (actionprojectile){
  if (strequals(#p(0),gun)){
    health-=strtofloat(#p(1));
  }
}

What i’ve done here is say if the player has been struck and if the first parameter of the projectile is gun, the subtract the second parameter from health.
Notice: you could from 0 when dealing with parameters. Same case applies for most programming aspects.

For those too lazy to read here, have a gun using all the principles I just explained:

if (playerenters){
  if (!isweapon)toweapons a gun;
  this.spread = .2;
  this.fireFreeze = .1;
  this.bullets = 20;
  this.damage = 14;
}

if (weaponfired){
  if (this.bullets <= 0)return;
  this.angle = getangle(vecx(playerdir),vecy(playerdir))+random(this.spread*-1,this.spread);
  setshootparams gun,#v(this.damage);
  shoot playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2,0,this.angle,0,a_bullet,aspritesheet.png;
  this.bullets--;
  freezeplayer this.fireFreeze;
}

and here’s the weapon to detect it:

if (playerenters && !isweapon)toweapons -projectiledetect;

if (actionprojectile){
  if (strequals(#p(0),gun)){
    if (playerhearts <= 0)return;
    playerhearts-=strtofloat(#p(1));
  }
}

[/QUOTE]

basicly where would i put the gani of the gun gani at?

In the “weaponfired” section right after the bullet check.

[QUOTE=Bleachlover551;91344]basicly where would i put the gani of the gun gani at?[/QUOTE]

If you’re not going to bother reading what I have to say i’m not going to bother helping you in the future. Go and read what I said…

sorry i was skimming becuase i was in a rush

[QUOTE=tricxta;91354]If you’re not going to bother reading what I have to say i’m not going to bother helping you in the future. Go and read what I said…[/QUOTE]

okay read it but im having trouble here is the whole bundle of work its not my work [ATTACH]2937[/ATTACH] but i want to use it just for offline fun. but i have lots of gani and ect im real good at scripting and graphics and stuff like that but this would me my weak side…for this section “_”

[QUOTE=Bleachlover551;91491]okay read it but im having trouble here is the whole bundle of work its not my work [ATTACH]2937[/ATTACH] but i want to use it just for offline fun. but i have lots of gani and ect im real good at scripting and graphics and stuff like that but this would me my weak side…for this section “_”[/QUOTE]

uhhh
you’re not good at scripting if you’re asking for help, don’t sugarcoat the truth.

[QUOTE=Yenairo;91496]
uhhh
you’re not good at scripting if you’re asking for help, don’t sugarcoat the truth.
[/QUOTE]

im good but not at stuff like this O.o

[QUOTE=Bleachlover551;91498]im good but not at stuff like this O.o[/QUOTE]

Whatever helps you sleep at night. Just saying, if you’re as good as you say, you should be able to figure it out by yourself.

i don’t think trigger actions work offline

[QUOTE=hosler;91511]i don’t think trigger actions work offline[/QUOTE]
Everything except weapon folders in the default qmenu and triggerhacks work offline.

[QUOTE=tricxta;91523]Everything except weapon folders in the default qmenu and triggerhacks work offline.[/QUOTE]

It not working it says Error: Expected format shoot real,real,real,real,real,real,string,string;

What are you even putting into the areas? (copypasta the code…)

Nah it’s fine, I left out the power argument, so the correct code is:
this.angle = getangle(vecx(playerdir),vecy(playerdir));
shoot playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2,0,this.angle,0,0,a_bullet,aspritesheet.png;

Perhaps if you simply referenced commands.rtf when you have a problem this could’ve all been avoided.

[QUOTE=tricxta;91626]
Nah it’s fine, I left out the power argument, so the correct code is:
this.angle = getangle(vecx(playerdir),vecy(playerdir));
shoot playerx+1.5+vecx(playerdir)*2,playery+2+vecy(playerdir)*2,0,this.angle,0,0,a_bullet,aspritesheet.png;

Perhaps if you simply referenced commands.rtf when you have a problem this could’ve all been avoided.
[/QUOTE]

can u fix my level i made im so lost and i actually read it.[ATTACH]2942[/ATTACH]