[Plugin] CSTL - Data container(s) (Currently vector)
#5

Quote:
Originally Posted by Teprey
View Post
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:
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));
    }
}
So this must be really fast compared to the old way of doing loops.
Now i understand, genius! Good job.
Reply


Messages In This Thread
CSTL - Data containers (Vector, Map) - by Teprey - 12.03.2011, 13:38
Re: CSTL - Data container(s) (Currently vector) - by Zh3r0 - 12.03.2011, 14:24
Re: CSTL - Data container(s) (Currently vector) - by TheArcher - 12.03.2011, 14:59
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 12.03.2011, 15:08
Re: CSTL - Data container(s) (Currently vector) - by Zh3r0 - 12.03.2011, 15:12
Re: CSTL - Data container(s) (Currently vector) - by [L3th4l] - 12.03.2011, 15:18
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 12.03.2011, 15:41
Re: CSTL - Data container(s) (Currently vector) - by Dreftas - 12.03.2011, 16:41
Re: CSTL - Data container(s) (Currently vector) - by Medal Of Honor team - 12.03.2011, 17:03
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 12.03.2011, 18:27
Re: CSTL - Data container(s) (Currently vector) - by hencz - 12.03.2011, 18:45
Re: CSTL - Data container(s) (Currently vector) - by anonymousx - 12.03.2011, 18:54
Re: CSTL - Data container(s) (Currently vector) - by 1337connor - 12.03.2011, 19:11
Re: CSTL - Data container(s) (Currently vector) - by xxmitsu - 12.03.2011, 19:17
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 12.03.2011, 19:27
Re: CSTL - Data container(s) (Currently vector) - by Patrik356b - 12.03.2011, 19:38
Re: CSTL - Data container(s) (Currently vector) - by RyDeR` - 12.03.2011, 22:35
Re: CSTL - Data container(s) (Currently vector) - by CyNiC - 13.03.2011, 03:05
Re: CSTL - Data container(s) (Currently vector) - by anonymousx - 13.03.2011, 07:45
Re: CSTL - Data container(s) (Currently vector) - by Kyosaur - 13.03.2011, 07:54
Re: CSTL - Data container(s) (Currently vector) - by Minokon - 13.03.2011, 09:39
Re: CSTL - Data container(s) (Currently vector) - by Macluawn - 13.03.2011, 15:35
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 14.03.2011, 13:54
Re: CSTL - Data container(s) (Currently vector) - by XFlawless - 14.03.2011, 14:22
Re: CSTL - Data container(s) (Currently vector) - by RyDeR` - 14.03.2011, 15:42
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 14.03.2011, 16:08
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 14.03.2011, 20:33
Re: CSTL - Data container(s) (Currently vector) - by Kyosaur - 15.03.2011, 05:19
Re: CSTL - Data container(s) (Currently vector) - by SlashPT - 15.03.2011, 06:58
Re: CSTL - Data container(s) (Currently vector) - by Macluawn - 15.03.2011, 07:05
Re: CSTL - Data container(s) (Currently vector) - by Retardedwolf - 15.03.2011, 10:00
Re: CSTL - Data container(s) (Currently vector) - by Slice - 15.03.2011, 11:43
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 15.03.2011, 12:25
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 15.03.2011, 15:18
Re: CSTL - Data container(s) (Currently vector) - by iggy1 - 21.03.2011, 08:42
Re: CSTL - Data container(s) (Currently vector) - by CaHbKo - 14.06.2011, 09:09
Re: CSTL - Data container(s) (Currently vector) - by Calgon - 14.06.2011, 09:16
Re: CSTL - Data container(s) (Currently vector) - by 0x5A656578 - 14.06.2011, 10:47
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 14.06.2011, 15:36
Re: CSTL - Data container(s) (Currently vector) - by CaHbKo - 19.06.2011, 12:07
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 19.06.2011, 15:19
Re: CSTL - Data container(s) (Currently vector) - by Macluawn - 24.06.2011, 21:48
Re: CSTL - Data container(s) (Currently vector) - by linuxthefish - 24.06.2011, 22:28
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 29.06.2011, 11:54
Re: CSTL - Data container(s) (Currently vector) - by GangsTa_ - 29.06.2011, 15:00
Re: CSTL - Data container(s) (Currently vector) - by iggy1 - 29.06.2011, 17:12
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 30.06.2011, 10:32
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 14.07.2011, 11:28
Re: CSTL - Data container(s) (Currently vector) - by Dreftas - 25.08.2011, 10:10
Re: CSTL - Data container(s) (Currently vector) - by papedo - 16.09.2011, 17:11
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 18.10.2011, 15:26
Re: CSTL - Data container(s) (Currently vector) - by Slice - 18.10.2011, 16:03
Re: CSTL - Data container(s) (Currently vector) - by SourceCode - 18.10.2011, 16:12
Re: CSTL - Data container(s) (Currently vector) - by Teprey - 18.10.2011, 19:11
Re: CSTL - Data container(s) (Currently vector) - by Babul - 20.10.2011, 18:22
Re: CSTL - Data container(s) (Currently vector) - by AndreT - 04.12.2011, 09:19
Re: CSTL - Data container(s) (Currently vector) - by SchurmanCQC - 07.01.2012, 19:40
Re: CSTL - Data container(s) (Currently vector) - by cyber_punk - 07.07.2012, 01:58
Re: CSTL - Data container(s) (Currently vector) - by AndreT - 07.07.2012, 06:16
Re: CSTL - Data container(s) (Currently vector) - by cyber_punk - 10.07.2012, 00:26
Re: CSTL - Data container(s) (Currently vector) - by Yiin - 09.05.2013, 13:05
Re: CSTL - Data container(s) (Currently vector) - by RCON1 - 22.09.2013, 09:34
Re: CSTL - Data container(s) (Currently vector) - by OxyG3N - 07.01.2014, 10:54
Re: CSTL - Data container(s) (Currently vector) - by detter - 12.01.2014, 15:29
Re: CSTL - Data container(s) (Currently vector) - by Michalec - 12.12.2015, 22:36

Forum Jump:


Users browsing this thread: 4 Guest(s)