Raised This Month: $51 Target: $400
 12% 

[CS:GO] Give weapon if don't have


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Baws
Veteran Member
Join Date: Oct 2012
Old 05-09-2015 , 18:59   [CS:GO] Give weapon if don't have
Reply With Quote #1

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"0true0.0true1.0);
    
timer_enabled GetConVarBool(cvar_timer_enabled);
    
HookConVarChange(cvar_timer_enabledCvarChanged);
 
    
cvar_delay CreateConVar("sm_timer_repeat_delay""3.0""Timer will repeat this many seconds"0true5.0);
    
delay GetConVarFloat(cvar_delay);
    
HookConVarChange(cvar_delayCvarChanged);
}
 
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(entitySDKHook_SpawnPostSpawnPost_Decoy)
    }
}

public 
SpawnPost_Decoy(entity)
{
    new 
client Entity_GetOwner(entity);

    
PrintToChat(client"test");

    if (
IsValidClient(client)&& !IsFakeClient(client))
    {
        if (
timer_enabled)
            
CreateTimer(delayTimer_callbackGetClientUserId(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:timerany:userid)
{
     new 
client GetClientOfUserId(userid);
 
    if (!
IsFakeClient(client)
    && 
IsClientInGame(client)
    && 
IsPlayerAlive(client))
        
GivePlayerItem(client"weapon_decoy");
}

stock IsValidClient(client)
{
    if (
client 
    
&& client <= MaxClients 
    
&& IsClientInGame(client))
        return 
true;

    return 
false;

__________________
Like my clean plugins and work?
Baws is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 05-10-2015 , 11:11   Re: [CS:GO] Give weapon if don't have
Reply With Quote #2

Code:
#include <sourcemod>
#include <sdktools>
#include <sdkhooks>
#include <smlib>

new Handle:cvar_timer_enabled = INVALID_HANDLE;
new Handle:cvar_delay = INVALID_HANDLE;

public OnPluginStart()
{
	cvar_timer_enabled = CreateConVar("sm_timer_repeat_enabled", "1", "Enabled timer repeat", 0, true, 0.0, true, 1.0);
	cvar_delay = CreateConVar("sm_timer_repeat_delay", "3.0", "Timer will repeat this many seconds", 0, true, 5.0);
}

public OnEntityCreated(entity, const String:classname[])
{
	if (GetConVarBool(cvar_timer_enabled) && StrEqual(classname, "weapon_decoy"))
	{
		SDKHook(entity, SDKHook_SpawnPost, SpawnPost_Decoy);
	}
}

public SpawnPost_Decoy(entity)
{
	new client = Entity_GetOwner(entity);

	if (IsClientInGame(client) && !IsFakeClient(client))
	{
		CreateTimer(GetConVarFloat(cvar_delay), Timer_callback, GetClientUserId(client), TIMER_REPEAT);
	}
}

public Action:Timer_callback(Handle:timer, any:data)
{
	new client = GetClientOfUserId(data);

	if (IsClientInGame(client) && !IsFakeClient(client) && IsPlayerAlive(client))
	{
		GivePlayerItem(client, "weapon_decoy");
	}
}
Drixevel is offline
Baws
Veteran Member
Join Date: Oct 2012
Old 05-10-2015 , 11:22   Re: [CS:GO] Give weapon if don't have
Reply With Quote #3

I tested it and this is the error:

Code:
L 05/10/2015 - 10:17:15: [SM] Native "IsClientInGame" reported: Client index -1 is invalid
L 05/10/2015 - 10:17:15: [SM] Displaying call stack trace for plugin "giveweapon.smx":
L 05/10/2015 - 10:17:15: [SM]   [0]  Line 27, C:\Users\Bilal\Desktop\Baws\AG CSGO\AG DECOYDODGEBALL SERVER\sourcemod-1.6.4-git4625-windows\addons\sourcemod\scripting\giveweapon.sp::SpawnPost_Decoy()
L 05/10/2015 - 10:17:20: [SM] Native "IsClientInGame" reported: Client index -1 is invalid
L 05/10/2015 - 10:17:20: [SM] Displaying call stack trace for plugin "giveweapon.smx":
__________________
Like my clean plugins and work?
Baws is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:16.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode