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

Solved [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ttfak12
Junior Member
Join Date: Mar 2016
Old 01-08-2020 , 03:04   [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
Reply With Quote #1

PHP Code:
HookEvent("tank_spawn"Event_Tank_Spawn);
public 
Action:Event_Tank_Spawn(Handle:eventString:name[], bool:dontBroadcast)
{
    new 
Client GetEventInt(event"userid");
        
CreateTimer(0.5SetTankGClient); 
}
public 
Action:SetTankG(Handle:timerany:Client)
{
    new 
tankHps GetConVarInt(FindConVar("z_tank_health"));
    new 
hardhp GetClientHealth(Client);
    if (
hardhp >= tankHp*21000)
    {

    }
}


 [
SMNative "GetClientHealth" reportedClient index 54 is invalid 

Last edited by ttfak12; 01-10-2020 at 01:44.
ttfak12 is offline
ttfak12
Junior Member
Join Date: Mar 2016
Old 01-08-2020 , 03:14   [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
Reply With Quote #2

PHP Code:
HookEvent("tank_spawn"Event_Tank_Spawn);
public 
Action:Event_Tank_Spawn(Handle:eventString:name[], bool:dontBroadcast)
{
    new 
Client GetEventInt(event"userid");
        
CreateTimer(0.5SetTankGClient); 
}
public 
Action:SetTankG(Handle:timerany:Client)
{
    new 
hardhp GetClientHealth(Client);
    if (
hardhp >= tankHp*21000)
    {

    }
}


 [
SMNative "GetClientHealth" reportedClient index 54 is invalid 
ttfak12 is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 01-08-2020 , 04:42   Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
Reply With Quote #3

You should post more lines from the log so it shows which line throws the error
Btw is a good practise to also check if the client is valid

I always use this stock here

stock bool IsValidClient(int iClient)
{
return (iClient > 0 && iClient <= MaxClients && IsClientInGame(iClient));
}

also "userid" returns the ClientUserId and not the ClientId (index) so u need to convert that inside the timer

GetClientHealth(GetClientOfUserId(Client));
__________________
Marttt is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 01-08-2020 , 05:57   Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
Reply With Quote #4

Code:
HookEvent("tank_spawn", Event_Tank_Spawn);

public void Event_Tank_Spawn(Event event, const char[] name, bool dontBroadcast)
{
	CreateTimer(0.5, SetTankG, event.GetInt("userid")); 
}

public Action SetTankG(Handle timer, any userid)
{
	int client;
	if ((client = GetClientOfUserId(userid) == 0 || !IsClientInGame(client) || !IsPlayerAlive(client))
		return Plugin_Stop;
	
    int hardhp = GetClientHealth(Client);
	
    if (hardhp >= tankHp * 2 - 1000)
    {

    }
	
	return Plugin_Stop;
}
Need to turn the userid into a client index in the callback.
Drixevel is offline
ttfak12
Junior Member
Join Date: Mar 2016
Old 01-08-2020 , 22:39   Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
Reply With Quote #5

Thank you both for your help.
I wrote it wrong.

HookEvent("tank_spawn", Event_Tank_Spawn);
public Action:Event_Tank_Spawn(Handle:event, String:name[], bool:dontBroadcast)
{
new Client = GetClientOfUserId(GetEventInt(event, "userid"));
CreateTimer(0.5, SetTankG, Client);
}

Now it works fine.
ttfak12 is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 01-08-2020 , 22:59   Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
Reply With Quote #6

You should be pushing the userid into CreateTimer and GetClientOfUserID in the timer callback to correctly validate the client. Drixevel already showed you this, your code above is wrong.
__________________

Last edited by Silvers; 01-08-2020 at 22:59.
Silvers is offline
ttfak12
Junior Member
Join Date: Mar 2016
Old 01-09-2020 , 10:37   Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
Reply With Quote #7

Quote:
Originally Posted by Silvers View Post
You should be pushing the userid into CreateTimer and GetClientOfUserID in the timer callback to correctly validate the client. Drixevel already showed you this, your code above is wrong.
thx. I solved
ttfak12 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 22:33.


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