Hi, I have been coding my addon for a while and I have come across a problem I didn’t think of.
After reloading the map / restarting the server, when it loads up non of the values “add” like when a player spawns it sets the players nwstring to something, then the client reads that and process’s it through the shared table.
The shared table values are added through a function…
These are basically snippets, but it explains how it works, and please dont judge my syntax thanks.
– default_abilities.lua
AddAbility( {
name = "Blink",
color = Color( 25,100,100 ),
cooldown = 10,
material = "",
ultimate = false,
func = function(ply)
ply:SetFOV( 150, 1 )
ply:Freeze( true )
timer.Simple(1.1,function()
ply:Freeze( false )
ply:SetPos( ply:GetEyeTrace().HitPos )
ply:SetFOV( 0, 1 )
UnstuckPlayer( ply )
end)
end
} )
– abilities.lua (shared)
Abilities = {}
function AddAbility( tab )
if not istable( tab ) then Error( "You cannot create an ability without ability info" ) return end
for k,v in pairs( Abilities ) do
if (v["name"] == tab["name"]) then
table.remove(Abilities, k)
end
end
table.insert( Abilities, tab )
end
hook.Add( "PlayerSpawn", "AbilitySet", function(ply)
ply:SetNWString( "Ability1", "Blink" )
ply:SetNWString( "Ability2", "Bounce" )
ply:SetNWString( "Ability3", "Drop" )
ply:SetNWString( "Ability4", "Cloak" )
end )
– cl_abilities.lua
if CLIENT then
local function AbilityMenu()
local Frame = vgui.Create( "DFrame" )
Frame:SetSize( 350, 500 )
Frame:Center()
Frame:MakePopup()
Frame:SetTitle( "Ability Selection Menu" )
local List = vgui.Create( "DIconLayout", Frame )
List:SetSize( Frame:GetWide() - 10, 80 )
List:SetPos( 7.5, 25 )
List:SetSpaceY( 5 )
List:SetSpaceX( 5 )
for i=1,4 do
for k,v in pairs( GetAbilities() ) do
if v[1] == i then
local label = vgui.Create( "DLabel", List )
label:SetSize( List:GetWide()/4 - 5, 75 )
label:SetText( "" )
label.Paint = function( self )
if v[2]["material"] != "" then
surface.SetDrawColor( 255,255,255,255 )
surface.SetMaterial( Material( v[2]["material"] ) )
surface.DrawRect( 0,0,self:GetWide(),self:GetTall() )
else
draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),v[2]["color"])
end
draw.SimpleText("Ability"..tostring(v[1]),"Trebuchet24",self:GetWide()/2,0,Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_TOP)
draw.SimpleText(tostring(v[2]["name"]),"DermaDefault",self:GetWide()/2,25,Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_TOP)
end
end
end
end
local Scroll = vgui.Create( "DScrollPanel", Frame )
Scroll:SetSize( Frame:GetWide() - 5, Frame:GetTall() - 115 )
Scroll:SetPos( 5, 110 )
local AList = vgui.Create( "DIconLayout", Scroll )
AList:SetSize( Scroll:GetWide() - 10, Scroll:GetTall() )
AList:SetSpaceY( 5 )
AList:SetSpaceX( 5 )
local currentabils = {}
for i=1,4 do
table.insert( currentabils, ply:GetNWString( "Ability"..tostring(i) ) )
end
for k,v in pairs( Abilities ) do
if not table.HasValue( currentabils, v["name"] ) then
local label = vgui.Create( "DButton", AList )
label:SetSize( List:GetWide()/4 - 5, 75 )
label:SetText( "" )
label.Paint = function( self )
if v["material"] != "" then
surface.SetDrawColor( 255,255,255,255 )
surface.SetMaterial( Material( v["material"] ) )
surface.DrawRect( 0,0,self:GetWide(),self:GetTall() )
else
draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),v["color"])
end
draw.SimpleText(tostring(v["name"]),"Trebuchet24",self:GetWide()/2,self:GetTall()/2,Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
end
label.DoClick = function()
local FFrame = vgui.Create( "DFrame" )
FFrame:SetSize( 350, 400 )
FFrame:Center()
FFrame:MakePopup()
FFrame:SetTitle( "Ability Binding Window" )
local List = vgui.Create( "DIconLayout", FFrame )
List:SetSize( Frame:GetWide() - 10, Frame:GetTall() - 10 )
List:SetPos( 7.5, 25 )
List:SetSpaceY( 5 )
List:SetSpaceX( 5 )
local label = vgui.Create( "DLabel", List )
label:SetSize( List:GetWide() - 5, 50 )
label:SetText( "" )
label.Paint = function( self )
draw.RoundedBox(0,0,0,self:GetWide(),self:GetTall(),Color( 150,150,150,150 ))
draw.SimpleText("Select an ability slot","Trebuchet24",self:GetWide()/2,25,Color(255,255,255),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER)
end
for i=1,4 do
local bind = vgui.Create( "DButton", List )
bind:SetSize( List:GetWide()/2 - 5, 75 )
bind:SetText( "Ability "..tostring(i) )
bind.DoClick = function()
RunConsoleCommand( "Ability"..tostring(i), tostring(v["name"]) )
FFrame:Remove()
end
end
end
end
end
end
end
If I save the files, shared, default_abils then client it will saved the abilities, I can view them, use them, it adds them to the table. If I load up the map, nothing happens, like the tables don’t get inserted?
Do you know how to fix this issue?