Jump to content

Making a function toggle able?


Fabio(GNR)

Recommended Posts

Posted (edited)

I got this god-mode script:

function godmode(attacker, weapon, bodypart) 
    cancelEvent() 
end 
  
addEventHandler("onClientPlayerDamage", getLocalPlayer(), godmode) 

But i want it to enable/disable by a command, how to? Thanks! :D:D

Edited by Guest
Posted

Make a variable which will enable/disable "god-mode" with the command. Then check if the variable is true or false, if it's true then cancel event.

Posted
Make a variable which will enable/disable "god-mode" with the command. Then check if the variable is true or false, if it's true then cancel event.

Could you explain me something about variables?

BTW: your 50p's public resources is broken :)

  • Discord Moderators
Posted
EDIT: so if im right, a variable is something thats used alot? or by many scripts?

EDIT2: Or to who/what it's aimed?

EDIt3: Or something a script can recognize easily?

A variable is even a term used in basic maths at primary school

It stores a value under a name given.

ie.

  
a = 2 
b = 4 
c = a + b 
  
d = "hello" 
e = a 

you can store everything under variables, elements, object, tables, etc.

to toggle something, 50p described it pretty well. You need to set a variable to true when toggled, and perform the opposite when it's true and set it to false.

for example:

  
toggle = false 
  
function toggleTest() 
if not toggle == false then 
outputChatBox ("Toggled off.") 
toggle = false 
else 
toggle = true 
outputChatBox ("Toggled on.") 
end 
end 
addCommandHandler("toggle", toggleTest) 
  

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...