22.07.2011, 23:16
(
Последний раз редактировалось Kwarde; 23.07.2011 в 08:35.
)
Hello there!
I see that there are quite alot (atleast too much) people whom are using callbacks as normal functions. Example:
I know, it will just work etc, but callbacks are NOT intended to be used as functions! - You can use 'stock' for this:
Why?
Very simple: "Callbacks": "Call" and "back". They're intended to be used as .. well.. callbacks. They're intended to call at any time when something specific happens. Here's just a small list which makes it clear:
* OnGameModeInit : Call this callback when a gamemode is initialising
* OnPlayerConnect : Call this callback when a player connected
* OnVehicleMod : Called when a vehicle's been modded
~etc
So, a 'SendMessageToAdmins' -for example, again- is NOT a callback. You could make an "OnMessageToAdminsSend", like this:
I hope that that's clear enough - If I should add anything, please say it
If there already exists something like this: Sorry for that; I searched for it (simply for 'callback' and 'callbacks'), and got only one result, and that was about hooking functions (or callbacks, can't remember very well)
Kind Regards,
Kevin aka Kwarde
I see that there are quite alot (atleast too much) people whom are using callbacks as normal functions. Example:
pawn Код:
forward SendMessageToAdmins(message[]);
public SendMessageToAdmins(message[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || !IsPlayerAdmin(i)) continue;
SendClientMessage(i, 0x00FF00AA, message);
}
return 1;
}
pawn Код:
stock SendMessageToAdmins(message[])
{
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || !IsPlayerAdmin(i)) continue;
SendClientMessage(i, 0x00FF00AA, message);
}
return 1;
}
Very simple: "Callbacks": "Call" and "back". They're intended to be used as .. well.. callbacks. They're intended to call at any time when something specific happens. Here's just a small list which makes it clear:
* OnGameModeInit : Call this callback when a gamemode is initialising
* OnPlayerConnect : Call this callback when a player connected
* OnVehicleMod : Called when a vehicle's been modded
~etc
So, a 'SendMessageToAdmins' -for example, again- is NOT a callback. You could make an "OnMessageToAdminsSend", like this:
pawn Код:
stock SendMessageToAdmins(message[])
{
new pCount;
for(new i = 0; i < MAX_PLAYERS; i++)
{
if(!IsPlayerConnected(i) || !IsPlayerAdmin(i)) continue;
pCount++;
SendClientMessage(i, 0x00FF00AA, message);
}
CallLocalFunction("OnMessageToAdminsSent", "sd", message, pCount); //<-- !!!
return 1;
}
forward OnMessageToAdminsSent(message[], ammount_of_players);
public OnMessageToAdminsSent(message[], ammount_of_players)
{
printf("The message \"%s\" was sent to %d players (the admins)", message, ammount_of_players);
return 1;
}
If there already exists something like this: Sorry for that; I searched for it (simply for 'callback' and 'callbacks'), and got only one result, and that was about hooking functions (or callbacks, can't remember very well)
Kind Regards,
Kevin aka Kwarde