Storing vehicle ID into a variable
#1

Would it be wiser to define a variable and store a player's current vehicle ID in that vairable than using 'GetPlayerVehicleID(playerid);' each time or even doing 'new vid = GetPlayerVehicleID(playerid);' each time you need to get the ID more than once.

Example:

pawn Код:
public OnPlayerStateChange(playerid, newstate, oldstate)
{
    ServerData[playerid][CurrentVehicleID] = GetPlayerVehicleID(playerid);
    return 1;
}
And using 'ServerData[playerid][CurrentVehicleID]' throughout the rest of the script.
Would all that be wiser than what I stated above?
Reply
#2

You could do this:
pawn Код:
ServerData[playerid][GetPlayerVehicleID(playerid)];
But you didn't explained carefully what do you want to do, at least myself didn't get it.
Reply
#3

Instead of having to search (prefer not to use get) for the player's vehicle ID each time I need to use it, would it be wiser and or more efficient to store it into a variable ONCE and get it from that variable each time it's needed?
Reply
#4

Yeh.. i use it, pretty helpful since you won't need to type this again. Normally i do that.

pawn Код:
new vehid = GetPlayerVehicleID(playerid);
Reply
#5

Yea, I suppose using GetPlayerVehicleID every time is less efficient then using a variable.

Could be possible to see how fast it takes for each, if needed.
Reply
#6

I did some benchmarking for this, here are the results if anyone is interested (Note: VehicleID is the player's vehicle variable):

pawn Код:
// First time
[04:57:18] GetPlayerVehicleID took 262 ms to execute
[04:57:19] VehicleID took 231 ms to execute
// Second time
[04:57:47] GetPlayerVehicleID took 308 ms to execute
[04:57:47] VehicleID took 218 ms to execute
// Third time
[04:57:49] GetPlayerVehicleID took 260 ms to execute
[04:57:49] VehicleID took 215 ms to execute
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)