Question.
#1

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?
Reply
#2

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
Reply
#3

My question is.
SpeedWarnCount[MAX_PLAYERS char];
What's that char for?
And what will if(SpeedWarnCount{id}++) do?
Reply
#4

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
Reply
#5

PHP код:
if(SpeedWarnCount{id}++) 
                        { 
                            
//code 
                        

                        else 
SpeedWarnCount{id} = 0
So how this was used for speed hack and increase the warnings?
Reply
#6

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.
Reply
#7

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;
                } 
Reply
#8

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.
Reply
#9

Thanks for explaining that to me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)