So I got this code and it's not working. What's not working? Well this code supposed to give a player a decoy if after 3 seconds it sees that the player don't have one. Sadly, it's not doing so that's why I came here to ask for your help.
PHP Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <smlib>
new Handle:cvar_delay = INVALID_HANDLE;
new Handle:cvar_timer_enabled = INVALID_HANDLE;
new bool:timer_enabled;
new Float:delay;
public Plugin:myinfo =
{
name = "GiveWeapon",
description = "Give weapon"
};
public OnPluginStart()
{
cvar_timer_enabled = CreateConVar("sm_timer_repeat_enabled", "1", "Enabled timer repeat", 0, true, 0.0, true, 1.0);
timer_enabled = GetConVarBool(cvar_timer_enabled);
HookConVarChange(cvar_timer_enabled, CvarChanged);
cvar_delay = CreateConVar("sm_timer_repeat_delay", "3.0", "Timer will repeat this many seconds", 0, true, 5.0);
delay = GetConVarFloat(cvar_delay);
HookConVarChange(cvar_delay, CvarChanged);
}
public CvarChanged(Handle:convar, const String:oldValue[], const String:newValue[])
{
timer_enabled = GetConVarBool(cvar_timer_enabled);
delay = GetConVarFloat(cvar_delay);
}
public OnEntityCreated(entity, const String:classname[])
{
if(StrEqual(classname, "weapon_decoy"))
{
SDKHook(entity, SDKHook_SpawnPost, SpawnPost_Decoy)
}
}
public SpawnPost_Decoy(entity)
{
new client = Entity_GetOwner(entity);
PrintToChat(client, "test");
if (IsValidClient(client)&& !IsFakeClient(client))
{
if (timer_enabled)
CreateTimer(delay, Timer_callback, GetClientUserId(client), TIMER_REPEAT);
}
}
/*public SpawnPost_Decoy(entity)
{
new client = GetEntPropEnt(entity, Prop_Send, "m_hOwnerEntity");
if (timer_enabled)
CreateTimer(delay, Timer_callback, GetClientUserId(client), TIMER_REPEAT);
}*/
public Action:Timer_callback(Handle:timer, any:userid)
{
new client = GetClientOfUserId(userid);
if (!IsFakeClient(client)
&& IsClientInGame(client)
&& IsPlayerAlive(client))
GivePlayerItem(client, "weapon_decoy");
}
stock IsValidClient(client)
{
if (client > 0
&& client <= MaxClients
&& IsClientInGame(client))
return true;
return false;
}
__________________