Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Making a Trap
Southlaguna Offline
Member

Posts: 70
Threads: 21
Joined: Jan 2012
Reputation: 0
#1
Making a Trap

Hey y'all. Once again another question on scripting shtuff. So 'm trying to make a trap that you can avoid once activated. But i cant figure out how to work the alState specifics. I want to make that if you leave the area before the trap makes contact with you, you survive. Heres how far ive gotten with this..


OnStart{
AddEntityCollideCallback("Player", "spike_trap", "SpikeTrapAltar", true, 1);
}

void SpikeTrapAltar(string &in asParent, string &in asChild, int alState)
{
PlaySoundAtEntity("swomp", "L01_pierce01", "spike_trap", 0.0, false);
PlaySoundAtEntity("swomp2", "L01_pierce02", "spike_trap", 0.0, false);

for (int x = 0; x <= 11; x += 1){
RotatePropToSpeed("roof_wheel_"+x, 1, 3, 0, 0, -1, false, "");
}
for (int i = 0; i <= 6; i += 1){
SetMoveObjectStateExt("roof_pole_"+i, -0.4f, 2.0f, 5.0f, 1.0f, true);
}
if (alState == 0){
AddTimer("pierce1", 0.3f, "TimerStopPierce");
}
if (alState == 1){
AddTimer("dead", 0.7f, "YourDeadBoy");
}

}
void YourDeadBoy ( string &in asTimer )
{
PlaySoundAtEntity("", "stab_impact.snt", "Player", 1.0f, false);
PlaySoundAtEntity("", "spiketrap_death", "Player", 1.0f, false);
SetPlayerHealth(0);
}
void TimerStopPierce ( string &in asTimer )
{
RemoveTimer("dead");
}
trap works, Just cant get the guy to survive when hes out of position... Help? Pweease

12-26-2015, 10:45 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#2
RE: Making a Trap

From what it looks like I think something like this should work: (With Mudbill's if tip and some corrections)
PHP Code: (Select All)
void OnStart()
{
    
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"false0);
}

void SpikeTrapAltar(string &in asParentstring &in asChildint alState)

    
PlaySoundAtEntity("swomp""L01_pierce01""spike_trap"0.0false);
    
PlaySoundAtEntity("swomp2""L01_pierce02""spike_trap"0.0false);

    for (
int x 0<= 11+= 1)
    {
        
RotatePropToSpeed("roof_wheel_"+x1300, -1false"");
    }
    for (
int i 0<= 6+= 1)
    {
        
SetMoveObjectStateExt("roof_pole_"+i, -0.4f2.0f5.0f1.0ftrue);
    }
    
    if (
alState == 1)
        
AddTimer("dead"0.7f"YourDeadBoy");
    else
        
AddTimer("pierce1"0.3f"TimerStopPierce"); 
}

