Raised This Month: $ Target: $400
 0% 

logevent hook


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-13-2012 , 15:52   logevent hook
Reply With Quote #1

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.
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
hornet
AMX Mod X Plugin Approver
Join Date: Mar 2010
Location: Australia
Old 06-13-2012 , 19:48   Re: logevent hook
Reply With Quote #2

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")
__________________
Quote:
vBulletin Tip #42: Not much would be accomplished by merging this item with itself.

Last edited by hornet; 06-13-2012 at 19:48.
hornet is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-13-2012 , 22:17   Re: logevent hook
Reply With Quote #3

Quote:
Originally Posted by hornet View Post
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?
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-14-2012 , 00:16   Re: logevent hook
Reply With Quote #4

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])

__________________
- tired and retired -

- my plugins -

Last edited by ConnorMcLeod; 06-14-2012 at 00:44.
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-14-2012 , 00:54   Re: logevent hook
Reply With Quote #5

Quote:
Originally Posted by ConnorMcLeod View Post
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?
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 06-14-2012 at 00:59. Reason: spoiled his code.
Liverwiz is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-14-2012 , 03:02   Re: logevent hook
Reply With Quote #6

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?
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 06-14-2012 at 03:03.
Liverwiz is offline
ConnorMcLeod
Veteran Member
Join Date: Jul 2006
Location: France (95)
Old 06-14-2012 , 12:22   Re: logevent hook
Reply With Quote #7

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 ?
__________________
- tired and retired -

- my plugins -
ConnorMcLeod is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-14-2012 , 12:33   Re: logevent hook
Reply With Quote #8

Quote:
Originally Posted by ConnorMcLeod View Post
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?
__________________
What an elegant solution to a problem that doesn't need solving....

Last edited by Liverwiz; 06-14-2012 at 12:34.
Liverwiz is offline
Backstabnoob
BANNED
Join Date: Feb 2009
Location: Iwotadai Dorm
Old 06-14-2012 , 15:13   Re: logevent hook
Reply With Quote #9

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.
Backstabnoob is offline
Liverwiz
Veteran Member
Join Date: Feb 2010
Location: Maryland
Old 06-14-2012 , 15:30   Re: logevent hook
Reply With Quote #10

Quote:
Originally Posted by Backstabnoob View Post
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!?
__________________
What an elegant solution to a problem that doesn't need solving....
Liverwiz is offline
Reply


Thread Tools
Display Modes

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 06:17.


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