• Trying to fix up an old stool from gmod 12
    0 replies, posted
Hello, Recently I've been learning lua, and decided that since no-one had done it yet, I'd try and fix the [URL="http://www.garrysmod.org/downloads/?a=view&id=109234"]Squad NPCs tool from GMod 12[/URL]. However, the first problem I have come across is very hard to figure out. The STool just wont appear in the Spawn Menu. I've compared the code and structure to other STools that work but nothing seems to be wrong. Anyone here know what the problem could be? Here's the entire code of the addon: [code]TOOL.Category = "Krak's Tools" TOOL.Name = "Squad NPCs" TOOL.Command = nil TOOL.ConfigName = "" TOOL.ClientConVar ["npc"] = "npc_combine_s" TOOL.ClientConVar ["weapon"] = "weapon_smg1" TOOL.ClientConVar ["squad"] = "alpha" TOOL.ClientConVar ["assign"] = "1" TOOL.ClientConVar ["spawnangle"] = "0" TOOL.ClientConVar ["offset_x"] = "0" TOOL.ClientConVar ["offset_y"] = "0" TOOL.ClientConVar ["offset_z"] = "0" TOOL.ClientConVar ["worldalign"] = "0" --TOOL.ClientConVar ["spawnflags"] = "0" --keyvalues={} npcs = { {"Combine Soldier","npc_combine_s"}, {"Combine Elite","npc_combine_elite"}, {"Combine Prison Guard","npc_combine_prisong"}, {"Metro Police","npc_metropolice"}, {"Citizen Refugee","npc_citizen"}, {"Citizen Downtrodden","npc_citizen_dt"}, {"Citizen Rebel","npc_rebel"}, {"Citizen Rebel Medic","npc_rebel_medic"}, {"Zombie","npc_zombie"}, {"Zombie Torso","npc_zombie_torso"}, {"Zombie (Poison)","npc_poisonzombie"}, {"Zombie (Fast)","npc_fastzombie"}, {"Zombie Torso (Fast)","npc_fastzombie_torso"}, {"Zombine","npc_zombine"}, {"Headcrab","npc_headcrab"}, {"Headcrab (Fast)","npc_headcrab_fast"}, {"Headcrab (Poison)","npc_headcrab_black"}, {"Antlion","npc_antlion"}, {"Antlion Guard","npc_antlionguard"}, {"Antlion Worker","npc_antlion_worker"}, --Add Story NPCs {"Barney","npc_barney"}, {"Alyx","npc_alyx"}, {"Eli Vance","npc_eli"}, {"Isaac Kleiner","npc_kleiner"}, {"Judith Mossman","npc_mossman"}, {"Dr. Magnusson","npc_magnusson"}, {"Wallace Breen","npc_breen"}, {"G-Man","npc_gman"}, {"D0g","npc_dog"}, {"Father Grigori","npc_monk"}, {"Vortigaunt","npc_vortigaunt"}, --Combine Stuff {"Manhack","npc_manhack"}, {"Rollermine","npc_rollermine"}, {"Combine Camera","npc_combine_camera"}, {"Combine Sniper *","npc_sniper"}, {"Combine Mine (Hopper)","combine_mine"}, {"Combine Turret (Ceiling)","npc_turret_ceiling"}, {"Combine Turret (Mobile)","npc_turret_floor"}, {"Combine Scanner","npc_cscanner"}, } if CLIENT then language.Add ("Tool_squadnpcs_name", "Squad NPC Tool") language.Add ("Tool_squadnpcs_desc", "Create NPCs that work and communicate in a squad.") language.Add ("Tool_squadnpcs_0", "Primary: Spawn NPC. Secondary: Assign Existing NPC to Squad.") language.Add ("Undone_Squad NPC", "Undone Squad NPC") math.randomseed(os.time()) end function TOOL:LeftClick( trace ) local ply = self:GetOwner() local tospawn = self:GetClientInfo("npc") local skin=tospawn if(tospawn=="npc_combine_elite" or tospawn=="npc_combine_prisong") then tospawn="npc_combine_s" end if(tospawn=="npc_rebel" or tospawn=="npc_citizen_dt" or tospawn=="npc_rebel_medic") then tospawn="npc_citizen" end local newEnt=ents.Create(tospawn) --Give Weapons if (self:GetClientInfo("weapon") != "" and self:GetClientInfo("weapon") != "weapon_none") then newEnt:SetKeyValue("additionalequipment", self:GetClientInfo("weapon")) end /*--Spawnflags and Key Values newEnt:SetKeyValue("spawnflags",self:GetClientInfo("spawnflags")) for k,v in SortedPairs(keyvalues) do newEnt:SetKeyValue(k,v) end*/ if(self:GetClientInfo("assign")=="1") then newEnt:SetKeyValue("squadname", self:GetClientInfo("squad")) end --Citizen Skins if(skin=="npc_rebel") then newEnt:SetKeyValue("citizentype",CT_REBEL) newEnt:SetKeyValue("spawnflags",SF_CITIZEN_RANDOM_HEAD) end if(skin=="npc_rebel_medic") then newEnt:SetKeyValue("citizentype",CT_REBEL) newEnt:SetKeyValue("spawnflags",SF_CITIZEN_MEDIC) end if(skin=="npc_citizen_dt") then newEnt:SetKeyValue("citizentype",CT_DOWNTRODDEN) end if(skin=="npc_citizen") then newEnt:SetKeyValue("citizentype",CT_REFUGEE) end --Combine Skins if(skin=="npc_combine_s") then newEnt:SetKeyValue("model","models/combine_soldier.mdl") end if(skin=="npc_combine_elite") then newEnt:SetKeyValue("model","models/combine_super_soldier.mdl") end if(skin=="npc_combine_prisong") then newEnt:SetKeyValue("model","models/combine_soldier_prisonguard.mdl") end if(skin=="npc_combine_icky") then newEnt:SetKeyValue("model","models/soldier_stripped.mdl") end if(skin=="npc_vortigaunt") then newEnt:SetKeyValue("model","models/vortigaunt.mdl") end if(skin=="npc_turret_ceiling") then newEnt:SetKeyValue("spawnflags","32") end newEnt:Spawn() newEnt:SetPos(trace.HitPos+Vector(self:GetClientInfo("offset_x"),self:GetClientInfo("offset_y"),self:GetClientInfo("offset_z")+1)) if(self:GetClientInfo("worldalign")=="1") then newEnt:SetAngles(Angle(0,self:GetClientInfo("spawnangle"),0)) else newEnt:SetAngles(Angle(0,ply:GetForward():Normalize():Angle().y+self:GetClientInfo("spawnangle"),0)) end -- undo.Create("Squad NPC") undo.AddEntity(newEnt) undo.SetPlayer(ply) undo.Finish() return true end function TOOL:RightClick(trace) local ply = self:GetOwner() --This is bad because it does not really know if the hit entity is an NPC. if(trace.Entity:GetClass()!="prop_physics" and trace.HitNonWorld)then trace.Entity:SetKeyValue("squadname", self:GetClientInfo("squad"), 1) --Debug Stuff Msg("Squad NPC attempt to Reassign squadname to ") Msg(self:GetClientInfo("squad")) Msg("\nActually is ") Msg(trace.Entity:GetKeyValues().squadname) Msg("\n") return true else return false end end --Reload function spams debug info function TOOL:Reload(trace) local ply = self:GetOwner() if(trace.HitNonWorld)then Msg("\nSquad is ") Msg(trace.Entity:GetKeyValues().squadname) Msg("\nModel is ") Msg(trace.Entity:GetModel()) Msg("\nType is ") Msg(trace.Entity:GetClass()) Msg("\n") return true else return false end end function TOOL:Think() if(squadnpcs_npc=="") then squadnpcs_npc="npc_combine_s" end if(squadnpcs_spawnangle=="") then squadnpcs_spawnangle="0" end if(squadnpcs_offset_x=="") then squadnpcs_offset_x="0" end if(squadnpcs_offset_y=="") then squadnpcs_offset_y="0" end if(squadnpcs_offset_z=="") then squadnpcs_offset_z="0" end end function TOOL.BuildCPanel( panel ) panel:AddControl("Header", { Text = "Squad NPCs", Description = "Create NPCs that work and communicate in a squad." }) local fullweps = list.Get("NPCWeapons") --local fullnpcs = list.Get("NPC") -- Set NPC params = {} params.Label = "NPC" params.Height = 400 params.Options = {} for k,v in pairs (npcs) do params.Options[v[1]] = {squadnpcs_npc = v[2]} end /*for k,v in pairs(fullnpcs) do params.Options[v.Name or k] = {squadnpcs_npc = v.Class} keyvalues=v.KeyValues squadnpcs_spawnflags=v.SpawnFlags end*/ panel:AddControl ("ListBox", params) -- Set Weapon params = {} params.Label = "Weapon" params.MenuButton = 0 params.Folder = "settings/menu/main/construct/test/" params.Options = {} list.Add("params.Options","weapon_none","None") for k,v in SortedPairs (fullweps) do params.Options[v] = {squadnpcs_weapon = k} end panel:AddControl ("ComboBox", params) params = {} params.Label = "Squad" params.MaxLength = 25 params.Text = squadnpcs_squad params.Command = "squadnpcs_squad" panel:AddControl("TextBox",params) params = {} params.Label = "Angle Offset" params.Type="Float" params.Min=0 params.Max=360 params.Command = "squadnpcs_spawnangle" panel:AddControl("Slider",params) panel:CheckBox("Align to World","squadnpcs_worldalign") params.Label = "X Offset" params.Min=-1000 params.Max=1000 params.Command = "squadnpcs_offset_x" panel:AddControl("Slider",params) p
Sorry, you need to Log In to post a reply to this thread.