AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   how to prevent registerhamfromentity being called for whole classname (https://forums.alliedmods.net/showthread.php?t=251376)

avril-lavigne 11-12-2014 00:38

how to prevent registerhamfromentity being called for whole classname
 
RegisterHamFromEntity(Ham_Killed, ent, "fw_killed",1)
RegisterHamFromEntity(Ham_TakeDamage, ent, "fw_takedamage_ent",1)

in ent create func

when I do damage or kill ent
forward(s) calls as many times as many entities in the world

example there are two ents. 1 hit to ent makes two fwd calls
4 ents - 8 fwd calls.

how to filter it to have 1 forward call per one entity ?
I want to spawn entity again after kill .

So now I have 2 ents instead of 1
than 4 instead of 2 and so on .

engfunc(EngFunc_AllocString, "info_target"))
I Know I can register it for info_target than filter for classname
but not sure

also I cant give weapon to ent
entity_set_string(ent, EV_SZ_weaponmodel, knifemdl)
doesnt work

Jhob94 11-12-2014 04:31

Re: how to prevent registerhamfromentity being called for whole classname
 
why do you register hamkilled? It's not necessary, hook damage pre and if damage > health, hook a death event for entities where you do all you need when the entity must be removed.

avril-lavigne 11-12-2014 06:41

Re: how to prevent registerhamfromentity being called for whole classname
 
Ive already tried that

I have Two bots-entities.
look at the log

1st hit produce TWO lines instead of ONE , for EACH entity in the world

L 11/12/2014 - 13:28:09: [soccer.amxx] damage 65.00 victim health 35.00
L 11/12/2014 - 13:28:09: [soccer.amxx] damage 65.00 victim health 35.00

second hit also 2 lines

L 11/12/2014 - 13:28:12: [soccer.amxx] damage 65.00 victim health -30.00
L 11/12/2014 - 13:28:12: [soccer.amxx] damage 65.00 victim health -30.00

So condition below makes TWO entities instead of "killed" one

PHP Code:

public fw_takedamage_ent(victiminflictorattackerFloat:damagedamage_type)
{
  if(
damage >= entity_get_float(victim,EV_FL_health))
 {
              
               
emit_sound(victimCHAN_AUTOdeath_sound[random_num(0sizeof death_sound 1)], 1.0ATTN_NORM0PITCH_NORM)
        switch(
entity_get_int(victimEV_INT_team))
        {
            case 
1:create_bott()
            case 
2:create_botct()
        }
   }


After killing entity I have 4 bots instead of 1
2 calls of forward multiply 2 entities = 4

If I have 4 bots-entities. killing just ONE makes over 8 new bots....

I need to filter just one ent being damaged to prevent multiple fwd calls

Jhob94 11-12-2014 07:06

Re: how to prevent registerhamfromentity being called for whole classname
 
Man that must not be a real problem. Just check amount of entities that exists and return if already have the necessary ents.

Arkshine 11-12-2014 07:36

Re: how to prevent registerhamfromentity being called for whole classname
 
Why do you need this forward? Why you don't register with classname? Explain better, give a context.

Jhob94 11-12-2014 08:58

Re: how to prevent registerhamfromentity being called for whole classname
 
Quote:

Originally Posted by Arkshine (Post 2223241)
Why do you need this forward? Why you don't register with classname? Explain better, give a context.

I think he is registering with classname, the problem is that there is more than 1 entity with same classname so it revives 2 times. Verify the amount of entities and return if is complete is a good option.

Nextra 11-12-2014 10:35

Re: how to prevent registerhamfromentity being called for whole classname
 
Hamsandwich registers callbacks on entity classes, always. RegisterHamFromEntity gets the virtual table from an entity, but still registers the callback on the whole class of that entity. Registering a Ham callback on a single entity is not possible, and you have to do such filtering in your plugin code. Registering from two different entities that have the same class will register two callbacks onto that class, and as such the callback will be called twice. All of this is expected with the design of Hamsandwich.

avril-lavigne 11-12-2014 19:18

Re: how to prevent registerhamfromentity being called for whole classname
 
thanks, I will make different classes for both ents . [solved]


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

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