• TTT Randomweaponloadout
    2 replies, posted
Hello I've recently started, coding lua for the server i am running. And i wanted to create a random weapon loadout, where you start with a random weapon at the start of the round. This is the code [CODE] if SERVER then AddCSLuaFile("randomweaponloadout.lua") end local weapons = { {["type"]="primary", ["name"]="weapon_zm_shotgun", ["ammo"]="Buckshot", ["clipsize"]=24}, {["type"]="primary", ["name"]="weapon_ttt_m16", ["ammo"]="Pistol", ["clipsize"]=60}, {["type"]="primary", ["name"]="weapon_zm_mac10", ["ammo"]="SMG1", ["clipsize"]=60}, {["type"]="primary", ["name"]="weapon_zm_rifle", ["ammo"]="357", ["clipsize"]=20}, {["type"]="primary", ["name"]="weapon_zm_sledge", ["ammo"]="", ["clipsize"]=""}, {["type"]="secondary", ["name"]="weapon_zm_revolver", ["ammo"]="AlyxGun", ["clipsize"]=36}, {["type"]="secondary", ["name"]="weapon_zm_pistol", ["ammo"]="Pistol", ["clipsize"]=60}, {["type"]="secondary", ["name"]="weapon_ttt_glock", ["ammo"]="Pistol", ["clipsize"]=60}, {["type"]="grenade", ["name"]="weapon_tttbasegrenade"}, {["type"]="grenade", ["name"]="weapon_zm_molotov"}, {["type"]="grenade", ["name"]="weapon_ttt_smokegrenade"} } hook.Add("PlayerLoadout", "GiveWeapon", function(ply) // select random weapons local primaryweapon = math.random(1,5) local secondaryweapon = math.random(6,8) local grenade = math.random(9,11) // primary ply:Give(weapons[primaryweapon].name) // secondary ply:Give(weapons[secondaryweapon].name) // ammo if weapons[primaryweapon].ammo == weapons[secondaryweapon].ammo then ply:GiveAmmo(weapons[primaryweapon].clipsize, weapons[primaryweapon].ammo) elseif weapons[primaryweapon].ammo == "" then ply:GiveAmmo(weapons[secondaryweapon].clipsize, weapons[secondaryweapon].ammo) else ply:GiveAmmo(weapons[primaryweapon].clipsize, weapons[primaryweapon].ammo) ply:GiveAmmo(weapons[secondaryweapon].clipsize, weapons[secondaryweapon].ammo) end // grenade ply:Give(weapons[grenade].name) // player alert local playerweapons = {} for k, v in pairs(ply:GetWeapons()) do playerweapons[v] = v:GetPrintName( ) end ply:ChatPrint("\n\nYou have been randomly given a "..weapons[primaryweapon].name.." a "..weapons[secondaryweapon].name.." and a "..weapons[grenade].name.." by the server Admins.".."\n\nHappy traiting!")[/CODE] The problem, i'm having when i start it up on a server , and try to login it says "too many lua errors", and produces the following error message in the server console. [CODE] [ERROR] lua/autorun/randomweaponloadout.lua:51: 'end' expected (to close 'function' at line 21) near '<eof>' 1. unknown - lua/autorun/randomweaponloadout.lua:0 [/CODE] All i understand from this error message, is that the function at line 22 needs and end to be closed, but what i don't understand is, where to close. I would love if you guys could help, me since i'm just starting coding in lua for gmod. Sorry if my English i'sent all that good, hope you still understand.
It wants an extra "end" on the very end of your file '<eof>' stands for "end of" or the end of the file. Also if it's kicking you, you can disable lua error kicking with sv_kickerrornum 0
Thank you will try that now. It worked, fixed the last error i was having this is the code now for anyone that want this to be on they're server. And thank you so much i really appreciate it.:smile: [CODE] if SERVER then AddCSLuaFile("randomweaponloadout.lua") end local weapons = { {["type"]="primary", ["name"]="weapon_zm_shotgun", ["ammo"]="Buckshot", ["clipsize"]=24}, {["type"]="primary", ["name"]="weapon_ttt_m16", ["ammo"]="Pistol", ["clipsize"]=60}, {["type"]="primary", ["name"]="weapon_zm_mac10", ["ammo"]="SMG1", ["clipsize"]=60}, {["type"]="primary", ["name"]="weapon_zm_rifle", ["ammo"]="357", ["clipsize"]=20}, {["type"]="primary", ["name"]="weapon_zm_sledge", ["ammo"]="", ["clipsize"]=""}, {["type"]="secondary", ["name"]="weapon_zm_revolver", ["ammo"]="AlyxGun", ["clipsize"]=36}, {["type"]="secondary", ["name"]="weapon_zm_pistol", ["ammo"]="Pistol", ["clipsize"]=60}, {["type"]="secondary", ["name"]="weapon_ttt_glock", ["ammo"]="Pistol", ["clipsize"]=60}, {["type"]="grenade", ["name"]="weapon_tttbasegrenade"}, {["type"]="grenade", ["name"]="weapon_zm_molotov"}, {["type"]="grenade", ["name"]="weapon_ttt_smokegrenade"} } hook.Add("PlayerLoadout", "GiveWeapon", function(ply) // select random weapons local primaryweapon = math.random(1,5) local secondaryweapon = math.random(6,8) local grenade = math.random(9,11) // primary ply:Give(weapons[primaryweapon].name) // secondary ply:Give(weapons[secondaryweapon].name) // ammo if weapons[primaryweapon].ammo == weapons[secondaryweapon].ammo then ply:GiveAmmo(weapons[primaryweapon].clipsize, weapons[primaryweapon].ammo) elseif weapons[primaryweapon].ammo == "" then ply:GiveAmmo(weapons[secondaryweapon].clipsize, weapons[secondaryweapon].ammo) else ply:GiveAmmo(weapons[primaryweapon].clipsize, weapons[primaryweapon].ammo) ply:GiveAmmo(weapons[secondaryweapon].clipsize, weapons[secondaryweapon].ammo) end // grenade ply:Give(weapons[grenade].name) // player alert local playerweapons = {} for k, v in pairs(ply:GetWeapons()) do playerweapons[v] = v:GetPrintName( ) end ply:ChatPrint("\n\nYou have been randomly given a "..weapons[primaryweapon].name.." a "..weapons[secondaryweapon].name.." and a "..weapons[grenade].name.." by the server god.".."\n\nHappy traiting!") end ) [/CODE]
Sorry, you need to Log In to post a reply to this thread.