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

Is worldspawn supposed to be invalid with pev_valid? (or is_valid_ent)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 10-21-2017 , 09:28   Is worldspawn supposed to be invalid with pev_valid? (or is_valid_ent)
Reply With Quote #1

I am working on a mod that involves sticking to walls, so, I'm hooking FM_Touch. However since some other pesky plugins are using ents, and it so happens that this plugin also hooks FM_Touch and destroys the ent, while being above my wall stick plugin in plugins.ini. So basically every single time that ent touches me, it gets destroyed, then it triggers the FM_Touch in my other plugin and causes invalid entity errors for pev().

I added a check for pev_valid but this broke my wallclimb / wallhang. Since it only returns 0 for worldspawn, and worldspawn is id 0, I just added an extra check.
Code:
public fwd_touch(id, world) {     if(world != 0 && !pev_valid(world))         return FMRES_IGNORED;     if(is_user_alive(id)) {         new classname[32];         pev(world, pev_classname, classname, charsmax(classname));         if(equal(classname, "worldspawn") || equal(classname, "func_wall") || equal(classname, "func_breakable"))             pev(id, pev_origin, g_wallorigin[id]);     }     return FMRES_IGNORED; }

This seems a bit hacky though, and based on my judgement worldspawn should always be a valid entity, but I don't know, so I'm asking here: is this normal? pev_valid returns 0 on worldspawn on both 1.8.3 and 1.8.2, only tested with reHLDS.
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.
aron9forever is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-21-2017 , 09:33   Re: Is worldspawn supposed to be invalid with pev_valid? (or is_valid_ent)
Reply With Quote #2

Entity must be valid all the time in Touch. So you can't remove it with remove_entity (EngFunc_RemoveEntity), you should use FL_KILLME flag.
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 10-21-2017 , 09:59   Re: Is worldspawn supposed to be invalid with pev_valid? (or is_valid_ent)
Reply With Quote #3

Quote:
Originally Posted by PRoSToTeM@ View Post
Entity must be valid all the time in Touch. So you can't remove it with remove_entity (EngFunc_RemoveEntity), you should use FL_KILLME flag.
I'm not even sure what the plugin does, it's pretty garbage and written by someone else, but I have been requested to implement it via its natives.

It's irrelevant to the topic, basically I was touching invalid ents, so I added a pev_valid() check, which returns 0 on worldspawn. My question is if this is the intended functionality or a bug(seems weird that worldspawn is an invalid ent since it has valid properties such as classname).

Code:
pev_valid(0) //returns 0, shouldn't it return 1 or 2? is_valid_ent(0) //returns 0, shouldn't it return 1?
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 10-21-2017 at 10:04.
aron9forever is offline
aron9forever
Veteran Member
Join Date: Feb 2013
Location: Rromania
Old 10-21-2017 , 10:22   Re: Is worldspawn supposed to be invalid with pev_valid? (or is_valid_ent)
Reply With Quote #4

Well I guess I can answer my own question here
Code:
int is_ent_valid(int iEnt) {     if (iEnt < 1 || iEnt > gpGlobals->maxEntities) // <-- shot in the balls here         return 0;     if (iEnt <= gpGlobals->maxClients)     {         if (!MF_IsPlayerIngame(iEnt))         {             return 0;         }     } else {         if (FNullEnt(TypeConversion.id_to_edict(iEnt)))         {             return 0;         }     }     return 1; }

It still seems weird that 0 is not a valid ent, at least in the scope of this implementation / issue. I'll let you decide on that.

Code:
pev(1, pev_classname, classname, charsmax(classname)); //works fine if player is valid pev(0, pev_classname, classname, charsmax(classname)); //works fine pev(-1, pev_classname, classname, charsmax(classname)); //run time error pev_valid(1) //returns 2 pev_valid(0) //returns 0 pev_valid(-1) //returns 0
seems inconsistent to me
__________________
Meanwhile, in 2050:
Quote:
Originally Posted by aron9forever
useless small optimizations
Quote:
Originally Posted by Black Rose View Post
On a map that is 512x512x128 units you end up with 3,355,443,200,000 different "positions". To store each one of those positions individually in the variable "user_or" you need 12 terabytes of memory.

Last edited by aron9forever; 10-21-2017 at 10:28.
aron9forever is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 10-22-2017 , 04:19   Re: Is worldspawn supposed to be invalid with pev_valid? (or is_valid_ent)
Reply With Quote #5

Yep, there is some inconsistency with 0 and -1 entity ids in engine and fakemeta modules, some natives treat null entity as -1, some as 0, some doesn't allow to set null in some variables (like trace.pHit).

Also, entity removing in Touch can produce random crashes, so anyway you should solve the problem with this plugin(s).
__________________

Last edited by PRoSToTeM@; 10-22-2017 at 04:24.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
Reply


Thread Tools
Display Modes

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 18:53.


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