• server randomly picking gamemode init
    12 replies, posted
Hello I recently finished my gmod gun game game mode, but now instead of having a fixed order of weapons I want different ones, is it possible to have multiple init lua files in my game mode and the server to randomly pick one of the init files to use? Thanks, matt
No, that's not how it works. Make multiple tables of weapon orders and use a random table in each round or something. ( The same way CS:GO does it )
How would I go about choosing a random one each round?
Why don't you just make a table containing each weapon set and then use table[math.random(1, #table)] to select the weapon set that will be used? [code] local PossibleWeaponLists = { { 'weapon_one', 'weapon_two', 'weapon_three' }, { 'weapon_three', 'weapon_two', 'weapon_one' } } GM.WeaponList = PossibleWeaponLists[math.random(1, #PossibleWeaponLists)] [/code]
Ok, thats a good idea, at the moment I have an if and else ifs: if (attacker:GetNWInt('level') == 0) then attacker:Give( "tfa_luger" ) attacker:GiveAmmo( 969, "357" ) else if (attacker:GetNWInt('level') == 1) then attacker:StripWeapon( "tfa_luger" ) attacker:Give( "tfa_deagle" ) attacker:GiveAmmo( 969, "357" ) do i need to include the else ifs still?
Put all of the weapon names in these tables. The index of the weapon should represent the level it is unlocked on; make sure your levels start from one and not zero (indexing in Lua starts from one). You should have a function that handles leveling a player up. You need to use the tables to avoid using 50 elseifs: [code] local WepList = { 'weapon_one', 'weapon_two', 'weapon_three' } local function LevelUp(ply) -- Or whatever the function is local level = ply:GetLevel() -- Or however to get the player's level if level == #WepList then -- do what happens when a player wins return -- Don't level up players if they win end ply:StripWeapon(WepList[level]) -- Strip the weapon for their level ply:Give(WepList[level+1]) -- GIve them the next level's weapon ply:GiveAmmo(weapons.Get(WepList[level+1]).Primary.Ammo) -- give them the new ammo ply:SetLevel(level + 1) end [/code]
thankyou for the help, ill be testing it soon, but say I have a weapon as weapon one, will i get it on spawn or will i have to keep my if (blahah level == 0) then give luger
Also since I don't think anyone has pointed out, you can have more files than only cl_init/init/shared - they're just names commonly used for clientside/serverside/shared states So if you did want more init files, you could have them named different but only include them serverside, meaning that's where they get loaded
Hmmm, i get an error and its something to do with the + symbol: p1:GetNWInt('level',0) +1 cant see whats wrong?
p1:SetNWInt ('level', p1:GetNWInt ('level') + 1) this should work
that worked thanks, but i cant seem to get the gamemode to work, but if you want the code here it is: [url]http://pastebin.com/zMDwWPH1[/url] [editline]1st June 2015[/editline] would it be possible to make different orders but with the same sort of code as mine: [url]http://pastebin.com/Ta5BPFCh[/url] As I am just a beginner and I am not very familiar with tables
[QUOTE=mattymoo142;47853866]that worked thanks, but i cant seem to get the gamemode to work, but if you want the code here it is: [url]http://pastebin.com/zMDwWPH1[/url] [editline]1st June 2015[/editline] would it be possible to make different orders but with the same sort of code as mine: [url]http://pastebin.com/Ta5BPFCh[/url] As I am just a beginner and I am not very familiar with tables[/QUOTE] It should be Primary.Ammo, not PrimaryAmmo. You're also leveling up the person 3 times for some reason. You only do SetNWInt() when you need to CHANGE the level, not when you need to GET it. Also, you should separate each task into functions (one for handling death, one for handling leveling up, one for handing the end of a round, and one for handling a new round). Also, you don't have your random weapon list thing on there, so you'd want to add that back. I also don't know why you're defining the weapon list twice when you can just do it outside of the functions.
Ok, I have put it into my init file, but i cant even get it to spawn me with a weapon to test it. [url]http://pastebin.com/vRqNLEZs[/url]
Sorry, you need to Log In to post a reply to this thread.