AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   RegisterHamFromEntity sends incorrectly (https://forums.alliedmods.net/showthread.php?t=92417)

Emp` 05-15-2009 04:01

RegisterHamFromEntity sends incorrectly
 
I have two plugins that use two different custom entities to think.

In the first code:
Code:

        new ent = fm_create_entity("info_target");
        set_pev(ent, pev_classname, "PPloop");
        RegisterHamFromEntity(Ham_Think, ent, "PartyLoop", 1);
        set_pev(ent, pev_nextthink, get_gametime()+1.0);

Second code:
Code:

                if( !pev_valid(hill) )
                        hill = fm_create_entity("info_target");
                set_pev(hill, pev_classname, "PPHill");
                set_pev(hill, pev_iuser1, HILL_TIME);

                if( HamThink == HamHook:-1 )
                        HamThink = RegisterHamFromEntity(Ham_Think, hill, "HillThink", 1);
                else
                        EnableHamForward( HamThink );

                set_pev(hill, pev_nextthink, get_gametime()+1.0);

However, the second HamThink is being passed the entity from the first HamThink.
Code:

public HillThink( ent )
{
        if( ent != hill ){
                new name[32];
                pev(ent, pev_classname, name, 31);
                client_print(0, print_chat, "%d is a hill apparently. class %s", ent, name );
                return;
        }
        //...
}

It prints: 82 is a hill apparently. class PPloop

Obviously I can do a classname check to get around this problem, but IMO it should not be doing this.

Have I misinterpreted RegisterHamFromEntity, after changing the classname do I need a delay before RegisterHamFromEntity, or is it just whacky?

SchlumPF* 05-15-2009 05:15

Re: RegisterHamFromEntity sends incorrectly
 
RegisterHamFromEntity checks the entitys classname and registeres a hook for all entitys whith the same classname. if your classname was a info_target, it will register a hook for info_target even though you might have changed the classname.
all you have to do is a single Ham_Think hook for info_targets and check which costum entities id matches the send one of Ham_Think

Emp` 05-15-2009 09:42

Re: RegisterHamFromEntity sends incorrectly
 
Quote:

Originally Posted by SchlumPF* (Post 827780)
if your classname was a info_target, it will register a hook for info_target even though you might have changed the classname.

That doesn't seem to make sense. RegisterHamFromEntity is supposed to be used on none default entities, why would I want to use it on "info_target" (I thought that was a default entity)

Quote:

Originally Posted by SchlumPF* (Post 827780)
all you have to do is a single Ham_Think hook for info_targets and check which costum entities id matches the send one of Ham_Think

I'd rather not...

hlstriker 05-15-2009 11:08

Re: RegisterHamFromEntity sends incorrectly
 
From hamsandwich.inc:
PHP Code:

/**
 * Hooks the virtual table for the specified entity's class.
 * An example would be: RegisterHam(Ham_TakeDamage, id, "player_hurt");
 * Look at the Ham enum for parameter lists.
 * Note: This will cause hooks for the entire internal class that the entity is
 *       not exclusively for the provided entity.
 *
 * @param function        The function to hook.
 * @param EntityId        The entity classname to hook.
 * @param callback        The forward to call.
 * @param post            Whether or not to forward this in post.
 * @return                 Returns a handle to the forward.  Use EnableHamForward/DisableHamForward to toggle the forward on or off.
 */
native HamHook:RegisterHamFromEntity(Ham:function, EntityId, const Callback[], Post=0); 

So, it does make more sense to use RegisterHam() if you already know your entities classname.

Arkshine 05-15-2009 11:15

Re: RegisterHamFromEntity sends incorrectly
 
RegisterHam() accepts only default entities as classname. I would use register_think(), it rocks. ^^

Emp` 05-15-2009 15:44

Re: RegisterHamFromEntity sends incorrectly
 
Quote:

Originally Posted by arkshine (Post 827926)
I would use register_think(), it rocks. ^^

Ya... but I want to be able to disable it.

Arkshine 05-15-2009 16:36

Re: RegisterHamFromEntity sends incorrectly
 
What about to change the classname when you want to disable it. Like "_PPloop" and the function will not called ?


All times are GMT -4. The time now is 01:30.

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