13.02.2019, 02:47
PHP код:
#if defined _INC_od_batch_operation
#endinput
#endif
#define _INC_od_batch_operation
#include <indirection\indirection>
#if !defined FIX_const
native CST_SetSVarInt(const varname[], int_value) = SetSVarInt;
native CST_GetSVarType(const varname[]) = GetSVarType;
native CST_DeleteSVar(const varname[]) = DeleteSVar;
native CST_SetPVarInt(playerid, const varname[], int_value) = SetPVarInt;
native CST_GetPVarType(playerid, const varname[]) = GetPVarType;
native CST_DeletePVar(playerid, const varname[]) = DeletePVar;
native CST_SetTimerEx(const funcname[], interval, repeating, const format[], {Float,_}:...) = SetTimerEx;
#else
#if !FIX_const
native CST_SetSVarInt(const varname[], int_value) = SetSVarInt;
native CST_GetSVarType(const varname[]) = GetSVarType;
native CST_DeleteSVar(const varname[]) = DeleteSVar;
native CST_SetPVarInt(playerid, const varname[], int_value) = SetPVarInt;
native CST_GetPVarType(playerid, const varname[]) = GetPVarType;
native CST_DeletePVar(playerid, const varname[]) = DeletePVar;
native CST_SetTimerEx(const funcname[], interval, repeating, const format[], {Float,_}:...) = SetTimerEx;
#endif
#endif
forward Batch_SVar(Func:func<>, const name[]);
public Batch_SVar(Func:func<>, const name[]) {
CST_DeleteSVar(name);
@.func();
Indirect_Release(func);
}
forward Batch_PVar(playerid, Func:func<i>, const name[]);
public Batch_PVar(playerid, Func:func<i>, const name[]) {
CST_DeletePVar(playerid, name);
@.func(playerid);
Indirect_Release(func);
}
stock BATCH({F@_@, F@_@i}:func = F@_@:0, playerid = INVALID_PLAYER_ID, const name[]) {
if (func == F@_@:0) {
func = F@_@:GetPublicAddressFromName(name);
}
if (playerid == INVALID_PLAYER_ID) {
if (CST_GetSVarType(name) == SERVER_VARTYPE_NONE) {
Indirect_Claim(func);
CST_SetSVarInt(name, CST_SetTimerEx("Batch_SVar", 0, 0, "is", _:func, name));
}
} else if (IsPlayerConnected(playerid)) {
if (CST_GetPVarType(playerid, name) == SERVER_VARTYPE_NONE) {
Indirect_Claim(func);
CST_SetPVarInt(playerid, name, CST_SetTimerEx("Batch_PVar", 0, 0, "iis", playerid, _:func, name));
}
}
}
#define BATCH(&%1) (_:BATCH_2:BATCH(addressof(%1<>),.name=#%1))
#define BATCH_2:BATCH(addressof(%1,%2<>)%3)) BATCH(addressof(%1<i>),%2,#%1))
example:
PHP код:
UpdateHUD(playerid)
{
// Update HUD
}
new PLAYER_MONEY[MAX_PLAYERS];
new PLAYER_CLAN[MAX_PLAYERS][20];
new PLAYER_LEVEL[MAX_PLAYERS];
AddToMoneyStat(playerid, amount) {
PLAYER_MONEY[playerid] += amount;
BATCH(&UpdateHUD, playerid);
}
SetClanStat(playerid, const clan[]) {
format(PLAYER_CLAN[playerid], 20, "%s", clan);
BATCH(&UpdateHUD, playerid);
}
SetLevelStat(playerid, level) {
PLAYER_LEVEL[playerid] = level;
BATCH(&UpdateHUD, playerid);
}
public OnPlayerConnect(playerid) {
AddToMoneyStat(playerid, 500);
SetClanStat(playerid, "LVPD");
SetLevelStat(playerid, 0);
}
It can be made in many ways. Global or per-player:
PHP код:
BATCH(&Func);
BATCH(&Func, playerid);
BATCH(.name = "Func");
BATCH(using inline Func);
BATCH(using public Func, playerid);