• Some questions I have.
    4 replies, posted
First off, I started working on my first gamemode yesterday. I would really appreciate if you guys could help me out, this are my questions: What would be the most efficient way to crosscheck the Frags each player has and select a Winner? I cant get " ply:SetMaxHealth( 75, true ) " to work, it says at 100 HP, what am i doing wrong? Is there any way to prevent players from respawning? Thank you in advance, I hope ive introduced these questions in the right section and format.
[B]1)[/B] Your first question, how do you want this to function? At the end of the round the one with most frags win, or is it the first person to reach x frags? [B]2)[/B]Where are you defining ply:SetMaxHealth? If you're using the correct code, are you sure you're using it at the right place? It most likely has to be run server side, and you need to make sure ply is actually you. [code] function GM:PlayerJoinTeam( ply, teamid ) ply.SetMaxHealth(75, true) end [/code] Should work, I guess. But I can't find setmaxhealth in the wiki, so are you sure that's the correct function? [B]3)[/B]"Is there any way to prevent players from respawning?" When? Are you asking how to make players only spawn once each round? If you're using Fretta, GM.MaximumDeathLength = 0 should prevent respawns. Btw, I'm no expert at this, so I might not be providing the best solution.
1. On Round End, the piece of code should review all players and see who has the biggest Frags count. 2. I dont know, i was suggested i used that. 3.Im not using Fretta, this is why i am asking, as i made a gamemode from "Scratch".
[code]local players = ents.getByClass("player") local max local winner for i,k in players do if k:frags() > max then max = k:frags() winner = k end end[/code] Something like that should work, copy and pasting probably won't but it should give you an idea. About setmaxhealth, that'll only set the upper limit. Try to also do sethealth. This MIGHT work about not respawing players, but I'm not sure. [code] roundinprogress = 0 -- (then set it to 1 when it is.) function GM:PlayerSpawn( ply ) if !roundinprogress then return false end end [/code]
Warsheep was heading towards the right solution for frag counting, but this will actually work: [lua] local function getBestPlayer() local best, score = NULL, -1 for k,v in pairs(player.GetAll()) do -- Note: In case of a tie, this code will just choose which player that comes first if v:Frags() > score then best = v end end return best end [/lua] Max health sets a limit that's used by some entities like item_healthkit or Lua scripts. You'd want to set the health to the value you prefer like Warsheep already stated, max health doesn't perform any automatic clamping of the players health. [lua] pl:SetMaxHealth(75) pl:SetHealth(75) [/lua] [b][url=http://maurits.tv/data/garrysmod/wiki/wiki.garrysmod.com/index89fc.html?title=Gamemode.PlayerDeathThink]Gamemode.PlayerDeathThink [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] Return false to prevent the player from respawning.
Sorry, you need to Log In to post a reply to this thread.