AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   DeathMsg is running more than once? (https://forums.alliedmods.net/showthread.php?t=126663)

Leon M. 05-12-2010 07:08

DeathMsg is running more than once?
 
Hi,

I would like to count specific death, but for some reason, the counter sometimes increased by more than one point. Any ideas?

Here is the code
PHP Code:

public plugin_init(){
    
register_plugin(PLUGINVERSIONAUTHOR)

    
register_event("DeathMsg""event_death_message""a")
    
register_event("TextMsg""event_round_restart""a""2=#Game_Commencing""2=#Game_will_restart_in")
    
register_logevent("event_round_start"2"0=World triggered""1=Round_Start")
}

public 
client_damage(iAttackeriVictimiDamageiWeaponiHitplaceTA){
    if (
iAttacker && iVictim){
        
g_iHits[iAttacker][iVictim]++
    }
}

public 
event_death_message(){
    new 
iKiller read_data(1)
    new 
iVictim read_data(2)
    if (!
iKiller || !iVictim){
        return 
PLUGIN_CONTINUE
    
}

    new 
szWeapon[20], iHeadshot read_data(3)
    
read_data(4szWeapon19)

    if (
get_user_team(iKiller) != get_user_team(iVictim)){

        if (
equal(szWeapon"p228") || equal(szWeapon"usp") || equal(szWeapon"glock18") || equal(szWeapon"fiveseven") || equal(szWeapon"elites") || equal(szWeapon"deagle")){
            
g_iPistolKills[iKiller]++
        }

        if (
equal(szWeapon"knife")){
            
g_iKnifeKills[iKiller]++
        }
    }

    
g_iPistolKills[iVictim] = 0
    g_iKnifeKills
[iVictim] = 0

    
return PLUGIN_CONTINUE



hleV 05-12-2010 09:47

Re: DeathMsg is running more than once?
 
You should check if iKiller != iVictim.

Leon M. 05-12-2010 10:02

Re: DeathMsg is running more than once?
 
Quote:

Originally Posted by hleV (Post 1178205)
You should check if iKiller != iVictim.

Why? I check the teams, I think this is enough.

ConnorMcLeod 05-12-2010 12:34

Re: DeathMsg is running more than once?
 
I don't see anything wrong.
You could make an else for knife check though, because both condition shouldn't be possible at the same time.
Also, you should really consider the use of a Trie to store pistols names.

Leon M. 05-12-2010 13:30

Re: DeathMsg is running more than once?
 
Hmm, thanks :(

However, I must learn something about Trie before I can use them.

hleV 05-12-2010 14:45

Re: DeathMsg is running more than once?
 
Quote:

Originally Posted by Leon M. (Post 1178221)
Why? I check the teams, I think this is enough.

It's not enough. You check if killer and victim's teams are equal. If killer is victim, teams will be the same too.

Leon M. 05-12-2010 15:40

Re: DeathMsg is running more than once?
 
Yeah, and the counters won't increased.

Leon M. 05-16-2010 09:23

Re: DeathMsg is running more than once?
 
Hi, I did not need to start a new thread. I only have a short question about the use of trie. Can someone show me examples about using of the celltrie.inc?

I must create and set a trie, and I must delete some informations!

Many Thanks in advance
Leon

ConnorMcLeod 05-16-2010 09:59

Re: DeathMsg is running more than once?
 
Since you are using csx, you could use forward client_death as well, so you directly get weapon index, and team attack.


Anyway here it is :

PHP Code:

#include <amxmodx>
#include <csx>

new Trie:g_tPistolsShortNames

public plugin_init()
{
//    register_plugin(PLUGIN, VERSION, AUTHOR)

    
register_event("DeathMsg""Event_DeathMsg""a""1<0")
    
// register_event("TextMsg", "Event_TextMsg_Restart", "a", "2&#Game_C", "2&#Game_w")
    // register_logevent("LogEvent_Round_Start", 2, "1=Round_Start")

    
g_tPistolsShortNames TrieCreate()

    
// set any value, later we only gonna check if the string key exists in this try
    
TrieSetCell(g_tPistolsShortNames"p228"CSW_P228)
    
TrieSetCell(g_tPistolsShortNames"usp"CSW_USP)
    
TrieSetCell(g_tPistolsShortNames"glock18"CSW_GLOCK18)
    
TrieSetCell(g_tPistolsShortNames"fiveseven"CSW_FIVESEVEN)
    
TrieSetCell(g_tPistolsShortNames"elites"CSW_ELITE)
    
TrieSetCell(g_tPistolsShortNames"deagle"CSW_DEAGLE)
}

public 
plugin_end()
{
    
TrieDestroy(g_tPistolsShortNames)
}

public 
client_damage(iAttackeriVictimiDamageiWeaponiHitplaceTA)
{
    if (
iAttacker && iVictim)
    {
        
g_iHits[iAttacker][iVictim]++
    }
}

public 
Event_DeathMsg()
{
    new 
iKiller read_data(1)
    new 
iVictim read_data(2)

    
g_iPistolKills[iVictim] = 0
    g_iKnifeKills
[iVictim] = 0

    
if(iKiller == iVictim)
    {
        return
    }

    if (
get_user_team(iKiller) != get_user_team(iVictim)){
    {
        new 
szWeapon[10]
        
read_data(4szWeaponcharsmax(szWeapon))
        if ( 
IsWeaponPistol(szWeapon) )
        {
            
g_iPistolKills[iKiller]++
        }
        else if(
equal(szWeapon"knife"))
        {
            
g_iKnifeKills[iKiller]++
        }
    }
}

IsWeaponPistol(const szWeaponShortName[])
{
    return 
TrieKeyExists(g_tPistolsShortNamesszWeaponShortName)
}

// not used
stock GetWeaponIndex(const szWeaponShortName[])
{
    new 
iId
    
if( TrieGetCell(g_tPistolsShortNamesszWeaponShortNameiId) )
    {
        return 
iId
    
}
    return 
0



Leon M. 05-16-2010 11:15

Re: DeathMsg is running more than once?
 
Thank you :)


All times are GMT -4. The time now is 03:38.

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