AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting (https://forums.alliedmods.net/forumdisplay.php?f=107)
-   -   [ H3LP ] Get All entity keyvalues (https://forums.alliedmods.net/showthread.php?t=305248)

DarthMan 02-13-2018 03:49

[ H3LP ] Get All entity keyvalues
 
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 !

hmmmmm 02-13-2018 08:49

Re: [ H3LP ] Get All entity keyvalues
 
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.

DarthMan 02-13-2018 10:31

Re: [ H3LP ] Get All entity keyvalues
 
Quote:

Originally Posted by hmmmmm (Post 2577954)
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 03-03-2018 04:04

Re: [ H3LP ] Get All entity keyvalues
 
Quote:

Originally Posted by hmmmmm (Post 2577954)
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 :(

hmmmmm 03-03-2018 05:57

Re: [ H3LP ] Get All entity keyvalues
 
Show us the code you're using that causes that error.

DarthMan 03-03-2018 06:17

Re: [ H3LP ] Get All entity keyvalues
 
Quote:

Originally Posted by hmmmmm (Post 2581095)
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


hmmmmm 03-03-2018 06:55

Re: [ H3LP ] Get All entity keyvalues
 
And what game are you on? Would also be good if you could send the bsp file of map you're doing this on.

DarthMan 03-03-2018 07:07

Re: [ H3LP ] Get All entity keyvalues
 
Quote:

Originally Posted by hmmmmm (Post 2581099)
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.

hmmmmm 03-03-2018 07:14

Re: [ H3LP ] Get All entity keyvalues
 
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.

nosoop 03-03-2018 07:19

Re: [ H3LP ] Get All entity keyvalues
 
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.


All times are GMT -4. The time now is 17:11.

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