• TOOL:Deploy only runs on the second deployment
    6 replies, posted
I've been working on a tool and it only seems to run TOOL:Deploy on the second occurrence expected. Just pulling it out the first time outright does not run the print in my code here. I've seen this with the tool when it worked completely differently which makes me think it is unrelated to the tool and might just be a bug or something. Any help's appreciated, thanks. TOOL.Category       = "Sledrace" TOOL.Name           = "#tool.slr_zonetool.name" TOOL.Command        = "gmod_toolmode slr_zonetool" TOOL.ToolNameHeight = 0 TOOL.InfoBoxHeight = 0 TOOL.CurrentBox = {     P1=nil,     P2=nil } TOOL.Locations = {     CurrentBox={},     Build={},     Start={},     Wall={},     Track={},     Finish={}, } TOOL.CurrentBoxCL = {     P1=nil,     P2=nil } TOOL.LocationsCL = {     Build={},     Start={},     Wall={},     Track={},     Finish={}, } if CLIENT then     TOOL.Information = {         {name="info"}, {name="leftBUILD",op=0},         {name="rightBUILD",op=0},         {name="leftBUILDuse",op=0},         {name="rightBUILDuse",op=0},         {name="leftBUILDshift",op=0},         {name="rightBUILDshift",op=0}     }     --Operations: 0=create mode; 1=edit mode; 2=save mode     --Stages: 0-?=create stages; ?-?=edit stages; ?-?=save stages     language.Add("tool.slr_zonetool.name", "Sledrace Zone Tool" )     language.Add("tool.slr_zonetool.desc", "Define and edit the nessasary zones for sledrace to work" )     language.Add("tool.slr_zonetool.leftBUILD", "Set position one to the player posistion")     language.Add("tool.slr_zonetool.rightBUILD", "Set position two to the player posistion")     language.Add("tool.slr_zonetool.leftBUILDuse", "Reset position one")     language.Add("tool.slr_zonetool.rightBUILDuse", "Reset posistion two")     language.Add("tool.slr_zonetool.leftBUILDshift", "Set posistion one to where the player is looking")     language.Add("tool.slr_zonetool.rightBUILDshift", "Set posistion two to where the player is looking")      end --[[ function TOOL:Initialize()     print("lol init tool")     if SERVER then         --Initalize networked strings         util.AddNetworkString("slr_left")         util.AddNetworkString("slr_right")     end end ]] function TOOL:LeftClick(trace)     if SERVER then         if (self:GetOwner():KeyDown(IN_USE)) then             self.CurrentBox.P1=nil             net.Start("slr_left")             net.WriteBool(false)             net.Send(self:GetOwner())                return         end         if (self:GetOwner():KeyDown(IN_SPEED)) then             self.CurrentBox.P1=self:GetOwner():GetEyeTrace().HitPos-self:GetOwner():GetEyeTrace().HitNormal             net.Start("slr_left")             net.WriteBool(true)             net.WriteVector(self.CurrentBox.P1)             net.Send(self:GetOwner())             return         end         self.CurrentBox.P1=self:GetOwner():GetPos()         net.Start("slr_left")         net.WriteBool(true)         net.WriteVector(self.CurrentBox.P1)         net.Send(self:GetOwner())     end end function TOOL:RightClick()     if SERVER then         if (self:GetOwner():KeyDown(IN_USE)) then             self.CurrentBox.P2=nil             net.Start("slr_right")             net.WriteBool(false)             net.Send(self:GetOwner())                return         end         if (self:GetOwner():KeyDown(IN_SPEED)) then             self.CurrentBox.P2=self:GetOwner():GetEyeTrace().HitPos-self:GetOwner():GetEyeTrace().HitNormal             net.Start("slr_right")             net.WriteBool(true)             net.WriteVector(self.CurrentBox.P2)             net.Send(self:GetOwner())             return         end         self.CurrentBox.P2=self:GetOwner():GetPos()         net.Start("slr_right")         net.WriteBool(true)         net.WriteVector(self.CurrentBox.P2)         net.Send(self:GetOwner())     end end function TOOL:Reload() end function TOOL:Deploy()     print("hfaslkjdhfkljashdkjlfhakljshdfkjlahsdjkflhkjashdkjfh") --here !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! end function TOOL:Holster()     if SERVER then         print("yup fuck u")         if(IsValid(self.Locations.CurrentBox)) then             self.Locations.CurrentBox:Remove()         end     end end function TOOL:Think()     if SERVER then         if(self.CurrentBox.P1 && self.CurrentBox.P2) then             if(!IsValid(self.Locations.CurrentBox) && self.Locations.CurrentBox!={}) then                 self.Locations.CurrentBox = ents.Create("slr_editablebox")                 local midpoint = LerpVector(.5, self.CurrentBox.P1, self.CurrentBox.P2)                 self.Locations.CurrentBox:SetPos(midpoint)                 self.Locations.CurrentBox:Spawn()                 self.Locations.CurrentBox:SetMaxBound(self.CurrentBox.P1-midpoint)                 self.Locations.CurrentBox:SetMinBound(self.CurrentBox.P2-midpoint)                 self.Locations.CurrentBox:SetParent(self)             end         end              end     if CLIENT then         --Sets the client side vars so they can be used for client side rendering         net.Receive("slr_left", function()             if (net.ReadBool()) then                 self.CurrentBoxCL.P1=net.ReadVector()             else                 self.CurrentBoxCL.P1=nil             end         end)         net.Receive("slr_right", function()             if (net.ReadBool()) then                 self.CurrentBoxCL.P2=net.ReadVector()             else                 self.CurrentBoxCL.P2=nil             end         end)     end end function TOOL:DrawToolScreen(width, height)--CLIENT ONLY     surface.SetDrawColor(Color(20,20,20))     surface.DrawRect(0,0,width,height) end function TOOL:DrawHUD()--CLIENT ONLY     --Draw the current box     if (self.CurrentBoxCL.P1 && self.CurrentBoxCL.P2) then         cam.Start3D()             render.DrawWireframeBox(Vector(),Angle(),self.CurrentBoxCL.P1,self.CurrentBoxCL.P2,Color(0,0,0))         cam.End3D()     end     --Whlie shift is held draw where player is looking     if (self:GetOwner():KeyDown(IN_SPEED)) then         cam.Start3D()             render.DrawWireframeSphere(self:GetOwner():GetEyeTrace().HitPos-self:GetOwner():GetEyeTrace().HitNormal, 10, 10, 10, Color(255,255,255))         cam.End3D()     end     --Small rewrite of the sandbox STool draw HUD because I wanted to be able to use shift and ctrl as modifier keys for keybinds. Im very extra     local mode = "slr_zonetool"     if (!self) then return end     local x, y = 50, 40     local w, h = 0, 0     local TextTable = {}     local QuadTable = {}     --Draws the gradient under the tool name and description     QuadTable.texture = surface.GetTextureID("gui/gradient")     QuadTable.color = Color(10, 10, 10, 180)     QuadTable.x = 0     QuadTable.y = y - 8     QuadTable.w = 600     QuadTable.h = self.ToolNameHeight - (y - 8)     draw.TexturedQuad(QuadTable)     --Draws the tool name text     TextTable.font = "GModToolName"     TextTable.color = Color(240, 240, 240, 255)     TextTable.pos = {x, y}     TextTable.text = "#tool."..mode..".name"     w, h = draw.TextShadow(TextTable, 2)     y = y + h     --Draws the description text     TextTable.font = "GModToolSubtitle"     TextTable.pos = {x, y}     TextTable.text = "#tool."..mode..".desc"     w, h = draw.TextShadow(TextTable, 1)     y = y + h + 8     self.ToolNameHeight = y     --Draws gradient under the info     QuadTable.y = y     QuadTable.h = self.InfoBoxHeight     local alpha = math.Clamp( 255 + ( self.LastMessage - CurTime() ) * 800, 10, 255 )     QuadTable.color = Color( alpha, alpha, alpha, 230 )     draw.TexturedQuad( QuadTable )     y = y + 4     TextTable.font = "GModToolHelp"     if ( !self.Information ) then         TextTable.pos = { x + self.InfoBoxHeight, y }         TextTable.text = self:GetHelpText()         w, h = draw.TextShadow( TextTable, 1 )         surface.SetDrawColor( 255, 255, 255, 255 )         surface.SetTexture(surface.GetTextureID("gui/info"))         surface.DrawTexturedRect( x + 1, y + 1, h - 3, h - 3 )         self.InfoBoxHeight = h + 8         return     end     local h2 = 0     for k, v in pairs( self.Information ) do --Loop over all entrys in Information and populate them         if ( type( v ) == "string" ) then v = { name = v } end -- If element of Information is just a string then make it a table containg the string in name ("string"->{name="string"})         if ( !v.name ) then continue end --If no name then skip         if ( v.stage && v.stage != self:GetStage() ) then continue end --If stage if not correct then skip         if ( v.op && v.op != self:GetOperation() ) then continue end --If operation not correct then skip         local txt = "#tool." .. GetConVarString( "gmod_toolmode" ) .. "." .. v.name         if ( v.name == "info" ) then             txt = self:GetHelpText()         end         TextTable.text = txt         TextTable.pos = { x + 21, y + h2 }         w, h = draw.TextShadow( TextTable, 1 )          --Shortcuts for icons in info space         if ( !v.icon ) then             if ( v.name:StartWith( "info" ) ) then v.icon = "gui/info" end             if ( v.name:StartWith( "left" ) ) then v.icon = "gui/lmb.png" end             if ( v.name:StartWith( "right" ) ) then v.icon = "gui/rmb.png" end             if ( v.name:StartWith( "reload" ) ) then v.icon = "gui/r.png" end             if ( v.name:StartWith( "use" ) ) then v.icon = "gui/e.png" end         end         if ( !v.icon2 ) then             if (!v.name:StartWith( "use" ) && v.name:EndsWith( "use" ) ) then v.icon2 = "gui/e.png" end             if (!v.name:StartWith( "shift" ) && v.name:EndsWith( "shift" ) ) then v.icon2 = "gui/shift.png" end --added shift to modifer keys             if (!v.name:StartWith( "ctrl" ) && v.name:EndsWith( "ctrl" ) ) then v.icon2 = "gui/ctrl.png" end --added ctrl to modifer keys         end                  self.Icons = self.Icons or {}         if ( v.icon && !self.Icons[ v.icon ] ) then self.Icons[ v.icon ] = Material( v.icon ) end         if ( v.icon2 && !self.Icons[ v.icon2 ] ) then self.Icons[ v.icon2 ] = Material( v.icon2 ) end         if ( v.icon && self.Icons[ v.icon ] && !self.Icons[ v.icon ]:IsError() ) then             surface.SetDrawColor( 255, 255, 255, 255 )             surface.SetMaterial( self.Icons[ v.icon ] )             surface.DrawTexturedRect( x, y + h2, 16, 16 ) --Icon1 draw (must be 16x16 png)         end         if ( v.icon2 && self.Icons[ v.icon2 ] && !self.Icons[ v.icon2 ]:IsError() ) then             surface.SetDrawColor( 255, 255, 255, 255 )             surface.SetMaterial( self.Icons[ v.icon2 ] )             surface.DrawTexturedRect( x - (11+(self.Icons[ v.icon2 ]:Width())), y + h2, self.Icons[ v.icon2 ]:Width(), self.Icons[ v.icon2 ]:Height()) --Icon2 draw (must be #x16 png)             draw.SimpleText( "+", "default", x - 8, y + h2 + 2, color_white )         end         h2 = h2 + h     end     self.InfoBoxHeight = h2 + 8 end
wdym you only call tool:deploy() once...
I mean the first time the player deploys the tool it doesn't run deploy. Only on the second and further times the player pulls out the tool. Made a separate addon and unloaded the first one and made this dummy tool to test if it still didn't work to further see if it is related to my stuff or not, and this code also didn't work: TOOL.Category       = "Sledrace" TOOL.Name           = "#tool.slr_dummy.name" TOOL.Command        = "gmod_toolmode slr_dummy" function TOOL:Deploy() print("yeah u deployed me") end
Not sure if this is any help: garrysmod/shared.lua at master · Facepunch/garrysmod · GitHub but you could try SWEP:Deploy() instead?
SWEP:Deploy works. Following code works just fine Cool bug garry very nice TOOL.Category       = "Sledrace" TOOL.Name           = "#tool.slr_dummy.name" TOOL.Command        = "gmod_toolmode slr_dummy" function SWEP:Deploy() print(" yeah u deployed") end
We do not take lord's name in vain, for he is a just and unmerciful one.
I think the problem is in if ( !self:GetToolObject() ) then return self.CanDeploy end Client runs Deploy faster than the ToolObject is loaded
Sorry, you need to Log In to post a reply to this thread.