پرش به مطلب اصلی

Per-player variable system

The per-player variable system (put short, PVar) is a new way of creating player variables efficiently and dynamically, meaning that they can be used in server's gamemode and filterscripts at the same time.

They are similar to SVars, but are on a per-player basis.

هشدار

This system was introduced in SA-MP 0.3a R5 and will not work in earlier versions!

Advantages​

The per-player variable system has several major advantages over creating an array sized MAX_PLAYERS.

  • PVars can be shared/accessed across gamemode scripts and filterscripts, making it easier to modularize your code.

  • PVars are automatically deleted when a player leaves the server (after OnPlayerDisconnect), meaning you don't have to manually reset variables for the next player who joins.

  • No real need for complex enums/player info structures.

  • Saves memory by not allocating pawn array elements for playerids which will probably never be used.

  • You can easily enumerate and print/store the PVar list. This makes both debugging and player info storage easier.

  • Even if a PVar hasn't been created, it still will return a default value of 0.

  • PVars can hold very large strings using dynamically allocated memory.

  • You can Set, Get, Create PVars ingame.

Drawbacks​

  • PVars are several times slower than regular variables. It is generally more favorable to trade in memory for speed, rather than the other way round.