Quote:
Originally Posted by Napoleon_be
Thanks for the suggestions HamletEagle, Everything is ready to get updated, only for one thing where i'm having trouble with. Which is the cvar for snipers.
This is the check i currently have but it doesn't work, can i get some on help this one?
PHP Code:
if((is_user_connected(iAttacker) && get_pcvar_num(pPlugin) && get_user_team(iVictim) != get_user_team(iAttacker)) || (is_user_connected(iAttacker) && get_pcvar_num(pPlugin) && get_user_team(iVictim) != get_user_team(iAttacker) && get_pcvar_num(pSnipersOnly) && gWeaponList & (1 << get_user_weapon(iAttacker))))
|
Huh... this is next-level stuff right here. Now seriously, don't duplicate if checks like that: it is not needed and makes your code ugly and hard to read.
Also, don't be afraid to split your checks in multiple if statements.
Your code didn't work because inside an if check that looks like if(A || B) A is firstly checked. If A is false, B is checked. If A is true, B is not checked.
So it firstly checks
PHP Code:
is_user_connected(iAttacker) && get_pcvar_num(pPlugin) && get_user_team(iVictim) != get_user_team(iAttacker))
and the if check passes without ever checking for pSnipersOnly cvar(and whenever A fails B will fail too because both A and B share the above check)
PHP Code:
//we are doing the main checks first - the part that you duplicated. We need them to be true to proceed no matter the value of pSnipersOnly
if(is_user_connected(iAttacker) && get_pcvar_num(pPlugin) && get_user_team(iVictim) != get_user_team(iAttacker))
{
//controls whether we will show a hit marker or not
new bool:showHitMarker;
if(get_pcvar_num(pSnipersOnly)) //snipers only
{
if(gWeaponList & (1 << get_user_weapon(iAttacker))) //we are holding a sniper
{
showHitMarker = true; //show hit marker
}
}
else
{
showHitMarker = true; //no restrictions on current weapon, show hit marker
}
if(showHitMarker)
{
//hit marker logic
}
}
You could write it as an one-liner but as I said before, it's horrible:
PHP Code:
is_user_connected(iAttacker) && get_pcvar_num(pPlugin) && get_user_team(iVictim) != get_user_team(iAttacker) && (!get_pcvar_num(pSnipersOnly) || get_pcvar_num(pSnipersOnly) && (gWeaponList & (1 << get_user_weapon(iAttacker))))
__________________