I'm pretty new to LUA and hammer and I'm trying to understand the basics of linking a gmod map made in hammer and a gamemode.
What I'm trying to do is read the "spawn_number" key I assigned my custom entity "ar_vehicle_spawn" inside of my hammer map, however it always returns nil and I can't figure out why it's not being listed.
[CODE]
n = 5
for _, v in pairs ( ents.GetAll() ) do
if v:GetClass() == "ar_vehicle_spawn" then
keys = v:GetKeyValues()
PrintTable(keys) -- This never lists a spawn_number key
print(v:GetKeyValues()["spawn_number"]) -- This always returns nil
if v:GetKeyValues()["spawn_number"] == n then
-- This code never gets executed because it's nil I assume
end
end
end
[/CODE]
Picture of my entity with the key in it: [url]https://puu.sh/wtSXJ/4e280c89f7.png[/url]
Output of PrintTable and print "spawn_number": [url]https://puu.sh/wtT3n/6b2f6c321a.png[/url]
GetKeyValues does not include custom key values.
You will want to use the hooks to capture and save them.
[url]http://wiki.garrysmod.com/page/GM/EntityKeyValue[/url]
[url]http://wiki.garrysmod.com/page/ENTITY/KeyValue[/url]
Took me a while to figure out how those hooks worked but I eventually got it, thanks for pointing me in the right direction, that solved it!
Sorry, you need to Log In to post a reply to this thread.