• lua help- derma panel launch
    2 replies, posted
So I am working on a script for a stats menu and I am having a bit of trouble. It's saved in garrysmod>lua>autorun. There are no errors or anything, it just doesn't do anything. Here is the script: _____________________________________________________________________________________________ stat={} stat.npckilled=0 stat.durgzuse=0 stat.bosskill=0 stat.pvpkill=0 stat.crateopen=0 function npcaddstat(victim,killer,weapon) victim:GetClass() if victim=="npc_slenderman" or "npc_spiderqueen" then stat.bosskill=stat.bosskill+1 print(stat.bosskill) else stat.npckilled=stat.npckilled+1 print(stat.npckilled) end end function durgzaddstat(ply, entity) entity:GetClass() if entity== "" or "" then stat.durgzuse=stat.durgzuse+1 end end function pvpaddstat(victim, inflictor, killer) if killer:IsPlayer() then stat.pvpkill=stat.pvpkill+1 end end function crateaddstat(ply, entity) entity:GetClass() if entity== "" then stat.crateopen=stat.crateopen+1 end end concommand.Add("showstats", function() if (CLIENT) then DermaPanel=vgui.Create( "DFrame" ) DermaPanel:SetPos( 50, 50 ) DermaPanel:SetSize( 300, 325 ) DermaPanel:SetTitle( "Fishing Statistics" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() TestingPanel = vgui.Create( "DPanel", DermaPanel ) TestingPanel:SetPos( 25, 50 ) TestingPanel:SetSize( 250, 250 ) TestingPanel.Paint = function() surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) end end end) function statmenucommand(ply, text, public) if (string.sub(text, 1,6)=="!stats") then ply:showstats end end hook.Add("GM:OnNPCKilled","npcstat",npcaddstat) hook.Add("GM:PlayerUse","durgzstat",durgzaddstat) hook.Add("GM:PlayerDeath","pvpstat",pvpaddstat) hook.Add("GM:PlayerSay", "stats chat command", statmenucommand) _____________________________________________________________________________________________ I want the panel to show up, that's all.
It seems you have quite a few errors in here. You have quite a few syntax errors. For example [CODE] function durgzaddstat(ply, entity) entity:GetClass() if entity== "" or "" then stat.durgzuse=stat.durgzuse+1 end end [/CODE] Just because you call a function on a variable does not change the variable, this is with most if not all functions. [CODE]hook.Add("GM:OnNPCKilled","npcstat",npcaddstat) hook.Add("GM:PlayerUse","durgzstat",durgzaddstat) hook.Add("GM:PlayerDeath","pvpstat",pvpaddstat) hook.Add("GM:PlayerSay", "stats chat command", statmenucommand)[/CODE] Hook prefixes do not begin with "GM:" GM is the gamemode's table which only exists during the gamemode's execution (within the gamemode's files). Unless you call GAMEMODE or gmod.GetGamemode(). Either way, the hook name is a simple name, like OnNPCKilled So, your set of hooks should look like [CODE]hook.Add("OnNPCKilled","npcstat",npcaddstat) hook.Add("PlayerUse","durgzstat",durgzaddstat) hook.Add("PlayerDeath","pvpstat",pvpaddstat) hook.Add("PlayerSay", "stats chat command", statmenucommand)[/CODE] Console commands created serverside cannot directly stream code to clients without PLAYER:SendLua([[]]) therefore [CODE]concommand.Add("showstats", function() if (CLIENT) then DermaPanel=vgui.Create( "DFrame" ) DermaPanel:SetPos( 50, 50 ) DermaPanel:SetSize( 300, 325 ) DermaPanel:SetTitle( "Fishing Statistics" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() TestingPanel = vgui.Create( "DPanel", DermaPanel ) TestingPanel:SetPos( 25, 50 ) TestingPanel:SetSize( 250, 250 ) TestingPanel.Paint = function() surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) end end end)[/CODE] must be executed directly clientside (Recommended) or streamed to the client via SendLua (Not Recommended). Also, the way you have this set up will record the stats of all players on the server for one instance of the server's execution (one map) Lua does not save variables nor does the language have any integrated way to save variables and preserve them past one instance. This is what i've managed to fix just by visual errors, [CODE]stat={} stat.npckilled=0 stat.durgzuse=0 stat.bosskill=0 stat.pvpkill=0 stat.crateopen=0 function npcaddstat(victim,killer,weapon) if victim:GetClass()=="npc_slenderman" or "npc_spiderqueen" then stat.bosskill=stat.bosskill+1 print(stat.bosskill) else stat.npckilled=stat.npckilled+1 print(stat.npckilled) end end function durgzaddstat(ply, entity) if entity:GetClass()== "" or "" then stat.durgzuse=stat.durgzuse+1 end end function pvpaddstat(victim, inflictor, killer) if killer:IsPlayer() then stat.pvpkill=stat.pvpkill+1 end end function crateaddstat(ply, entity) if entity:GetClass()== "" then stat.crateopen=stat.crateopen+1 end end concommand.Add("showstats", function() if (CLIENT) then DermaPanel=vgui.Create( "DFrame" ) DermaPanel:SetPos( 50, 50 ) DermaPanel:SetSize( 300, 325 ) DermaPanel:SetTitle( "Fishing Statistics" ) DermaPanel:SetVisible( true ) DermaPanel:SetDraggable( true ) DermaPanel:ShowCloseButton( true ) DermaPanel:MakePopup() TestingPanel = vgui.Create( "DPanel", DermaPanel ) TestingPanel:SetPos( 25, 50 ) TestingPanel:SetSize( 250, 250 ) TestingPanel.Paint = function() surface.SetDrawColor( 50, 50, 50, 255 ) surface.DrawRect( 0, 0, TestingPanel:GetWide(), TestingPanel:GetTall() ) end end end) function statmenucommand(ply, text, public) if (string.sub(text, 1,6)=="!stats") then ply:RunConsoleCommand("showstats") end end hook.Add("OnNPCKilled","npcstat",npcaddstat) hook.Add("PlayerUse","durgzstat",durgzaddstat) hook.Add("PlayerDeath","pvpstat",pvpaddstat) hook.Add("PlayerSay", "stats chat command", statmenucommand)[/CODE]\ Just a few tips: Tab your code, make it easy for people to read. Some editors with syntax highlighting (Sublime-text 2 with FJPte's GLua syntaxer) will do this for you. Organize your functions into tables, this could mean instead of going [CODE]statmenucommand[/CODE] go [CODE]stat.menucommand[/CODE] Read some lua documentation, and get plenty of practice. You have a good understanding of it, just need to grasp the syntax a tad bit better.
Would I still save this in autorun or should I put it in autorun>client? Thank you so much for the help by the way
Sorry, you need to Log In to post a reply to this thread.