AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Set user flags from const... (https://forums.alliedmods.net/showthread.php?t=214041)

Unkolix 04-22-2013 08:16

Set user flags from const...
 
Can't try this, but will this work ok? Will this add all the flags in the const?
PHP Code:

new const FreeFlags[][] = {
    
"ADMIN_IMMUNITY""ADMIN_RESERVATION""ADMIN_CHAT"
}
/***/
public somefuction(id) {
    
set_user_flags(idFreeFlags)



Backstabnoob 04-22-2013 08:22

Re: Set user flags from const...
 
It won't, first off these are constants not strings and secondly you can't use array in the set_user_flags native.

Code:
new const FreeFlags[ ] = { ADMIN_IMMUNITY, ADMIN_RESERVATION, ADMIN_CHAT } public somefunction( id ) {       new iFlags       for( new i; i < sizeof FreeFlags; i ++ ) iFlags = iFlags | FreeFlags[ i ]       set_user_flags( id, iFlags ) }
Probably can be done better than using a loop but I have no idea about bitwise operators

Or a better way:

Code:
new const FreeFlags = ADMIN_IMMUNITY | ADMIN_RESERVATION | ADMIN_CHAT public somefunction( id ) {      set_user_flags( id, FreeFlags ) }

Unkolix 04-22-2013 08:23

Re: Set user flags from const...
 
Oh lol... I absolutely forgot about this... :D

Thanks! :)

Sherazaa 04-23-2013 14:02

Re: Set user flags from const...
 
Why did you not do that :

Code:
new const FreeFlags = ADMIN_IMMUNITY & ADMIN_RESERVATION & ADMIN_CHAT

Why you set an OR BITWISE operator and not an AND BITWISE ?

pokemonmaster 04-23-2013 15:11

Re: Set user flags from const...
 
Quote:

Originally Posted by Sherazaa (Post 1938306)
Why did you not do that :

Code:
new const FreeFlags = ADMIN_IMMUNITY & ADMIN_RESERVATION & ADMIN_CHAT

Why you set an OR BITWISE operator and not an AND BITWISE ?

Bit-wise operators do not work according to their names.
Re-read the bitwise tutorial you would understand it
I think this will make you understand.

^SmileY 04-23-2013 15:24

Re: Set user flags from const...
 
PHP Code:

set_user_flags(id,read_flags("abcd....")); // And other flags 

Ps. These set_user_flags it will replate existing flags example:

If the player have "a" flag, its will replace again with a flag "a" i not understand the Optmization of this, so for remove the "z" user flag, it will used with a

PHP Code:

remove_user_flags(id,read_flags("z")); // Or others flags 


A better example:

If will turn a normal user admin with a flag "a", write this:

PHP Code:

set_user_flags(id,read_flags("a")); 

But the result is the player with these flags: "az"

so to remove the "z" flag, you need to:

PHP Code:

remove_user_flags(id,read_flags("z")); // Or others flags 

I not sure of this

Unkolix 04-23-2013 16:05

Re: Set user flags from const...
 
So I can do it like this?
PHP Code:

new g_flags
/***/
g_flags register_cvar("flags""abcde")
/***/
new flags[22]
get_pcvar_string(g_flagsflagscharsmax(flags));
set_user_flags(id,read_flags(flags)); 


^SmileY 04-23-2013 16:24

Re: Set user flags from const...
 
Yes perfectly...


All times are GMT -4. The time now is 10:56.

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