12.03.2011, 15:08
Its "dynamic array" (you dont have to know maximum size for it, unlike normal arrays in PAWN)
For example you can store all online playerids in it, and the vector size changes according to player count.
Then if you need to loop through all players online, you do not have to loop from 0 to MAX_PLAYER and check if player is online, but you can just loop through vector (hard to explain)
Example filterscript:
For example you can store all online playerids in it, and the vector size changes according to player count.
Then if you need to loop through all players online, you do not have to loop from 0 to MAX_PLAYER and check if player is online, but you can just loop through vector (hard to explain)
Example filterscript:
pawn Code:
#include <a_samp>
#include <cstl>
new const USERS_ONLINE = 0; // vector of all online users
public OnPlayerConnect(playerid)
{
// now we add connected user into vector
vector_push_back(USERS_ONLINE, playerid);
}
public OnPlayerDisconnect(playerid, reason)
{
new index;
// get index of playerid in vector
index = vector_find(USERS_ONLINE, playerid);
if (index != -1) // if vector contains this playerid, remove it (because player disconnected)
{
vector_remove(USERS_ONLINE, index);
}
}
stock KickAllPlayers() // with this we can kick all players (not recommended)
{
for (new i = 0 ; i < vector_size(USERS_ONLINE) ; i++)
{
Kick(vector_get(USERS_ONLINE, i));
}
}