Setting Player Team Works, But Then Is Unassigned? (Custom Gamemode)
3 replies, posted
I'm making a custom gamemode and I have two teams. I have two files in which one sets the team as player load, and the other where the file checks the team to preform other functions.
I'll post my code. To give a backstory, I do two checks for debugging. I printed the team in the player load, which prints out one of the two teams I have set. However, in the think function to check teams, it always prints out team 1001 (I.E unassigned).
These are all server files btw.
Console:
LOADPLAYER RAN
CHECKPLAYER RAN
Load File:
function Func.loadPlayer(ply, steamid, uid)
// TeamChangeAbility
ply.GMBF3changeTeam = true
ply:SetModel("models/player/p2_chell.mdl")
ply:Give("weapon_pistol")
// Team player amount
local team0Amount = team.NumPlayers(0)
local team1Amount = team.NumPlayers(1)
// Set teams
if team0Amount > team1Amount then
ply:SetTeam(1) // Set to Team 1
elseif team0Amount < team1Amount then
ply:SetTeam(0) // Set to Team 0
else
local teamToSet = math.random() > 0.45 and 1 or 0
ply:SetTeam(teamToSet)
end
print(ply:Team())
end
hook.Add("PlayerAuthed", "LoadPlayer", Func.loadPlayer)
When creating a gamemode you want to override the Gamemode functions rather than hooking into them. Otherwise the orginal function from the base gamemode may get called as well. All functions starting with GM in at the Garry's Mod Lua Documentation are gamemode functions. PlayerAuthed is an example of a gamemode function that should be overriden.
function GM:PlayerAuthed( ply, steamid, uniqueid ) --[[Code goes here]] end
Didn't work. I set a custom function to call a custom hook.
https://i.gyazo.com/e2fa904803b6514279dc31adb796bf51.png
This runs before anything else. I then call that hook instead of player authed. Maybe I'm doing it wrong?
Found the problem, it was some ULX/ULib bullshit.
Sorry, you need to Log In to post a reply to this thread.