Raised This Month: $51 Target: $400
 12% 

GetEntPropEnt Error Handling


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Reflex
Member
Join Date: Apr 2008
Location: Russia, St. Petersburg
Old 08-30-2015 , 15:34   GetEntPropEnt Error Handling
Reply With Quote #1

Hello guys maybe you could help me a bit.

I do have a method which should destroy given client's projectiles.

Code:
new ent = -1;
while ((ent = FindEntityByClassname(ent, "tf_projectile_*")) != -1) {
    if (GetEntPropEnt(ent, Prop_Send, "m_hOwnerEntity") == client) {
        AcceptEntityInput(ent, "Kill");
    }
    // WARNING: next code block will cause issues!
    if (GetEntPropEnt(ent, Prop_Send, "m_hThrower") == client) {
        AcceptEntityInput(ent, "Kill");
    }
}
I would like to write the code once and support any further game updates which may add new projectiles. The problem is that some projectiles (rockets, arrows, bolts) store their owner inside m_hOwnerEntity prop but other projectiles (pipes, stickies) uses m_hThrower prop for that.

How could I check if entity do have one of the properties that I may need without running into `Native "GetEntPropEnt" reported: Property "m_hThrower" not found` error?
__________________

Last edited by Reflex; 08-30-2015 at 15:36. Reason: added code warning comment
Reflex is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 08-30-2015 , 15:39   Re: GetEntPropEnt Error Handling
Reply With Quote #2

I think FindSendPropOffs should return -1 if it's not found

edit: actually that takes classnames, but I guess FindDataMapOffs should work as long as they exist there too

Last edited by Miu; 08-30-2015 at 15:55.
Miu is offline
Reflex
Member
Join Date: Apr 2008
Location: Russia, St. Petersburg
Old 08-30-2015 , 18:02   Re: GetEntPropEnt Error Handling
Reply With Quote #3

Miu, thank you, FindDataMapOffs did the trick. Seems I need to read the dosc more carefully next time.

I'll leave my solution here for those who care.

Code:
stock DestroyClientProjectiles(client)
{
    new offset;
    new ent = -1;
    while ((ent = FindEntityByClassname(ent, "tf_projectile_*")) != -1) {
        // destroy rockets, arrows, bolts, etc
        offset = FindDataMapOffs(ent, "m_hOwnerEntity");
        if (offset != -1 && GetEntDataEnt2(ent, offset) == client) {
            AcceptEntityInput(ent, "Kill");
            continue;
        }
        
        // destroy pipes, stickies and other throwables
        offset = FindDataMapOffs(ent, "m_hThrower");
        if (offset != -1 && GetEntDataEnt2(ent, offset) == client) {
            AcceptEntityInput(ent, "Kill");
        }
    }
}
__________________
Reflex 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 15:42.


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