Hi there
I am trying to get some data from the map that I am using. The map creates a bunch of entities, some of which are of entity type "power_socket". In EntSpy I can see that they have a "buildingid" assigned to them, but how do I get this from the code?
I have made a function that uses the OnEntityCreated hook to get the entity. After checking if the class is actually power_socket, I try to do ent.buildingid but without luck. Any chance you guys can help me out?
[img]http://i.imgur.com/1qDpZo8.png[/img]
Kind regards
Maldark
[img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetKeyValues]Entity:GetKeyValues[/url]
[editline]8th April 2016[/editline]
aka
[code]
yourentity:GetKeyValues()["buildingid"]
[/code]
would return 2.
[QUOTE=whitestar;50089722][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Entity/GetKeyValues]Entity:GetKeyValues[/url]
[editline]8th April 2016[/editline]
aka
[code]
yourentity:GetKeyValues()["buildingid"]
[/code]
would return 2.[/QUOTE]
Hi there, appreciate the help. I've tried doing the GetKeyValues and looping over all of them before asking for help here, sadly none of the keys were buildingid.
Using the following code:
[img]http://i.imgur.com/ljXEo9D.png[/img]
I am getting this lua error:
sv_buildings.lua:45: attempt to concatenate field 'buildingid' (a nil value)
what happens if you print the keyvalues table?
Try adding this to your init.lua
[code]
function ENT:KeyValue( key, value )
if key == "buildingid" then
self.bid = value
end
end
[/code]
Then you can get the building id of the entity by doing ent.bid
[QUOTE=whitestar;50092603]what happens if you print the keyvalues table?[/QUOTE]
Here you go: [img]http://i.imgur.com/wNDdkZx.png[/img]
[QUOTE=Nick78111;50092683]Try adding this to your init.lua
[code]
function ENT:KeyValue( key, value )
if key == "buildingid" then
self.bid = value
end
end
[/code]
Then you can get the building id of the entity by doing ent.bid[/QUOTE]
Just tried, gives me the same error as before, "attempt to concatenate field 'buildingid' (a nil value)"
[QUOTE=maldark;50092834]Here you go: [img]http://i.imgur.com/wNDdkZx.png[/img]
Just tried, gives me the same error as before, "attempt to concatenate field 'buildingid' (a nil value)"[/QUOTE]
Are you sure you are targeting the correct entity there? It seems that buildingid is not set from looking at that
[QUOTE=BillyOnWiiU;50093123]Are you sure you are targeting the correct entity there? It seems that buildingid is not set from looking at that[/QUOTE]
I am not sure what to tell you. I did not make the map, but I am pretty sure that I am targetting the correct entity. It shows up with "power_socket" as classname in Entspy and I've counted, the amount of power_sockets in Entspy correlate with the amount of times the "(ent:GetClass() == "building_cap")" is true. If there is anything you can think of, let me know and I'll gladly test it.
Thank you
EDIT: I also just noticed, the hammerid is set to 0, although in the Entspy image I linked you can clearly see that it is not 0. I don't know if this gives you any hints to what could be wrong?
what about making a server concommand, which loops through ALL entitities with the given class and lists ALL keys of that entity?
[QUOTE=whitestar;50094321]what about making a server concommand, which loops through ALL entitities with the given class and lists ALL keys of that entity?[/QUOTE]
This gives the same as shown in #6:
[img]http://i.imgur.com/9xzCYYY.png[/img]
which is produced by the following code: [img]http://i.imgur.com/liLna42.png[/img]
Got it working last night, had to use the EntityKeyValue hook and assign the building id to the entity there.
Appreciate your help.
Sorry, you need to Log In to post a reply to this thread.