Raised This Month: $ Target: $400
 0% 

Helps with errors OnEntityCreated & OnEntityDestroyed


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ClassicGuzzi
Veteran Member
Join Date: Oct 2013
Location: Argentina
Old 03-06-2015 , 01:41   Helps with errors OnEntityCreated & OnEntityDestroyed
Reply With Quote #1

I'm having errors with this code on those functions:

PHP Code:
public OnEntityDestroyed(entity)
{
    if(!
g_isDBmap) return;
    if(!
IsValidEntity(entity)) return;
    
int rIndex GetRocketIndex(EntIndexToEntRef(entity));
    if(
rIndex == -1) return;
        [...] 
Error:
Quote:
L 03/06/2015 - 01:40:06: [SM] Native "EntIndexToEntRef" reported: Invalid entity index -2123601431
L 03/06/2015 - 01:40:06: [SM] Displaying call stack trace for plugin "dodgeball_redux.smx":
L 03/06/2015 - 01:40:06: [SM] [0] Line 1864, C:\Users\Daniel\Documents\GitHub\dodgeball\ad dons\sourcemod\scripting\dodgeball_redux.sp:: OnEntityDestroyed()
How could the entity parameter be a invalid entity? I added that IsValidEntity check and It didn't help.
So EntIndexToEntRef(entity) is getting a invalid entity and I don't know what to do.


2nd problem:

PHP Code:
public OnEntityCreated(entity, const String:classname[])
{
    if(!
g_isDBmap) return;
    if(!
StrEqual("tf_ammo_pack",classname)) return;
    
    
int dissolver CreateEntityByName("env_entity_dissolver");

    if (
dissolver == -1) return;
    
    
DispatchKeyValue(dissolver"dissolvetype""0");
    
DispatchKeyValue(dissolver"magnitude""1");
    
DispatchKeyValue(dissolver"target""!activator");

    
AcceptEntityInput(dissolver"Dissolve"entity);
    
AcceptEntityInput(dissolver"Kill");

Error:
Quote:
L 03/06/2015 - 01:40:18: SourceMod error session started
L 03/06/2015 - 01:40:18: Info (map "arena_well") (file "errors_20150306.log")
L 03/06/2015 - 01:40:18: [SM] Native "CreateEntityByName" reported: Cannot create new entity when no map is running
L 03/06/2015 - 01:40:18: [SM] Displaying call stack trace for plugin "dodgeball_redux.smx":
L 03/06/2015 - 01:40:18: [SM] [0] Line 1844, C:\Users\Daniel\Documents\GitHub\dodgeball\ad dons\sourcemod\scripting\dodgeball_redux.sp:: OnEntityCreated()
L 03/06/2015 - 02:44:58: Error log file session closed.
L 03/06/2015 - 02:58:55: SourceMod error session started
L 03/06/2015 - 02:58:55: Info (map "tfdb_inferno_a5") (file "errors_20150306.log")
L 03/06/2015 - 02:58:55: [SM] Native "CreateEntityByName" reported: Cannot create new entity when no map is running
L 03/06/2015 - 02:58:55: [SM] Displaying call stack trace for plugin "dodgeball_redux.smx":
L 03/06/2015 - 02:58:55: [SM] [0] Line 1844, C:\Users\Daniel\Documents\GitHub\dodgeball\ad dons\sourcemod\scripting\dodgeball_redux.sp:: OnEntityCreated()
The weird part about this is that it is called even on non DB maps. How could the OnEntityCreated be called while the map isn't running? and even then if the CreateEntityByName is being called it's mean that the entity created was "tf_ammo_pack" (dropped weapons and building's parts.

If anyone could help me on these one it would be great!
By the way, here is the code on GitHub, any suggestions (even if they are for something else in the code) are welcomed).
__________________

Last edited by ClassicGuzzi; 03-06-2015 at 01:43.
ClassicGuzzi is offline
psychonic

BAFFLED
Join Date: May 2008
Old 03-06-2015 , 08:56   Re: Helps with errors OnEntityCreated & OnEntityDestroyed
Reply With Quote #2

The "entity" var in OnEntityCreated and OnEntityDestroyed is already a (backwards-compatible) EntRef, not necessarily an index.

If you need it to be an explicit reference, you would actually need to to EntRefToEntIndex first, and then EntIndexToEntRef.
psychonic is offline
ClassicGuzzi
Veteran Member
Join Date: Oct 2013
Location: Argentina
Old 03-06-2015 , 11:22   Re: Helps with errors OnEntityCreated & OnEntityDestroyed
Reply With Quote #3

Quote:
Originally Posted by psychonic View Post
The "entity" var in OnEntityCreated and OnEntityDestroyed is already a (backwards-compatible) EntRef, not necessarily an index.

If you need it to be an explicit reference, you would actually need to to EntRefToEntIndex first, and then EntIndexToEntRef.
Wow thanks, that's really helpful!

By the way, is there any list or something to know which functions will work (or won't) with entity reference?

Also the "Cannot create new entity when no map is running" could it be related to having problem with the host? Like having a lot of warp/lose connection for a couple seconds, etc ?
__________________
ClassicGuzzi is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 03-06-2015 , 11:38   Re: Helps with errors OnEntityCreated & OnEntityDestroyed
Reply With Quote #4

Quote:
Originally Posted by ClassicGuzzi View Post
Wow thanks, that's really helpful!

By the way, is there any list or something to know which functions will work (or won't) with entity reference?
All of SM's entity methods should work with entity references. EntIndexToEntRef is the obvious exception here. The problem is that methods will error out if the entity reference is no longer valid.

Quote:
Originally Posted by ClassicGuzzi View Post
Also the "Cannot create new entity when no map is running" could it be related to having problem with the host? Like having a lot of warp/lose connection for a couple seconds, etc ?
The server creates entities as the map is loading, but SM will stop you from manually creating entities until the map finishes loading. If you really want to remove map entities, you should use Stripper: Source to do it.
__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 03-06-2015 at 11:39.
Powerlord is offline
psychonic

BAFFLED
Join Date: May 2008
Old 03-06-2015 , 11:42   Re: Helps with errors OnEntityCreated & OnEntityDestroyed
Reply With Quote #5

Quote:
Originally Posted by ClassicGuzzi View Post
By the way, is there any list or something to know which functions will work (or won't) with entity reference?
All first-party APIs should input and output references where an entity is passed. However, unless noted otherwise, this is usually going to be a backwards compatible reference, rather than an explicit one.

It makes the API a bit odd for your specific case of needing to turn it into an explicit reference, but it's not too bad once understand what's going on underneath. Similar needs to be done if you explicitly need an index and have any chance of the entity being a non-networked ent.

Quote:
Originally Posted by ClassicGuzzi View Post
Also the "Cannot create new entity when no map is running" could it be related to having problem with the host? Like having a lot of warp/lose connection for a couple seconds, etc ?
Is it possible that you're hitting that in OnEntityDestroyed at the end of a map, where all entities get destroyed?
psychonic is offline
ClassicGuzzi
Veteran Member
Join Date: Oct 2013
Location: Argentina
Old 03-06-2015 , 11:43   Re: Helps with errors OnEntityCreated & OnEntityDestroyed
Reply With Quote #6

Quote:
Originally Posted by Powerlord View Post
All of SM's entity methods should work with entity references. EntIndexToEntRef is the obvious exception here. The problem is that methods will error out if the entity reference is no longer valid.
That's ok, that's why I should always use INVALID_ENT_REFERENCE to check en entity reference.

Quote:
Originally Posted by Powerlord View Post
The server creates entities as the map is loading, but SM will stop you from manually creating entities until the map finishes loading. If you really want to remove map entities, you should use Stripper: Source to do it.
That's not what I want, this was made to dissolve dropped weapons while playing. I guess I'll just make g_isDBmap false on map end, and it won't be true again until the map is already running.

Thanks
__________________
ClassicGuzzi 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 10:56.


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