Помогите оптимизировать код и исправить ошибки
в public Action:AFK_Timer_Func(Handle:timer, any:client) закомментировал PrintToChatAll, потому что когда АФК-КТ умирает в чат бесконечно пишется текст что игрок убит (пока не начнется новый раунд.
Сделал как то замудрено: HookEvent("player_death", playerDeath); и в нем PrintToChatAll теперь пишется 1 раз, чат не засирает, но меня напрягает громоздкий код и
ошибки в логах
PHP:
#include <sourcemod>
#include <sdktools_functions>
new Handle:my_timer[MAXPLAYERS+1];
new Float:afk_timer = 3.0,
Float:afk_pos[MAXPLAYERS+1][3];
public OnPluginStart()
{
HookConVarChange(CreateConVar("afk_timer", "5"), cvar_afk_timer);
HookEvent("player_death", playerDeath);
}
public cvar_afk_timer(Handle:convar, const String:oldValue[], const String:newValue[]) afk_timer = float(EditValue(newValue));
EditValue(const String:newValue[])
{
new value = StringToInt(newValue);
if (value < 1) value = 1;
return value;
}
public OnClientDisconnect(client)
{
if (my_timer[client] != INVALID_HANDLE)
{
KillTimer(my_timer[client]);
my_timer[client] = INVALID_HANDLE;
}
}
public OnClientPutInServer(client)
{
if (!IsFakeClient(client))
{
my_timer[client] = CreateTimer(afk_timer, AFK_Timer_Func, client, TIMER_REPEAT);
}
}
public Action:AFK_Timer_Func(Handle:timer, any:client)
{
//if (GetClientTeam(client) == 3 && !IsPlayerAlive(client)) return Plugin_Continue;
// afk
decl Float:x_vec[3];
GetClientAbsOrigin(client, x_vec);
if (GetClientTeam(client) == 3 && !(GetUserFlagBits(client) & ADMFLAG_ROOT) && x_vec[0] == afk_pos[client][0] && x_vec[1] == afk_pos[client][1])
{
//if (GetClientTeam(client) == 3 && !IsPlayerAlive(client))
my_timer[client] = INVALID_HANDLE;
ForcePlayerSuicide(client);
//PrintToChatAll("\x01\x05[AFK-CT]\x01 Игрок \x03%N\x01 убит!", client)
return Plugin_Continue;
}
else
{
afk_pos[client][0] = x_vec[0];
afk_pos[client][1] = x_vec[1];
}
return Plugin_Continue;
}
public Action:playerDeath(Handle:event, const String:name[], bool:dontBroadcast)
{
new client = GetClientOfUserId(GetEventInt(event, "userid"));
if (GetClientTeam(client) == 3)
{
PrintToChatAll("\x01\x05[AFK-CT]\x01 Игрок \x03%N\x01 убит!", client)
}
}
Сделал как то замудрено: HookEvent("player_death", playerDeath); и в нем PrintToChatAll теперь пишется 1 раз, чат не засирает, но меня напрягает громоздкий код и
ошибки в логах
C-подобный:
L 01/21/2013 - 23:11:36: [SM] Native "GetClientAbsOrigin" reported: Client 1 is not in game
L 01/21/2013 - 23:11:36: [SM] Displaying call stack trace for plugin "AFKControl.smx":
L 01/21/2013 - 23:11:36: [SM] [0] Line 55, AFKControl.sp::AFK_Timer_Func()
L 01/21/2013 - 23:11:39: [SM] Native "GetClientAbsOrigin" reported: Client 1 is not in game
L 01/21/2013 - 23:11:39: [SM] Displaying call stack trace for plugin "AFKControl.smx":
L 01/21/2013 - 23:11:39: [SM] [0] Line 55, AFKControl.sp::AFK_Timer_Func()
L 01/21/2013 - 23:11:42: [SM] Native "GetClientAbsOrigin" reported: Client 1 is not in game
L 01/21/2013 - 23:11:42: [SM] Displaying call stack trace for plugin "AFKControl.smx":
L 01/21/2013 - 23:11:42: [SM] [0] Line 55, AFKControl.sp::AFK_Timer_Func()
L 01/21/2013 - 23:11:45: [SM] Native "GetClientAbsOrigin" reported: Client 1 is not in game
L 01/21/2013 - 23:11:45: [SM] Displaying call stack trace for plugin "AFKControl.smx":
L 01/21/2013 - 23:11:45: [SM] [0] Line 55, AFKControl.sp::AFK_Timer_Func()
Последнее редактирование: