AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   2 questions %i and setting admin (https://forums.alliedmods.net/showthread.php?t=233529)

kasu007 01-16-2014 05:47

2 questions %i and setting admin
 
I tryed searching which is more useful or best to use %i OR %d for integer values
are there some privilegs using 1 to other.

And when Player already is admin.

lets say I want to remove admin, but not from the sql database and then
PHP Code:

server_cmd("amx_reloadadmins"); 

Just set temporarly no admin.

PHP Code:

#include <amxmodx>
#include <amxmisc>

public plugin_init() {
    
register_plugin("No Admin""v1""kasu");
    
register_clcmd("say /noadmin""noAdmin");
}

public 
noAdmin(id){
    
set_user_flags(idread_flags("z"));
    
client_print(idprint_chat"Should be no admin but your still... :S");


and 3rd :D
which is faster
setting using array as boolean or integer
PHP Code:

global_variable[512];

function 
bla(eventplayer, ....){
    
global_variable[event] = true;
    OR
    
global_variable[event] = 1;


which is faster / better way to use

and is there a way to set values "false" or / 0 in array without going through all array.
example
global_variable[16] = true;
global_variable[129] = true;
global_variable[3] = true;

is there a quick way like setting string array to 0
as global_variable[0] = 0;
but can you do the same for bool / int array

Black Rose 01-16-2014 13:54

Re: 2 questions %i and setting admin
 
%i and %d are the same.

An array is always initialized as 0, 0.0 or false depending on the tag. If you don't do anything all cells will have that value.
Do you mean clearing an array that has been set? If so, arrayset() is a useful function.
Code:
    new myArray[512];     arrayset(myArray, 0, sizeof myArray);

I do believe (I'm not sure) that booleans are basically integers in PAWN. So I don't think you would see an improvement using booleans. Either way, if your array only has 2 values (0 and 1) it's considered good practice too use a boolean.
If you have less than 32 values in that array you can use bitmasking on one integer instead. I don't know if it is more efficient, but it probably is. It is harder to read and understand though. That can easily be solved by some macros.

Clearing a string by setting the first cell to 0 is really a lie. Most string related functions will stop once it hits 0 so no function will process the string beyond that first cell, but all the other cells still remains. There's no point of using arrayset() because most functions will create a new null at the end of the string.

I don't have an answer to the admin/flags question.

YamiKaitou 01-16-2014 14:44

Re: 2 questions %i and setting admin
 
set_user_flags does not remove existing flags, it just adds to them. So you need to use remove_user_flags first, then set_user_flags

kasu007 01-16-2014 17:09

Re: 2 questions %i and setting admin
 
arrayset works, thanks for that.
PHP Code:

new myArray[512];
arrayset(myArray0sizeof myArray);

but inside the funtion will it do?
for(new 
ii<512i++){
   
myArray[i] = 0;


or it someway deletes array and re creates it?

Black Rose 01-16-2014 17:21

Re: 2 questions %i and setting admin
 
Quote:

Originally Posted by kasu007 (Post 2086931)
PHP Code:

but inside the funtion will it do?
for(new 
ii<512i++){
   
myArray[i] = 0;



Sometimes, yes. But not on null value.
This is the native and it can be found in amxmodx.cpp.
Code:
static cell AMX_NATIVE_CALL arrayset(AMX *amx, cell *params) {     cell value = params[2];     if (!value)     {         memset(get_amxaddr(amx, params[1]), 0, params[3] * sizeof(cell));     } else {         int size = params[3];         cell *addr = get_amxaddr(amx, params[1]);         for (int i=0; i<size; i++)         {             addr[i] = value;         }     }     return 1; }


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

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