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

Solved CS:GO Hook and GivePlayerItem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 08-04-2018 , 19:48   CS:GO Hook and GivePlayerItem
Reply With Quote #1

Hey, currently i have a error in my code, i would like to Hook player_spawn and give player weapon_deagle, but the compiler show me the error: error 017: undefined symbol "client"

Code:

PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_spawn"OnPlayerSpawn);
}

public 
Action OnPlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    if (
IsClientInGame(client))
    {
        
GivePlayerItem(client"weapon_deagle");
    }
    
    return 
Plugin_Continue;

any help is welcome, thanks

Last edited by iskenderkebab33; 11-03-2018 at 17:27.
iskenderkebab33 is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 08-04-2018 , 20:17   Re: CS:GO Hook and GivePlayerItem
Reply With Quote #2

on event hooks, a client is not defined so you need to get the event parameter
PHP Code:
int client GetClientOfUserId(event.GetInt("userid")); 
since you won't modify the event you can call it as void instead as an action, so no need of a return.
PHP Code:
#include <sdktools>

public void OnPluginStart() 

    
HookEvent("player_spawn"OnPlayerSpawn); 


public 
void OnPlayerSpawn(Event event, const char[] namebool dontBroadcast
{
    
int client GetClientOfUserId(event.GetInt("userid"));

    if (
client != && IsClientInGame(client))  //edit after neuro toxins post
    

        
GivePlayerItem(client"weapon_deagle"); 
    } 

__________________
coding & free software

Last edited by shanapu; 08-04-2018 at 20:25.
shanapu is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-04-2018 , 20:22   Re: CS:GO Hook and GivePlayerItem
Reply With Quote #3

PHP Code:
public void OnPluginStart()
{
    
HookEvent("player_spawn"OnPlayerSpawn);
}

public 
Action OnPlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
// Get client from userid in event parameters
    
int client GetClientOfUserId(event.GetInt("userid"));

    
// Make sure client is valid
    
if (client == 0)
        return 
Plugin_Continue;

    if (
IsClientInGame(client))
    {
        
GivePlayerItem(client"weapon_deagle");
    }
    
    return 
Plugin_Continue;

__________________
Neuro Toxin is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 08-04-2018 , 20:23   Re: CS:GO Hook and GivePlayerItem
Reply With Quote #4

Quote:
Originally Posted by Neuro Toxin View Post
PHP Code:
    // Make sure client is valid 
especially this
__________________
coding & free software
shanapu is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 08-04-2018 , 20:26   Re: CS:GO Hook and GivePlayerItem
Reply With Quote #5

I'm pretty sure spawn is called on connect, then when the team menu appears. I remember also adding checks for a valid team and is alive before giving items.
__________________

Last edited by Neuro Toxin; 08-04-2018 at 20:26.
Neuro Toxin is offline
iskenderkebab33
Senior Member
Join Date: Jun 2018
Old 08-04-2018 , 20:32   Re: CS:GO Hook and GivePlayerItem
Reply With Quote #6

thank you guys!
iskenderkebab33 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 06:37.


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