• Custom Gamemode Help
    6 replies, posted
Hey, I'm having trouble giving the player weapons on the start of a round in a small gamemode I am making to learn Lua. Here is some code for the round_controller Lua file: local plyLoadout = { "weapon_shotgun", "weapon_smg1" } local plyMeta = FindMetaTable("Player") function plyMeta:GiveLoadout() if !IsValid(self) then print("Player is not valid") return end self:StripWeapons() for k, v in pairs(plyLoadout) do self:Give(v) end end The problem is the player is not returning as valid. I've tried testing player validity in the GM:PlayerSpawn hook and it works fine. Here is my init.lua: AddCSLuaFile("cl_init.lua") AddCSLuaFile("shared.lua") include("shared.lua") include("round_controller/sv_round_controller.lua") function GM:PlayerSpawn(ply) ply:SetGravity(.80) ply:SetMaxHealth(100) ply:SetRunSpeed(350) ply:SetWalkSpeed(350) end
Because you use wrong function. PlayerLoadout this one you need
Thanks for the response, but I want the GiveLoadout function called every time a new round starts. I already have the metatable function set up to run each time a new round starts. Would I be able to do this using PlayerLoadout? Shouldn't I just be able to give weapons to a player using Player:Give?
You need to link PlayerLoadout to your function
I'm sorry, but I don't really have an idea on how to do that. I tried using hook.Run in the beginround function, and it still fails to index the target the weapons should go to. Here is the beginround function that I had before trying things (probably a mess, but I'm winging it as I go): function roundfunc.BeginRound() if roundvars.roundActive == true then print("Round is already in progress") elseif roundvars.currentRound < roundvars.maxRounds then roundvars.currentRound = roundvars.currentRound + 1 roundvars.roundActive = true plyMeta:GiveLoadout() else print("Game Restarting") roundfunc.ResetGame() end end I'm calling this using concommands
Because who is plyMeta? You need to call it on every player. PlayerLoadout is GM hook, not Player hook, so it's called for player.
Oh yea thanks, I was treating the metamethod as a normal function Can't test now, but I can probably figure it out. Thanks!
Sorry, you need to Log In to post a reply to this thread.