Jump to content


Photo

Howto: Disable a pressure plate trap via a switch


14 replies to this topic

#1 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 19971 posts

Posted 07 May 2016 - 12:11 PM

Evening

 

So I am trying to repurpose a Presure_plate_trap from one of my maps (see attached)

 

The issue I want to be able to disable the trap from firing and the pressure place from moving via a switch...

 

Any idea's..?

 

Attached File  Pressure_plate_trap.pfb.txt   4.27KB   39 downloads



#2 ERH+

ERH+

    Advanced Member

  • Member
  • PipPipPip
  • 704 posts

Posted 07 May 2016 - 12:35 PM

Script with $trigger_multiple_1.remove(); ?

 

or

scriptEvent void disable(); Disables the mover/trigger

 

scriptEvent void enable(); Enables the mover/trigger

Edited by ERH+, 07 May 2016 - 12:45 PM.

S2wtMNl.gif


#3 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 07 May 2016 - 12:54 PM

You could use a func_remove instead of a script to remove the trigger. It's an extra entity but on the plus side, no scripting and it can be packaged as part of your prefab.



#4 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 19971 posts

Posted 07 May 2016 - 01:31 PM

@ERH, so to add this into the map.script file it would look as follows..?

void pressure_plate_trap()
{
     scriptEvent void disable($pp_trigger_multiple_01); Disables the mover/trigger
     scriptEvent void enable($pp_trigger_multiple_01); Enables the mover/trigger 
}

And I assume I will have to target a "atdm:target_callscriptfunction" from the switch..?

 

@Steve, the issue is I want to disable/enable the trap from the switch. I assume the func_remove would permanently remove it from the map? or will the func_remove replace the removed item when targeted from a switch..?



#5 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 07 May 2016 - 01:39 PM

@Steve, the issue is I want to disable/enable the trap from the switch. I assume the func_remove would permanently remove it from the map? or will the func_remove replace the removed item when targted from a switch..?

 
Ah, ok. The func_remove would remove it permanently.

Gimme a few mins before you try a script. I am sure this can be done without...

#6 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 19971 posts

Posted 07 May 2016 - 01:47 PM

Awesome, ta.



#7 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 07 May 2016 - 01:52 PM

I was thinking that you could use an atdm::target_postscriptevent to call the Enable() and Disable() methods on the trigger. You could, but you'd have to use a complicated setup involving atdm::target_changetargets to toggle between the enabler and the disabler.
 

Easier just to go for a script like ERH+ suggested

 

(untested) For your map script file:

float pressure_plate_active = 1;
void toggle_pressure_plate_trap()
{
    entity trap_trigger = $trigger_multiple_1;   // PUT THE NAME OF YOUR TRIGGER HERE BETWEEN THE $ AND ;
    if ( pressure_plate_active == 1 )
    {
        trap_trigger.disable();
        pressure_plate_active = 0;
    } else {
        trap_trigger.enable();
        pressure_plate_active = 1;
    }
}

Then create an atdm::target_callscriptfunction and giuve it spawnarg "call" "toggle_pressure_plate_trap", and target it from your switch.

 

Edit: Fixed per Biker's post below


Edited by SteveL, 07 May 2016 - 06:32 PM.


#8 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 19971 posts

Posted 07 May 2016 - 05:43 PM

Grand thanks Steve, already had the "atdm::target_callscriptfunction" in place so testing now....

 

[update]

 

Got an error on map load, it complains about line "        trap_trigger.Disable();" saying unknown value "Disable". So I changed first letter on Disable and Enable to lower case on a wild guess and that fixed it.



#9 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 07 May 2016 - 06:30 PM

Grand thanks Steve, already had the "atdm::target_callscriptfunction" in place so testing now....

 

[update]

 

Got an error on map load, it complains about line "        trap_trigger.Disable();" saying unknown value "Disable". So I changed first letter on Disable and Enable to lower case on a wild guess and that fixed it.

 

Oops, my bad. Those functions are upper case in the c++ code, but lower case for game scripts. Not by accident, it's meant to stop them getting confused. Except that I did get confused and I remembered it the wrong way round. Cool you got it sorted :)



#10 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 19971 posts

Posted 07 May 2016 - 06:33 PM

Dont know if is a script issue or a DR issue, but flipping the switch has no effect. Will look at it again tomoz, Ive commited the latest version of the map if you want to have a look.



#11 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 07 May 2016 - 06:35 PM

Ack, happy to take a look if needed.



#12 demagogue

demagogue

    Mod hero

  • Active Developer
  • PipPipPipPipPip
  • 5380 posts

Posted 07 May 2016 - 10:58 PM

The lazy way would be to use two pressure plate entities (a functional and inert one) on top of each other and just mutually spawn/remove them with the switch. But if the script functions work then you've already solved it and just have to get it set up right.


Posted Image

#13 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 19971 posts

Posted 08 May 2016 - 03:57 AM

Ack, happy to take a look if needed.

I'll drop you a PM



#14 SteveL

SteveL

    Hero Coder

  • Active Developer
  • PipPipPipPip
  • 3669 posts

Posted 08 May 2016 - 09:41 AM

For anyone finding this thread later, the script above does work ok. 



#15 Bikerdude

Bikerdude

    Mod hero

  • Member
  • PipPipPipPipPip
  • 19971 posts

Posted 08 May 2016 - 11:20 AM

it was a small typo on my part.





Reply to this topic



  


0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users