Raised This Month: $ Target: $400
 0% 

Hooking event problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 09-21-2011 , 19:08   Hooking event problem
Reply With Quote #1

Greetings, im having a bit of trouble "hooking" a triggerevent from an i_t_g entity from within TFC.

First of all, I did a test as you can see with the outcommented register_logevent, which calls the function "test", this works perfectly as expected.

When I try to call the function "cmdCam" instead, I get a bunch of errors:

PHP Code:
[ENGINEInvalid player 0 (not in-game)
[
AMXXRun time error 10 (plugin "cam.amxx") (native "attach_view"
Can anyone see what im missing here?

PHP Code:
#include <amxmodx> 
#include <engine> 

new const pl_cm_class[] = "PlayerCamera" 

public plugin_init() 
{   
     
register_logevent("cmdCam",3,"1=triggered""2=SidescrollStart")
     
//register_logevent("test",3,"1=triggered", "2=SidescrollStart")

    
register_think(pl_cm_class,"Think_PlayerCamera")    


public 
cmdCam(id
    
Create_PlayerCamera(id

Create_PlayerCamera(id

    new 
ent
    
while ((ent find_ent_by_class(ent,pl_cm_class)) != 0
    { 
        if (
entity_get_edict(ent,EV_ENT_owner) == id
        { 
            
attach_view(id ent
            return 
        } 
    } 
    
ent create_entity("info_target"
     
    if( !
ent 
        return; 
     
    
entity_set_string(entEV_SZ_classnamepl_cm_class
     
    
entity_set_model(ent"models/rpgrocket.mdl"
     
    
entity_set_byte(entEV_INT_solidSOLID_TRIGGER
    
entity_set_int(entEV_INT_movetypeMOVETYPE_FLYMISSILE
     
    
entity_set_edict(entEV_ENT_ownerid
     
    
entity_set_int(ent,EV_INT_rendermodekRenderTransTexture
    
entity_set_float(entEV_FL_renderamt0.0 
     
    
attach_view(id,ent
    
entity_set_float(entEV_FL_nextthinkget_gametime()) 
    

public 
test(id)
{
    
client_print(id,print_chat"TestTest")
    return 
PLUGIN_CONTINUE

teh ORiON is offline
lucas_7_94
Leche Loco
Join Date: Mar 2009
Location: Argentina
Old 09-21-2011 , 19:11   Re: Hooking event problem
Reply With Quote #2

check if the player is valid?
__________________
ATWWMH - MiniDuels
Madness is like gravity, just need a little push.
lucas_7_94 is offline
Send a message via Skype™ to lucas_7_94
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-21-2011 , 20:43   Re: Hooking event problem
Reply With Quote #3

AFAIK logevent doesn't parse "id", it doesn't parse anything actually.
You need to get the log argument with read_logdata() or read_logargv(), then use parse_loguser() on it to get the player name and then use get_user_index() to get the player's entity index which you can use on that function.
__________________

Last edited by Hunter-Digital; 09-21-2011 at 20:45.
Hunter-Digital is offline
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 09-21-2011 , 21:05   Re: Hooking event problem
Reply With Quote #4

Ok, seems a bit tedious, is there a better way that would accomplish the same as logevent?
teh ORiON is offline
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 09-22-2011 , 05:46   Re: Hooking event problem
Reply With Quote #5

Also im a bit puzzled over that it infact works with, client_print, which effectively also need the ID?
teh ORiON is offline
teh ORiON
Member
Join Date: Sep 2011
Location: Denmark
Old 09-22-2011 , 06:22   Re: Hooking event problem
Reply With Quote #6

Ok, for anyone interested, this fixed it for me:

PHP Code:
stock get_loguser_index()
{
    new 
loguser[80], name[32], userid;
    
read_logargv(0logusercharsmax(loguser))
    
parse_loguser(logusername31)
    return 
get_user_index(name);

And then using
PHP Code:
new id get_loguser_index() 
In the appropriate function. Thanks Hunter for heading me in the right direction!
teh ORiON is offline
e12harry
Member
Join Date: Apr 2010
Old 09-22-2011 , 06:25   Re: Hooking event problem
Reply With Quote #7

Quote:
Originally Posted by teh ORiON View Post
Also im a bit puzzled over that it infact works with, client_print, which effectively also need the ID?
In your case in client_print id is propably 0. If so message is printed to all players, and that is why you see it.
e12harry is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 09-22-2011 , 14:09   Re: Hooking event problem
Reply With Quote #8

Quote:
Originally Posted by teh ORiON View Post
Also im a bit puzzled over that it infact works with, client_print, which effectively also need the ID?
You need to improve your debugging, print arguments in client prints so you'll see exacly what you get

If there's a game event message that can be used with register_event/message() then you can use it that way but with logevent you need to parse stuff with that stock
__________________
Hunter-Digital 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 19:31.


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