I need a function for my script, which turns a certain action on and off when pressing a button
-
This is my script, as you can see I had to put the same function by directing buttons one to turn on and another to turn it off because I don't know what I should do to use only one button, join my script in 1 only and it will turn on when press a button and pressing that button again turns it off.
NightVisionON()
{
self endon("disconnect"); self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado"); for(;;) { if(self actionslotfourbuttonpressed()) { self setinfraredvision(true); } wait 0.01; }
}
NightVisionOFF()
{
self endon("disconnect"); for(;;) { if(self actionslotonebuttonpressed()) { self setinfraredvision(false); } wait 0.01; }
}
-
NightVisionToggle() { level endon("game_ended"); self endon("disconnect"); self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado"); for(;;) { if(self actionslotfourbuttonpressed()) { if (!isDefined(self.nightvision)) { self.nightvision = true; self setinfraredvision(true); } else { self.nightvision = undefined; self setinfraredvision(false); } } wait 0.05; } }
using the isDefined(variable) you can create a variable on the player and use that as the check for the toggle. Hopefully this makes sense
-
Cahz I speak Spanish and when translating it I understood something like
if(isdefined(self setinfraredvision)) if(self actionslotonebuttonpressed()) { self setinfraredvision(false); }
-
Cahz Thank you very much for helping me again, very kind of you. I already did it, I am going to leave the code here in case someone is interested or is looking for the same goal as me.
-
Remember call night vision
NightVision()
{
self endon("disconnect"); self iprintlnbold("^2Presiona [{+actionslot 4}] para activar visión de Infectado"); for(;;) { if(self actionslotfourbuttonpressed()) { self InfraredVision(); } wait 0.01; }
}
InfraredVision()
{
if (!IsDefined(self.InfraredVision))
{
self.InfraredVision = true;
self setinfraredvision(true);
self IPrintLn("InfraredVision: ^2Enabled");
}
else
{
self.InfraredVision = undefined;
self setinfraredvision(false);
self IPrintLn("InfraredVision: ^1Disabled");
}
}