• Need help with STool scripting
    9 replies, posted
I've been trying to learn how to make STools in GMod. However the Wiki has one (incomplete) tutorial. I've snooped around in other STools (door, smart weld, etc.) and came up with this script: [lua] // Define these! TOOL.Category = "My Category" // Name of the category TOOL.Tab = "Tutorial" // Name of the tab TOOL.Name = "Example" // Name to display TOOL.Command = nil // Command on click (nil for default) TOOL.ConfigName = "" // Config file name (nil for default) // An example clientside convar TOOL.ClientConVar["duration"] = 10 if ( CLIENT ) then language.Add("Tool_samstool_name", "Igniter") language.Add("Tool_samstool_desc", "BLAH") language.Add("Tool_samstool_0", " ") end function TOOL.BuildCPanel( CPanel ) CPanel:AddControl("Header", { Text = "#Tool_samstool_name", Description = "#Tool_samstool_desc" } ) CPanel:AddControl("Slider", { Label = "duration", Type = "Float", Min = 0, Max = 120, Command = "samstool_duration" } ) end function TOOL:LeftClick( tr ) if(!tr.Entity) then return false end if(!tr.Entity:IsValid()) then return false end if(tr.Entity:IsPlayer()) then return false end if(tr.Entity:IsWorld()) then return false end if ( CLIENT ) then return true local TIME = self:GetClientNumber("duration") tr.Entity:Extinguish() tr.Entity:Ignite( TIME, 0 ) return true end function TOOL:RightClick( tr ) if(!tr.Entity) then return false end if(!tr.Entity:IsValid()) then return false end if(tr.Entity:IsPlayer()) then return false end if(tr.Entity:IsWorld()) then return false end if ( CLIENT ) then return true tr.Entity:Extinguish() return true end function TOOL:Reload( tr ) if(!tr.Entity) then return false end if(!tr.Entity:IsValid()) then return false end if(tr.Entity:IsPlayer()) then return false end if(tr.Entity:IsWorld()) then return false end if ( CLIENT ) then return true tr.Entity:Remove() return true end function TOOL:Think() end [/lua] just a small test. When I start my game the tool is there, but none of the information is there (name, description, functionality). I've looked over the code, tried placing it in an addon format. Nothing. What am I doing wrong?
99% of the time, it's the "Tool_samstool_xxxx" part. It needs to match the name of the STool script itself. For instance, I have a STool called "Incendiary Fire". Its script is named IncFire.lua. Thus, I need to use "Tool_IncFire_name", "Incendiary Fire"
No, it's not that. my .lua file is called samstool.lua hmm... Could it be the fact that I have a slider and a ConVar named the same thing?
I highly doubt it - the label is just text. Let's make sure it's in the right folder. It should be in "garrysmod\garrysmod\addons\[YourAddon]\lua\weapons\gmod_tool\stools". You aren't getting any errors in the console, are you? If your script had an error, it'd cause your problem.
The file is currently in "C:\Program Files\Steam\steamapps\<username>\garrysmod\garrysmod\gamemodes\sandbox\entities\weapons\gmod_tool\stools" I don't recall seeing an error, but I'll double check in the morning (3AM right now).
In your left click, right click, and reload you forgot end by if ( CLIENT ) then return true
Aha! Errors! Fix those and get back to us. Also, try to get in a habit of always checking your console, even if everything *seems* to be working right. Don't forget that you have the "clear" command which will clear the console log and make it easier to check.
ok I'll fix that and then check. EDIT: Hmm... It's still not working. I couldn't find any errors as my console is spammed with 'missing vgui material' =( EDIT2: *facepalm* Notepad++ glitched out on me and didn't save correctly. Retesting... EDIT3: It's working now. I need to look into the console spam though. anyone know about this? [code]--- Missing Vgui material icons/silk/16/help[/code]
Temporarily move all your other addons to another folder, so you don't have to see their errors. It'll make Gmod load (much) faster, too, which is nice for testing. Oh, speaking of testing, here's a nice trick: You don't have to exit the game and restart it to reload changes to your SENT or STool scripts - just enter "lua_reloadents" into the console.
cool thanks!
Sorry, you need to Log In to post a reply to this thread.