PDA

View Full Version : Few questions


sondriz
10-03-2014, 14:31
Hey guys,

http://puu.sh/bXQpc/e9553094fe.png
Coming from Java, this is quite confusing. I understand that cases are not fallthrough which means I can do this:


switch(i) {
case 1, 2:
doSomething();
default:
doNothing();
}


Rather than this:


switch(i) {
case 1:
case 2:
doSomething();
break;
default:
doNothing();
break;
}

So there's no need to break the loop as far as I understand because it's terminated instantly?

Oh, and question two:

To check an AdminFlag for instance:

if (GetAdminFlag(client, AdminFlag.Custom4, NOTHING) {

I kind of guessed the AdminFlag thingy and Custom4 was just with some looking, I have no idea what AccessMode is so could someone please explain that? Also it would be nice if you could give me some sort of web page where I can check things like these.

I checked the SDK page, but I couldn't really find any elaborate information about functions like this. All I found out about it was that I need the accessmode, the client, and the specified adminflag as a parameter but I never said what they were.

So, if possible could you answer these questions and maybe give me some useful pages? I'm aware of the FAQ and I've read a bit of the introduction (planning to finish it).

Thank you, sorry for all these questions and it's probably very basic lol

Powerlord
10-03-2014, 14:43
AdmAccessMode is an enum with two values:

Access_Real - This is the flags that are assigned to the user directly.
Access_Effective - This is the flags a user has both directly and through groups.

Normally you'll want Access_Effective.
Incidentally, it's Admin_Custom4 not Admin.Custom4 unless this changed in SourceMod 1.7 and I'm not aware of it.

Now that I've answered the question, time for some advice: Rather than using GetAdminFlag, you should use either RegAdminCmd (instead of RegConsoleCmd) or CheckCommandAccess (https://sm.alliedmods.net/api/index.php?fastload=show&id=497&) (instead of GetAdminFlag). These participate in the Overrides system, which allows a flag to be changed using the Overrides system (https://wiki.alliedmods.net/Overriding_Command_Access_%28Sourcemod%29). If the command name given in CheckCommandAccess is not an actual command, you can set the fourth argument to true to speed up processing slightly.

sondriz
10-03-2014, 15:28
Thank you, can I ask how you found the enum so I can find it myself in the future in situations like these+

I'll use Access_Effective, it seems appropriate for what I'm trying to do.
Yeah, Admin_Custom4 seems to be correct. After using Java, I'm used to accessing it with a dot, so an underscore seems weird to me like Admin_Custom4 is its own class.

So basically you access enums with ENUMFILENAME_ENUMVALUETHINGY rather than in java where it would be ENUMFILENAME.ENUMVALUETHINGY?

I've taken a look at these, but I don't think that it's good for what I'm trying to do. Right now, I'm just adding this admin flag check to a default sourcemod plugin (rtv) rather than creating a new one from scratch. If I was creating my own plugin, I would have definitely uesd the system which was created for it.

Thank you a lot :)

Powerlord
10-03-2014, 16:04
Thank you, can I ask how you found the enum so I can find it myself in the future in situations like these+

I'll use Access_Effective, it seems appropriate for what I'm trying to do.
Yeah, Admin_Custom4 seems to be correct. After using Java, I'm used to accessing it with a dot, so an underscore seems weird to me like Admin_Custom4 is its own class.

So basically you access enums with ENUMFILENAME_ENUMVALUETHINGY rather than in java where it would be ENUMFILENAME.ENUMVALUETHINGY?

In SourcePawn, you don't include the enum name at all. If you look at the AdminFlag enum (https://sm.alliedmods.net/api/index.php?fastload=file&id=28&file=&), you'll notice that all its values start with Admin_:

/**
* Access levels (flags) for admins.
*/
enum AdminFlag
{
Admin_Reservation = 0, /**< Reserved slot */
Admin_Generic, /**< Generic admin abilities */
Admin_Kick, /**< Kick another user */
Admin_Ban, /**< Ban another user */
Admin_Unban, /**< Unban another user */
Admin_Slay, /**< Slay/kill/damage another user */
Admin_Changemap, /**< Change the map */
Admin_Convars, /**< Change basic convars */
Admin_Config, /**< Change configuration */
Admin_Chat, /**< Special chat privileges */
Admin_Vote, /**< Special vote privileges */
Admin_Password, /**< Set a server password */
Admin_RCON, /**< Use RCON */
Admin_Cheats, /**< Change sv_cheats and use its commands */
Admin_Root, /**< All access by default */
Admin_Custom1, /**< First custom flag type */
Admin_Custom2, /**< Second custom flag type */
Admin_Custom3, /**< Third custom flag type */
Admin_Custom4, /**< Fourth custom flag type */
Admin_Custom5, /**< Fifth custom flag type */
Admin_Custom6, /**< Sixth custom flag type */
/* --- */
};

To make matters more confusing, other commands (like RegAdminCmd and CheckCommandAccess) don't even use these and instead use the ADMFLAG_ constants, which are bitflags.

Enum names are really just used to throw warnings if you call a command that expects a value from that enum and you instead pass a raw number.