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

Client index 0 is invalid?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 01-07-2014 , 01:14   Client index 0 is invalid?
Reply With Quote #1

Hello i'm writing a plugin for L4D2 anti player TK,everything can work but the log file always show errors like this:

PHP Code:
L 01/07/2014 14:06:52: [SMNative "GetClientTeam" reportedClient index 0 is invalid
L 01
/07/2014 14:06:52: [SMDisplaying call stack trace for plugin "l4d2_zantiTK.smx":
L 01/07/2014 14:06:52: [SM]   [0]  Line 32l4d2_antiTK.sp::Player_Hurt()
L 01/07/2014 14:06:53: [SMNative "GetClientTeam" reportedClient index 0 is invalid
L 01
/07/2014 14:06:53: [SMDisplaying call stack trace for plugin "l4d2_zantiTK.smx":
L 01/07/2014 14:06:53: [SM]   [0]  Line 32l4d2_antiTK.sp::Player_Hurt()
L 01/07/2014 14:06:53: [SMNative "GetClientTeam" reportedClient index 0 is invalid
L 01
/07/2014 14:06:53: [SMDisplaying call stack trace for plugin "l4d2_zantiTK.smx":
L 01/07/2014 14:06:53: [SM]   [0]  Line 32l4d2_antiTK.sp::Player_Hurt()
L 01/07/2014 14:06:54: [SMNative "GetClientTeam" reportedClient index 0 is invalid
L 01
/07/2014 14:06:54: [SMDisplaying call stack trace for plugin "l4d2_zantiTK.smx":
L 01/07/2014 14:06:54: [SM]   [0]  Line 32l4d2_antiTK.sp::Player_Hurt()
L 01/07/2014 14:06:54: [SMNative "GetClientTeam" reportedClient index 0 is invalid
L 01
/07/2014 14:06:54: [SMDisplaying call stack trace for plugin "l4d2_zantiTK.smx":
L 01/07/2014 14:06:54: [SM]   [0]  Line 32l4d2_antiTK.sp::Player_Hurt()
L 01/07/2014 14:06:54: [SMNative "GetClientTeam" reportedClient index 0 is invalid
L 01
/07/2014 14:06:54: [SMDisplaying call stack trace for plugin "l4d2_zantiTK.smx":
L 01/07/2014 14:06:54: [SM]   [0]  Line 32l4d2_antiTK.sp::Player_Hurt()
L 01/07/2014 14:06:59: [SMNative "GetClientTeam" reportedClient index 0 is invalid
L 01
/07/2014 14:06:59: [SMDisplaying call stack trace for plugin "l4d2_zantiTK.smx":
L 01/07/2014 14:06:59: [SM]   [0]  Line 32l4d2_antiTK.sp::Player_Hurt()
L 01/07/2014 14:07:00: [SMNative "GetClientTeam" reportedClient index 0 is invalid
L 01
/07/2014 14:07:00: [SMDisplaying call stack trace for plugin "l4d2_zantiTK.smx":
L 01/07/2014 14:07:00: [SM]   [0]  Line 32l4d2_antiTK.sp::Player_Hurt() 
My sourcecode is here,any help?
PHP Code:
#include <sdktools>
#include <sourcemod>
#include <sdkhooks>
#pragma semicolon 1

#define CVAR_FLAGS FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY

#define IsValidClient(%1)        (1 <= %1 <= MaxClients && IsClientInGame(%1))

#define PLUGIN_VERSION "1.0"

public Plugin:myinfo 
{
    
name "Anti TK",
    
author "xxx",
    
description "Regen and TK",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net/"
}

public 
OnPluginStart()
{
    
HookEvent("player_hurt"Player_Hurt);
}

public 
Action:Player_Hurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    new 
victim GetEventInt(event"userid");
    
    if(
IsValidClient(victim))
    {
        if(
GetClientTeam(attacker) == && GetClientTeam(victim) == 2)
        {
            new 
dmg_health GetEventInt(event"dmg_health");     // get the amount of damage done
                
new health GetEntProp(attackerProp_Data"m_iHealth") - dmg_health;
                
SetEntProp(attackerProp_Data"m_iHealth"health);
        }
    }

Also there's a littile bug: when player health is 0,player won't incapacitate still stand there?

Last edited by gilmon; 01-07-2014 at 01:16.
gilmon is offline
Send a message via MSN to gilmon
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 01-07-2014 , 01:30   Re: Client index 0 is invalid?
Reply With Quote #2

What is "IsValidClient" doing/NOT doing?

Error's description is kind of, well, obvious.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 01-07-2014 , 01:41   Re: Client index 0 is invalid?
Reply With Quote #3

You should check valid attacker too:
PHP Code:
if(IsValidClient(attacker) && IsValidClient(victim))
{
    
//attcker is player and victim is player too.


Last edited by yokomo; 01-07-2014 at 01:42.
yokomo is offline
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 01-07-2014 , 01:41   Re: Client index 0 is invalid?
Reply With Quote #4

ok after remove it still like that(thanks)

also 0 health is a problem
gilmon is offline
Send a message via MSN to gilmon
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 01-07-2014 , 01:41   Re: Client index 0 is invalid?
Reply With Quote #5

If you're using ...
PHP Code:
stock bool:IsValidClient(iClient)
{
    if(
iClient <= || iClient MaxClients || !IsClientInGame(iClient))
        return 
false;
    return 
true;

... you should check if the attacker is valid as-well.
That should fix your problem.
Note: Client index 0, is the world-spawn, not an actual player index.

Edit: 3 Posts in a minute...

Last edited by ReFlexPoison; 01-07-2014 at 01:42.
ReFlexPoison is offline
gilmon
Senior Member
Join Date: Feb 2011
Location: China
Old 01-07-2014 , 01:45  
Reply With Quote #6

Quote:
Originally Posted by yokomo View Post
You should check valid attacker too:
PHP Code:
if(IsValidClient(attacker) && IsValidClient(victim))
{
    
//attcker is player and victim is player too.

Thanks,no more client 0 error now

Thanks everyone here,now the only problem is health 0,any fix?

I tried something like this but no luck(no error)

PHP Code:
new iDmgEntity CreateEntityByName("point_hurt");
SetEntityHealth(attacker1);
DispatchKeyValue(attacker"targetname""bm_target");
DispatchKeyValue(iDmgEntity"DamageTarget""bm_target");
DispatchKeyValue(iDmgEntity"Damage""100");
DispatchKeyValue(iDmgEntity"DamageType""0");
DispatchSpawn(iDmgEntity);
AcceptEntityInput(iDmgEntity"Hurt"attacker);
DispatchKeyValue(attacker"targetname""bm_targetoff");
RemoveEdict(iDmgEntity); 

Last edited by thetwistedpanda; 01-11-2014 at 17:00.
gilmon is offline
Send a message via MSN to gilmon
TnTSCS
AlliedModders Donor
Join Date: Oct 2010
Location: Undisclosed...
Old 01-07-2014 , 10:26   Re: Client index 0 is invalid?
Reply With Quote #7

Take a look at SMLib's Entity_Hurt code.

PHP Code:
/**
 * Does damage to an entity.
 * This is a powerful function that allows you to specify
 * who the attacker is, the damage type and also what weapon
 * should be displayed in the hud kill message.
 * Note that for entities that fire another entity (RPG's, Crossbow's,
 * you have to pass the bullet's class, not the weapon's class !
 * It hasn't been tested how expensive this function is, as it
 * uses the entity point_hurt.
 * If you need a cheaper function use Entity_RemoveHealth().
 *
 * @param entity            Entity index.
 * @param damage            Amount of damage.
 * @param attacker        Entity Index of the attacker.
 * @param damageType        Use the DMG_ definations.
 * @param fakeClassName    Classname to fake, you can set this if you
 *                         want a specific weapon to be shown in the HUD kill message.
 * @return                 True on success, false otherwise.
 */
stock bool:Entity_Hurt(entitydamageattacker=0damageType=DMG_GENERIC, const String:fakeClassName[]=""
__________________
View my Plugins | Donate
TnTSCS is offline
Root_
Veteran Member
Join Date: Jan 2012
Location: ryssland
Old 01-07-2014 , 10:42   Re: Client index 0 is invalid?
Reply With Quote #8

SDKHooks_TakeDamage
__________________


dodsplugins.com - Plugins and Resources for Day of Defeat
http://twitch.tv/zadroot
Root_ is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 01-07-2014 , 15:16   Re: Client index 0 is invalid?
Reply With Quote #9

I don't see why people check if the victim is valid, the event can't be called if there is no victim, it just logical.
Mathias. is offline
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 01-07-2014 , 15:31   Re: Client index 0 is invalid?
Reply With Quote #10

Quote:
Originally Posted by Black-Rabbit View Post
I don't see why people check if the victim is valid, the event can't be called if there is no victim, it just logical.
Cuz valve

Cuz whynot

Cuz does it really matter?

You can just recompile the plugin to your liking if you are going to use it.

Last edited by ReFlexPoison; 01-07-2014 at 15:31.
ReFlexPoison 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 12:30.


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