AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   Displaying call stack trace for plugin (https://forums.alliedmods.net/showthread.php?t=199003)

kikal767 10-23-2012 00:59

Displaying call stack trace for plugin
 
I have write a new plugins..and I got this error logs

PHP Code:

L 10/23/2012 12:43:05: [SMNative "GetEntPropEnt" reportedProperty "m_jockeyVictim" not found (entity 0/worldspawn)
L 10/23/2012 12:43:05: [SMDisplaying call stack trace for plugin "L4d2_Jockey acid swipe.smx":
L 10/23/2012 12:43:05: [SM]   [0]  Line 79D:\steamapps\common\left 4 dead 2\left4dead2\addons\sourcemod\scripting\L4d2_Jockey Acid Swipe.sp::Event_PlayerHurt() 

PHP Code:

public Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
Jockey GetClientOfUserId(GetEventInt(event"attacker"));
    new 
target GetClientOfUserId(GetEventInt(event"userid"));
    new 
duration GetConVarInt(FindConVar("sm_Jockey_acidswipe_duration"));
    new 
stack GetConVarInt(FindConVar("sm_Jockey_acidswipe_stack"));
    new 
Jockey_Victim GetEntPropEnt(JockeyProp_Send"m_jockeyVictim");
    
    
decl String:weapon[64];
    
GetEventString(event"weapon"weaponsizeof(weapon));
    
    if((
GetClientTeam(target) == 2) && (StrEqual(weapon"jockey_claw")))
    {
        if (
IsValidEntity(Jockey_Victim) && Jockey_Victim != 0)
        {
            return 
Plugin_Continue;
        } else
        {
            
attacker[target] = Jockey;
            if(
hurtsLeft[target] <= 0)
            {
                
hurtsLeft[target] = duration;
                
CreateTimer(1.0Acid_Damagetarget);
            } else
            {
                if(
stack == -1)
                {
                    
hurtsLeft[target] = duration;
                } else
                {
                    if(
stack >= 0)
                    {
                        
hurtsLeft[target] += stack;
                    } else
                    {
                        
//sm_Jockey_acidswipe_stack has invalid value so log error
                        
LogError("sm_Jockey_acidswipe_stack has an invalid value. Accepted values are -1 and higher.");
                    }
                }
            }
        }
    }
    return 
Plugin_Continue;
}

public 
Action:Acid_Damage(Handle:timerany:client)
{
    if(
hurtsLeft[client] <= 0)
    {
        
attacker[client] = 0;
        return;
    } else
    {
        
hurtsLeft[client] -= 1;
    }
    if(
client == 0)
    {
        
attacker[client] = 0;
        
hurtsLeft[client] = 0;
        return;
    }
    if(!
IsClientInGame(client))
    {
        
attacker[client] = 0;
        
hurtsLeft[client] = 0;
        return;
    }
    if(!
IsPlayerAlive(client))
    {
        
attacker[client] = 0;
        
hurtsLeft[client] = 0;
        return;
    }
    if(
GetClientTeam(client) != 2)
    {
        
attacker[client] = 0;
        
hurtsLeft[client] = 0;
        return;
    }
    
#if defined DEBUG
    
    
EmitSoundToClient(ClientAcid_Sound);

    
#endif
    
    
DamageEffect(client);
    
    if(
hurtsLeft[client] > 0)
    {
        
CreateTimer(1.0Acid_Damageclient);
    }
    return;


PHP Code:

public OnMapStart()
{
    
PrecacheSound(Acid_Soundtrue);
}

public 
Action:round_start(Handle:event, const String:name[], bool:dontBroadcast)
{

    if(
timer_handle != INVALID_HANDLE )
                {
                    
KillTimer(timer_handle);
                    
timer_handle=INVALID_HANDLE;
                }
    if(
timer_handle == INVALID_HANDLE)
                {
                    
timer_handle=CreateTimer(GetConVarFloat(sm_Jockey_Msg_time), Msg0TIMER_REPEAT);
                }
}

public 
Action:Event_RoundEnd(Handle:eventString:event_name[], bool:dontBroadcast)
{
    if(
timer_handle != INVALID_HANDLE)
    {
        
KillTimer(timer_handle);
        
timer_handle=INVALID_HANDLE;
    }



FaTony 10-23-2012 01:12

Re: Displaying call stack trace for plugin
 
Attacker can be anything, not necessarily player, much less jockey. Add checks.

kikal767 10-23-2012 01:19

Re: Displaying call stack trace for plugin
 
Add checks like this?

PHP Code:

    if((GetClientTeam(target) == 2) && (StrEqual(weapon"jockey_claw")) && GetClientTeam(Jockey) == 3


Impact123 10-23-2012 02:11

Re: Displaying call stack trace for plugin
 
Much more like this
Code:

if(client > 0 && client <= MaxClients && IsClientInGame(client ))
Also you will get an error too if you check the team for an invalid index.

Yours sincerely
Impact

GsiX 10-23-2012 03:45

Re: Displaying call stack trace for plugin
 
if this is valid net_prop you should move it inside the filter suggested by Impact123

PHP Code:

new Jockey_Victim GetEntPropEnt(JockeyProp_Send"m_jockeyVictim"); 


kikal767 10-23-2012 05:41

Re: Displaying call stack trace for plugin
 
Thanks all....

like this ?
PHP Code:

if((GetClientTeam(target) == 2) && (StrEqual(weapon"jockey_claw")) && (GetClientTeam(Jockey) == 3) && Jockey && Jockey <= MaxClients && IsClientInGame(Jockey)) 

OR like this
PHP Code:

if((GetClientTeam(target) == 2) && (StrEqual(weapon,  "jockey_claw")) && (GetClientTeam(Jockey) == 3)  &&  IsClientInGame(Jockey)) 

And thanks GsiX

Is the core like this?

PHP Code:

public Action:Event_PlayerHurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
Jockey GetClientOfUserId(GetEventInt(event"attacker"));
    new 
target GetClientOfUserId(GetEventInt(event"userid"));

    
decl String:weapon[64];
    
GetEventString(event"weapon"weaponsizeof(weapon));
    
    if((
GetClientTeam(target) == 2) && (StrEqual(weapon"jockey_claw")) && (GetClientTeam(Jockey) == 3) && IsClientInGame(Jockey))
    {
        new 
Jockey_Victim GetEntPropEnt(JockeyProp_Send"m_jockeyVictim");
        if (
IsValidEntity(Jockey_Victim) && Jockey_Victim != 0)
        {
            return 
Plugin_Continue;
        } else
        {
            new 
duration GetConVarInt(FindConVar("sm_Jockey_acidswipe_duration"));
            new 
stack GetConVarInt(FindConVar("sm_Jockey_acidswipe_stack"));
            
            
attacker[target] = Jockey;
            if(
hurtsLeft[target] <= 0)
            {
                
hurtsLeft[target] = duration;
                
CreateTimer(1.0Acid_Damagetarget);
            } else
            {
                if(
stack == -1)
                {
                    
hurtsLeft[target] = duration;
                } else
                {
                    if(
stack >= 0)
                    {
                        
hurtsLeft[target] += stack;
                    } else
                    {
                        
//sm_Jockey_acidswipe_stack has invalid value so log error
                        
LogError("sm_Jockey_acidswipe_stack has an invalid value. Accepted values are -1 and higher.");
                    }
                }
            }
        }
    }
    return 
Plugin_Continue;



Bacardi 10-23-2012 10:21

Re: Displaying call stack trace for plugin
 
When use "player_hurt" event, "attacker" can return with invalid userid == 0,
happens when player hurt by fire, fall damage or get hurt something else than other player(s).

When try get client index by given userid,
GetClientOfUserId(userid) will return 0 if not found. 0 is invalid client index.

Valid client index is between 1 and your server maxplayers.

It is important to look first client index before continue check rest player things.

PHP Code:

public OnPluginStart()
{
    
HookEventEx("player_hurt"player_hurt);
}

public 
player_hurt(Handle:event, const String:name[], bool:dontBroadcast)
{
    new 
attacker GetClientOfUserId(GetEventInt(event"attacker"));
    new 
victim GetClientOfUserId(GetEventInt(event"userid"));

    if(
attacker == || attacker == victim// attacker else than player || attacker is victim
    
{
        return; 
// Don't continue callback
    
}

    new 
String:weapon[30];
    
GetEventString(event"weapon"weaponsizeof(weapon));

    if( !
StrEqual(weapon"jockey_claw") ) // weapon not "jockey_claw"
    
{
        return;
    }

    
// Add here your your rest code
    // attacker is jockey if weapon "jockey_claw", not need check team. If jockey not have more weapons.
    // victim should be survivor, I assume now those Special Infected can't hurt each other, I could be wrong.




sry bad english.

kikal767 10-23-2012 13:59

Re: Displaying call stack trace for plugin
 
Thanks all....
I had knew a lot about player_hur !!!

FaTony 10-24-2012 03:04

Re: Displaying call stack trace for plugin
 
Quote:

Originally Posted by Bacardi (Post 1824083)
When use "player_hurt" event, "attacker" can return with invalid userid == 0,
happens when player hurt by fire, fall damage or get hurt something else than other player(s).

When try get client index by given userid,
GetClientOfUserId(userid) will return 0 if not found. 0 is invalid client index.

It can also be anything that does damage, not just 0.


All times are GMT -4. The time now is 11:43.

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