Raised This Month: $ Target: $400
 0% 

[SOLVED] find_ent_by_owner() on client_disconnect()


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 07-27-2011 , 06:54   [SOLVED] find_ent_by_owner() on client_disconnect()
Reply With Quote #1

Hi,
I got a problem when remove entity created by owner when owner disconnect from server. You can see an example code that i used in server. I got this error log:
Code:
L 07/27/2011 - 17:17:46: [ENGINE] Invalid player 12 (not in-game)
L 07/27/2011 - 17:17:46: [AMXX] Displaying debug trace (plugin "TestCreateEntity.amxx")
L 07/27/2011 - 17:17:46: [AMXX] Run time error 10: native error (native "find_ent_by_owner")
And this is the code:
PHP Code:
public client_disconnect(id)
{
    
//I want remove all ent created by owner when he disconnect from server.
    
RemoveUserEntity(id)
}

public 
EventRoundStart()
{
    
RemoveAllBananaEntity()
}

//Cl_cmd
public CreateBananaEnt(id)
{
    if(!
is_user_alive(id)) return PLUGIN_HANDLED
    
    
if(pev(idpev_flags) & FL_ONGROUND)
    {
        
CreateTripEntity(id)
    }

        return 
PLUGIN_HANDLED
}

CreateTripEntity(id)
{
    static 
Float:origin[3], ent
    pev
(idpev_originorigin)
    
    
ent engfunc(EngFunc_CreateNamedEntityengfunc(EngFunc_AllocString"info_target"))
    if(
pev_valid(ent))
    {
        
set_pev(entpev_classname"banana_ent")
        
set_pev(entpev_originorigin)
        
engfunc(EngFunc_SetModelentMODEL_BANANA)
        
engfunc(EngFunc_SetSizeentFloat:{-3.0, -3.0, -3.0}, Float:{3.03.03.0})
        
set_pev(entpev_solid1)
        
set_pev(entpev_movetype6)
        
set_pev(entpev_sequence1)
        
set_pev(entpev_ownerid)
        
set_rendering(entkRenderFxGlowShell303030kRenderTransAlpha10)
        
emit_sound(entCHAN_VOICESOUND_BANANA1.0ATTN_NORM0PITCH_NORM)
        
client_print(idprint_center"Banana entity has been created")
    }
}

//Remove all ent created by owner
RemoveUserEntity(id)
{
    new 
ent find_ent_by_owner(-1"banana_ent"id0)
    while(
ent 0)
    {
        if(
pev_valid(ent)) remove_entity(ent)
        
ent find_ent_by_owner(-1"banana_ent"id0)
    }
}

//Remove all banana ent found on map 
RemoveAllBananaEntity()
{    
    new 
ent find_ent_by_class(-1"banana_ent")
    while(
ent 0)
    {
        
remove_entity(ent)
        
ent find_ent_by_class(-1"banana_ent")
    }

All i want to do is remove all entity created by owner when he left the server.
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019

Last edited by yokomo; 04-22-2012 at 14:45. Reason: Solved
yokomo is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-27-2011 , 10:59   Re: [Help] find_ent_by_owner() on client_disconnect()
Reply With Quote #2

If you are getting that error, then you will have to manually check for ownership using the find_ent_by_class() and entity_get_edict(..., EV_INT_owner).
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
yokomo
Surprise Ascot!
Join Date: May 2010
Location: Malaysia
Old 07-27-2011 , 12:03   Re: [Help] find_ent_by_owner() on client_disconnect()
Reply With Quote #3

Quote:
Originally Posted by Exolent[jNr] View Post
If you are getting that error, then you will have to manually check for ownership using the find_ent_by_class() and entity_get_edict(..., EV_INT_owner).
Can you make an example how to check it?

***Edited***

I've looking in OT's nademode code and found how the way he remove owner's entity it look like this:
PHP Code:
RemovePlayerEntity(id)
{
    static 
ent
    ent 
= -1
    
    
while ((ent find_ent_by_class(entTRIP_CLASSNAME)))
    {
        if(
pev(entpev_owner) != id)
            continue
        
        if(
pev_valid(ent)) remove_entity(ent)
    }

Tested no error log yet.
__________________
Team-MMG CS1.6 Servers:
✅ MultiMod -- 103.179.44.152:27016
✅ Zombie Plague -- 103.179.44.152:27015
✅ Zombie Escape -- 103.179.44.152:27017
✅ Klassik Kombat -- 103.179.44.152:27018
✅ Boss-Battle -- 103.179.44.152:27019

Last edited by yokomo; 07-27-2011 at 12:17.
yokomo is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-27-2011 , 12:16   Re: [Help] find_ent_by_owner() on client_disconnect()
Reply With Quote #4

Code:
new ent = find_ent_by_class -1 while ent > 0     if valid ent and id = ent owner         remove ent     ent = find_ent_by_class ent
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-27-2011 , 12:24   Re: [Help] find_ent_by_owner() on client_disconnect()
Reply With Quote #5

Hmm, wouldn't this:
Code:
    while(ent > 0)
    {
        remove_entity(ent)
        ent = find_ent_by_class(-1, "banana_ent")
    }
...make an infinite loop ? since find_ent_by_class() would always return the same entity over and over...

Anyway... you should use ent instead of -1 there and asign ent to -1 when you create it... but I'm gonna add the owner check aswell:
Code:
new ent = -1
// "id" is player's entity id

while((ent = find_ent_by_class(ent, "banana_ent")) != 0)
{
    if(entity_get_int(ent, EV_ENT_owner) == id)
        remove_entity(ent)
}
__________________

Last edited by Hunter-Digital; 07-27-2011 at 12:40.
Hunter-Digital is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 07-27-2011 , 12:32   Re: [Help] find_ent_by_owner() on client_disconnect()
Reply With Quote #6

Quote:
Originally Posted by Hunter-Digital View Post
...make an infinnite loop ? since find_ent_by_class() would always return the same entity over and over...
It can't return the same entity after it is removed.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
Hunter-Digital
Veteran Member
Join Date: Aug 2006
Location: In the Game [ro]
Old 07-27-2011 , 12:39   Re: [Help] find_ent_by_owner() on client_disconnect()
Reply With Quote #7

Quote:
Originally Posted by Exolent[jNr] View Post
It can't return the same entity after it is removed.
Oh right =) but if it didn't remove that entity the loop would've failed.

Still, it would be faster to input the entity back to the function to limit the search range... just pointing it out.

EDIT: Also, AFAIK, it would also be useless to check for valid entity since that function only returns valid entities... reference to yokomo's last edit.
__________________

Last edited by Hunter-Digital; 07-27-2011 at 12:41.
Hunter-Digital 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 01:09.


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