void YourDeadBoy string &in asTimer )
{
    
PlaySoundAtEntity("""stab_impact.snt""Player"1.0ffalse);
    
PlaySoundAtEntity("""spiketrap_death""Player"1.0ffalse);
    
SetPlayerHealth(0);
}
void TimerStopPierce string &in asTimer )
{
    
RemoveTimer("dead");


alStates don't refresh once their called, but if the callback's bool abDeleteOnCollide is set to false, it will fire again when alState condition is fulfilled again.

Take a note of the last two parameters in these examples.
This will trigger every time Player Enters or Leaves the area.
PHP Code: (Select All)
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"false0); 

This will trigger Only once when Player Enters or Leaves the area for the first time.
PHP Code: (Select All)
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"true0); 

More examples:
Spoiler below!

This will trigger every time Player Enters the area.
PHP Code: (Select All)
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"false1); 

This will trigger every time Player Leaves the area.
PHP Code: (Select All)
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"false, -1); 

This will trigger Only once Player Enters the area.
PHP Code: (Select All)
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"true1); 

This will trigger Only once Player Leaves the area.
PHP Code: (Select All)
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"true, -1); 


Useful note:
Mudbill Wrote:I can't remember if using 0 and "true" can trigger exiting if the player starts the map within the area. It might not count spawning as entering, and thus trigger exit first.


Also you Check for alState 0, which never happens.
PHP Code: (Select All)
(alState == 0)
{
 
//Never happens
 //alState is 1 or -1 inside the function you called


Because once the Callback is decided it can't be 0 (both) at once, it will be either -1 (leave) or 1 (enter).
(This post was last modified: 12-27-2015, 12:11 AM by Spelos.)
12-26-2015, 11:01 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#3
RE: Making a Trap

Your last argument in the AddEntityCollideCallback should be 0 if you'd like to test it for both leaving and entering of the area. If you set it to 1, it will only run the check upon entering, meaning it cannot be -1 (leaving). Set it to -1 and it will be opposite. That's why 0 exists, because it acts as both.

And also as Spelos said, your == 0 check is never fulfilled. You probably meant to put -1 there if you wanted to test it upon leaving the area. Since the state is either one or the other, you could use the "else" keyword for simplification:

PHP Code: (Select All)
if (alState == 1)
    
AddTimer("dead"0.7f"YourDeadBoy");
else 
    
AddTimer("pierce1"0.3f"TimerStopPierce"); 

PS: If you use only one line after an if-statement, the block itself isn't necessary.

FORGOT TO MENTION AN IMPORTANT DETAIL:
You must set the boolean in your callback to "false" or else it will never trigger upon exit because it triggers entering first and is then removed. This means you need to manually prevent this event from happening more than wanted.

(This post was last modified: 12-26-2015, 11:55 PM by Mudbill.)
12-26-2015, 11:39 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#4
RE: Making a Trap

Although...
In my suggestion I called the function again, since I think it can't refresh the alState.

When it's called, it's 1 or -1 and it stays that way for the rest of the function.
Or was my whole life a complete lie?

If player goes and touches the area, won't it always be "1" just as he has it?
I can't imagine a situation where you leave the area (for it to be -1) that you haven't enter.

That's what I thought needed to be handled by the second callback.

I hope I'm not mistaken... I haven't tested it to be honest...

Re: Mudbill's PS: "Oh my god! Mind = Blown"
(This post was last modified: 12-26-2015, 11:53 PM by Spelos.)
12-26-2015, 11:46 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#5
RE: Making a Trap

(12-26-2015, 11:46 PM)Spelos Wrote: Although...
In my suggestion I called the function again, since I think it can't refresh the alState.

When it's called, it's 1 or -1 and it stays that way for the rest of the function.
Or was my whole life a complete lie?

If player goes and touches the area, won't it always be "1" just as he has it?
I can't imagine a situation where you leave the area (for it to be -1) that you haven't enter.

That's what I thought needed to be handled by the second callback.

I hope I'm not mistaken... I haven't tested it to be honest...

Using 0 will check for both, but it will only trigger -1 if the boolean is set to false (so that it can trigger multiple times). If it can only trigger once, then the player has to enter the area first, and if the callback is then removed, it won't check for exists. Therefore you can use 2 callbacks, one with '1' and one with '-1' using the "true" boolean and it will check enter and exit ONCE EACH. Alternatively you can use 0 in a single callback and it will check both, but the boolean must be "false" for this to work. This also means it will trigger both enter and exit EVERY TIME, unless you explicitly tell it not to.

If this event is meant to happen only once it might be best to use 2 callbacks:

PHP Code: (Select All)
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"true1);
AddEntityCollideCallback("Player""spike_trap""SpikeTrapAltar"true, -1); 

PPS: I can't remember if using 0 and "true" can trigger exiting if the player starts the map within the area. It might not count spawning as entering, and thus trigger exit first.

(This post was last modified: 12-27-2015, 12:00 AM by Mudbill.)
12-26-2015, 11:53 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#6
RE: Making a Trap

Ah! I see!
I updated my first reply to reflect those changes and my god, Mudbill...
You taught me something new about C#, I think you deserve a cookie or something.
12-26-2015, 11:59 PM
Find
Southlaguna Offline
Member

Posts: 70
Threads: 21
Joined: Jan 2012
Reputation: 0
#7
RE: Making a Trap

Nope wasn't the solution... player still died upon exiting the area, though I did eventually figure it out. To simple really shouldn't have taken me this much effort lol. Thanks anyway!

01-03-2016, 08:26 AM
Find
Traggey Offline
is mildly amused

Posts: 3,257
Threads: 74
Joined: Feb 2012
Reputation: 185
#8
RE: Making a Trap

Please post under the correct forum next time, thank you.

Moved.
01-03-2016, 10:32 PM
Find




Users browsing this thread: 2 Guest(s)