Difference between revisions of "User:Nosoop/Guide/How to X"

From AlliedModders Wiki
Jump to: navigation, search
(Add reference to overrides)
 
(Good practice to provide a command string for override purposes)
Line 22: Line 22:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
Under no circumstance should you leave the <code>command</code> parameter blank; even if you want to check access based on existing admin flags, you should provide a unique "command" string to allow server operators to override access themselves.
  
 
To assign access levels for specific strings, modify <tt>configs/admin_overrides.cfg</tt>.
 
To assign access levels for specific strings, modify <tt>configs/admin_overrides.cfg</tt>.
  
 
For more detailed information, see [[Overriding_Command_Access_(SourceMod)|this page on overriding command access]].
 
For more detailed information, see [[Overriding_Command_Access_(SourceMod)|this page on overriding command access]].

Revision as of 04:10, 2 February 2021

This is a page on how to do things that are common in plugins. These are intended to be best practices.

Determine if a client has access to something

Use the admin overrides system with the CheckCommandAccess function. For example, if you want to determine if a client has access to the sm_ban command:

if (CheckCommandAccess(client, "sm_ban", ADMFLAG_BAN)) {
    // client has access to the "sm_ban" command
}

The command parameter can be an arbitrary string; it does not have to point to a valid command:

if (CheckCommandAccess(client, "has_fancy_color_trails", ADMFLAG_CUSTOM1, true)) {
    // client has access to the "has_fancy_color_trails" override;
    // if an override entry isn't set it falls back to ADMFLAG_CUSTOM1.
    // ignores the privileges set on a command of that name if it exists
}

Under no circumstance should you leave the command parameter blank; even if you want to check access based on existing admin flags, you should provide a unique "command" string to allow server operators to override access themselves.

To assign access levels for specific strings, modify configs/admin_overrides.cfg.

For more detailed information, see this page on overriding command access.