Raised This Month: $ Target: $400
 0% 

[Tutorial] How to PROPERLY make a self toggle command


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
sdz
Senior Member
Join Date: Feb 2012
Old 01-21-2014 , 02:40   [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #1

So I see that alot of people like to uh.. make a command with a 0|1 option to toggle it on/off, and personally that's just inefficient for the user/admin.
Before I start: I want to say that this is generally what I like to do, as it might be a little extra work on my end, but it defiantly looks much nicer and refined.


Instead of using an argument to declare if we want to have, for instance, God Mode enabled, we can use a Global Variable.

This will be our FINISHED PRODUCT:
Spoiler


Here is an example of the OLD METHOD.
Spoiler


I'm no master of sourcepawn, but I can tell you that there's really a ton wrong with this. For one, perhaps someone puts an argument value of 2? To fix this problem, we'll add a global client boolean, Implement our OnClientConnect()/OnClientPostAdminCheck() and OnClientDisconnect() and modify our godmode command slightly:
Spoiler


As you can see, we've used our boolean to check and determine if the player has godmode. We also set it to 0 when they connect and disconnect because if we didn't, a player could leave and another would take their place, and this would assign the old client's value to the new client. (Pretty much, g_bIsEnabled[22].)

EXTRA NOTES:

Quote:
Originally Posted by ddhoward View Post

Here's some more suggestions for making a command like this (that supports targeting other players)
  • Do CheckCommandAccess on an override similar to but different from the command name, such as "sm_godmode_admin" or "sm_godmode_targetothers" if your command was sm_godmode. If the player does not have access to that override (and/or no arguments exist), then ignore all arguments and simply toggle godmode on the using player, as you have done already in your code.
  • If the player has access to the override, and at least 1 argument has been given, run that first argument through ProcessTargetString.
  • If a second argument is not given, toggle godmode on all the given targets provided by ProcessTargetString. If a second argument WAS given, use the argument to determine if godmode should be toggled/enabled/disabled.

Last edited by sdz; 01-22-2014 at 00:22.
sdz is offline
 



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 18:38.


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