I'm making a gamemode and I'm trying to get info from a table of jobs to make a SetJob function. I'm trying to set their job by doing this: pl:SetJob("somejob"). I also need to get the player model from the table, here's the table:
[lua]JobTeams = {}//I took this from derprp
function Job( Name, color, model, Description, Weapons, Salary )
local CustomTeam = {name = Name, model = model, Des = Description, Weapons = Weapons, salary = Salary}
table.insert(JobTeams, CustomTeam)
team.SetUp(#JobTeams, Name, color)
local Team = #JobTeams
if SERVER then
timer.Simple(0.1, function(CustomTeam) AddTeamCommands(CustomTeam) end, CustomTeam)
end
return Team
end
hook.Add("InitPostEntity", "AddTeams", function()
if file.Exists("CustomTeams.txt") then
RunString(file.Read("CustomTeams.txt"))
if SERVER then resource.AddFile("data/CustomTeams.txt") end
if CLIENT and not LocalPlayer():IsSuperAdmin() then file.Delete("CustomTeams.txt") end
end
end)
GM.Name = "some RP"
GM.Author = "Carbine"
GM.Email = "N/A"
GM.Website = "N/A"
GM.TeamBased = true
DeriveGamemode( "sandbox" )
TEAM_POLICE = Job("Police Officer", Color(255, 140, 0, 255), "models/player/police.mdl", [[fight crime and keep the city safe]], {"weapon_mad_p228"}, 20)
TEAM_CITIZEN = Job("Citizen", Color(255,0,0,255), "models/player/group01/male_01.mdl", [[you dont have a job, go get one.]], {}, 0)[/lua]
so, how would I do this?
[lua]function GetTableFromJobName(name)
for k , v in pairs(JobTeams) do
if v.name == name then
return v
end
end
return;
end
[/lua]
thanks, now how would I get the model/weapon/salary from it? I was thinking something like this: ply:SetModel(JobTeams(a[model]))
would ply:SetModel(GetTableFromJobName(pl:Job).model) work?
pl:Job()
I'm assuming it's a function since you used a colon (so you must call it)
[QUOTE=|FlapJack|;23999221]pl:Job()
I'm assuming it's a function since you used a colon (so you must call it)[/QUOTE]
oh, forgot to add that, no wonder it didn't work.
I fixed a lot of things but I'm having problems with these lines:
[lua]function GM:Initialize( ply )
timer.Create("money", 120, 0, function(ply)
player.GetByID(1):AddMoney( 100 )
player.GetByID(1):AddNotify( "#You earned $100", NOTIFY_GENERIC, 8 )
end)
end
function GM:PlayerInitialSpawn()
player.GetByID(1):SetJob("NewComer")
end
function GM:PlayerSpawn(ply)
if ply:IsAdmin() then
ply:StripWeapons()
ply:Give("physgun")
ply:SelectWeapon("physgun")
ply:SetRunSpeed(150)
ply:SetWalkSpeed(100)
ply:SetModel(SetJob(pl:Job()).model)
end
end[/lua]
the AddNotify isn't working for some reason, then in console it says SetJob is a nil value same with ply:IsAdmin(). btw SetJob is flapjack's GetTableFromJobName function.
[editline]05:06PM[/editline]
here's what I get in console:
Timer Error: gamemodes\carbrp\gamemode\init.lua:20: attempt to call method 'AddNotify' (a nil value)
I also need to make commands for the jobs so I made this:
[lua]function JobCommands(command)
for k , v in pairs(JobTeams) do
concommand.Add(JobTeams().command)
end
return;
end [/lua]
I thought it would work but I dont really understand it.
Sorry, you need to Log In to post a reply to this thread.