Grenade: Difference between revisions

From Unofficial EFPSE wiki Extended
Jump to navigation Jump to search
No edit summary
mNo edit summary
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
@everyoneDo you want to make some kind of grenades in your game? I've got you here pal!
Created by Мужик с Чашкой
 
Do you want to make some kind of grenades in your game? I've got you here pal!


Put these lines of code into your loop_script:
Put these lines of code into your loop_script:
Line 46: Line 48:


Cons: To prevent spawning things through walls when you stand next to them, we have to spawn things one unit inside player's radius. It pushes back a little, barely noticeable while in movement. But if you make your projectile radius bigger that zero - pushback is much more noticable. By tweaking the 15 number - you can increase the pushback even more without changing the projectile radius.
Cons: To prevent spawning things through walls when you stand next to them, we have to spawn things one unit inside player's radius. It pushes back a little, barely noticeable while in movement. But if you make your projectile radius bigger that zero - pushback is much more noticable. By tweaking the 15 number - you can increase the pushback even more without changing the projectile radius.
Here's a FSM for your grenade if you want to make it explode by touching walls/floors. Don't forget to include DEATH/DEAD states:
<pre>
state IDLE ROLL 0
frame 0 0.0 0 0 0 NONE
frame 0 0.0 0 0 0 SETVAR timer -1
frame 0 0.01 0 0 0 READY
state ROLL SROLL 0
frame 0 0.0 0 0 0 NONE
frame 0 0.02 0 0 0 CHECKPOS newX newY newZ
frame 0 0.0 0 0 0 INCREMENT newZ 0.001
frame 0 0.0 0 0 0 DECREMENT newX $oldX
frame 0 0.0 0 0 0 DECREMENT newY $oldY
frame 0 0.0 0 0 0 DECREMENT newZ $oldZ
frame 0 0.0 0 0 0 DIVIDE newX $newY
frame 0 0.02 0 0 0 CHECKPOS oldX oldY oldZ
frame 0 0.0 0 0 0 INCREMENT oldZ 0.001
frame 0 0.0 0 0 0 INCREMENT timer 1
frame 0 0.0 0 0 0 JUMPIFLESS timer 1 ROLL
frame 0 0.0 0 0 0 INCREMENT TRatio $newX
frame 0 0.0 0 0 0 SETVAR MRatio $TRatio
frame 0 0.0 0 0 0 DIVIDE MRatio $timer
frame 0 0.0 0 0 0 MULTIPLY MRatio $MRatio
frame 0 0.0 0 0 0 JUMPIFGREATER timer 2 ROLL
frame 0 0.0 0 0 0 SETVAR CRatio $MRatio
frame 0 0.0 0 0 0 SETVAR MaxRatio $CRatio
frame 0 0.0 0 0 0 SETVAR MinRatio $CRatio
frame 0 0.0 0 0 0 MULTIPLY MaxRatio 1.01
frame 0 0.0 0 0 0 MULTIPLY MinRatio 0.99
frame 0 0.0 0 0 0 JUMPIFGREATER CRatio 100000 MAXROLL
frame 0 0.0 0 0 0 JUMPIFLESS CRatio 0.001 MINROLL
state SROLL NONE 0
frame 0 0.00 0 0 0 NONE
frame 0 0.02 0 0 0 CHECKPOS newX newY newZ
frame 0 0.0 0 0 0 INCREMENT newZ 0.001
frame 0 0.0 0 0 0 DECREMENT newX $oldX
frame 0 0.0 0 0 0 DECREMENT newY $oldY
frame 0 0.0 0 0 0 DECREMENT newZ $oldZ
frame 0 0.0 0 0 0 DIVIDE newX $newY
frame 0 0.02 0 0 0 CHECKPOS oldX oldY oldZ
frame 0 0.0 0 0 0 INCREMENT oldZ 0.001
frame 0 0.0 0 0 0 INCREMENT timer 1
frame 0 0.0 0 0 0 INCREMENT TRatio $newX
frame 0 0.0 0 0 0 SETVAR MRatio $TRatio
frame 0 0.0 0 0 0 DIVIDE MRatio $timer
frame 0 0.0 0 0 0 MULTIPLY MRatio $MRatio
frame 0 0.0 0 0 0 JUMPIFGREATER MRatio $MaxRatio DEATH
frame 0 0.0 0 0 0 JUMPIFLESS MRatio $MinRatio DEATH
frame 0 0.0 0 0 0 JUMPIFEQUALS newZ 0 DEATH
state MAXROLL NONE 0
frame 0 0.00 0 0 0 NONE
frame 0 0.02 0 0 0 CHECKPOS newX newY newZ
frame 0 0.0 0 0 0 INCREMENT newZ 0.001
frame 0 0.0 0 0 0 DECREMENT newX $oldX
frame 0 0.0 0 0 0 DECREMENT newY $oldY
frame 0 0.0 0 0 0 DECREMENT newZ $oldZ
frame 0 0.0 0 0 0 DIVIDE newX $newY
frame 0 0.02 0 0 0 CHECKPOS oldX oldY oldZ
frame 0 0.0 0 0 0 INCREMENT oldZ 0.001
frame 0 0.0 0 0 0 INCREMENT timer 1
frame 0 0.0 0 0 0 SETVAR MRatio $newX
frame 0 0.0 0 0 0 MULTIPLY MRatio $MRatio
frame 0 0.0 0 0 0 JUMPIFLESS MRatio 100000 DEATH
frame 0 0.0 0 0 0 JUMPIFEQUALS newZ 0 DEATH
state MINROLL NONE 0
frame 0 0.00 0 0 0 NONE
frame 0 0.02 0 0 0 CHECKPOS newX newY newZ
frame 0 0.0 0 0 0 INCREMENT newZ 0.001
frame 0 0.0 0 0 0 DECREMENT newX $oldX
frame 0 0.0 0 0 0 DECREMENT newY $oldY
frame 0 0.0 0 0 0 DECREMENT newZ $oldZ
frame 0 0.0 0 0 0 DIVIDE newX $newY
frame 0 0.02 0 0 0 CHECKPOS oldX oldY oldZ
frame 0 0.0 0 0 0 INCREMENT oldZ 0.001
frame 0 0.0 0 0 0 SETVAR MRatio $newX
frame 0 0.0 0 0 0 MULTIPLY MRatio $MRatio
frame 0 0.0 0 0 0 JUMPIFGREATER MRatio 0.001 DEATH
frame 0 0.0 0 0 0 JUMPIFEQUALS newZ 0 DEATH
</pre>

