1. Post #1

    October 2008
    5 Posts
    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.

    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
    




    Can someone please show me how to make it work?
    Thomas

    sorry for my bad english...

  2. Post #2
    melindagreen's Avatar
    November 2009
    1,563 Posts
    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.

  3. Post #3
    MoronYard
    _nonSENSE's Avatar
    May 2010
    1,264 Posts
    Use lua tags instead of code tags, this is hard to go through. Also, any errors?

  4. Post #4

    October 2008
    5 Posts
    Use lua tags instead of code tags, this is hard to go through. Also, any errors?
    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\tiberiumgreenspawn er.lua:49: attempt to index global 'tr' (a nil value)"
    and it doesn't spawn anything...

  5. Post #5
    MoronYard
    _nonSENSE's Avatar
    May 2010
    1,264 Posts
    On line 46 of the posted code, replace

    ent:SetPos(tr.HitPos)

    with

    ent:SetPos(trace.HitPos) 

  6. Post #6
    melindagreen's Avatar
    November 2009
    1,563 Posts
    How would I get this to spawn the petrol mod oil drills???

  7. Post #7

    October 2008
    5 Posts
    On line 46 of the posted code, replace


    ent:SetPos(tr.HitPos)

    with


    ent:SetPos(trace.HitPos)
    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.

  8. Post #8
    MoronYard
    _nonSENSE's Avatar
    May 2010
    1,264 Posts
    No problem.