AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugin/Gameplay Ideas and Requests (https://forums.alliedmods.net/forumdisplay.php?f=60)
-   -   Solved [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid (https://forums.alliedmods.net/showthread.php?t=320760)

ttfak12 01-08-2020 03:04

[L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
 
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 


ttfak12 01-08-2020 03:14

[L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
 
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 


Marttt 01-08-2020 04:42

Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
 
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));

Drixevel 01-08-2020 05:57

Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
 
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.

ttfak12 01-08-2020 22:39

Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
 
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.

Silvers 01-08-2020 22:59

Re: [L4D1] [SM] Native "GetClientHealth" reported: Client index 54 is invalid
 
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.

ttfak12 01-09-2020 10:37

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

Originally Posted by Silvers (Post 2679483)
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


All times are GMT -4. The time now is 20:51.

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