Vehicles
#1

Lets say that I want to make anticheat for every vehicl for itself.
Example
If he is in infernus and goes over 260 he will get kicked.
If he is in maverick and goes over 200 he will get kicked

Is there any efficient way to do it or I can do it only like
PHP код:
if(GetPlayerState(i) == PLAYER_STATE_DRIVER)
        {
            new 
vID GetVehicleModel(GetPlayerVehicleID(i));
            switch(
vID)
            {
                case 
411//Infernus
                
{
                    if(
GetSpeed(i) > 250)
                    { 
Reply
#2

i think making a switchcase with vehicleid is efficent enough, but you should not comapre the result from get speed with an integer since it's probably a float, which means the server has to convert the integer to float before comparing
Reply
#3

Quote:
Originally Posted by [Bios]Marcel
Посмотреть сообщение
i think making a switchcase with vehicleid is efficent enough, but you should not comapre the result from get speed with an integer since it's probably a float, which means the server has to convert the integer to float before comparing
GetSpeed is custom function in my GM and it is working as it should.. thx for answer
Reply
#4

You should make an Array, this way you could dynamically save each vehicle speed ingame (if you extend this a bit of course) and you don't need to write 150 values yourself (or 212 if you do this for all vehicle types) - at least you will save all case and if statements.

You could design the array like follows:

Код:
new Float:MaxVehicleSpeeds[212] =
{
220.0, // Landstalker - ID 400 - subtract 400 from the model id to access this slot
190.0,
...
};
The check would look like this:

Код:
new vid = GetPlayerVehicleID(i);
new mid = GetVehicleModel(vid);
new Float:speed = GetSpeed(i);

if(speed > MaxVehicleSpeeds[mid - 400] && MaxVehicleSpeeds[mid - 400] > 0.1) // exceeding speed
{
}
I also added a check to prevent kicking everyone who is in a vehicle that has no speed set.

Your version is perfectly fine by the way, however I wouldn't want to write 212 cases with an if inside, instead of just writing/gathering the values.
Reply
#5

I am not asking for easiest way to do it. I am asking for efficient way to do it. Which way will cause less lag?? Array or case?
If case is better it is not problem for me to write 212 cases..
Reply
#6

Quote:
Originally Posted by Micko123
Посмотреть сообщение
I am not asking for easiest way to do it. I am asking for efficient way to do it. Which way will cause less lag?? Array or case?
If case is better it is not problem for me to write 212 cases..
None of them will cause any lagg. But yea, theoretically your switch() code is faster. Which is a totally neglible difference. So, use what you like more. I just like the Array version more because it's cleaner code in my opinion.

BTW: If your server experiences lagg issues because you check vehicle speeds, you are doing something terribly wrong (Not that you do, just for example).
PAWN can handle more stuff than you might think.
Reply
#7

Sometimes you have to make compromises. Over 1400 lines with lots of duplicated code (cases) or less than 250 lines without duplicated code (array).
Reply
#8

Quote:
Originally Posted by Vince
Посмотреть сообщение
Sometimes you have to make compromises. Over 1400 lines with lots of duplicated code (cases) or less than 250 lines without duplicated code (array).
One direct question. I want to run that timer every second. Which one is more optimized?
Reply
#9

Quote:
Originally Posted by Micko123
Посмотреть сообщение
One direct question. I want to run that timer every second. Which one is more optimized?
Both are fast enough to not worry about it. Like I said above, the switch() code may be 0.0000000001ms faster though.
Reply
#10

Can you give me example code for array for infernus (id 411)??
I don't get it.. xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)