Raised This Month: $ Target: $400
 0% 

2 questions %i and setting admin


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kasu007
Junior Member
Join Date: Jan 2013
Old 01-16-2014 , 05:47   2 questions %i and setting admin
Reply With Quote #1

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
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

Last edited by kasu007; 01-16-2014 at 06:18. Reason: 3rd question
kasu007 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 01-16-2014 , 13:54   Re: 2 questions %i and setting admin
Reply With Quote #2

%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.
__________________
Black Rose is offline
YamiKaitou
Has a lovely bunch of coconuts
Join Date: Apr 2006
Location: Texas
Old 01-16-2014 , 14:44   Re: 2 questions %i and setting admin
Reply With Quote #3

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
__________________
ProjectYami Laboratories

I do not browse the forums regularly anymore. If you need me for anything (asking questions or anything else), then PM me (be descriptive in your PM, message containing only a link to a thread will be ignored).
YamiKaitou is offline
kasu007
Junior Member
Join Date: Jan 2013
Old 01-16-2014 , 17:09   Re: 2 questions %i and setting admin
Reply With Quote #4

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?

Last edited by kasu007; 01-16-2014 at 17:10.
kasu007 is offline
Black Rose
Veteran Member
Join Date: Feb 2011
Location: Stockholm, Sweden
Old 01-16-2014 , 17:21   Re: 2 questions %i and setting admin
Reply With Quote #5

Quote:
Originally Posted by kasu007 View Post
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; }
__________________

Last edited by Black Rose; 01-16-2014 at 17:22.
Black Rose 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 10:06.


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