AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   logevent hook (https://forums.alliedmods.net/showthread.php?t=187480)

Liverwiz 06-13-2012 15:52

logevent hook
 
I'm trying to hook an event of Terrorists (or CT) winning, but it would seem my code is improper. Someone give me a hand?

PHP Code:

//init
register_logevent("event_Tvictory" 2"3=Terrorists_Win")

public 
event_Tvictory()
{
    if(!
get_pcvar_num(toggle_pcvar) || !get_pcvar_num(frags_pcvar) || !get_pcvar_num(sc_pcvar))
        return     
PLUGIN_CONTINUE    
        
    
new players[32], num
    get_players
(playersnum"aceh""T")

    for(new 
i=0,idi<numi++)
    {
        
id players[i]
        if(
g_bknuckles[id] && is_user_connected(id) )
            
giveFrags(id1"SC_WIN")
    }
    
    return 
PLUGIN_CONTINUE


i probably just simply don't understand register_logevent sufficiently.

hornet 06-13-2012 19:48

Re: logevent hook
 
The Logevent should be fine, if your ever unsure then run a simple test - show a text message to see if your successfully hooking the event.

Code:
get_players(players, num, "aceh", "T")
->
Code:
get_players(players, num, "aceh", "TERRORIST")

Liverwiz 06-13-2012 22:17

Re: logevent hook
 
Quote:

Originally Posted by hornet (Post 1728326)
The Logevent should be fine, if your ever unsure then run a simple test - show a text message to see if your successfully hooking the event.

Code:
get_players(players, num, "aceh", "T")
->
Code:
get_players(players, num, "aceh", "TERRORIST")

Though you are correct, that didn't fix my problem.
How do you properly formulate a register_logevent() hook?

ConnorMcLeod 06-14-2012 00:16

Re: logevent hook
 
You can run this and look in log file if the log you are trying to register does exist, and if it exists if you have correctly formulated it.
You will have to figure which arguments don't have to be specified in filters though, because plugin is an idiot.

PHP Code:

#include <amxmodx>

#define VERSION    "1.0.1"
new g_iState

public plugin_init()
{
    
state Stopped
    register_plugin
("LogEvents Logger"VERSION"ConnorMcLeod")
    
register_srvcmd("logevents""ServerCommand_LogEvents"_"<print> | <log> | <stop>")
}

public 
plugin_log() <Stopped> {}
public 
plugin_log() <Running>
{
    static 
szMain[256], szDetail[256], szRegistered[256]
    static 
iArgsNumnmszTemp[64]

    
read_logdata(szMaincharsmax(szMain))

    
iArgsNum read_logargc()

    
0
    m 
formatex(szRegisteredcharsmax(szRegistered), "register_logevent(^"logevent_function^", %d"iArgsNum)

    for(new 
ii<iArgsNumi++)
    {
        
read_logargv(iszTempcharsmax(szTemp))
        if( !
&& contain(szTemp"<STEAM_") != -)
        {
            
+= formatex(szDetail[n], charsmax(szDetail)-n"^n%d=%s"iszTemp)
            if( 
replace(szRegisteredcharsmax(szRegistered), "logevent_function^"", "logevent_function_p^"") )
            {
                
+= 2
            
}
            
// replace(szRegistered, charsmax(szRegistered), "logevent_function(", "logevent_function_p(")
            // m = strlen(szRegistered)
        
}
        else
        {
            
+= formatex(szDetail[n], charsmax(szDetail)-n"^n%d=%s"iszTemp)
            
+= formatex(szRegistered[m], charsmax(szRegistered)-m", ^"%d=%s^""iszTemp)
        }
    }
    
+= formatex(szRegistered[m], charsmax(szRegistered)-m")^n")

    if(
g_iState==2)
    {
        static 
szLogFile[64], date[22]
        if( !
szLogFile[0] )
        {
            
get_localinfo("amxx_logs"szLogFilecharsmax(szLogFile))
            
get_time("%Y%m%d"datecharsmax(date))
            
format(szLogFilecharsmax(szLogFile), "%s/logevents_%s.log"szLogFiledate)
        }
        
get_time("%m/%d/%Y - %H:%M:%S"datecharsmax(date))
        new 
fp fopen(szLogFile"at")
        
fprintf(fp"L %s: %s%s^n%s^n^n"dateszMainszDetailszRegistered)
        
fclose(fp)
    }
    else
    {
        
server_print("^n%s%s^n%s"szMainszDetailszRegistered)
    }
}

public 
ServerCommand_LogEvents()
{
    new 
szArg1[6]
    
read_argv(1szArg1charsmax(szArg1))

    static const 
szStates[][] = {"stop""print""log"}

    for(new 
ii<sizeof(szStates); i++)
    {
        if( 
equal(szArg1szStates[i]) && g_iState != )
        {
            
g_iState i
            
break
        }
    }

    if( 
g_iState )
    {
        
state Running
    
}
    else
    {
        
state Stopped
    
}
    
server_print("[LogEvents Logger] Currently : %s"szStates[g_iState])



Liverwiz 06-14-2012 00:54

Re: logevent hook
 
Quote:

Originally Posted by ConnorMcLeod (Post 1728424)
You can run this and look in log file if the log you are trying to register does exist, and if it exists if you have correctly formulated it.
Spoiler

I just remembered that you wrote that logger, Connor. But then i found this code written by SnoW:
Code:
    register_event("SendAudio", "terrorist_win", "a", "2=%!MRAD_terwin");     register_event("SendAudio", "counterterrorist_win", "a", "2=%!MRAD_ctwin");
in this plugin: http://forums.alliedmods.net/showthread.php?p=717780
and it works wonderfully. What say you?

Liverwiz 06-14-2012 03:02

Re: logevent hook
 
Ok...I've been testing this for a while and it's really weird why it won't give the frags. Maybe one of y'all can see something i missed.

PHP Code:

// init
        // Thanks snow for these events in your Mod Points plugin. 
        //    http://forums.alliedmods.net/showthread.php?p=717780
    
register_event("SendAudio""event_CTvictory""a""2=%!MRAD_ctwin")
    
register_event("SendAudio""event_Tvictory""a""2=%!MRAD_terwin")

public 
event_CTvictory()
{
    
client_print(0print_chat"[BKF-CTvict] CTs won!")
    if(!
get_pcvar_num(toggle_pcvar) || !get_pcvar_num(frags_pcvar) || !get_pcvar_num(sc_pcvar))
        return     
PLUGIN_CONTINUE    
        
    
new players[32], num
    get_players
(playersnum"aceh""CT")

    for(new 
i=0idi<numi++)
    {
        
id players[i]
        
client_print(idprint_chat"YOU WON!")
        if(
g_bknuckles[id] && is_user_connected(id) )
            
giveFrags(id1"SC_WIN")
    }
    
    return 
PLUGIN_CONTINUE
}
public 
event_Tvictory()
{
    
client_print(0print_chat"[BKF-Tvic] Terrors win!")
    if(!
get_pcvar_num(toggle_pcvar) || !get_pcvar_num(frags_pcvar) || !get_pcvar_num(sc_pcvar))
        return 
PLUGIN_CONTINUE    
        
    
new players[32], num
    get_players
(playersnum"aceh""TERRORIST")
    
    for(new 
i=0,idi<numi++)
    {
        
id players[i]
        
client_print(idprint_chat"YOU WON!")
        if(
g_bknuckles[id] && is_user_connected(id) )
            
giveFrags(id1"SC_WIN")
    }
    
    return 
PLUGIN_CONTINUE
}
stock giveFrags(idpoints, const reason[]="NO_REASON")    // RETURNS: 1 if successful 0 if fail
{
    if(!
is_user_connected(id) || is_user_bot(id) || get_pcvar_num(frags_pcvar) == 0)
        return 
0
        
    
if(g_idPending[id])    // check if ID is pending: authorize accordingly
    
{
        new 
sid[32]; get_user_authid(idsidcharsmax(sid) )
        if( 
equali(sid"steam_id_pending") )
        {
            
client_print_color(idDontChange"[BKF] You are not currently authorized. No frags will be given.")
            return 
0
        
}
        else 
            
retrieveFrags(id)
    }
        
    new 
message[200]
    new 
crntLvl getLevel(id)  // get user's current level so we can see if they level up
    
    
gi_playerFrags[id]+= points  // give them the points. 
    
    
if(points 0)    // show message to reflect weather points are negative or positive
        
formatex(messagecharsmax(message), "%L %L (%L)"id"LOSE_FRAGS"abs(points), idreasonid"LEVEL"getLevel(id) )
    else
        
formatex(messagecharsmax(message), "%L %L (%L)"id"WIN_FRAGS"pointsidreasonid"LEVEL"getLevel(id) )
    
    
// if recieved frags for winning the round SC Mode is on; we want to reflect that
    
if(equal(reason"WIN_ROUND") )
        
client_print_color(idDontChange"[BKF-sc] %L %L"id"WIN_FRAGS"pointsidreason)
    else        
// display the message
        
client_print_color(idDontChange"[BKF] %s"message)
    
        
// SuperCharged mode's functionality
    
if(get_pcvar_num(sc_pcvar) == 1)
    {
        
gi_playerFrags[id]++
        
client_print_color(idDontChange"[BKF-sc] %L"id"SC_FRAG_MSG")
    }
    
        
// Announcement & check about levelup
    
if(crntLvl getLevel(id) && get_pcvar_num(printall_pcvar))
    {
        new 
sz_name[32]; get_user_name(idsz_namecharsmax(sz_name) )
        
client_print_color(0DontChange"[BKF] %L"LANG_PLAYER"LVL_UP_MSG"sz_namegetLevel(id) )
        
client_cmd(0LEVELUP_SOUND)
        
giveFrags(id1"LEVEL_UP")
    }
    return 
1


all client_print statements print properly, just not when it gets to giveFrags anyone see what i'm missing?

ConnorMcLeod 06-14-2012 12:22

Re: logevent hook
 
PHP Code:

    if(g_idPending[id])    // check if ID is pending: authorize accordingly
    
{
        new 
sid[32]; get_user_authid(idsidcharsmax(sid) )
        if( 
equali(sid"steam_id_pending") )
        {
            
client_print_color(idDontChange"[BKF] You are not currently authorized. No frags will be given.")
            return 
0
        
}
        else 
            
retrieveFrags(id)
    } 

WTF !!
How could an alive player be pending ?

Liverwiz 06-14-2012 12:33

Re: logevent hook
 
Quote:

Originally Posted by ConnorMcLeod (Post 1728653)
WTF !!
How could an alive player be pending ?

STEAM_ID is irrelevant from connection and spawn. That is why client_authorized() and client_putinserver() are separate functions. It is a rare occurance for a user to connect to a server and never get a STEAMID, but i have seen it happen in the wild. This simply makes sure that if a user was not authenticated (has a STEAMid) at connection he can still play, progress, and save data if he is authorized later. If not, we throw out his data when it comes time to save. Essentially writing a pseudo client_authorized that is on the fly, along with gameplay.

Either way....what's wrong with that code?

Backstabnoob 06-14-2012 15:13

Re: logevent hook
 
You could save some memory if you created a global variable for each player and set it to 1 in client_authorized, then check if it's set instead of comparing a whole string.

Liverwiz 06-14-2012 15:30

Re: logevent hook
 
Quote:

Originally Posted by Backstabnoob (Post 1728781)
You could save some memory if you created a global variable for each player and set it to 1 in client_authorized, then check if it's set instead of comparing a whole string.

That's a good idea, thanks! I'll use it.



but can no one tell me why that isn't working!?


All times are GMT -4. The time now is 06:17.

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