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

[ H3LP ] Get All entity keyvalues


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
DarthMan
Veteran Member
Join Date: Aug 2011
Old 02-13-2018 , 03:49   [ H3LP ] Get All entity keyvalues
Reply With Quote #1

Hello. Is there any way to get all keyvalues of entities from the bsp file? I want to get for each entity, every keyvalue because I'm working on an EntMod and that seems to be the trickier part in SourceMod. Any help would be appreciated. Thanks !
DarthMan is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 02-13-2018 , 08:49   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #2

Thing is that they're not actually stored as KeyValues internally. They're just a bunch of string compares that (usually) map the key/value to member variables of the entity. If you want to find what keys are accepted by an entity, go to the CEntityType::KeyValue function and follow those string compares, I'm not sure if theres an easier way to do this. This can be seen here: https://mxr.alliedmods.net/hl2sdk-sd...shared.cpp#320

nosoop does have a plugin that reads the entity lump from OnLevelInit, which contains the raw entity data as it is from bsp (looks like this: https://developer.valvesoftware.com/..._Format#Entity) and converts it into KeyValues, so that might be what you're looking for.

Also if you're trying to add your own custom keyvalues into the bsp and reading them from a plugin, I made an extension that makes that easy to do: https://github.com/SlidyBat/CustomKeyValues

Hope this H3LPs.

Last edited by hmmmmm; 02-13-2018 at 08:51.
hmmmmm is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 02-13-2018 , 10:31   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #3

Quote:
Originally Posted by hmmmmm View Post
Thing is that they're not actually stored as KeyValues internally. They're just a bunch of string compares that (usually) map the key/value to member variables of the entity. If you want to find what keys are accepted by an entity, go to the CEntityType::KeyValue function and follow those string compares, I'm not sure if theres an easier way to do this. This can be seen here: https://mxr.alliedmods.net/hl2sdk-sd...shared.cpp#320

nosoop does have a plugin that reads the entity lump from OnLevelInit, which contains the raw entity data as it is from bsp (looks like this: https://developer.valvesoftware.com/..._Format#Entity) and converts it into KeyValues, so that might be what you're looking for.

Also if you're trying to add your own custom keyvalues into the bsp and reading them from a plugin, I made an extension that makes that easy to do: https://github.com/SlidyBat/CustomKeyValues

Hope this H3LPs.
Thanks, will have a look
DarthMan is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-03-2018 , 04:04   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #4

Quote:
Originally Posted by hmmmmm View Post
Thing is that they're not actually stored as KeyValues internally. They're just a bunch of string compares that (usually) map the key/value to member variables of the entity. If you want to find what keys are accepted by an entity, go to the CEntityType::KeyValue function and follow those string compares, I'm not sure if theres an easier way to do this. This can be seen here: https://mxr.alliedmods.net/hl2sdk-sd...shared.cpp#320

nosoop does have a plugin that reads the entity lump from OnLevelInit, which contains the raw entity data as it is from bsp (looks like this: https://developer.valvesoftware.com/..._Format#Entity) and converts it into KeyValues, so that might be what you're looking for.

Also if you're trying to add your own custom keyvalues into the bsp and reading them from a plugin, I made an extension that makes that easy to do: https://github.com/SlidyBat/CustomKeyValues

Hope this H3LPs.
Property "m_iHammerID" not found
DarthMan is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 03-03-2018 , 05:57   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #5

Show us the code you're using that causes that error.
hmmmmm is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-03-2018 , 06:17   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #6

Quote:
Originally Posted by hmmmmm View Post
Show us the code you're using that causes that error.
Code:
void StoreEnts() {     for(int iEnt = MaxClients + 1; iEnt < MAX_ENTS + MaxClients; iEnt++)     {         if(IsValidEntity(iEnt))         {             KeyValues kKeys = LevelEntity_GetKeysByEntity(iEnt);                         if(kKeys)             {                 char szKeyBuffer[128], szValueBuffer[128];                 kKeys.GotoFirstSubKey(false);                 do                 {                     kKeys.GetSectionName(szKeyBuffer, charsmax(szKeyBuffer));                     kKeys.GetString(NULL_STRING, szValueBuffer, charsmax(szValueBuffer));                                         if(!g_aEntVars[iEnt])                         g_aEntVars[iEnt] = CreateArray(64, 1);                                         if(g_aEntVars[iEnt])                     {                         char szBuffer[256];                         FormatEx(szBuffer, charsmax(szBuffer), "%s*%s", szKeyBuffer, szValueBuffer);                         PushArrayString(g_aEntVars[iEnt], szBuffer);                         PrintToServer(szBuffer);                     }                 }                 while(kKeys.GotoNextKey(false));                 delete kKeys;             }         }     } }

Code:
L 03/03/2018 - 08:58:05: [SM] Exception reported: Property "m_iHammerID" not found (entity 23/ff_entity_system_helper)
L 03/03/2018 - 08:58:05: [SM] Blaming: max_entmod.smx
L 03/03/2018 - 08:58:05: [SM] Call stack trace:
L 03/03/2018 - 08:58:05: [SM]   [0] GetEntProp
L 03/03/2018 - 08:58:05: [SM]   [1] Line 74, C:\sourceserver\FortressForever\addons\sourcemod\scripting\include\level_keyvalues.inc::LevelEntity_GetKeysByEntity
L 03/03/2018 - 08:58:05: [SM]   [2] Line 82, C:\sourceserver\FortressForever\addons\sourcemod\scripting\max_entmod.sp::StoreEnts
L 03/03/2018 - 08:58:05: [SM]   [3] Line 44, C:\sourceserver\FortressForever\addons\sourcemod\scripting\max_entmod.sp::OnConfigsExecuted

Last edited by DarthMan; 03-03-2018 at 06:35.
DarthMan is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 03-03-2018 , 06:55   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #7

And what game are you on? Would also be good if you could send the bsp file of map you're doing this on.

Last edited by hmmmmm; 03-03-2018 at 06:55.
hmmmmm is offline
DarthMan
Veteran Member
Join Date: Aug 2011
Old 03-03-2018 , 07:07   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #8

Quote:
Originally Posted by hmmmmm View Post
And what game are you on? Would also be good if you could send the bsp file of map you're doing this on.
It's FortressForever. The problem is not the bsp file, it's the datamap because FortressForever doesn't have a m_iHammerID property.

Last edited by DarthMan; 03-03-2018 at 07:08.
DarthMan is offline
hmmmmm
Great Tester of Whatever
Join Date: Mar 2017
Location: ...
Old 03-03-2018 , 07:14   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #9

Guess you can't use the nosoop plugin out of the box then, since the hammerid is needed to uniquely identify the entity in the entity lump

Would still be good to see the bsp file to see what kind of values entities have in case there is possibly something else you could use to id the all the entities.
hmmmmm is offline
nosoop
Veteran Member
Join Date: Aug 2014
Old 03-03-2018 , 07:19   Re: [ H3LP ] Get All entity keyvalues
Reply With Quote #10

My plugin assumes entities have a Hammer ID that can be accessed (to associate them with the entity lump data); if you can dump your map's entities with, say, Stripper:Source I could verify whether or not Fortress Forever fits those assumptions.

Otherwise you can just grab the OnLevelInit forward and ParseEntityList functions and iterate the resulting KeyValues structure yourself. Unless you have some unique key per entity, you may have some trouble getting the key/value pairs associated with actual entities.

You could probably jump into C++ and iterate over entities' external names; nothing comparable in SourceMod at this time though, and out of my scope of development.
__________________
I do TF2, TF2 servers, and TF2 plugins.
I don't do DMs over Discord -- PM me on the forums regarding inquiries.
AlliedModders Releases / Github / TF2 Server / Donate (BTC / BCH / coffee)
nosoop 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 11:54.


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