SA-MP Forums Archive
Question. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Question. (/showthread.php?tid=633463)



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{idis 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 
0sizeof(AirVehicles); i++)
                {
                    if(
model == AirVehicles[i]) {
                        
found true;
                        break;
                    }
                }
                if(
found == false) {
                    new 
Float:XFloat:YFloat:Z;
                    
GetVehicleVelocity(vehicleidXYZ);
                    if(
VectorSize(XYZ) > 1.35)
                    {
                        if(
SpeedWarnCount{playerid}++)
                        {
                            new 
str[120];
                            
format(strsizeof(str), "> [SERVER]: %s(%i) possible speed hacks."GetName(playerid), playerid);
                            
SendMessageToAdmins(1COLOR_ADMREDstr);
                        }
                    }
                    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.