View Single Post
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-14-2017 , 16:49   Re: Some simple solutions
#2

Code:
if(cs_get_user_team(id) == CS_TEAM_T) //this may be error 
if(cs_get_user_team(id) == CsTeams:CS_TEAM_T) //the best way to be sure
It won't throw any warning. cs_get_user_team is already tagged as CsTeams. You should take a look at how tags work.

Code:
set_user_gravity(id, 0.8) //this may be error 
set_user_gravity(id, Float:0.8) //the best way to be sure
Same thing, tagging a float as a Float makes no sense.

Code:
new p_Gravity[MAX_PLAYERS] = 0.8 //this may be error 
new p_Gravity[MAX_PLAYERS] = float:0.8 //the best way to be sure ("float" for defination, "Float" for function - upper case)
First line is wrong, p_Gravityshould be tagged as Float(i.e. new Float:pGravity[MAX_PLAYERS). Also p usually stands from "pointers", so you should use f if you really want to use HN.
Second line is also wrong, float it's a custom tag, the default one is called Float. Again, variable should be tagged as Float, not the value(because the value it's already a float).

Correct way:
Code:
new Float:p_Gravity[MAX_PLAYERS]
I would also like to add something about this kind of initialization:
PHP Code:
new var[33] = 
This won't set all array cells to 1, only the first one(var[0] is 1, but var[1],var[2], ... are 0). If you want to initialize the entire array with 1, you should do:
PHP Code:
new var[33] = {1, ...} 
Code:
p_Money[id] = get_cvar_num("max_money") //this may be error
Won't throw any error if the cvar is present. Anyway, don't use cvars, use pcvars, they are faster(get_pcvar_num).

Code:
#define MAX_PLAYERS 33 
new cvar_max_money 
new p_Money[MAX_PLAYERS] 

public plugin_init() { 
    register_plugin(PLUGIN, VERSION, AUTHOR) 
    cvar_max_money = get_cvar_num("max_money") 
} 
public client_connect(id) { 
    p_Money[id] = cvar_max_money 
}
What you did here is basically to cache the cvar value, so if it's changed in-game it won't take affect until the next map change.

Code:
new p_Name[33] 
get_user_name(id, p_Name, 33)
p_Name should be 32, not 33 and in get_user_name you should put size - 1, so 31. Indexing pName by MAX_PLAYERS is confusing. You would do that when you want to have an array for players, but here you are using a char array to store the name of ONLY ONE player at a time. So just put 32.
The usage of charsmax() is correct.

Code:
set_user_health(id, get_user_health(id) + 50) 
set_user_armor(id, get_user_armor(id) + 50) 
p_UsrXP[id] = p_UserXP[id] + 50  

new i_Val = 50 
set_user_health(id, get_user_health(id) + i_Val) 
set_user_armor(id, get_user_armor(id) + i_Val) 
p_UsrXP[id] += i_Val
While you could argue that's for readability it does not provide any performance optimization.

Don't get me wrong, I'm not picking on you, I'm trying to explain some stuff that seems to confuse you.
__________________

Last edited by HamletEagle; 03-14-2017 at 16:54.
HamletEagle is offline