For some reason, I crash whenever I type kill in console or die normally (fall damage, etcetera).
This only happens on a gamemode I am creating (new to lua).
If someone could take a look at it and see what might be wrong, that would be great:
shared.lua
[lua]
GM.Name = "Cooperative Association Role-Play"
GM.Author = "Steven"
GM.Email = "N/A"
GM.Website = "N/A"
function GM.Initialize()
end
[/lua]
init.lua
[lua]
AddCSLuaFile( "cl_init.lua" ) -- This means the client will download these files
AddCSLuaFile( "cl_hud.lua" )
AddCSLuaFile( "shared.lua" )
include('shared.lua') -- At this point the contents of shared.lua are ran on the server only.
include( 'sh_player.lua' )
AddCSLuaFile( "sh_player.lua" )
SPAWNCASH = 5000 --Can be changed to your starting amount
function FirstSpawn( ply )
local cash = ply:GetPData("money") --Get the saved money amount
if cash == nil then --If it doesn't exist supply the player with the starting money amount
ply:SetPData("money", SPAWNCASH) --Save it
ply:SetMoney( SPAWNCASH ) --Set it to the networked ints that can be called from the client too
else
ply:SetMoney( cash ) --If not, set the networked ints to what we last saved
end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", FirstSpawn )
function fPlayerDisconnect( ply )
ply:SaveMoney()
ply:SaveMoneyTXT()
end
function GM:InitPostEntity( )
local ents = ents.Create("shop_drugs")
ents:SetPos(Vector(-7880.031250, -7736.325684, 72.031250))
ents:SetAngles(Angle(0.273574,179.401199, 0.000000))
ents:Spawn()
end
function GM:PlayerLoadout( ply )
ply:Give( "weapon_physcannon" )
ply:Give( "weapon_physgun" )
end
[/lua]
cl_init.lua
[lua]
include( "shared.lua" )
include( 'sh_player.lua' )
-- Hud
function hud() -- Consider functions like a cyber button, and everything INSIDE the function turns on when this cyber button is pressed.
local health = LocalPlayer():Health()
local percent = "%"
local cash = LocalPlayer():GetMoney()
draw.RoundedBox(1, 7.5, ScrH() - 100 - 20, 300, 40, Color(0,0,0,200))
draw.RoundedBox(1, 11, ScrH() - 97.5 - 20, health * 2.95, 35, Color(255,0,0,255))
draw.SimpleText(string.format("Health: %i%s", health, percent), "Trebuchet24", 15, ScrH() - 72.5 - 40, Color(255,255,255,255))
draw.SimpleText(string.format("$%s", cash), "Trebuchet24", 15, ScrH() - 110 - 40, Color(255,255,255,255))
end
hook.Add("HUDPaint", "MyHudName", hud) -- I'll explain hooks and functions in a second
function hidehud(name)
for k, v in pairs({"CHudHealth", "CHudBattery", "CHudAmmo", "CHudSecondaryAmmo"}) do
if name == v then return false end
end
end
hook.Add("HUDShouldDraw", "HideOurHud:D", hidehud)
[/lua]
sh_player.lua
[lua]
local meta = FindMetaTable("Player") --Get the meta table of player
function meta:AddMoney(amount)
local current_cash = self:GetMoney()
self:SetMoney( current_cash + amount )
end
function meta:SetMoney(amount)
self:SetNetworkedInt( "Money", amount )
self:SaveMoney()
end
function meta:SaveMoney()
local cash = self:GetMoney()
self:SetPData("money", cash)
end
function meta:SaveMoneyTXT()
file.Write(gmod.GetGamemode().Name .."/Money/".. string.gsub(self:SteamID(), ":", "_") ..".txt", self:GetMoneyString())
end
function meta:TakeMoney(amount)
--Add money function here
self:AddMoney(-amount)
end
function meta:GetMoney()
return self:GetNetworkedInt( "Money" )
end
[/lua]
These are all placed in the gamemode folder of my gamemode. I excluded my drug dealer npc, considering I removed it and removed the spawning code and tried to see if that was the problem and it still did it.
Am I missing something, or do I need to add something to the gamemode to allow me to die?
Thanks,
Stevolas
you probably don't have a model
[QUOTE=PortalGod;45394115]you probably don't have a model[/QUOTE]
The default playermodel is models/player.mdl. It doesn't have a ragdoll, so the game will CTD whenever you die. Set the player's model in GM:PlayerLoadout.
I noticed I didn't have a model and was going to add that later. Didn't know it would crash if I didn't have a model. Will add it now, thanks for the fast reply.
Sorry, you need to Log In to post a reply to this thread.