• Custom Entity -> Hammer FGD string to Keyvalue to set Gamemode Option
    1 replies, posted
Trying to make a custom entity for my upcoming gamemode project, and I have been having a bit of a problem. The FGD works fine, and you can set the string value to the key, but when you run the gamemode, the entity doesn't exist. I used this same exact method on my "my_custom_spawnpoint" entity, which is literally just an "ENT.Type = point", and it's recognized and runs perfectly. This one, however, does not. The problem is when it comes to loading the entity in the code with "for k,v pairs in (ents.FindByClass("my_custom_entity"))", it says no results (nil). Here is what I've tried thus far. I am not seeking someone else to do my work for me, I've actually tried to do it. [b]my_custom_entity[/b] [code] -- This is just a simple point entity made to carry the keyvalue "objective" to determine which gametype will load -- That way, only one of the four modes will load, saving runtime by not running the other three. ENT.Type = "point" function ENT:KeyValue(key, value) if key == "objtype" then self.GameType = tostring(value) end end [/code] [b]custom.fgd[/b] [code]@PointClass base(Targetname, Origin, Angles) = my_custom_entity: "Set the map objective for gamemode detection. Type the name of the objective type to load in this map." [ objtype(string) : "Objective Title" : "" : "Proper name for the objective that this map will load (one, two, three, four, etc)" ] [/code] [b]controller.lua[/b] [code] local TypeLoader = ents.FindByClass("my_custom_entity") PrintTable(TypeLoader) for k,v in pairs(ents.FindByClass("my_custom_entity")) do print("*********************************GameType found") end [/code] Result: nil
We're rewriting the whole GameType situation above, we can ignore it.
Sorry, you need to Log In to post a reply to this thread.