Hi all. This has stumped me for a while now.
In my init.lua file I have created the following:
function pickKiller ()
local randomply = table.Random(player.GetAll())
player_manager.SetPlayerClass(randomply, "Myers")
end
What I am trying to do is select a random player on the server and then force that player to join the class called “Myers”.
It isn’t working and I’m not quite sure why. Please help me.
ALSO, on a sidenote, is there a way to test my gamemode on a local server with my brother? I transferred the folder over via USB and placed it in his gamemodes folder but he still cannot find the local server when I host it.
I’d really recommend setting up a local dedicated server. It has different client/server behaviors than a listen server.
In what way is it not working? Do you have errors?
Strangely, I have no errors. It just doesn’t seem to be running even though I call the function to run in the same init.lua file.
Have you tried simple debugging? Print something in the function and make sure it’s running. Make sure the player it picks is valid, etc.
What does this say in console? The best way to debug your code is through prints
function pickKiller ()
local randomply = table.Random(player.GetAll())
print("PICKED", randomply)
player_manager.SetPlayerClass(randomply, "Myers")
end
Ok, thanks to Exho I fixed it. Now, it has an issue with setting the player class.
The console says: SetPlayerClass - attempt to use unknown player class ROLE_TRAITOR!
Here is my code from the shared.lua:
local ROLE_TRAITOR = {}
ROLE_TRAITOR.WalkSpeed = 300
ROLE_TRAITOR.RunSpeed = 600
ROLE_TRAITOR.MaxHealth = 250
ROLE_TRAITOR.StartHealth = 250
ROLE_TRAITOR.TeammateNoCollide = true
ROLE_TRAITOR.JumpPower = 2
ROLE_TRAITOR.Weapons = function(info)
info.Player:ChatPrint("You are a runner! Run and hide from Michael Myers and use traps to stop him.")
timer.Simple( 5, function()
info.Player:Give("weapon_pistol")
for k, ply in pairs( player.GetAll() ) do
ply:ChatPrint("The runners are now armed with pistols!")
end
end)
end
player_manager.RegisterClass("player_default", ROLE_TRAITOR, nil)
And then in the init.lua, where it is called to be set:
function GM:PlayerSpawn (ply)
player_manager.SetPlayerClass(ply, "ROLE_TRAITOR")
player_manager.OnPlayerSpawn(ply)
player_manager.RunClass(ply, Weapons)
end
You don’t need to give your brother the gamemode via USB, all .lua files are sent to the clients when they join anyway. The only thing you’d need to transfer are sounds, textures, and models. And him not being able to find your server has nothing to do with the gamemode.
If you’re on the same internet, find your IPv4 and have him enter “connect” followed by the IPv4 into the console to join. If you’re on different internets he will need to join your IPv6 and you will need to have ports forwarded.