15.02.2011, 16:20
(
Last edited by Y_Less; 28/02/2012 at 12:29 PM.
)
UPDATE: Help no longer needed. This is an old topic which holds documentation for a now developed and tested YSI feature.
Hello.
I am looking for people to help test a new experimental library I have developed, based around an entirely new concept I call "player sets". I have in the past abstracted things like admin levels and factions in to "player groups", but this code goes one further and allows you to use any combination of players in the same way. To see what I mean, take a look at this example:
Now that doesn't look like much, in fact it looks quite pointless - there's nothing gained that you couldn't do directly. The real power of this library comes from how you can call the function. The code above calls the function with a single player, let's instead call it with an array:
That will now call "SetHealth" for FOUR players (5, 7, 11 and 34). So we have actually written a function which can take a variable OR an array (that doesn't sound like much, but hopefully the more experienced coders will appreciate this). Note that here the array passed is a list of players. If there are less that "MAX_PLAYERS" in the array, the last item MUST be "INVALID_PLAYER_ID" so the code knows to stop searching.
That's not all you can call it with:
y_groups groups:
boolean arrays:
Custom enum arrays:
This can vastly simplify the amount of code you need to write, you can write a generic message function and wrap it:
Notes:
The "#define" lines I've included above the functions are important.
DO NOT use "return" in your function when using "@PlayerVar", it will break the code quite impressively!
There are three ways to use the collection of players passed to the function: "@PlayerVar", "@PlayerArray" and "@PlayerSet":
The difference is not very clear here, but the first is a single variable, the second is an array, the third is an iterator. When using "@PlayerVar" the code will loop over all passed players internally and call the function once per player. The second version puts all the selected players in to a bit array (technically in to an array from "y_playerarray", which is slightly different, but still compressed data); this means that you have all the players at once in a single array. The third version returns a reference to an iterator; with this you can loop over players but not view them all at once, you can also pass this very efficiently to other "PSF" functions.
Hello.
I am looking for people to help test a new experimental library I have developed, based around an entirely new concept I call "player sets". I have in the past abstracted things like admin levels and factions in to "player groups", but this code goes one further and allows you to use any combination of players in the same way. To see what I mean, take a look at this example:
pawn Code:
#include <YSI\y_playerset>
#define SetHealth PSF:_SetHealth
stock _SetHealth(@PlayerVar:playerid, Float:health)
{
SetPlayerHealth(playerid, health);
}
CMD:health(playerid, params[])
{
SetHealth(playerid, 40.0);
}
pawn Code:
#include <YSI\y_playerset>
#define SetHealth PSF:_SetHealth
stock _SetHealth(@PlayerVar:playerid, Float:health)
{
SetPlayerHealth(playerid, health);
}
CMD:health(playerid, params[])
{
new
players[MAX_PLAYERS] = {5, 7, 11, 34, INVALID_PLAYER_ID};
SetHealth(players, 50.0);
}
That's not all you can call it with:
y_groups groups:
pawn Code:
new Group:x = Group_Create("x");
SetHealth(x, 60.0);
// Will not set anyone's health because the "x" group is empty, but would
// normally set all the members to 60.
pawn Code:
new bool:truefalse[MAX_PLAYERS] = {true, false, false, false, true, ...};
SetHealth(truefalse, 70.0);
// Will set players 0 and 4 to 70 as they are the only ones set to true.
pawn Code:
enum e_PLAYER_INFO
{
Float:e_PLAYER_INFO_HEALTH,
bool:e_PLAYER_INFO_ADMIN,
e_PLAYER_INFO_OTHER
}
new
gPlayerInfo[MAX_PLAYERS][e_PLAYER_INFO];
pawn Code:
SetHealth(gPlayerInfo<e_PLAYER_INFO_ADMIN>, 100.0);
// Will set the health of everyone who is connected and set as admin in
// "gPlayerInfo" to 100.
pawn Code:
#define SendMessage PSF:_SendMessage
stock _SendMessage(@PlayerVar:playerid, colour, msg[])
{
SendClientMessage(playerid, colour, msg);
}
stock SendAdminMessage(colour, msg[])
{
SendMessage(gPlayerInfo<e_PLAYER_INFO_ADMIN>, colour, msg);
}
The "#define" lines I've included above the functions are important.
DO NOT use "return" in your function when using "@PlayerVar", it will break the code quite impressively!
There are three ways to use the collection of players passed to the function: "@PlayerVar", "@PlayerArray" and "@PlayerSet":
pawn Code:
#define SetHealth1 PSF:_SetHealth1
stock _SetHealth1(@PlayerVar:playerid, Float:health)
{
SetPlayerHealth(playerid, health);
}
#define SetHealth2 PSF:_SetHealth2
stock _SetHealth2(@PlayerArray:players<MAX_PLAYERS>, Float:health)
{
foreach (new playerid : PA(players))
{
SetPlayerHealth(playerid, health);
}
}
#define SetHealth3 PSF:_SetHealth3
stock _SetHealth3(@PlayerSet:players, Float:health)
{
foreach (new playerid : PS(players))
{
SetPlayerHealth(playerid, health);
}
}