Latest revision as of 14:28, 25 July 2025

Created by Мужик с Чашкой

Do you want to make some kind of grenades in your game? I've got you here pal!

Put these lines of code into your loop_script:

//BOMB THROWING LOGIC
player check rotation rotx roty
degtorad=$roty
degtorad-=45
degtorad*=0.034906585
global.bombthrowy=SIN($degtorad)
global.bombthrowx=COS($degtorad)

global.bombthrowx*=-15
global.bombthrowy*=-15

degtorad=$roty
degtorad*=0.0174532925
fixbty=SIN($degtorad)
global.bombthrowy+=$fixbty

degtorad=$rotx
degtorad*=0.0174532925
global.bombthrowf=SIN($degtorad)
global.bombthrowf*=350

global.bombthrowv=COS($degtorad)
global.bombthrowv*=-350
global.bombthrowv+=80

global.bombthrowz=COS($degtorad)
global.bombthrowz*=-21
global.bombthrowz+=21

21 = player height divided by 2. 15 = player radius minus one plus grenade radius (works best when it's zero). 350 = throw force.

Use this frame into FSM:

frame 0 0.01 0 0 0 SPAWN fbombprj $global.bombthrowx,$global.bombthrowz,$global.bombthrowy $global.bombthrowf,$global.bombthrowv

"fbombprj" - is an enemy with zero radius that does nothing and act as a throwable object, since decorations don't have any physics.

Pros: Now you have a means of throwing stuff. It even takes into account if you look up or down.

Cons: To prevent spawning things through walls when you stand next to them, we have to spawn things one unit inside player's radius. It pushes back a little, barely noticeable while in movement. But if you make your projectile radius bigger that zero - pushback is much more noticable. By tweaking the 15 number - you can increase the pushback even more without changing the projectile radius.

Here's a FSM for your grenade if you want to make it explode by touching walls/floors. Don't forget to include DEATH/DEAD states:

state IDLE ROLL 0
frame 0 0.0 0 0 0 NONE
frame 0 0.0 0 0 0 SETVAR timer -1 
frame 0 0.01 0 0 0 READY

state ROLL SROLL 0
frame 0 0.0 0 0 0 NONE
frame 0 0.02 0 0 0 CHECKPOS newX newY newZ
frame 0 0.0 0 0 0 INCREMENT newZ 0.001
frame 0 0.0 0 0 0 DECREMENT newX $oldX
frame 0 0.0 0 0 0 DECREMENT newY $oldY
frame 0 0.0 0 0 0 DECREMENT newZ $oldZ
frame 0 0.0 0 0 0 DIVIDE newX $newY
frame 0 0.02 0 0 0 CHECKPOS oldX oldY oldZ
frame 0 0.0 0 0 0 INCREMENT oldZ 0.001
frame 0 0.0 0 0 0 INCREMENT timer 1
frame 0 0.0 0 0 0 JUMPIFLESS timer 1 ROLL
frame 0 0.0 0 0 0 INCREMENT TRatio $newX
frame 0 0.0 0 0 0 SETVAR MRatio $TRatio
frame 0 0.0 0 0 0 DIVIDE MRatio $timer
frame 0 0.0 0 0 0 MULTIPLY MRatio $MRatio
frame 0 0.0 0 0 0 JUMPIFGREATER timer 2 ROLL
frame 0 0.0 0 0 0 SETVAR CRatio $MRatio
frame 0 0.0 0 0 0 SETVAR MaxRatio $CRatio
frame 0 0.0 0 0 0 SETVAR MinRatio $CRatio
frame 0 0.0 0 0 0 MULTIPLY MaxRatio 1.01
frame 0 0.0 0 0 0 MULTIPLY MinRatio 0.99
frame 0 0.0 0 0 0 JUMPIFGREATER CRatio 100000 MAXROLL
frame 0 0.0 0 0 0 JUMPIFLESS CRatio 0.001 MINROLL

state SROLL NONE 0
frame 0 0.00 0 0 0 NONE
frame 0 0.02 0 0 0 CHECKPOS newX newY newZ
frame 0 0.0 0 0 0 INCREMENT newZ 0.001
frame 0 0.0 0 0 0 DECREMENT newX $oldX
frame 0 0.0 0 0 0 DECREMENT newY $oldY
frame 0 0.0 0 0 0 DECREMENT newZ $oldZ
frame 0 0.0 0 0 0 DIVIDE newX $newY
frame 0 0.02 0 0 0 CHECKPOS oldX oldY oldZ
frame 0 0.0 0 0 0 INCREMENT oldZ 0.001
frame 0 0.0 0 0 0 INCREMENT timer 1
frame 0 0.0 0 0 0 INCREMENT TRatio $newX
frame 0 0.0 0 0 0 SETVAR MRatio $TRatio
frame 0 0.0 0 0 0 DIVIDE MRatio $timer
frame 0 0.0 0 0 0 MULTIPLY MRatio $MRatio
frame 0 0.0 0 0 0 JUMPIFGREATER MRatio $MaxRatio DEATH
frame 0 0.0 0 0 0 JUMPIFLESS MRatio $MinRatio DEATH
frame 0 0.0 0 0 0 JUMPIFEQUALS newZ 0 DEATH

state MAXROLL NONE 0
frame 0 0.00 0 0 0 NONE
frame 0 0.02 0 0 0 CHECKPOS newX newY newZ
frame 0 0.0 0 0 0 INCREMENT newZ 0.001
frame 0 0.0 0 0 0 DECREMENT newX $oldX
frame 0 0.0 0 0 0 DECREMENT newY $oldY
frame 0 0.0 0 0 0 DECREMENT newZ $oldZ
frame 0 0.0 0 0 0 DIVIDE newX $newY
frame 0 0.02 0 0 0 CHECKPOS oldX oldY oldZ
frame 0 0.0 0 0 0 INCREMENT oldZ 0.001
frame 0 0.0 0 0 0 INCREMENT timer 1
frame 0 0.0 0 0 0 SETVAR MRatio $newX
frame 0 0.0 0 0 0 MULTIPLY MRatio $MRatio
frame 0 0.0 0 0 0 JUMPIFLESS MRatio 100000 DEATH
frame 0 0.0 0 0 0 JUMPIFEQUALS newZ 0 DEATH

state MINROLL NONE 0
frame 0 0.00 0 0 0 NONE
frame 0 0.02 0 0 0 CHECKPOS newX newY newZ
frame 0 0.0 0 0 0 INCREMENT newZ 0.001
frame 0 0.0 0 0 0 DECREMENT newX $oldX
frame 0 0.0 0 0 0 DECREMENT newY $oldY
frame 0 0.0 0 0 0 DECREMENT newZ $oldZ
frame 0 0.0 0 0 0 DIVIDE newX $newY
frame 0 0.02 0 0 0 CHECKPOS oldX oldY oldZ
frame 0 0.0 0 0 0 INCREMENT oldZ 0.001
frame 0 0.0 0 0 0 SETVAR MRatio $newX
frame 0 0.0 0 0 0 MULTIPLY MRatio $MRatio
frame 0 0.0 0 0 0 JUMPIFGREATER MRatio 0.001 DEATH
frame 0 0.0 0 0 0 JUMPIFEQUALS newZ 0 DEATH