Member
Join Date: Jun 2012
Location: Poland - Wojnowice
|
08-05-2012
, 13:46
Timer invalid handle
|
#1
|
Hi,
my plugin for survival versus work. But sometimes it stop works. I have this issue too in other plugins wchich uses timers. Here is errors:
Code:
08/05/2012 - 19:35:03: [SM] Native "AcceptEntityInput" reported: Entity -1 (-1) is not a CBaseEntity
L 08/05/2012 - 19:35:03: [SM] Displaying call stack trace for plugin "autolauncher.smx":
L 08/05/2012 - 19:35:03: [SM] [0] Line 149, autolauncher.sp::SurvivalAutoStart()
L 08/05/2012 - 19:35:03: [SM] [1] Line 116, autolauncher.sp::Spawn_Timer()
L 08/05/2012 - 19:39:29: [SM] Native "KillTimer" reported: Invalid timer handle fbea0533 (error 1)
After server restart, timers still doesnt work.
Here is code:
Code:
#pragma semicolon 1
#include <sourcemod>
#include <sdktools>
#include <colors>
#include <smlib>
#define PLUGIN_NAME "l4d2 versus survival auto launcher"
public Plugin:myinfo =
{
name = PLUGIN_NAME,
author = "Pawemol",
description = "Auto Launcher for Versus Survival ",
version = "1.0",
url = "minigun.pl"
}
new bool:isVersusSurvival = false;
new bool:runda_on = false;
new Handle:timer_is_on = INVALID_HANDLE;
new Handle:czas;
public OnPluginStart()
{
decl String:game_name[64];
GetGameFolderName(game_name, sizeof(game_name));
if (!StrEqual(game_name, "left4dead2", false))
{
SetFailState("Plugin jest tylko do left 4 dead 2.");
}
decl String:mode[36];
new Handle:game_mode = FindConVar("mp_gamemode");
if (game_mode != INVALID_HANDLE)
{
GetConVarString(FindConVar("mp_gamemode"), mode, sizeof(mode));
}
CloseHandle(game_mode);
isVersusSurvival = StrEqual(mode, "mutation15");
czas = CreateConVar("czas", "89", "Czas po którym samo włącza się radio na survival versus?");
HookEvent("survival_round_start", start_rundy_survival, EventHookMode_PostNoCopy);
HookEvent("round_start", start_rundy, EventHookMode_PostNoCopy);
HookEvent("round_end", koniec_rundy, EventHookMode_Post);
HookEvent("item_pickup", Podniesienie_Przedmiotu, EventHookMode_PostNoCopy);
LoadTranslations("autolauncher.phrases");
HookConVarChange(czas, ConVarChanged);
AutoExecConfig(true, "sv_time");
}
public ConVarChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
decl String:nazwa_convar[90];
GetConVarName(convar, nazwa_convar, sizeof(nazwa_convar));
PrintToServer("Convar %s zmieniła wartość z %s na %s.", nazwa_convar, oldValue, newValue);
if (StringToInt(newValue) < 1)
{
PrintToServer("Minimalna prędkość włączania radia to 1s. A została podana wartość mniejsza niż minimalna. Zostaje więc przywrócona stara wartość ConVar.");
SetConVarInt(convar, StringToInt(oldValue));
}
else if (StringToInt(oldValue) > StringToInt(newValue))
{
PrintToServer("Teraz radio w trybie przetrwanie(kontra) będzie się włączać %i s szybciej.", StringToInt(oldValue) - StringToInt(newValue));
}
else if (StringToInt(oldValue) < StringToInt(newValue))
{
PrintToServer("Teraz radio w trybie przetrwanie(kontra) będzie się włączać %i s wolniej.", StringToInt(newValue) - StringToInt(oldValue));
}
else
{
PrintToServer("Została podana zła wartość convar. Musi zostać przywrócona stara wartość.");
SetConVarInt(convar, StringToInt(oldValue));
}
//PrintToserver("Teraz radio w trybie Przetrwanie(kontra)
}
public OnMapStart()
{
timer_is_on = INVALID_HANDLE;
runda_on = false;
}
public Podniesienie_Przedmiotu(Handle:event, const String:name[], bool:dontBroadcast)
{
if (timer_is_on == INVALID_HANDLE && isVersusSurvival && !runda_on)
{
timer_is_on = CreateTimer(float(GetConVarInt(czas)), Spawn_Timer, _, TIMER_FLAG_NO_MAPCHANGE);
runda_on = true;
}
}
public start_rundy(Handle:event, const String:name[], bool:dontBroadcast)
{
if (timer_is_on == INVALID_HANDLE && isVersusSurvival && !runda_on)
{
timer_is_on = CreateTimer(float(GetConVarInt(czas)), Spawn_Timer, _, TIMER_FLAG_NO_MAPCHANGE);
runda_on = true;
}
}
public koniec_rundy(Handle:event, const String:name[], bool:dontBroadcast)
{
if (GetEventInt(event, "reason") == 0)
{
runda_on = false;
if (timer_is_on != INVALID_HANDLE)
{
KillTimer(timer_is_on);
timer_is_on = INVALID_HANDLE;
}
}
}
public Action:Spawn_Timer(Handle:timer)
{
if (timer_is_on != INVALID_HANDLE && runda_on && isVersusSurvival)
{
CPrintToChatAll("%t", "Radio");
SurvivalAutoStart();
timer_is_on = INVALID_HANDLE;
}
}
public start_rundy_survival(Handle:event, const String:name[], bool:dontBroadcast)
{
CPrintToChatAll("%t", "Round_Start");
CPrintToChatAll("%t", "Prepare");
if (timer_is_on != INVALID_HANDLE)
{
KillTimer(timer_is_on);
timer_is_on = INVALID_HANDLE;
}
}
public OnMapEnd()
{
runda_on = false;
if (timer_is_on != INVALID_HANDLE)
{
KillTimer(timer_is_on);
timer_is_on = INVALID_HANDLE;
}
}
static SurvivalAutoStart()
{
new trigger = FindSurvivalButton();
if (trigger == -1)
{
CheatCommand(GetRandomClient(), "director_force_panic_event");
}
AcceptEntityInput(trigger, "Press");
CPrintToChatAll("%t", "Info");
}
static FindSurvivalButton()
{
decl String:buffer[96];
new ent = -1;
while ((ent = FindEntityByClassname(ent, "func_button")) != -1)
{
if (ent)
{
Entity_GetName(ent, buffer, sizeof(buffer));
if (StrContains(buffer, "survival", true) != -1)
{
return ent;
}
}
}
return -1;
}
CheatCommand(client, const String:command[], const String:arguments[]="")
{
if (!client) return;
new admindata = GetUserFlagBits(client);
SetUserFlagBits(client, ADMFLAG_ROOT);
new flags = GetCommandFlags(command);
SetCommandFlags(command, flags & ~FCVAR_CHEAT);
FakeClientCommand(client, "%s %s", command, arguments);
SetCommandFlags(command, flags);
SetUserFlagBits(client, admindata);
}
GetRandomClient()
{
for( new i = 1; i <= MaxClients; i++ )
if( IsClientInGame(i) && !IsFakeClient(i) )
return i;
return 0;
}
|
|