AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved Get 'Owner' of other third entity (https://forums.alliedmods.net/showthread.php?t=333250)

sursista 06-27-2021 17:19

Get 'Owner' of other third entity
 
Hi, I haven't touched anything Pawn in many years and I'm a little green.

I want to get the owner of a third entity such as a bazooka.

The plugin works like this:

1-You buy the Item, you receive a flag.
2-If the victim receives 500HP of damage from a Player (the player receives another flag).
3-If the victim dies, all the attackers that inflicted a damage of 500HP, will also die.

So far everything works fine, the problem comes when we handle third entities, such as the famous plugins of:

1-ZP Bazooka.
2-ZP Taun Cannon.
3-ZP Plasma Rifle.
4-Other entities that cause harm to the victim "Player".

I have tried everything and searched but without success, I do not handle the issue of entities well.

PHP Code:

public fw_TakeDamage(victiminflictorattackerFloat:damagedamage_type)
{
    if (
flag_get(g_IsSweetRevengevictim) && !zp_core_is_zombie(attacker))
    {
        if (
victim == attacker || !is_user_alive(attacker))
            return 
HAM_IGNORED;
    
        if(
is_user_alive(victim) && !zp_core_is_zombie(attacker) || is_user_alive(victim) && !zp_core_is_zombie(inflictor))
        {        
            
g_fDamage[attacker] += damage;
                
            
set_hudmessage(25525500.030.8806.04.00.10.24)
            
ShowSyncHudMsg(attackerg_hudmsg1"Zombie Hurt Limit:  %.2fHP/%iHP."g_fDamage[attacker], 500// Example damage
                
            
if (g_fDamage[attacker] >= 500// Example damage
            
{
                
flag_set(g_IsAttackerattacker)
                
                if (
flag_get(g_IsAttackerattacker))
                    
set_user_rendering(attackerkRenderFxGlowShell2552550kRenderNormal 15)
    
            }
        }
    }
    return 
HAM_IGNORED;
}

public 
fw_PlayerKilled(victimattackershouldgib)
{
    if (
flag_get(g_IsSweetRevengevictim))
    {    
        if (
is_user_alive(victim) || !zp_core_is_zombie(victim))
            return;
        
        static 
victim_name[33
        
        
get_user_name(victimvictim_namesizeof victim_name -1
        
        
ChatColor(0"!gZombie %s !tbought '!gSweet Revenge!t' and everyone who !gHurt Zombie!t: !g500HP !talso !gDied!t!"victim_name
        
        for( new 
id 1id <= 32id++ )
        {
            if (
flag_get(g_IsAttackerid))
            {    
                
set_user_rendering(id)
                
                
user_kill(id);
                
                
g_fDamage[id] = 0.0;
            }
        }
        
flag_unset(g_IsSweetRevengevictim)
    }



Natsheh 06-27-2021 21:46

Re: Get 'Owner' of other third entity
 
It depends on how youre actually dealing the damage in the third party plugins such as custom weapons etc...

Celena Luna 06-28-2021 00:03

Re: Get 'Owner' of other third entity
 
I think as long as the entity deal damage via ExecuteHamB TakeDamge with correct attacker and victim input, it should work.

The attacker from those entity should be get from pev_owner

PHP Code:

public ShootEntity(id)
{
    new 
ent;
    
//Do usual create entity stuff ()
    //...
    
set_pev(entpev_ownerid)
    
//...
}

public 
ShootEntityTouch(entid_touched)
{
    
//Do the usual check stuff like valid, alive,...
    
static iOwneriOwner pev(entpev_owner)
    static 
iVictimiVitcim FM_NULLENT;
    static 
FloatfOrigin[3]; pev(entpev_originfOrigin);

    
//In loop-for or loop-while to check AoE damage
    
while((iVictim engfunc(EngFunc_FindEntityInSphereiVictimfOriginEXP_RADIUS)) > 0)
    {
        if(
is_user_alive(iVictim) && zp_get_user_zombie(iVictim))
        {
            
ExecuteHamB(Ham_TakeDamageiVictimentiOwnerDAMAGEDMG_GENERIC); //ent or iOwner is fine.
        
}
    }
    
//finish up


Some plugin used ent as attacker so that would lead to not passing though "player takedamage" forward
ExecuteHam also won't pass though takedamage forward, must be ExecuteHamB

sursista 06-28-2021 05:52

Re: Get 'Owner' of other third entity
 
Quote:

Originally Posted by Celena Luna (Post 2751362)
I think as long as the entity deal damage via ExecuteHamB TakeDamge with correct attacker and victim input, it should work.

The attacker from those entity should be get from pev_owner

PHP Code:

public ShootEntity(id)
{
    new 
ent;
    
//Do usual create entity stuff ()
    //...
    
set_pev(entpev_ownerid)
    
//...
}

public 
ShootEntityTouch(entid_touched)
{
    
//Do the usual check stuff like valid, alive,...
    
static iOwneriOwner pev(entpev_owner)
    static 
iVictimiVitcim FM_NULLENT;
    static 
FloatfOrigin[3]; pev(entpev_originfOrigin);

    
//In loop-for or loop-while to check AoE damage
    
while((iVictim engfunc(EngFunc_FindEntityInSphereiVictimfOriginEXP_RADIUS)) > 0)
    {
        if(
is_user_alive(iVictim) && zp_get_user_zombie(iVictim))
        {
            
ExecuteHamB(Ham_TakeDamageiVictimentiOwnerDAMAGEDMG_GENERIC); //ent or iOwner is fine.
        
}
    }
    
//finish up


Some plugin used ent as attacker so that would lead to not passing though "player takedamage" forward
ExecuteHam also won't pass though takedamage forward, must be ExecuteHamB

It seems to be working, I changed how the bazooka plugin kills its victims and now if it registers it when dying, but not when taking damage in TakeDamage:

PHP Code:

    new maxdamage get_cvar_num("zp_bazooka_damage");
    new 
damageradius get_cvar_num("zp_bazooka_radius");

    new 
PlayerPos[3], distance
    
for (new 1<= 32i++) 
    {
        if ( 
is_user_alive(i)) 
        {       
            new 
id pev(entpev_owner)

            if(
is_user_alive(id)) 
            {
            if((
zp_core_is_zombie(id)) || ((zp_class_nemesis_get(id))))
            if((
zp_core_is_zombie(i)) || (zp_class_nemesis_get(i))) 
                continue;

            if((!
zp_core_is_zombie(id)) && (!zp_class_nemesis_get(id))) 
            if((!
zp_core_is_zombie(i)) && (!zp_class_nemesis_get(i))) 
                continue;
            }

            
get_user_origin(iPlayerPos);

            
distance get_distance(PlayerPosNonFloatEndOrigin);

            if (
distance <= damageradius)
            { 
            
message_begin(MSG_ONEgmsg_screenshake, {0,0,0}, i);
            
write_short(1<<14);
            
write_short(1<<14);
            
write_short(1<<14);
            
message_end();

            new 
attacker pev(entpev_owner);
    
            
baz_damage(iattackermaxdamage floatround(floatmul(float(maxdamage), floatdiv(float(distance), float(damageradius)))), "bazooka");
            }
        }
    } 

And call function final:

PHP Code:

baz_damage(idattackerdamageweaponDescription[])
{
    if ( 
zp_core_is_zombie(attacker) || !is_user_alive(attacker) || zp_class_nemesis_get(attacker) ) 
    {
        
ChatColor(attacker"!g[ESSA] !tThe /gbug bazooka !tis !gFixed!")
        return;
    }

    if ( 
pev(idpev_takedamage) == DAMAGE_NO 
        return;
    if ( 
damage <= 
        return;

    new 
userHealth get_user_health(id);

    if (
userHealth damage <= 
    {
    
dmgcount[attacker] += userHealth damage;
    
set_msg_block(gmsg_deathBLOCK_SET);
    
//ExecuteHamB(Ham_Killed, id, attacker, 2);
    
ExecuteHamB(Ham_TakeDamageid 2attackerfloat(damage), DMG_GENERIC); 
    
set_msg_block(gmsg_deathBLOCK_NOT);


    
message_begin(MSG_BROADCASTgmsg_death);
    
write_byte(attacker);
    
write_byte(id);
    
write_byte(0);
    
write_string(weaponDescription);
    
message_end();

    
set_pev(attackerpev_fragsfloat(get_user_frags(attacker) + 1));



Celena Luna 06-28-2021 06:29

Re: Get 'Owner' of other third entity
 
PHP Code:

if (userHealth damage <= 
{
    
dmgcount[attacker] += userHealth damage;
    
set_msg_block(gmsg_deathBLOCK_SET);
    
//ExecuteHamB(Ham_Killed, id, attacker, 2);
    
ExecuteHamB(Ham_TakeDamageid 2attackerfloat(damage), DMG_GENERIC); 
    
set_msg_block(gmsg_deathBLOCK_NOT);


isn't the condition of this part is "Do when victim gonna dead"?
Because of that, it only Execute Ham_TakeDamage when people is about to dead when taking that damage

=>

Quote:

Originally Posted by sursista (Post 2751338)
it registers it when dying, but not when taking damage

But it is OK to keep it like that though. I looked into the code of ZP Bazooka and found it is actually the part after that that you suppose to change:

(look at the highlight part and compare with your code)
Spoiler


The plugin "does damage" by setting player health though pev so it won't go through TakeDamage forward.

You should replace it with this:
PHP Code:

ExecuteHamB(Ham_TakeDamageid 2attackerfloat(damage), DMG_GENERIC); 


sursista 06-28-2021 07:12

Re: Get 'Owner' of other third entity
 
Quote:

Originally Posted by Celena Luna (Post 2751380)
PHP Code:

if (userHealth damage <= 
{
    
dmgcount[attacker] += userHealth damage;
    
set_msg_block(gmsg_deathBLOCK_SET);
    
//ExecuteHamB(Ham_Killed, id, attacker, 2);
    
ExecuteHamB(Ham_TakeDamageid 2attackerfloat(damage), DMG_GENERIC); 
    
set_msg_block(gmsg_deathBLOCK_NOT);


isn't the condition of this part is "Do when victim gonna dead"?
Because of that, it only Execute Ham_TakeDamage when people is about to dead when taking that damage

=>



But it is OK to keep it like that though. I looked into the code of ZP Bazooka and found it is actually the part after that that you suppose to change:

(look at the highlight part and compare with your code)
Spoiler


The plugin "does damage" by setting player health though pev so it won't go through TakeDamage forward.

You should replace it with this:
PHP Code:

ExecuteHamB(Ham_TakeDamageid 2attackerfloat(damage), DMG_GENERIC); 


It seems silly but it makes sense, now I understand it, thank you very much for everything, now work! :)

sursista 06-28-2021 11:11

Re: Get 'Owner' of other third entity
 
Quote:

Originally Posted by sursista (Post 2751382)
It seems silly but it makes sense, now I understand it, thank you very much for everything, now work! :)

I have removed the [SOLVED] prefix because I have found one last error and that is:

-If the victim is damaged with damage greater than her life, the bug reoccurs, even if other attackers damage the victim and obtain a flag. If the first / third attacker kills the victim with a single hit (only one), the bug occurs, and does not call the other functions.

My Code (Sweet Revenge)

PHP Code:

public fw_TakeDamage(victiminflictorattackerFloat:damagedamage_type)
{
    
//if (flag_get(g_IsSweetRevenge, victim) && !zp_core_is_zombie(attacker))
    //{
        
if (victim == attacker || !is_user_alive(attacker))
            return 
HAM_IGNORED;
    
        if(
is_user_alive(victim) && !zp_core_is_zombie(attacker))
        {    
            
g_fDamageToSweetRevenge[attacker] += damage;
                
            
set_hudmessage(25525500.030.8806.04.00.10.24)
            
ShowSyncHudMsg(attackerg_hudmsg1"[ESSA] Zombie Hurt Limit:  %.2fHP/%iHP."g_fDamageToSweetRevenge[attacker], get_pcvar_num(g_sr_damage_hp))
                
            if (
g_fDamageToSweetRevenge[attacker] >= get_pcvar_float(g_sr_damage_hp))
            {
                
flag_set(g_IsAttackerattacker)
                
                if (
flag_get(g_IsAttackerattacker))
                {
                    if (
get_pcvar_num(g_sr_glow_victim) > 0)
                        
set_user_rendering(attackerkRenderFxGlowShellget_pcvar_num(g_sr_glow_victim_R), get_pcvar_num(g_sr_glow_victim_G), get_pcvar_num(g_sr_glow_victim_B), kRenderNormal 15)
                    else
                        
set_user_rendering(attacker)
                }
            }
        }    
    
//}
        
return HAM_IGNORED;
}

public 
fw_Killed(victimattackershouldgib)
{
    
//if (flag_get(g_IsSweetRevenge, victim))
    //{
        
if (get_pcvar_num(g_sr_aura))
            
remove_task(victim+TASK_AURA)
            
        if (
is_user_alive(victim) || !zp_core_is_zombie(victim))
            return;
            
        
flag_set(g_IsAttackerattacker)
        
        for( new 
id 1id <= 32id++ )
        {    
            if (
flag_get(g_IsAttackerid))
            {    
                
sr_damage(victimid"sweetrevenge");
                
                
set_user_rendering(id)
                
                
g_fDamageToSweetRevenge[id] = 0.0;
            }
        }
        
        static 
victim_name[33
    
        
get_user_name(victimvictim_namesizeof victim_name -1
        
        
set_hudmessage(015000.350.5006.04.00.10.24)
        
ShowSyncHudMsg(0g_hudmsg2"[ESSA] Zombie %s bought 'Sweet Revenge' and everyone who Hurt Zombie: %iHP also Died!"victim_nameget_pcvar_num(g_sr_damage_hp)) 
        
        
ChatColor(0"!g[ESSA] Zombie %s !tbought '!gSweet Revenge!t' and everyone who !gHurt Zombie!t: !g%iHP !talso !gDied!t!"victim_nameget_pcvar_num(g_sr_damage_hp)) 
    
        if(
get_pcvar_num(g_sr_done_sound))
        {
            new 
sound[SOUND_MAX_LENGTH]
    
            
ArrayGetString(g_sound_sweetrevenge_donerandom_num(0ArraySize(g_sound_sweetrevenge_done) - 1), soundcharsmax(sound))
            
emit_sound(0CHAN_VOICEsound1.0ATTN_NORM0PITCH_NORM)
        }
    
//}


Code Bazooka (Example)

PHP Code:

baz_damage(idattackerdamageweaponDescription[])
{
    if ( 
zp_core_is_zombie(attacker) || !is_user_alive(attacker) || zp_class_nemesis_get(attacker) ) 
    {
        
ChatColor(attacker"!g[ESSA] !tThe '!gbug bazooka!t' is !gFixed!")
        return;
    }

    if ( 
pev(idpev_takedamage) == DAMAGE_NO 
        return;
    if ( 
damage <= 
        return;

    new 
userHealth get_user_health(id);

    if (
userHealth damage <= 
    {
    
dmgcount[attacker] += userHealth damage;
    
set_msg_block(gmsg_deathBLOCK_SET);
    
ExecuteHamB(Ham_Killedidattacker2); 
    
set_msg_block(gmsg_deathBLOCK_NOT);

    
message_begin(MSG_BROADCASTgmsg_death);
    
write_byte(attacker);
    
write_byte(id);
    
write_byte(0);
    
write_string(weaponDescription);
    
message_end();

    
//set_pev(attacker, pev_frags, float(get_user_frags(attacker) + 1));

    
new kname[32], vname[32], kauthid[32], vauthid[32], kteam[10], vteam[10];

    
get_user_name(attackerkname31);
    
get_user_team(attackerkteam9);
    
get_user_authid(attackerkauthid31);

    
get_user_name(idvname31);
    
get_user_team(idvteam9);
    
get_user_authid(idvauthid31);

    
log_message("^"%s<%d><%s><%s>^" killed ^"%s<%d><%s><%s>^" with ^"%s^""
    
knameget_user_userid(attacker), kauthidkteam
    
vnameget_user_userid(id), vauthidvteamweaponDescription);
    }
    else 
    {
    
dmgcount[attacker] += damage;
    new 
origin[3];
    
get_user_origin(idorigin);

    
message_begin(MSG_ONE,gmsg_damage,{0,0,0},id);
    
write_byte(21);
    
write_byte(20);
    
write_long(DMG_BLAST);
    
write_coord(origin[0]);
    
write_coord(origin[1]);
    
write_coord(origin[2]);
    
message_end();

    
ExecuteHamB(Ham_TakeDamageid2attackerfloat(damage), DMG_GENERIC); 
    
//set_pev(id, pev_health, pev(id, pev_health) - float(damage));
    
}


I insist, if the attacker damages the victim and the first hit is not definitive, everything works fine, but if the attacker or other attackers kill the victim with a single hit of damage, the bug happens.

Natsheh 06-28-2021 11:53

Re: Get 'Owner' of other third entity
 
Celena luna

What is 2 suppose to mean in Execution of ham_TakeDamage

Code:

ExecuteHamB(Ham_TakeDamage, id , 2, attacker, float(damage), DMG_GENERIC);
You do realize that the second argument or parameter in Ham_TakeDamage is the inflictor index which holds the entity id that dealt the damage or dealing the damage it can be a nonplayer entity or a player entity.

For the topic author id suggest to organize your code more often.

sursista 06-28-2021 12:03

Re: Get 'Owner' of other third entity
 
Quote:

Originally Posted by Natsheh (Post 2751404)
Celena luna

What is 2 suppose to mean in Execution of ham_TakeDamage

Code:

ExecuteHamB(Ham_TakeDamage, id , 2, attacker, float(damage), DMG_GENERIC);
You do realize that the second argument or parameter in Ham_TakeDamage is the inflictor index which holds the entity id that dealt the damage or dealing the damage it can be a nonplayer entity or a player entity.

I am a bit green, that part of the code I have not written, nor do I know what the number '2' means, if someone with more experience knows it, maybe we can understand it, but I suppose it will be the entity. If the attacker does damage (and it is not definitive) it does receive it and it works well, but it does not work when the attacker kills the victim with a single hit, such as increasing the damage from a cvar (to make a test)

Natsheh 06-28-2021 12:12

Re: Get 'Owner' of other third entity
 
I already know you didn't write the code infact it was taken from someone on the forums lets not get into who wrote it and who didn't the number 2 is a player index since entities with id numbers from 1 - 32 are reserved for players/clients


All times are GMT -4. The time now is 15:50.

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