16.04.2011, 14:17
I'd just like to add a few comments to this thread, because a few people have missed this out:
PVars are convenient - yes, but the lookup speed is also slower.
I'd suggest using normal arrays/enums for player variables, however you should use PVars for variables that aren't always going to be in use, say that you put a player in a DM arena, you want to track where they are, but not all players are going to be there, you should use PVars, here's a quick example of what I mean:
Basically, what I mean is - not everyone will be in the arena, so using is a lot more convenient - but you're also saving memory, because that variable won't always be in use so it won't always be declared, unlike arrays/normal variables.
PVars are convenient - yes, but the lookup speed is also slower.
I'd suggest using normal arrays/enums for player variables, however you should use PVars for variables that aren't always going to be in use, say that you put a player in a DM arena, you want to track where they are, but not all players are going to be there, you should use PVars, here's a quick example of what I mean:
pawn Код:
stock PutPlayerInArena(playerid) {
// This function was created for the purpose of this thread.
SetPlayerPos(playerid, 0, 0, 0);
SetPlayerInterior(playerid, 0);
SetPVarInt(playerid, "Arena", 1);
return 1;
}
CMD:sawnoff(playerid, params[]) {
if(GetPVarInt(playerid, "Arena") != 0) // We're tracking if the player is in the arena. If a PVar doesn't exist, it'll return 0.
return SendClientMessage(playerid, 0, "You can't do this while you're in the arena!");
// Giving the player a sawn-off shotgun with 500 ammo (example from wiki)
GivePlayerWeapon(playerid, 26, 500);
return 1;
}