Checking Teams / Setting mode / Returning only 1 valuel on GM:PlayerSpawn
0 replies, posted
Hi, I've been trying to make my gamemode give weapons/set model on playerspawn using the new Gmod 13 format (using player.lua, instead of customizing teams in init.lua)
I've run into a problem. I'm trying to make my function "ply:GamemodeTeam" be called and a value taken from my "teams" table. I'm really bad at explaining things, so I'll try my best to tell in the code. (I tend to over complicate things as well)
I've tried the (hated and inefficient) "for x, var in pairs(table[argvalue].tablepart) etc.
Anyways; here's the code.
player.lua
[CODE]
local ply = FindMetaTable("Player")
local teams = {}
teams[1] = {name = "Red", color = Vector( 1.0, .2, .2 ), weapons = {"weapon_crowbar", "weapon_smg1"} } //Add weapons here, teams can be viewed in shared.lua
teams[2] = {name = "Blue", color = Vector( .2, .2, 1.0 ), weapons = {"weapon_crowbar", "weapon_ar2"} }
teams[3] = {name = "Waiting", color = Vector( .6, .2, .8 ), weapons = {"weapon_crowbar"} }
function ply:SetGamemodeTeam( n )
if not teams[n] then return end
self:SetTeam( n )
self:SetPlayerColor( teams[n].color )
self:GiveGamemodeWeapons()
return true
end
function ply:GiveGamemodeWeapons()
local w = self:Team()
self:StripWeapons()
for k, wep in pairs(teams[w].weapons) do
self:Give(wep)
end
end
//These are 3 different methods I've tried
//Method 1:
//Upper section where teams is:
teams[1] = {name = "Red", color = Vector( 1.0, .2, .2 ), weapons = {"weapon_crowbar", "weapon_smg1"}, Model = {("models/player/arctic.mdl")} }
//Lower area, where the function is
function ply:GamemodeTeam()
local n = self:Team()
for m, mdl in pairs(teams[n].Model) do
self:SetModel(mdl)
end
end
//^^That one very clearly shouldn't work, in retrospect
//Then there was this one, to check if it was actually getting there
function ply:GamemodeTeam( t )
local t = self:Team()
PrintMessage(HUD_PRINTTALK, "Yup")
end
//It would return 3 "yup"s, which I presume means that it is returning all 3 values, which is a problem, as I want it to return 1.
//I'm currently trying this one, not much luck, and I assume I'm doing it very wrong
function ply:GamemodeTeam1( t )
local t = self:Team()
PrintMessage(HUD_PRINTTALK, "T1")
end
function ply:GamemodeTeam2( t )
local t = self:Team()
PrintMessage(HUD_PRINTTALK, "T2")
end
function ply:GamemodeTeam3( t )
local t = self:Team()
PrintMessage(HUD_PRINTTALK, "T3")
end
//This one is still just returning 3 "yup"s
[/CODE]
init.lua
[CODE]
AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")
include("player.lua")
//Serverside stuff
function GM:PlayerConnect( name, ip )
print("Player " .. name .. " has joined the game.")
end
function GM:PlayerInitialSpawn( ply )
print("Player " .. ply:Nick() .. " has spawned.")
ply:SetGravity(.5)
ply:SetWalkSpeed(350)
ply:SetRunSpeed(900)
ply:SetGamemodeTeam( 1 )
end
function GM:PlayerAuthed( ply, steamID, uniqueID )
print("Player " .. ply:Nick() .. " is authed.")
end
//Where I'm trying to actually set the model (twice, for some reason)
//Also, as for the GamemodeTeam1,2, & 3 in player.lua, I know you can manage to call it from just one, so this method isn't working for that reason, and ahh such a mess!
function GM:PlayerSpawn(ply)
if ply:GamemodeTeam() == 1 then
ply:SetAmmo(1000, "smg1")
ply:SetModel("models/player/arctic.mdl")
elseif ply:GamemodeTeam() == 2 then
ply:SetAmmo(1000, "ar2")
ply:SetModel("models/player/leet.mdl")
elseif ply:GamemodeTeam() == 3 then
ply:SetModel("models/player/alyx.mdl")
end
//Random Statement
local rand = math.random(1, 2)
if rand == 1 then
ply:SetGamemodeTeam(1)
elseif rand == 2 then
ply:SetGamemodeTeam(2)
end
RED = team.NumPlayers(1)
BLU = team.NumPlayers(2)
if RED > BLU then
ply:SetGamemodeTeam(2)
elseif BLU > RED then
ply:SetGamemodeTeam(1)
end
end
[/CODE]
It's really messy right now, and I'm just confusing myself. If anyone can help me sort this mess out, I'd really appreciate it :)
Sorry, you need to Log In to post a reply to this thread.