Raised This Month: $32 Target: $400
 8% 

[Help] Giving players healthshots


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
trannygranny
Junior Member
Join Date: Jul 2017
Old 05-14-2018 , 22:33   [Help] Giving players healthshots
Reply With Quote #1

Code:
#include <sourcemod>
#include <sdkhooks>
#include <sdktools_functions>

public Plugin:myinfo = 
{
    name = "Give Healthshot",
    description = "Gives a healthshot to all players every round."
}

public OnPluginStart()
{
    HookEvent( "player_spawn", SpawnEvent );
}

public Action:SpawnEvent(Handle:event,const String:name[],bool:dontBroadcast)
{
	new client_id = GetEventInt(event, "userid");
	new client = GetClientOfUserId(client_id);
	ServerCommand( "sm_giveweapon %i weapon_healthshot", client );
	ServerCommand( "sm_giveweapon %i healthshot", client );
}
Anyone know why this isn't working?
trannygranny is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 05-14-2018 , 22:49   Re: [Help] Giving players healthshots
Reply With Quote #2

If whatever plugin provides that functionality just uses ProcessTargetString, then it won't understand cliend IDs and you use should use the user ID prefixed by #.

If that plugin provides natives (which it does, from Googling), you should absolutely use them and not ServerCommand.

If you have a specific question about that other plugin, you should ask in its thread.
Fyren is offline
LenHard
Senior Member
Join Date: Jan 2016
Old 05-15-2018 , 05:03   Re: [Help] Giving players healthshots
Reply With Quote #3

PHP Code:
#include <sourcemod>
#include <sdktools_functions>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
}

public 
void Event_PlayerSpawn(Event hEvent, const char[] sEventNamebool bDontBroadcast)
{
    
int iUser hEvent.GetInt("userid");

    if (
IsClientInGame(GetClientOfUserId(iUser))) {
        
CreateTimer(0.7Timer_DelayiUser); // Delay to be safe
    
}
}

public 
Action Timer_Delay(Handle hTimerint iUser)
{
    
int client GetClientOfUserId(iUser);
    
    if (
IsClientInGame(client)) {
        
GivePlayerItem(client"weapon_healthshot");
    }

Try this
__________________

Last edited by LenHard; 05-15-2018 at 05:04.
LenHard is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 05-15-2018 , 05:51   Re: [Help] Giving players healthshots
Reply With Quote #4

Quote:
Originally Posted by LenHard View Post
PHP Code:
#include <sourcemod>
#include <sdktools_functions>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
}

public 
void Event_PlayerSpawn(Event hEvent, const char[] sEventNamebool bDontBroadcast)
{
    
int iUser hEvent.GetInt("userid");

    if (
IsClientInGame(GetClientOfUserId(iUser))) {
        
CreateTimer(0.7Timer_DelayiUser); // Delay to be safe
    
}
}

public 
Action Timer_Delay(Handle hTimerint iUser)
{
    
int client GetClientOfUserId(iUser);
    
    if (
IsClientInGame(client)) {
        
GivePlayerItem(client"weapon_healthshot");
    }

Try this
If this is for TF2, when a player touches the resupply locker, they will lose the weapon and not get it back. You need to hook post_inventory _application instead and get rid of the timer. If this is not for TF2, completely disregard this post.

Last edited by ThatKidWhoGames; 05-15-2018 at 05:53.
ThatKidWhoGames is offline
Psyk0tik
Veteran Member
Join Date: May 2012
Location: Homeless
Old 05-15-2018 , 07:25   Re: [Help] Giving players healthshots
Reply With Quote #5

Quote:
Originally Posted by LenHard View Post
PHP Code:
#include <sourcemod>
#include <sdktools_functions>

#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
}

public 
void Event_PlayerSpawn(Event hEvent, const char[] sEventNamebool bDontBroadcast)
{
    
int iUser hEvent.GetInt("userid");

    if (
IsClientInGame(GetClientOfUserId(iUser))) {
        
CreateTimer(0.7Timer_DelayiUser); // Delay to be safe
    
}
}

