I want to know if this is a good start to the "rank up" system. Also, the reason I have a random number generator is so with each level you get a different weapon. (I know I'm doing a bad job of explaining so do comment any confusions you have.)
function GM:PlayerInitialSpawn( ply )
player_manager.SetPlayerClass( ply, SMG_1 )
local Rand = math.random( 1, 3 )
if Rand <= 1 then
ply:Give("sfw_prisma")
elseif Rand <= 2 then
ply:Give("sfw_neutrino")
else Rand <= 3 then
ply:Give("weapon_ss2_uzi")
end
if Player:Frags(+1) then player_manager.SetPlayerClass( ply, SMG_2 )
local Rand = math.random( 1, 3 )
if Rand <= 1 then
ply:Give("sfw_grinder")
elseif Rand <= 2 then
ply:Give("sfw_blizzard")
else Rand <= 3 then
ply:Give("ree_thompson")
end
if Player:Frags(+1) then player_manager.SetPlayerClass( ply, SMG_3 )
local Rand = math.random( 1, 3 )
if Rand <= 1 then
ply:Give("weapon_752_dc15s")
elseif Rand <= 2 then
ply:Give("sanctum2_smg")
else Rand <= 3 then
ply:Give("ree_mp5")
end
Player:Frags doesn't accept anything in arguments
How would I make it so if the player gets a kill it will change their class?
Garry's Mod Wiki
do some searching
-- If someone dies just give the attacker a new "class"
function GM:PlayerDeath( victim, inflictor, attacker )
-- Do something like
attacker:StripWeapons()
-- and then just give a new weapon
attacker:Give( "weapon_crowbar" )
end
How about this.
function GM:PlayerInitialSpawn( ply )
player_manager.SetPlayerClass( ply, SMG_1 )
local Rand = math.random( 1, 3 )
if Rand <= 1 then
ply:Give("sfw_prisma")
elseif Rand <= 2 then
ply:Give("sfw_neutrino")
else Rand <= 3 then
ply:Give("weapon_ss2_uzi")
end
function GM:PlayerDeath( victim, inflictor, attacker )
attacker:StripWeapons()
player_manager.SetPlayerClass( ply, SMG_2 )
local Rand = math.random( 1, 3 )
if Rand <= 1 then
ply:Give("sfw_grinder")
elseif Rand <= 2 then
ply:Give("sfw_blizzard")
else Rand <= 3 then
ply:Give("ree_thompson")
end
function GM:PlayerDeath( victim, inflictor, attacker )
attacker:StripWeapons()
player_manager.SetPlayerClass( ply, SMG_3 )
local Rand = math.random( 1, 3 )
if Rand <= 1 then
ply:Give("weapon_752_dc15s")
elseif Rand <= 2 then
ply:Give("sanctum2_smg")
else Rand <= 3 then
ply:Give("ree_mp5")
end
I didn't even realise but your math.random part isn't correct either, also why are you using 2 PlayerDeath hooks?
Oh and ply is not and argument of PlayerDeath. If you want to make a gungame gamemode, just use something like this:
(Also remember you only need one PlayerDeath hook for this, not two.)
function GM:PlayerDeath( victim, inflictor, attacker )
attacker:StripWeapons() -- Strips the weapons of the attacker
local Rand = math.random( 1, 3 )
if Rand == 1 then -- If the math.random that you set is 1
attacker:Give("weapon_752_dc15s") -- Gives the attacker a weapon
elseif Rand == 2 then -- If the math.random that you set is 2
attacker:Give("sanctum2_smg")
elseif Rand == 3 then -- If the math.random that you set is 3
attacker:Give("ree_mp5")
end
end
There's a better of doing it.
https://wiki.garrysmod.com/page/table/Random
Like this?
SMG_1 = {“sfw_prism” , “sfw_neutrino” , “weapon_ss2_uzi”}
function GM:PlayerDeath( victim, inflictor, attacker,)
attacker:StripWeapons()
attacker:Give(table.Random(SMG_1))
end
Now how would I make it so if the player gets a kill they will upgraded to the next level and then they will be give a random weapon from that next level. Would I have to use SetNWInt/GetNWInt?
Do you need to inform player about its level?
No.
So you don't need any of network things
How does this sound in terms of leveling up system?
Ranks = {
SMG_1 ,
SMG_2 ,
}
SMG_1_Weapons = {“sfw_prism” , “sfw_neutrino” , “weapon_ss2_uzi”}
SMG_2_Weapons = {sfw_grinder , sfw_blizzard , ree_thompson}
function GM:PlayerInitialSpawn( ply )
ply:StripWeapons()
ply:Give(table.Random(SMG_1_Weapons))
end
function GM:PlayerDeath( victim, inflictor, attacker,)
player_manager.SetPlayerClass( attacker, attacker:GetClassID() + 1 )
if
attacker:GetClassID() = SMG_2
then
attacker:StripWeapons()
attacker:Give(table.Random(SMG_2_Weapons))
end
So I wrote some shit. This not tested and it requires adjustment. Don't judge me.
if ( SERVER ) then
util.AddNetworkString('gg.PlayerInitialized')
gungame = {}
local _weapons = {}
local minLevel = 1 -- i guess it should be 1
local maxLevel = 1
function gungame.AddLevel(name, order)
_weapons[order] = {Name = name}
if ( order > maxLevel ) then
maxLevel = order
end
end
function gungame.AddWeaponsToLevel(name, tbl)
for k, v in ipairs(_weapons) do
if ( v.Name == name ) then
for m, n in ipairs(tbl) do
v[m] = n
end
end
end
end
function gungame.GetTable()
return _weapons
end
function gungame.GetMinLevel()
return minLevel
end
function gungame.GetMaxLevel()
return maxLevel
end
function gungame.GetLevelMinFrags(lvl)
local t = gungame.GetTable()[lvl]
local key = next(t)
local max = t[key]
for k, v in pairs(t) do
if k < key then
key = k
end
end
return k
end
function gungame.GetLevelMaxFrags(lvl)
local t = gungame.GetTable()[lvl]
local key = next(t)
local max = t[key]
for k, v in pairs(t) do
if k > key then
key = k
end
end
return k
end
function gungame.GetLevelTable(lvl)
return gungame.GetTable()[lvl]
end
local function PLAYER = FindMetaTable('Player')
function PLAYER:SetLevel(lvl, frags)
-- You probably ask me why here 2 hooks? Because it's API!
if ( self.Level > lvl ) then
hook.Run('gg.OnPlayerLevelDown', pl, lvl, frags)
elseif ( self.Level < lvl ) then
hook.Run('gg.OnPlayerLevelUp', pl, lvl, frags)
end
self.Level = lvl
end
/*---------------------------------------------------------------------------
cfg
---------------------------------------------------------------------------*/
gungame.AddLevel('Skillzya', 1)
gungame.AddWeaponsToLevel('Skillzya', {
[0] = 'weapon_class', -- index is needle count of frags
[5] = 'weapon_class',
[10] = 'weapon_class'
})
gungame.AddLevel('Shooter', 2)
gungame.AddWeaponsToLevel('Shooter', {
[15] = 'weapon_class',
[20] = 'weapon_class',
[25] = 'weapon_class'
})
gungame.AddLevel('Sniper', 3)
gungame.AddWeaponsToLevel('Sniper', {
[35] = 'weapon_class',
[40] = 'weapon_class',
[45] = 'weapon_class'
})
/*---------------------------------------------------------------------------
Player Initialize
---------------------------------------------------------------------------*/
net.Receive('gg.PlayerInitialized', function(len, pl)
pl:SetLevel( gungame.GetMinLevel() )
end)
/*---------------------------------------------------------------------------
Main shit
---------------------------------------------------------------------------*/
hook.Add('PlayerDeath', 'gg.PlayerDeath', function(victim, inflictor, attacker)
if ( IsValid(victim) ) then
local lvl = victim.Level
if ( lvl != gungame.GetMinLevel() ) then
-- also you can make a to streak for downgrade
lvl = lvl - 1
victim:SetFrags( gungame.GetLevelMaxFrags(lvl) ) -- so here I set a last weapon in previous level I wish
attacker:SetLevel(lvl, gungame.GetLevelMaxFrags(lvl))
end
end
if ( IsValid(attacker) ) then
local lvl = attacker.Level
if ( lvl != gungame.GetMaxLevel() ) then
local frags = attacker:Frags()
local lvlTable = gungame.GetLevelTable(lvl)
if ( frags > gungame.GetLevelMaxFrags(lvl) ) then
lvl = lvl + 1
attacker:SetLevel(lvl, gungame.GetLevelMinFrags(lvl))
elseif ( lvlTable[frags] != nil ) then
end
else
-- you are winner!
end
end
end)
/*---------------------------------------------------------------------------
Giving Weapons
---------------------------------------------------------------------------*/
local function GiveNewLevelWeapon(pl, lvl, frags)
local t = gungame.GetLevelTable(lvl)
local wep = t[frags]
pl:Give(wep)
end
hook.Add('gg.OnPlayerLevelDown', 'GivingWeaponUp', GiveNewLevelWeapon)
hook.Add('gg.OnPlayerLevelUp', 'GivingWeaponDown', GiveNewLevelWeapon)
end
if ( CLIENT ) then
hook.Add('InitPostEntity', 'gg.InitPostEntity', function()
net.Start('gg.PlayerInitialized')
net.SendToServer()
end)
end
I mean nice, but that's not really gonna teach OP anything.
I'll try to test it Monday and see if it works.
This should give you an idea of how to make a level based gun game system, haven't tested it but this should work.
randLvl1Weapons = {"sfw_prism", "sfw_neutrino", "weapon_ss2_uzi"} -- Level 1 weapon table
randLvl2Weapons = {"sfw_grinder", "sfw_blizzard", "ree_thompson"} -- Level 2 weapon table
function GM:PlayerInitialSpawn( ply )
ply:StripWeapons() -- Strips the weapons of the attacker
ply:Give( randLvl1Weapons[ math.random( #randLvl1Weapons ) ] ) -- Gives the player a level 1 weapon
ply:SetNWInt("GunGameLevel", 1) -- Set the players level (There is no point in networking this if you're not planning on using this value clientside, but it's easier so whatever)
end
function GM:PlayerDeath( victim, inflictor, attacker )
attacker:StripWeapons() -- Strips the weapons of the attacker
if ply:GetNWInt("GunGameLevel") < 3 then -- If the players level is under 3 (We only have 2 levels, so we don't want to go above 2)
ply:SetNWInt("GunGameLevel", ply:GetNWInt("GunGameLevel") + 1) -- Add a level
end
if ply:GetNWInt("GunGameLevel") == 1 then -- If the players level is 1 then
attacker:Give( randLvl1Weapons[ math.random( #randLvl1Weapons ) ] ) -- Give the player a random Level 1 weapon
elseif ply:GetNWInt("GunGameLevel") == 2 then -- If the players level is 2 then
attacker:Give( randLvl2Weapons[ math.random( #randLvl2Weapons ) ] ) -- Give the player a random Level 2 weapon
end
end
I don't think that random is good solution in gun game mode because weapons must be given in order way like it was made in CS.
I mean if he wants to do it that way, sure. But in his code he made it random, so i went with that method.
That's what I'm looking for. Also, really thank you for the help. <3
We already established that we don't need to network anything so NW functions are useless, and terrible.
local gg_weapons = {
"weapon_1", -- lvl 1
"weapon_2", -- lvl 2
"weapon_3" -- lvl 3
}
local clamp = math.Clamp;
hook.Add("PlayerDeath", "", function(victim, _, attacker)
attacker.gg_level = clamp((attacker.gg_level and attacker.gg_level + 1 or 1), 1, 3);
victim.gg_level = clamp((victim.gg_level and victim.gg_level - 1 or 1), 1, 3);
attacker:StripWeapons();
attacker:Give(gg_weapons[attacker.gg_level]);
end);
hook.Add("PlayerSpawn", "", function(ply)
ply:StripWeapons();
ply:Give(gg_weapons[ply.gg_level]);
end);
This should give you an idea, it's untested and was written in 20 seconds so I wouldn't c+p it.
Again, that doesn't teach him anything. And networking those few values won't kill the servers performance, so it won't matter.
wrong. dont use nw functions, at all.
Sorry, you need to Log In to post a reply to this thread.