Raised This Month: $ Target: $400
 0% 

[Tutorial] How to PROPERLY make a self toggle command


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-03-2014 , 16:43   Re: [Tutorial] How to PROPERLY make a toggle command
Reply With Quote #1

Quote:
Originally Posted by Dr. McKay View Post
PHP Code:
return Action:3
Quote:
Originally Posted by Powerlord View Post
Why are you using "Action:3" instead of "Plugin_Handled" ?
Little late to the party?
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-03-2014 at 16:43.
Powerlord is offline
Dr. McKay
Sir Dr. SourceMod Plugin Approver Esq. Ltd. M.D. PhD
Join Date: Aug 2011
Location: Atlantis
Old 03-03-2014 , 18:20   Re: [Tutorial] How to PROPERLY make a toggle command
Reply With Quote #2

Quote:
Originally Posted by Powerlord View Post
Little late to the party?
Yeah, I was bored.
__________________
Dr. McKay is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-21-2014 , 17:07   Re: [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #3

Using Plugin_Handled rather than the number it represents is to promote code visibility. It's just easier to read.



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 ddhoward; 01-21-2014 at 17:08.
ddhoward is offline
sdz
Senior Member
Join Date: Feb 2012
Old 01-22-2014 , 00:22   Re: [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #4

Quote:
Originally Posted by ddhoward View Post
Using Plugin_Handled rather than the number it represents is to promote code visibility. It's just easier to read.



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.
Well put. I'll quote this in the OP
sdz is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-22-2014 , 19:59   Re: [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #5

It is annoying when people make actions
Variables and return them, because it's not readable.

As far as enums, I don't think it's a problem if its something simple like integers, but I stick to defines.. Even though they are not type-checked. The problem is when you get inti those hacky struct/enum lookalikes - those should die in fires.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 01-22-2014 , 21:20   Re: [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #6

Quote:
Originally Posted by friagram View Post
The problem is when you get inti those hacky struct/enum lookalikes - those should die in fires.
like this?
Spoiler
Mitchell is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 01-22-2014 , 21:55   Re: [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #7

Quote:
Originally Posted by friagram View Post
Even though they are not type-checked. The problem is when you get inti those hacky struct/enum lookalikes - those should die in fires.
How dare you, they are extremely useful, I compare them to C struct but with sourcepawn cell instead of bytes even if it do not offer all the features wanted!
Mathias. is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-23-2014 , 14:06   Re: [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #8

Here's another thing you can do to save ur cookies.

PHP Code:
//Flags for what donor perks a client has enabled
#define TF2DATA_FLAG_NONE          0
#define TF2DATA_FLAG_ONE          (1 << 0)
#define TF2DATA_FLAG_TWO       (1 << 1)
#define TF2DATA_FLAG_THREE          (1 << 2)
#define TF2DATA_FLAG_FOUR   (1 << 3)

// ... blablabla

            
new fFlags GetClientCookies(iClientg_cTF2DataFlagsCookie);

            if (
fFlags 0)
            {
                
fFlags 0;
            }

            
/*switch (iParam)
            {
                case 0:
                {
                    fFlags |= TF2DATA_FLAG_THREE;
                    SetClientCookies(iClient, g_cTF2DataFlagsCookie, fFlags);
                }
                case 1:
                {
                    fFlags &= ~TF2DATA_FLAG_THREE;
                    SetClientCookies(iClient, g_cTF2DataFlagsCookie, fFlags);
                }
            }*/

            
fFlags ^= TF2DATA_FLAG_THREE;
            
SetClientCookies(iClientg_cTF2DataFlagsCookiefFlags); 
Doing it bitwise means you don't need to have a separate cookie or variable for every single thing.

My GetClientCookies has StringToInt and returns -1 if the cookies were not found or something like that.

Quote:
Originally Posted by friagram View Post
There are a few things I notice people doing:
Over/under validating clients.
Storing/passing entities or clients rather than using entrefs/serials/userids in delayed callbacks.
I learned that (entrefs) the hard way when messing with the Throwable Sapper plugin hey maybe I can go work on the next version's bugfixes using that

What do you mean by over/under validation though?
__________________

Last edited by Chdata; 01-23-2014 at 14:26.
Chdata is offline
ddhoward
Veteran Member
Join Date: May 2012
Location: California
Old 01-23-2014 , 15:53   Re: [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #9

Overvalidation would be something like checking if the "client" argument > 0 && <= MaxClients... when the function that called the current function (and passed the client argument) already did that. Or perhaps the hooked event cannot possibly pass a non-client in that manner.

For example, if you've hooked player_death... you don't need to verify that the player who died is <= MaxClients. The check is pointless.

Undervalidation would be the opposite, and is generally the result of an inexperienced scripter.


Also, I think you meant to post the cookies thing in the other thread.
__________________

Last edited by ddhoward; 01-23-2014 at 16:09.
ddhoward is offline
Chdata
Veteran Member
Join Date: Aug 2012
Location: Computer Chair, Illinois
Old 01-23-2014 , 17:58   Re: [Tutorial] How to PROPERLY make a self toggle command
Reply With Quote #10

No, because what I posted is related to toggling something on/off or true/false.
__________________
Chdata is offline
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 18:38.


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