AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Why is this getting called multiple times? (https://forums.alliedmods.net/showthread.php?t=173985)

bibu 12-13-2011 16:31

Why is this getting called multiple times?
 
Ok, I would like to hook, when T's and CT's win. Doing it right now like that:

PHP Code:

public plugin_init()
{
    
register_event("SendAudio""t_win""a""2&%!MRAD_terwin")
    
register_event("SendAudio""ct_win""a""2&%!MRAD_ctwin")
}

public 
t_win()
{
    
client_print(0print_chat"[Team] T's win!")
}

public 
ct_win()
{
    
client_print(0print_chat"[Team] CT's win!")


This works perfectly, and both get called once when their team wins. However, when I add some more stuff, it does give the winner team another +1 round as win, and all players die when there was a bomb explosion, all players were outside of the range for sure. And also, it calls sometimes both events multiple times. Could anyone help me with that? There are no other 3rd party plugins installed.

PHP Code:

public plugin_init()
{
    
register_event("SendAudio""t_win""a""2&%!MRAD_terwin")
    
register_event("SendAudio""ct_win""a""2&%!MRAD_ctwin")
}

public 
t_win()
{
    
client_print(0print_chat"[Team] All CTs should die now!")
    
    
cvar get_pcvar_num(amx_sl_silentkill)
    
    new 
iPlayers[32], iNumid 
    get_players
(iPlayersiNum
    for(new 
ii<iNumi++) 
    {
        
id iPlayers[i]
        
        if(
is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_CT)
        {
            if(
cvar)
            {
                
user_silentkill(id)
            }
            else
            {
                
user_kill(id1)
            }
        }
    }
}

public 
ct_win()
{
    
client_print(0print_chat"[Team] All T's should die now!")
    
    
cvar get_pcvar_num(amx_sl_silentkill)
    
    new 
iPlayers[32], iNumid 
    get_players
(iPlayersiNum
    for(new 
ii<iNumi++) 
    {
        
id iPlayers[i]
        
        if(
is_user_alive(id) && cs_get_user_team(id) == CS_TEAM_T)
        {
            if(
cvar)
            {
                
user_silentkill(id)
            }
            else
            {
                
user_kill(id1)
            }
        }
    }



Wildo 12-17-2011 17:25

Re: Why is this getting called multiple times?
 
Im interested in this too, since i just like bibu can't get it to work prober. :/ Anyone ?

ConnorMcLeod 12-17-2011 17:36

Re: Why is this getting called multiple times?
 
Debug it and log what is happening.

bibu 12-17-2011 17:44

Re: Why is this getting called multiple times?
 
Did some prints as you can see. There is nothing in the logs.

bibu 12-18-2011 07:00

Re: Why is this getting called multiple times?
 
See here, I tested it alone when I was Terrorist, twice. It worked fine. After adding a bot in the CT team, it even forced T's to die.

Quote:

Scoring will not start until both teams have players
[Slay Loser Team] All CTs should die now!
Scoring will not start until both teams have players
[Slay Loser Team] All CTs should die now!
nub connected
nub is joining the Counter-Terrorist force
nub died
[Slay Loser Team] All CTs should die now!
[Slay Loser Team] All CTs should die now!
[Slay Loser Team] All T's should die now!

ConnorMcLeod 12-18-2011 07:10

Re: Why is this getting called multiple times?
 
Show the whole plugin code.

bibu 12-18-2011 07:21

Re: Why is this getting called multiple times?
 
See the second method, just remove the cvar part and see if it happens for you. I tried it on a local server and on a public one. Happend on both.

ConnorMcLeod 12-18-2011 07:45

Re: Why is this getting called multiple times?
 
I get this log file :
Code:

L 12/18/2011 - 13:42:08 - 20.087203: Round Start
L 12/18/2011 - 13:42:45 - 56.659656: TERRORISTs WIN slay CTs <%!MRAD_terwin>
L 12/18/2011 - 13:42:45 - 56.659656: TERRORISTs WIN slay CTs <%!MRAD_terwin>
L 12/18/2011 - 13:42:45 - 56.659656: TERRORISTs WIN slay CTs <%!MRAD_terwin>
L 12/18/2011 - 13:42:45 - 56.659656: Round End
L 12/18/2011 - 13:42:45 - 56.659656: CTs WIN slay TERRORISTs <#Target_Bombed>
L 12/18/2011 - 13:42:45 - 56.659656: Round End
L 12/18/2011 - 13:42:50 - 61.662677: New Round

With plugin :

PHP Code:

#include <amxmodx>

#define VERSION "0.0.1"
#define PLUGIN "Slay Loosers Debug"

new bool:g_bRestarting

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
    
register_event("HLTV""Event_HLTV_New_Round""a""1=0""2=0")
    
register_logevent("LogEvent_Round_Start"2"1=Round_Start")
    
register_logevent("Logevent_Round_End"2"1=Round_End")
    
register_event("TextMsg""Event_TextMsg_Restart""a""2&#Game_C""2&#Game_w")
    
register_event("SendAudio""Event_SendAudio_terwin""a""2=%!MRAD_terwin")
    
register_event("SendAudio""Event_SendAudio_ctwin""a""2=%!MRAD_ctwin")
    
LogToFile("NEW MAP")
}

public 
Event_SendAudio_terwin()
{
    new 
szAudioString[32]
    
read_data(2szAudioStringcharsmax(szAudioString))
    
LogToFile("TERRORISTs WIN slay CTs <%s>"szAudioString)
    new 
iPlayers[32], iNum
    get_players
(iPlayersiNum"ae""CT")
    for(--
iNumiNum>=0iNum--)
    {
        
user_kill(iPlayers[iNum], 1)
    }
}

public 
Event_SendAudio_ctwin()
{
    new 
szAudioString[32]
    
read_data(2szAudioStringcharsmax(szAudioString))
    
LogToFile("CTs WIN slay TERRORISTs <%s>"szAudioString)
    new 
iPlayers[32], iNum
    get_players
(iPlayersiNum"ae""TERRORIST")
    for(--
iNumiNum>=0iNum--)
    {
        
user_kill(iPlayers[iNum], 1)
    }
}

public 
Event_TextMsg_Restart()
{
    
g_bRestarting true
    LogToFile
("Restart has been triggered")
}

public 
Event_HLTV_New_Round()
{
    if( 
g_bRestarting )
    {
        
LogToFile("New Round (RESTARTED)")
        
g_bRestarting false
    
}
    else
    {
        
LogToFile("New Round")
    }
}

public 
LogEvent_Round_Start()
{
    
LogToFile("Round Start")
}

public 
Logevent_Round_End()
{
    
LogToFile("Round End")
}

LogToFile(const fmt[], any:...)
{
    static 
szLogFile[64]
    static 
date[64]
    if( !
szLogFile[0] )
    {
        
get_localinfo("amxx_logs"szLogFilecharsmax(szLogFile))
        
format(szLogFilecharsmax(szLogFile), "%s/slay_loosers_%s.log"szLogFiledate)
    }

    new 
szLog[256]
    
vformat(szLogcharsmax(szLog), fmt2)

    
get_time("%m/%d/%Y - %H:%M:%S"datecharsmax(date))

    new 
fp fopen(szLogFile"at")
    
fprintf(fp"L %s - %f: %s^n"dateget_gametime(), szLog)
    
fclose(fp)



So, yes, i guess there is a problem with amxx.

Have you tried with last official amxx release ?


EDIT :

I've fixed with rechecking in callback.
I still log Round_End 2 times...

PHP Code:

#include <amxmodx>

#define VERSION "0.0.2"
#define PLUGIN "Slay Loosers Debug"

new bool:g_bRestarting

public plugin_init()
{
    
register_plugin(PLUGINVERSION"ConnorMcLeod")
    
register_event("HLTV""Event_HLTV_New_Round""a""1=0""2=0")
    
register_logevent("LogEvent_Round_Start"2"1=Round_Start")
    
register_logevent("Logevent_Round_End"2"1=Round_End")
    
register_event("TextMsg""Event_TextMsg_Restart""a""2&#Game_C""2&#Game_w")
    
register_event("SendAudio""Event_SendAudio""a")
    
LogToFile("NEW MAP")
}

public 
Event_SendAudio()
{
    new 
szAudioString[32], Float:flGameTime get_gametime()
    
read_data(2szAudioStringcharsmax(szAudioString))
    if( 
equal(szAudioString"%!MRAD_terwin") )
    {
        static 
Float:flOldTerGameTime
        
if( flGameTime flOldTerGameTime )
        {
            
flOldTerGameTime flGameTime
            LogToFile
("TERRORISTs WIN slay CTs <%s>"szAudioString)
            new 
iPlayers[32], iNum
            get_players
(iPlayersiNum"ae""CT")
            for(--
iNumiNum>=0iNum--)
            {
                
user_kill(iPlayers[iNum], 1)
            }
        }
    }
    else if( 
equal(szAudioString"%!MRAD_ctwin" ) )
    {
        static 
Float:flOldCtGameTime
        
if( flGameTime flOldCtGameTime )
        {
            
flOldCtGameTime flGameTime
            LogToFile
("CTs WIN slay TERRORISTs <%s>"szAudioString)
            new 
iPlayers[32], iNum
            get_players
(iPlayersiNum"ae""TERRORIST")
            for(--
iNumiNum>=0iNum--)
            {
                
user_kill(iPlayers[iNum], 1)
            }
        }
    }
}

public 
Event_TextMsg_Restart()
{
    
g_bRestarting true
    LogToFile
("Restart has been triggered")
}

public 
Event_HLTV_New_Round()
{
    if( 
g_bRestarting )
    {
        
LogToFile("New Round (RESTARTED)")
        
g_bRestarting false
    
}
    else
    {
        
LogToFile("New Round")
    }
}

public 
LogEvent_Round_Start()
{
    
LogToFile("Round Start")
}

public 
Logevent_Round_End()
{
    
LogToFile("Round End")
}

LogToFile(const fmt[], any:...)
{
    static 
szLogFile[64]
    static 
date[64]
    if( !
szLogFile[0] )
    {
        
get_localinfo("amxx_logs"szLogFilecharsmax(szLogFile))
        
format(szLogFilecharsmax(szLogFile), "%s/slay_loosers_%s.log"szLogFiledate)
    }

    new 
szLog[256]
    
vformat(szLogcharsmax(szLog), fmt2)

    
get_time("%m/%d/%Y - %H:%M:%S"datecharsmax(date))

    new 
fp fopen(szLogFile"at")
    
fprintf(fp"L %s - %f: %s^n"dateget_gametime(), szLog)
    
fclose(fp)



bibu 12-18-2011 08:04

Re: Why is this getting called multiple times?
 
Wow, this is really weird. I wonder why this was never found out before :)

I tried it now with 1.8.2, and it is the same. A little odd is, that I was using this way in several mods to reverse the players to change the teams. But what would I need todo now? File a bug? Or would you look in it abit more?

ConnorMcLeod 12-18-2011 08:12

Re: Why is this getting called multiple times?
 
Tried with amx1.8.1 and have same results.

Code:

L 12/18/2011 - 14:08:44 - 1.000000: NEW MAP
L 12/18/2011 - 14:08:53 - 9.003758: Round Start
L 12/18/2011 - 14:09:08 - 24.115863: Restart has been triggered
L 12/18/2011 - 14:09:08 - 24.115863: Restart has been triggered
L 12/18/2011 - 14:09:09 - 25.117305: New Round (RESTARTED)
L 12/18/2011 - 14:09:10 - 26.117609: Round Start
L 12/18/2011 - 14:09:45 - 61.448158: TERRORISTs WIN slay CTs <%!MRAD_terwin>
L 12/18/2011 - 14:09:45 - 61.448158: Round End
L 12/18/2011 - 14:09:50 - 66.451591: New Round
L 12/18/2011 - 14:09:51 - 67.452041: Round Start
L 12/18/2011 - 14:09:52 - 68.142684: Restart has been triggered
L 12/18/2011 - 14:09:52 - 68.142684: Round End
L 12/18/2011 - 14:09:55 - 71.144470: New Round (RESTARTED)
L 12/18/2011 - 14:09:56 - 72.145050: Round Start
L 12/18/2011 - 14:10:43 - 119.130653: TERRORISTs WIN slay CTs <%!MRAD_terwin>
L 12/18/2011 - 14:10:43 - 119.130653: TERRORISTs WIN slay CTs <%!MRAD_terwin>
L 12/18/2011 - 14:10:43 - 119.130653: TERRORISTs WIN slay CTs <%!MRAD_terwin>
L 12/18/2011 - 14:10:43 - 119.130653: Round End
L 12/18/2011 - 14:10:43 - 119.130653: CTs WIN slay TERRORISTs <#Target_Bombed>
L 12/18/2011 - 14:10:43 - 119.130653: Round End
L 12/18/2011 - 14:10:48 - 124.134735: New Round
L 12/18/2011 - 14:10:49 - 125.137092: Round Start



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

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