Im making my own leveling system for a game mode im making and i need it so when you get 5 kills you go to lvl 2 30 kills you go to lvl 3 50 kills you go to lvl 4 and 100 kills you go to lvl 5 and if you get to lvl 5 you are the winner and the game mode restarts, how would i do that?
[lua]hook.Add("PlayerInitialSpawn", "SetLevel", function( ply )
ply:SetNWInt("level", 1) -- On first spawn, set players level to 1
end)
function Levels( ply )
local BestScore = 100 -- Defining local variables for later use
local BestPlayer
for k,v in pairs( player.GetAll() ) do -- Looping trough a table of all players where v is an individual player.
local Frags = v:Frags() -- Getting a player's frags
if Frags == BestScore then -- If it's higher then the current BestScore then
BestPlayer = v:GetName() -- And make the player the new BestPlayer
end
end
if ply:Frags() => 5 then -- If a players frags are equal to or greater than 5 then...
ply:SetNWInt("level", 2) -- Set his level to 2
elseif ply:Frags() == 30 then -- And so on ...
ply:SetNWInt("level", 3)
elseif ply:Frags() == 50 then
ply:SetNWInt("level", 4)
elseif ply:Frags() == 100 then
ply:SetNWInt("level", 5)
for k, v in pairs(player.GetAll()) do
v:Freeze( true )
v:ChatPrint("Player "..BestPlayer.." has won the game")
-- Probably add a timer which changes the map here?
end
end
end[/lua]
Untested, but should work.
[lua]
hook.Add("PlayerInitialSpawn", "SetLevel", function( ply )
ply:SetNWInt("lvl", 1)
end)
local rounds = 3
local function PlayerDie(Vic, Inf, Kil)
if(Kil:Frags() == 5) then
Kil:SetNWInt("lvl", 2)
elseif(Kil:Frags() == 30) then
Kil:SetNWInt("lvl", 3)
elseif(Kil:Frags() == 50) then
Kil:SetNWInt("lvl", 4)
elseif(Kil:Frags() == 100) then
Kil:SetNWInt("lvl", 5)
RoundEnd(Kil)
end
end
hook.Add("PlayerDie", "LevelSystemDeath", PlayerDie)
local function RoundEnd(ply)
rounds = rounds - 1
for k, v in pairs(player.GetAll()) do
v:Lock()
v:ChatPrint("Player "..ply:Nick().." has won the game")
end
if(rounds == 0) then
timer.Simple(10, function()
RunConsoleCommand("changelevel", "gm_construct") -- Make your own rotation system
end)
else
timer.Simple(2, function()
RoundRestart()
end)
end
end
local function RoundRestart()
game.CleanUpMap()
for k, v in pairs(player.GetAll()) do
v:Spawn()
v:SetFrags(0)
v:SetDeaths(0)
v:ChatPrint("New round in 5 seconds")
end
timer.Simple(5, function()
for k, v in pairs(player.GetAll)) do
v:UnLock()
end
end)
end
[/lua]
That will actually work, but yet again it is untested
[QUOTE=patrickrender;23077039]Im making[/QUOTE]
Looks like your not since you just got all the code
[QUOTE=Willox;23082264][lua]
hook.Add("PlayerInitialSpawn", "SetLevel", function( ply )
ply:SetNWInt("lvl", 1)
end)
local rounds = 3
local function PlayerDie(Vic, Inf, Kil)
if(Kil:Frags() == 5) then
Kil:SetNWInt("lvl", 2)
elseif(Kil:Frags() == 30) then
Kil:SetNWInt("lvl", 3)
elseif(Kil:Frags() == 50) then
Kil:SetNWInt("lvl", 4)
elseif(Kil:Frags() == 100) then
Kil:SetNWInt("lvl", 5)
RoundEnd(Kil)
end
end
hook.Add("PlayerDie", "LevelSystemDeath", PlayerDie)
local function RoundEnd(ply)
rounds = rounds - 1
for k, v in pairs(player.GetAll()) do
v:Lock()
v:ChatPrint("Player "..ply:Nick().." has won the game")
end
if(rounds == 0) then
timer.Simple(10, function()
RunConsoleCommand("changelevel", "gm_construct") -- Make your own rotation system
end)
else
timer.Simple(2, function()
RoundRestart()
end)
end
end
local function RoundRestart()
game.CleanUpMap()
for k, v in pairs(player.GetAll()) do
v:Spawn()
v:SetFrags(0)
v:SetDeaths(0)
v:ChatPrint("New round in 5 seconds")
end
timer.Simple(5, function()
for k, v in pairs(player.GetAll)) do
v:UnLock()
end
end)
end
[/lua]
That will actually work, but yet again it is untested[/QUOTE]
This will work better than mine, but only because I typed mine in like 1 minute, after all, i'm not gonna script this guys gamemode
I did it in about 2, btw the function levels doesnt get called and your if is wrong
[QUOTE=LuckyLuke;23082398]This will work better than mine, but only because I typed mine in like 1 minute, after all, i am unable to script this guys gamemode[/QUOTE]
Fixed
[QUOTE=LuckyLuke;23082398]I typed mine in like 1 minute[/QUOTE]
I doubt you're THAT good at lua.
[QUOTE=Jova;23083534]I doubt you're THAT good at lua.[/QUOTE]
It didnt work anyway and it was clearly like 10 mins or so because he had to find some other code to C&P
[QUOTE=Jova;23083534]I doubt you're THAT good at lua.[/QUOTE]
Why?
And Flawless, please, stop thinking you are better than everyone else seriously, okay, i'm not very good at lua, but i'm trying to help.
Just ignore Flawless, and its not that much code and if you've done anything like that it's not that hard to type it in a minute.
-snip-
I need no reason.
How about we stop raging? :D
NEVER! This is facepunch you have to rage apparently.
-snip-
[QUOTE=??????;23086100]NEVER! This is facepunch you have to rage apparently.[/QUOTE]
We only have to rage because King Flawless always starts a ragefest on his first post in a thread
Holy shit how about you all stop trying to prove who's e-dick is bigger.
You gave the guy some code, works or not it is still a basic understanding for him to learn from, if it doesn't work then good it will hopefully force him to try and fix it himself.
And King Flawless, you're not better than these guys, you're probably at the same level as OP.
[QUOTE=Willox;23082264][lua]
hook.Add("PlayerInitialSpawn", "SetLevel", function( ply )
ply:SetNWInt("lvl", 1)
end)
local rounds = 3
local function PlayerDie(Vic, Inf, Kil)
if(Kil:Frags() == 5) then
Kil:SetNWInt("lvl", 2)
elseif(Kil:Frags() == 30) then
Kil:SetNWInt("lvl", 3)
elseif(Kil:Frags() == 50) then
Kil:SetNWInt("lvl", 4)
elseif(Kil:Frags() == 100) then
Kil:SetNWInt("lvl", 5)
RoundEnd(Kil)
end
end
hook.Add("PlayerDie", "LevelSystemDeath", PlayerDie)
local function RoundEnd(ply)
rounds = rounds - 1
for k, v in pairs(player.GetAll()) do
v:Lock()
v:ChatPrint("Player "..ply:Nick().." has won the game")
end
if(rounds == 0) then
timer.Simple(10, function()
RunConsoleCommand("changelevel", "gm_construct") -- Make your own rotation system
end)
else
timer.Simple(2, function()
RoundRestart()
end)
end
end
local function RoundRestart()
game.CleanUpMap()
for k, v in pairs(player.GetAll()) do
v:Spawn()
v:SetFrags(0)
v:SetDeaths(0)
v:ChatPrint("New round in 5 seconds")
end
timer.Simple(5, function()
for k, v in pairs(player.GetAll)) do
v:UnLock()
end
end)
end
[/lua]
That will actually work, but yet again it is untested[/QUOTE]
NETWORKED INT's!!! :derp:
[QUOTE=Wizey!;23110460]NETWORKED INT's!!! :derp:[/QUOTE]
I simply edited the guy i forgots code :c
[QUOTE=LuckyLuke;23084385]Why?[/QUOTE]
Even though that script is simple, you would need to be an expert at lua to be able to type it up in just 1 minute. you would need to know EXACTLY what you're going to type the entire time.
For a levelling system, just use [b][url=http://wiki.garrysmod.com/?title=Player.SetPData]Player.SetPData [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and [b][url=http://wiki.garrysmod.com/?title=Player.GetPData]Player.GetPData [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
[B]EDIT:[/B]
Don't listen to that, I forgot you don't want it to be permanent.
Just use [b][url=http://wiki.garrysmod.com/?title=Entity.SetNetworkedInt]Entity.SetNetworkedInt [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] and [b][url=http://wiki.garrysmod.com/?title=Entity.GetNetworkedInt]Entity.GetNetworkedInt [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]
Sorry, you need to Log In to post a reply to this thread.