Whenever I open the menu to use a key, I crash.
No idea why, but I do.
I am at a loss, here is my code:
init.lua
[LUA]
if SERVER then
include("sh_init.lua")
end
if CLIENT then
include("cl_init.lua")
end
ply = LocalPlayer()
if ply.DarkRPVars.AFK then
timer.Pause("KeyTimer")
else
timer.UnPause("KeyTimer")
end
[/LUA]
cl_init.lua
[LUA]
include("shared.lua")
ply = LocalPlayer()
if ply:IsUserGroup("VIP") then
WalletMax = 15
else
if ply:IsUserGroup("VIP+") then
WalletMax = 20
else
WalletMax = 10
end
end
function SetupDataTables()
self:NetworkVar( "String", 1, "keys")
self:NetworkVar( "String", 2, "WalletMax")
end
keys = file.Read("keys.txt")
if keys == nil then
keys = 0
file.Write( "keys.txt", keys )
end
if keys != 0 then
keys = file.Read("keys.txt")
end
function KeyTimerFunc()
timer.Create( "KeyTimer", 1, 0, 0, AddKey())
end
function AddKey()
--default time is 3 hours, or 216000
if keys == WalletMax then
Entity( 1 ):PrintMessage( HUD_PRINTTALK, "Key Wallet Full!" )
timer.Stop("KeyTimer")
else
keys = keys + 1
timer.Start("KeyTimer")
file.Write( "keys.txt", keys )
end
end
hook.Add( "Initialize", "Key Timer", KeyTimerFunc )
hook.Add( "HUDPaint", "HelloThere", HudDraw)
function HudDraw()
draw.DrawText( keys.." Keys", "TargetID", 50, 15, Color( 0, 0, 0, 255 ), TEXT_ALIGN_CENTER )
draw.RoundedBox( 10, 20, 15, 60, 25, Color( 0, 0, 0, 100 ) ) -- Draw a blue button
end
concommand.Add( "AddKeys", function()
if keys == WalletMax then
Entity( 1 ):PrintMessage( HUD_PRINTTALK, "Key Wallet Full!" )
else
keys = keys + 1
file.Write( "keys.txt", keys )
end
end )
concommand.Add( "AddFiveKeys", function()
if keys == WalletMax then
Entity( 1 ):PrintMessage( HUD_PRINTTALK, "Key Wallet Full!" )
else
keys = keys + 5
if keys > WalletMax then
keys = keys - 5
end
file.Write( "keys.txt", keys )
end
end )
concommand.Add( "OpenMenu", function()
local Frame = vgui.Create( "DFrame" )
Frame:SetTitle( "Advanced Knife System" )
Frame:SetSize( 300, 300 )
Frame:Center()
Frame:MakePopup()
Frame.Paint = function( self, w, h ) -- 'function Frame:Paint( w, h )' works too
draw.RoundedBox( 0, 0, 0, w, h, Color( 0, 0, 0, 255 ) ) -- Draw a red box instead of the frame
end
local Button = vgui.Create( "DButton", Frame )
Button:SetText( "Use Key" )
Button:SetTextColor( Color( 255, 255, 255 ) )
Button:SetPos( 100, 100 )
Button:SetSize( 100, 30 )
Button.Paint = function( self, w, h )
draw.RoundedBox( 0, 0, 0, w, h, Color( 41, 128, 185, 250 ) ) -- Draw a blue button
end
Button.DoClick = function()
if keys == 0 then
Entity( 1 ):PrintMessage( HUD_PRINTTALK, "Not enough keys." )
else
Entity( 1 ):PrintMessage( HUD_PRINTTALK, "Used 1 Key!" )
skins = file.Read("allknives.txt")
tbl = string.Explode( '\n', skins, false )
recievedskin = table.Random( tbl )
RunConsoleCommand("GiveMeTheGun")
keys = keys - 1
file.Write( "keys.txt", keys )
end
end
end )
[/LUA]
sh_init.lua
[LUA]
//hi
concommand.Add("GiveMeTheGun", function(ply, command, arguments)
skins = file.Read("allknives.txt")
tbl = string.Explode( '\n', skins, false )
recievedskin = table.Random( tbl )
RunConsoleCommand("GiveMeTheGun")
keys = file.Read("keys.txt")
if keys == nil then
keys = 0
file.Write( "keys.txt", keys )
end
if keys != 0 then
keys = file.Read("keys.txt")
end
keys = keys - 1
file.Write( "keys.txt", keys )
ply:Give( recievedskin )
ply:PrintMessage( HUD_PRINTTALK, "Recieved"..recievedskin.."!" )
end)
[/LUA]
shared.lua
EMPTY
Could you please use the code tags?
Anyways, first thing that comes to mind is probably a large amount of items you added trying to load them all at once when you open the menu.
Best thing would probably be to Precache the model upon joining.
[QUOTE=kpjVideo;50737015]Could you please use the code tags?
Anyways, first thing that comes to mind is probably a large amount of items you added trying to load them all at once when you open the menu.
Best thing would probably be to Precache the model upon joining.[/QUOTE]
how would I precache them?
[editline]19th July 2016[/editline]
[QUOTE=kpjVideo;50737015]Could you please use the code tags?
Anyways, first thing that comes to mind is probably a large amount of items you added trying to load them all at once when you open the menu.
Best thing would probably be to Precache the model upon joining.[/QUOTE]
I actually might be getting close to a solution. It is reading the list, but for some reason it gives me this error:
[LUA]
Attempted to create unknown entity type csgo_bayonet_night!
NULL Ent in GiveNamedItem!
[/LUA]
but it reads the list and prints that it gave it to me.
The problem is that it doesn't actually give me the gun.
Sorry, you need to Log In to post a reply to this thread.