Question. -
StrikerZ - 01.05.2017
PHP код:
static SpeedWarnCount[MAX_PLAYERS char];
if(SpeedWarnCount{id}++)
{
//code
}
else SpeedWarnCount{id} = 0;
So here is some code taken from my friend. I don't understand what did he do here. It checks if SpeedWarnCount has a value more than 0 but no code increases it there atm. So how does this code works like?
Re: Question. -
SyS - 01.05.2017
i think you meant why the value is not increased on that if statement,right? if that's what you meant then here is the answer suffix ++ operator works like that it only get evaluated after the statement it involves get executed
Re: Question. -
StrikerZ - 01.05.2017
My question is.
SpeedWarnCount[MAX_PLAYERS char];
What's that char for?
And what will if(SpeedWarnCount{id}++) do?
Re: Question. -
SyS - 01.05.2017
These are packed strings and uses less memory as compared to normal arrays (values between 0-255). They are accessed using {} as [] in normal arrays.
if(SpeedWarnCount{id}++)
checks SpeedWarnCount{id} is 0 or not then it increments it's value by 1
Re: Question. -
StrikerZ - 01.05.2017
PHP код:
if(SpeedWarnCount{id}++)
{
//code
}
else SpeedWarnCount{id} = 0;
So how this was used for speed hack and increase the warnings?
Re: Question. -
SyS - 01.05.2017
that will never work...the else statement will get executed always.
Edit:
to be more clear i will tell you why it won't work
PHP код:
if(SpeedWarnCount{id}++)
^^ i the above statement the execution goes in this order (reason i said above)
PHP код:
checks SpeedWarnCount{id} is not 0
then "if checking" completes
PHP код:
SpeedWarnCount{id}++
^^ this will execute value will becomes 1 from 0
since above if checking failed (as it was 0)
PHP код:
else SpeedWarnCount{id} = 0;
^^ this will execute and sets its value to 0.
Re: Question. -
StrikerZ - 01.05.2017
Let me show the whole code.
PHP код:
static SpeedWarnCount[MAX_PLAYERS char];
new bool:found = false;
for(new i = 0; i < sizeof(AirVehicles); i++)
{
if(model == AirVehicles[i]) {
found = true;
break;
}
}
if(found == false) {
new Float:X, Float:Y, Float:Z;
GetVehicleVelocity(vehicleid, X, Y, Z);
if(VectorSize(X, Y, Z) > 1.35)
{
if(SpeedWarnCount{playerid}++)
{
new str[120];
format(str, sizeof(str), "> [SERVER]: %s(%i) possible speed hacks.", GetName(playerid), playerid);
SendMessageToAdmins(1, COLOR_ADMRED, str);
}
}
else SpeedWarnCount{playerid} = 0;
}
Re: Question. -
SyS - 01.05.2017
that will work as else statement is not the else statement of the if we talked about as it was about vectorsize and the speedwarndcount will get increased too.
Re: Question. -
StrikerZ - 01.05.2017
Thanks for explaining that to me.