I've been building a custom gamemode for me and my friends, and everything was good until I added an entity. I put it in the folder every tut i could find said it should be in, but no luck.
Its in addons/ADDONNAME/gamemodes/GMNAME/entities/entities, and I tried the init, clinit, and shared in folder version and the single lua file version, but neither work. I tried using other, proven working entities in the folder, to no avail. But if in my code I adresss an entity outside my addon, it works! Also, it works when i put the gamemode folder that is at addons/ADDONNAME/gamemodes in the gamemodes folder. My gamemode itself loads, just not the entity. (When in addons, when its in gamemode its broken) Code---
Gamemode init
[code]
DeriveGamemode("sandbox")
AddCSLuaFile("cl_init.lua")
AddCSLuaFile(GM.Folder .. "/entities/entities/cnc_money/init.lua")
AddCSLuaFile(GM.Folder .. "/entities/entities/cnc_money/cl_init.lua")
AddCSLuaFile(GM.Folder .. "/entities/entities/cnc_money/shared.lua")
util.AddNetworkString("respawngui")
util.AddNetworkString("giveloadout")
util.AddNetworkString("drawpickupoverlay")
function GM:PlayerDeath(ply, wep, attacker)
net.Start("respawngui")
net.WriteEntity(ply)
net.WriteEntity(attacker)
net.Send(ply)
local plyweapons = ply:GetWeapons()
for k, gun in pairs(plyweapons) do
ply:DropWeapon( gun )//TODO ++++++++++++++++++++++++++++++ Drop money on death (once money entity works :{ )
end
end
net.Receive("giveloadout", function(length, ply)
local loadout = net.ReadTable()
local ability = net.ReadString()
local cop = net.ReadBool()
ply:SetNWString("ability", ability)
ply:SetNWBool("cop", cop)
ply:Spawn()
ply:StripWeapons()
for k, v in pairs (loadout) do
ply:Give(v)
end
end)
//Money System Stuff
function GM:InitPostEntity()
if not(file.Exists("copsncrims", "DATA")) then
file.CreateDir( "copsncrims" )
end
end
//Concommands
concommand.Add( "giveccmoney", function( ply, cmd, args )
local syntax = "Wrong Syntax! Use 'giveccmoney player amount'!"
if(#args != 2)then
print(syntax)
return
end
local exists = false
for k, plyr in pairs(player.GetAll())do
if(args[1] == plyr:Nick())then
exists = true
end
end
if(exists == false)then
print(syntax)
return
end
for k, plyr in pairs(player.GetAll())do
if(args[1] == plyr:Nick())then
plyr:SetNWInt("money", plyr:GetNWInt("money") + tonumber(args[2]))
end
end
end)
concommand.Add( "saveccmoney", function( ply )
file.Write("copsncrims/money.txt", "--COPS 'N CRIMS MONEY DATA--".."%")
for _, player in pairs( player.GetAll() ) do
file.Append("copsncrims/money.txt", player:Nick().."-"..player:GetNWInt("money").."%")//This system could be a problem if the player changes their name
print("Saved Cops 'n Crims money for "..ply:Nick())
end
end )
concommand.Add( "loadccmoney", function( ply )
if not(file.Exists("copsncrims/money.txt", "DATA")) then
ply:PrintMessage(HUD_PRINTTALK, "No file found! Money could not be loaded. (Next time try 'saveccmoney' in the console!)")
end
if(file.Exists("copsncrims/money.txt", "DATA")) then
for _, theplayer in pairs( player.GetAll() ) do
local filecont = file.Read("copsncrims/money.txt", "DATA")
local entries = string.Explode("%", filecont)
for k, entry in pairs(entries) do
local sides = string.Explode("-", entry)
if(sides[1] == theplayer:Nick()) then
theplayer:SetNWInt("money", tonumber(sides[2]))
print("Loaded Cops 'n Crims money for "..theplayer:Nick())
end
end
end
end
end )
concommand.Add( "deleteccmoney", function( ply )
if(file.Exists("copsncrims/money.txt", "DATA")) then
file.Delete("copsncrims/money.txt")
print(ply:Nick().." deleted all your money! GET HIM!!!")
end
end )
//End Concommands
function GM:PlayerInitialSpawn(ply)
ply:SetNWInt("money", 0)
end
function GM:PlayerSay(sender, text)
textbits = string.Explode(" ", text)
if(textbits[1] == "moneystack" && #textbits == 2)then
local ent = ents.Create("cnc_money")
ent:SetPos(sender:EyePos() + (sender:GetAimVector() * 16))
ent:SetAngles(sender:EyeAngles())
ent:Spawn()
return ""
end
return text
end
function GM:PlayerCanPickupWeapon( ply, wep )
net.Start("drawpickupoverlay")
net.WriteString(wep:GetPrintName())
net.Send()
end
[/code]
Gamemode clinit
[code]
DeriveGamemode("sandbox")
function AddLoadout(row, level, loadoutname, frame, guns, iscop, ability)
local swidth = surface.ScreenWidth()
local sheight = surface.ScreenHeight()
local loadout = vgui.Create( "DButton", frame )
loadout:SetSize( swidth / 10 * 1, sheight / 15 * 1)
loadout:AlignLeft(swidth / 10 * row)
loadout:AlignTop(sheight / 10 * level)
loadout:SetText(loadoutname)
loadout.DoClick = function()
net.Start("giveloadout")
net.WriteTable(guns)
if(ability != null)then
net.WriteString(ability)
end
net.WriteBool(iscop)
net.SendToServer()
frame:Close()
end
end
net.Receive("respawngui",function() //This kept not working because I spelled it 'ie' not 'ei'... XD
local ply = net.ReadEntity()
local attacker = net.ReadEntity()
local swidth = surface.ScreenWidth()
local sheight = surface.ScreenHeight()
local frame = vgui.Create( "DFrame" )-- ____
-- / \
frame:SetSize( swidth * 0.8, sheight * 0.8 )-- |<><>|
frame:SetTitle( "Respawn as..." )-- | |
frame:SetVisible( true )-- (<><><><><>)
frame:SetDraggable( true )-- \|/ \|/
frame:Center()-- & (.)(.) &
frame:ShowCloseButton(false)-- {====}
frame:MakePopup() -- {====}
//Cop Loadouts
AddLoadout(1, 1, "Scout", frame, {"m9k_m16a4_acog", "m9k_sig_p229r"}, true)
AddLoadout(1, 2, "Spy", frame, {"m9k_remington7615p", "m9k_sig_p229r"}, true)
AddLoadout(1, 3, "Heavy", frame, {"m9k_mossberg590", "m9k_sig_p229r"}, true)
AddLoadout(1, 4, "Explosives Tech", frame, {"m9k_suicide_bomb", "m9k_proxy_mine", "m9k_sig_p229r"}, true)
AddLoadout(1, 5, "Small Arms", frame, {"m9k_amd65", "m9k_sig_p229r"}, true)
//Crim Loadouts
AddLoadout(3, 1, "Drug Dealer", frame, {"m9k_ragingbull"}, false, "drug")
AddLoadout(3, 2, "Gangster", frame, {"m9k_mp40", "m9k_model627"}, false)
AddLoadout(3, 3, "Thug", frame, {"m9k_fists", "m9k_1897winchester"}, false)
AddLoadout(3, 4, "Hitman", frame, {"m9k_psg1", "m9k_m92beretta"}, false)
AddLoadout(3, 5, "Bomber", frame, {"m9k_ied_detonator", "m9k_knife"}, false)
end
)
net.Receive("drawpickupoverlay", function()
local iscop = LocalPlayer():GetNWBool("cop")
local msg = "sell"
if(iscop)then
msg = "confiscate"
end
draw.DrawText("P to pick up "..net.ReadString()..", O to "..msg..".", "CenterPrintText", ScrW() * 0.9, ScrH() * 0.1, Color(0, 255, 0, 255), TEXT_ALIGN_CENTER)
end)
//Draw all dat dosh mone on yo skr33n
function GM:HUDPaint()
draw.DrawText(("Money: $"..LocalPlayer():GetNWInt("money")), "CloseCaption_Bold", ScrW() * 0.9, ScrH() * 0.05, Color(0, 255, 0, 255), TEXT_ALIGN_CENTER)
end
[/code]
Folder structure
addons/ADDONNAME
entity - addons/ADDONNAME/gamemodes/GMNAME/entities/entities/ENTITY.lua or ENTITYFOLDER/init, cl_init, and shared lua.
gamemode clinit & init - addons/ADDONNAME/gamemodes/GMNAME/gamemode/clinit and init
PLEASE HELP! I NEED THIS TO WORK :(
Why not put the gamemode directly into the game modes folder?
[QUOTE=boxvader;49222290]Why not put the gamemode directly into the game modes folder?[/QUOTE]
Well, I want to publish it, and if i doesnt work in the addons, it wont work on some1 elses computer.
It'll work on anyone's computer? It can just be put into gamemodes, everyone has that folder.
Gamemodes are usually run on servers and most people place it into the gamemodes folder not the addons section.
All game modes must be places in the garrysmod/gamemodes folder. All content for the gamemode may then be placed in the addons folder (or the gamemode/content folder).
Only the owner of the server has to have the gamemode, and it has to be manually installed anyways. The content could be uploaded to the workshop for downloading by the players (clients), but you do not want every player who joins the server to have the game mode anyways.
And as a side question... You are building a game mode, but you do not understand where to put it? Try looking up how to host a dedicated server. Using that will not only help you to test the game mode alone, but it will build your knowledge on how all off of it works and where everything goes.
Sorry, you need to Log In to post a reply to this thread.