Raised This Month: $ Target: $400
 0% 

How can I turn on and off a function on the best way?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
proffs
Senior Member
Join Date: Jul 2013
Old 07-20-2014 , 05:24   How can I turn on and off a function on the best way?
Reply With Quote #1

How can I turn on and off a function on the best way?

For example those noclip and godmode toggles on block makers.
How can I on the best way make a toggle?

Where I can in a menu turn on and off a function.

Thanks
proffs is offline
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-20-2014 , 11:44   Re: How can I turn on and off a function on the best way?
Reply With Quote #2

you can do it with something like this:
PHP Code:
new bool:g_Noclip[33]

public 
client_connect(id)
{
    
g_Noclip[id] = false
}

public 
menu_show(id
{
    new 
menu menu_create("testmenu""handler")
    
    
menu_additem(menug_Noclip[id] ? "Noclip (Deactivate)" "Noclip (Activate)")
    
    
menu_display(id)
}

public 
handler(idmenuitem)
{
    if(
item == 0)
    {
        
g_Noclip[id] = !g_Noclip[id]
        
        
set_user_noclip(idg_Noclip[id] ? 0)
    }
    
    
menu_destroy(menu)
    return 
PLUGIN_HANDLED

mottzi is offline
Send a message via MSN to mottzi
Bos93
Veteran Member
Join Date: Jul 2010
Old 07-20-2014 , 12:21   Re: How can I turn on and off a function on the best way?
Reply With Quote #3

mottzi, you can change g_Noclip to get_user_noclip ;-)
__________________
Bos93 is offline
Send a message via ICQ to Bos93 Send a message via Skype™ to Bos93
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-20-2014 , 12:24   Re: How can I turn on and off a function on the best way?
Reply With Quote #4

Quote:
Originally Posted by Bos93 View Post
mottzi, you can change g_Noclip to get_user_noclip ;-)
This is true, but only for the current example, that mottzi gave. It was about the way you can detect and turn on/off the function. And actually, the best way is with bool, because it has only two values, which you can easily reverse in this way. (bool[id] = !bool[id])
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
NikKOo31
Senior Member
Join Date: May 2013
Location: Home
Old 07-20-2014 , 14:59   Re: How can I turn on and off a function on the best way?
Reply With Quote #5

Quote:
Originally Posted by Flick3rR View Post
This is true, but only for the current example, that mottzi gave. It was about the way you can detect and turn on/off the function. And actually, the best way is with bool, because it has only two values, which you can easily reverse in this way. (bool[id] = !bool[id])
PHP Code:
set_user_noclip(id, !get_user_noclip(id)) 
__________________
Hey ^_^
NikKOo31 is offline
Flick3rR
Veteran Member
Join Date: Feb 2014
Location: Bulgaria, Stara Zagora
Old 07-20-2014 , 15:28   Re: How can I turn on and off a function on the best way?
Reply With Quote #6

Guys... We are talking about the way to do it. It may not be a single native, but whole algorhytm of functions. I think he was asking how to return the current value and detect it's reversing.
__________________
Flick3rR is offline
Send a message via Skype™ to Flick3rR
mottzi
Veteran Member
Join Date: May 2010
Location: Switzerland
Old 07-20-2014 , 21:46   Re: How can I turn on and off a function on the best way?
Reply With Quote #7

As Flicker correctly mentioned, I was only giving an exapmle of how you'd do something like this - of course you don't need to store the state in a variable when premade functions are availiable.

Flicker, you can also use the "!"-Operator with integer-values.
mottzi is offline
Send a message via MSN to mottzi
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 13:06.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode