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

Solved Why do these two give different results?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
glittershii
Junior Member
Join Date: Oct 2017
Old 10-02-2017 , 13:36   Why do these two give different results?
Reply With Quote #1

I have a game that gives players -15 frags on teamkill.
I don't want this so I give players 16 frags to counter the penalty. They end up earning 1 frag.

I then perform actions based on the updated/fixed score. Here's the relevant bit of code:

PHP Code:
public void OnPluginStart() 

    
HookEventEx("entity_killed"Event_EntityKilled);  


public 
void Event_EntityKilled(Handle:event, const String:name[], bool:Broadcast
{
    
int i_Attacker GetEventInt(event"entindex_attacker"); 
    
SetEntProp(i_AttackerProp_Data"m_iFrags"GetClientFrags(i_Attacker) + 16);
    
PrintToChatAll("[debug] %i"GetClientFrags(i_Attacker));

    
//perform further calculations based on the final fixed score (changelevel if m_iFrags is over 20, etc)

Here's the same code but hooked to player_death instead:

PHP Code:
public void OnPluginStart() 

    
HookEventEx("player_death"Event_PlayerDeath);


public 
void Event_PlayerDeath(Handle:event, const String:name[], bool:Broadcast
{
    new 
i_Attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
SetEntProp(i_AttackerProp_Data"m_iFrags"GetClientFrags(i_Attacker) + 16);
    
PrintToChatAll("[debug] %i"GetClientFrags(i_Attacker));
    
    
//perform further calculations based on the final fixed score (changelevel if m_iFrags is over 20, etc)

Assuming the player has a starting score of 0 frags and he teamkills someone:

The score shows 1 positive frag.
Plugin hooked to entity_killed prints 1.
Plugin hooked to player_death prints 16.

..why? Why is the latter not printing 1?

Last edited by glittershii; 10-07-2017 at 13:37. Reason: solved
glittershii is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-02-2017 , 14:23   Re: Why do these two give different results?
Reply With Quote #2

What freaking game ? SourceMod support many game mods!!
__________________
Do not Private Message @me
Bacardi is offline
glittershii
Junior Member
Join Date: Oct 2017
Old 10-02-2017 , 16:46   Re: Why do these two give different results?
Reply With Quote #3

Quote:
Originally Posted by Bacardi View Post
What freaking game ? SourceMod support many game mods!!
I thought it was irrelevant to the question since those are generic Source events. Game is No More Room in Hell.
glittershii is offline
Mitchell
~lick~
Join Date: Mar 2010
Old 10-02-2017 , 17:03   Re: Why do these two give different results?
Reply With Quote #4

Quote:
Originally Posted by glittershii View Post
I thought it was irrelevant to the question since those are generic Source events. Game is No More Room in Hell.
It's never irrelevant, some of the events are generic yes, but some games, like NMRiH are not made by Valve.
I was thinking this was for l4d or cs:s
Mitchell is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-02-2017 , 17:14   Re: Why do these two give different results?
Reply With Quote #5

Quote:
Originally Posted by glittershii View Post
I thought it was irrelevant to the question since those are generic Source events. Game is No More Room in Hell.
Thank you very much!

You are not only one.
Most new forum users also start ask/request/"need help asap"-topics but never they say (first)... what game.

Like what you mention before, "I have a game that gives players -15 frags on teamkill."
I don't remember any other game what does this. Or is it gameplay by SourceMod plugin (vip, zombie, etc. etc.)?
There is so many... possibilities.

But thanks for info, let's see if someone help in this when have time.

*edit
Aaa.. FREE game
__________________
Do not Private Message @me

Last edited by Bacardi; 10-02-2017 at 17:16.
Bacardi is offline
Bacardi
Veteran Member
Join Date: Jan 2010
Location: mom's basement
Old 10-02-2017 , 19:14   Re: Why do these two give different results?
Reply With Quote #6

You could follow events...

con_timestamp 1
con_logfile events.txt
sm_cvar net_showevents 2



I don't have opportunity test teamkill, but in suicide action, player_death event come first, entity_killed as second.
Code:
Server event "player_death", Tick 45318:
- "userid" = "5"
- "attacker" = "0"
- "weapon" = "env_explosion"
player_death
Server event "entity_killed", Tick 45318:
- "entindex_killed" = "1"
- "entindex_attacker" = "423"
- "entindex_inflictor" = "423"
- "damagebits" = "64"
entity_killed
I didn't quite understand your examples, but quick thinking...
Frag penalty comes after player_death.

What I tested, I lost 1 frag after player_death event.


*edit
Try this.
Assume, players are in same team,
when "attacker" userid return client index, it create small timer and pass m_iFrags later on attacker.
PHP Code:
public void OnPluginStart()
{
    
HookEventEx("player_death"player_death);
    
//HookEventEx("entity_killed", entity_killed);
}

public 
void player_death(Handle eventchar[] namebool Broadcast)
{
    
int player GetClientOfUserId(GetEventInt(event"attacker"));

    if(
player != 0)
    {
        
//PrintToServer("player_death %i", GetClientFrags(player));
        
        
DataPack pack;
        
CreateDataTimer(0.0delaypackTIMER_FLAG_NO_MAPCHANGE);
        
pack.WriteCell(GetClientUserId(player));
        
pack.WriteCell(GetEntProp(playerProp_Data"m_iFrags"));
        
pack.Reset();
    }
}

public 
Action delay(Handle timerDataPack pack)
{
    
int player GetClientOfUserId(pack.ReadCell());

    if(
player != 0)
    {
        
int frags pack.ReadCell();
        
//PrintToServer("delay %i %i", player, frags);
        
SetEntProp(playerProp_Data"m_iFrags"frags);
    }
}

public 
void entity_killed(Handle eventchar[] namebool Broadcast)
{
    
int player GetEventInt(event"entindex_attacker");
    
//PrintToServer("entity_killed %i", GetClientFrags(player));

__________________
Do not Private Message @me

Last edited by Bacardi; 10-02-2017 at 19:39.
Bacardi is offline
glittershii
Junior Member
Join Date: Oct 2017
Old 10-02-2017 , 22:48   Re: Why do these two give different results?
Reply With Quote #7

Hey, thanks for taking your time to test that out.

Code:
Player 'survivor1' died at the hands of 'survivor2'.
player_death 0
entity_killed -15
delay 1 0
This is the server output when running your code /w the commented out parts included. Frags stay at 0

Now, back to the original code, this is what I don't understand:

PHP Code:
//hooked to entity_killed
//m_iFrags is 0
public void Event_EntityKilled(Handle:event, const String:name[], bool:Broadcast//m_iFrags is -15
{
    
int i_Attacker GetEventInt(event"entindex_attacker"); 
    
SetEntProp(i_AttackerProp_Data"m_iFrags"GetClientFrags(i_Attacker) + 16); //m_iFrags is 1
    
PrintToChatAll("[debug, entitykilled.sp] %i"GetClientFrags(i_Attacker)); //m_iFrags is 1. Good!


PHP Code:
//hooked to player_death
//m_iFrags is 0
public void Event_PlayerDeath(Handle:event, const String:name[], bool:Broadcast//m_iFrags is -15
{
    new 
i_Attacker GetClientOfUserId(GetEventInt(event"attacker"));
    
SetEntProp(i_AttackerProp_Data"m_iFrags"GetClientFrags(i_Attacker) + 16); //m_iFrags should be 1
    
PrintToChatAll("[debug, playerdeath.sp] %i"GetClientFrags(i_Attacker)); //m_iFrags is 16. Hm, what!? 
I mean I guess I can leave the script hooked to entity_death, or use player_death and add a delay between the second and third line, but still...
Why does this happen?

Last edited by glittershii; 10-02-2017 at 23:03.
glittershii is offline
Dr!fter
The Salt Boss
Join Date: Mar 2007
Old 10-02-2017 , 23:08   Re: Why do these two give different results?
Reply With Quote #8

This really isn't this hard, player_death event happens before the frags is changed so it's 0. Entity killed is after the score stuff is handled so it's -15.

Last edited by Dr!fter; 10-02-2017 at 23:08.
Dr!fter is offline
glittershii
Junior Member
Join Date: Oct 2017
Old 10-02-2017 , 23:11   Re: Why do these two give different results?
Reply With Quote #9

Quote:
Originally Posted by Dr!fter View Post
This really isn't this hard, player_death event happens before the frags is changed so it's 0. Entity killed is after the score stuff is handled so it's -15.
Right I see. Okay I'll tweak my code based on that. Thanks for the explanation.
glittershii 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 14:09.


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