public 
Action Timer_Delay(Handle hTimerint iUser)
{
    
int client GetClientOfUserId(iUser);
    
    if (
IsClientInGame(client)) {
        
GivePlayerItem(client"weapon_healthshot");
    }

Try this
Shorten the code up a bit like this:

PHP Code:
#include <sourcemod>
#include <sdktools_functions>
#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
}

public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int iUser GetClientOfUserId(event.GetInt("userid"));
    if (
IsClientInGame(iUser))
    {
        
CreateTimer(0.7Timer_DelayiUser); // Delay to be safe
    
}
}

public 
Action Timer_Delay(Handle timerany client)
{
    if (
IsClientInGame(client))
    {
        
GivePlayerItem(client"weapon_healthshot");
    }

__________________
Psyk0tik is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 05-15-2018 , 11:22   Re: [Help] Giving players healthshots
Reply With Quote #6

Quote:
Originally Posted by Crasher_3637 View Post
Shorten the code up a bit like this:

PHP Code:
#include <sourcemod>
#include <sdktools_functions>
#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawnEventHookMode_Post);
}

public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int iUser GetClientOfUserId(event.GetInt("userid"));
    if (
IsClientInGame(iUser))
    {
        
CreateTimer(0.7Timer_DelayiUser); // Delay to be safe
    
}
}

public 
Action Timer_Delay(Handle timerany client)
{
    if (
IsClientInGame(client))
    {
        
GivePlayerItem(client"weapon_healthshot");
    }

PHP Code:
#include <sourcemod>
#include <sdktools_functions>
#pragma semicolon 1
#pragma newdecls required

public void OnPluginStart()
{
    
HookEvent("player_spawn"Event_PlayerSpawn);
}

public 
void Event_PlayerSpawn(Event event, const char[] namebool dontBroadcast)
{
    
int userid event.GetInt("userid"), client GetClientOfUserId(userid);
    if (
IsValidClient(client))
    {
        
CreateTimer(0.7Timer_Delayuserid); // Delay to be safe
    
}
}

public 
Action Timer_Delay(Handle timerany userid)
{
    
int client GetClientOfUserId(userid);
    if (
IsValidClient(client))
    {
        
GivePlayerItem(client"weapon_healthshot");
    }
}

bool IsValidClient(int client)
{
    return 
client && client <= MaxClients && IsClientInGame(client);

Added a proper valid client check. I believe IsClientInGame still counts the console. Also, the event mode defaults to post so I got rid of that.

Last edited by ThatKidWhoGames; 05-15-2018 at 11:57.
ThatKidWhoGames is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 05-15-2018 , 11:31   Re: [Help] Giving players healthshots
Reply With Quote #7

don't pass clientIDs through timers, always use userIDs
__________________
coding & free software
shanapu is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 05-15-2018 , 11:36   Re: [Help] Giving players healthshots
Reply With Quote #8

Quote:
Originally Posted by shanapu View Post
don't pass clientIDs through timers, always use userIDs
Out of curiosity, why is that? I've seen people say that before. Is it to make sure the correct player you are trying to target is affected?

Last edited by ThatKidWhoGames; 05-15-2018 at 11:36.
ThatKidWhoGames is offline
shanapu
Veteran Member
Join Date: Apr 2015
Location: .de
Old 05-15-2018 , 11:51   Re: [Help] Giving players healthshots
Reply With Quote #9

Quote:
Originally Posted by ThatKidWhoGames View Post
Out of curiosity, why is that? I've seen people say that before. Is it to make sure the correct player you are trying to target is affected?
yes, when the timer (or Request Frame) runs the client could disconnect and a new player could join and get the same clientID.
__________________
coding & free software
shanapu is offline
ThatKidWhoGames
Veteran Member
Join Date: Jun 2013
Location: IsValidClient()
Old 05-15-2018 , 11:56   Re: [Help] Giving players healthshots
Reply With Quote #10

Quote:
Originally Posted by shanapu View Post
yes, when the timer (or Request Frame) runs the client could disconnect and a new player could join and get the same clientID.
Thanks for the info! As such, I have updated my post with the code to use the userid instead of the client's id.
ThatKidWhoGames 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 15:44.


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