AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hooking event problem (https://forums.alliedmods.net/showthread.php?t=167920)

teh ORiON 09-21-2011 19:08

Hooking event problem
 
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



lucas_7_94 09-21-2011 19:11

Re: Hooking event problem
 
check if the player is valid?

Hunter-Digital 09-21-2011 20:43

Re: Hooking event problem
 
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.

teh ORiON 09-21-2011 21:05

Re: Hooking event problem
 
Ok, seems a bit tedious, is there a better way that would accomplish the same as logevent?

teh ORiON 09-22-2011 05:46

Re: Hooking event problem
 
Also im a bit puzzled over that it infact works with, client_print, which effectively also need the ID?

teh ORiON 09-22-2011 06:22

Re: Hooking event problem
 
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!

e12harry 09-22-2011 06:25

Re: Hooking event problem
 
Quote:

Originally Posted by teh ORiON (Post 1560652)
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.

Hunter-Digital 09-22-2011 14:09

Re: Hooking event problem
 
Quote:

Originally Posted by teh ORiON (Post 1560652)
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 :P

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 :P


All times are GMT -4. The time now is 19:31.

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