• Spawn an entity with a Stool?!
    7 replies, posted
  • Need some help... I am new at lua, and i wanted to make a stool that can spawn a entity. The idea was that i can spawn green tiberium with a stool in stead of clicking in the entity tab. I already made something but that didn't work... except for the description and so. [PHP] TOOL.Category = "My own shit" TOOL.Name = "#Tiberium Green Spawner" TOOL.Command = nil TOOL.ConfigName = "" TOOL.Tab = "Tiberium" if (CLIENT) then language.Add("Tool_tiberiumgreenspawner_name", "Tiberium Tool") //hud info -name- language.Add("Tool_tiberiumgreenspawner_desc", "Spawns Tiberium Green.") //hud info -description- language.Add("Tool_tiberiumgreenspawner_0", "Left click to spawn Green Tiberium") //hud info -description- end function TOOL:UpdateGhostSensor(Entity, Player) // make a ghost if (!Entity) then return end if (!Entity:IsValid()) then return end local TR = utilx.GetPlayerTrace(Player, Player:GetCursorAimVector()) local Trace = util.TraceLine(TR) if (!Trace.Hit) then return end if (Trace.Entity && Trace.Entity:GetClass() == "wtib_tiberium_green" || Trace.Entity:IsPlayer()) then Entity:SetNoDraw(true) return end local Ang = Trace.HitNormal:Angle() Ang.pitch = Ang.pitch + 90 local Minimum = Entity:OBBMins() Entity:SetPos(Trace.HitPos - Trace.HitNormal * Minimum.z) Entity:SetAngles(Ang) Entity:SetNoDraw(false) end function TOOL:LeftClick( trace ) local ent = ents.Create( "wtib_tiberium_green" ) if ( !ent:IsValid() ) then return end ent:SetPos(tr.HitPos) ent:Spawn() end function TOOL.BuildCPanel(panel) panel:AddControl("Label", { Text = "This tool lets you spawn Green Tiberium" }) // extra info panel:AddControl("Label", { Text = "Becarefull with it." } ) // extra info end [/PHP] Can someone please show me how to make it work? Thomas sorry for my bad english...
  • Avatar of melindagreen
  • oh jeeze.. I have this problem with the oil drills in the oilmod. it spawns the thumper and it supplies crude oil but its not animated. IDEA! look at the old tiberium addon and see how that STOOL is set up because it let you spawn with the tool.
  • [QUOTE=_nonSENSE;24178116]Use lua tags instead of code tags, this is hard to go through. Also, any errors?[/QUOTE] yes wen i press left mouse button with the stool on the place in the map i want tiberium, i get "...ua\weapons\gmod_tool\stools\tiberiumgreenspawner.lua:49: attempt to index global 'tr' (a nil value)" and it doesn't spawn anything...
  • Avatar of _nonSENSE
  • On line 46 of the posted code, replace [lua]ent:SetPos(tr.HitPos)[/lua] with [lua]ent:SetPos(trace.HitPos) [/lua]
  • [QUOTE=_nonSENSE;24178609]On line 46 of the posted code, replace ent:SetPos(tr.HitPos) with ent:SetPos(trace.HitPos) [/QUOTE] Omg you are awesome. it works perfectly. i spawned 3 crystals and they grow out of the ground and replecated themselfs. thanks for the help.