• LUA 'GunGame' Script will not even load
    8 replies, posted
I'm a new LUA Scripter, coding for my own Sandbox Server. The script is located in lua/autorun/server, just to wrap that up. Please don't be hard on me, i'm only learning still. Anyway, this script won't load. Whenever I run the supposed command 'Start_GunGame' in Console, it doesn't do anything. [lua]local function EndGunGame() for k, v in pairs (player.GetAll()) do v:Kill() v:GodEnable() MsgAll("The Gun Game has ended.\n") end end local function StartGunGame() for i = 1,30 if i == 30 do EndGunGame() for k, v in pairs (player.GetAll()) do MsgAll("A Gun Game has begun. Hold on to your butts!\n") v:EmitSound("hl1/fvox/boop.wav", 500, 200) v:Give("Weapon_Pistol") v:GiveAmmo(100, "Pistol") v:GodDisable() end end end end StartGunGame() concommand.Add("Start_GunGame", StartGunGame)[/lua]
I don't have time to test your script, but i see a few errors. [lua]for i = 1,30[/lua] you forgot a do at the end, every "for" loop needs a "do" at the end of it like: [lua]for i = 1, 30 do[/lua] and [lua]if i == 30 do[/lua] if statements need a "then" at the end of them, not "do". Like this: [lua]if i == 30 then[/lua] i'll take a closer look later on if no one else has answered by the time I get back home.
Alright, it worked. But now I edited the script and there is now a problem with this. End_GunGame works, but not Start_GunGame. (Console Commands) [lua] local function GunGameWeapons( ply ) ply:StripWeapons() ply:Give("weapon_pistol") ply:GiveAmmo(100,"pistol") end hook.Add("PlayerSpawn", "GunGame Respawn Weapons", GunGameWeapons) GunGameWeapons() local function EndGunGame() hook.Remove("PlayerSpawn", "GunGame Respawn Weapons") game.ConsoleCommand("sbox_godmode 1\n") game.ConsoleCommand("sbox_plpldamage 1\n") game.ConsoleCommand("sbox_noclip 1\n") for k, v in pairs (player.GetAll()) do v:EmitSound("ambient/alarms/klaxon1.wav", 100, 100) v:Kill() v:GodEnable() v:ChatPrint("The Gun Game has ended.") end end concommand.Add("End_GunGame", EndGunGame) local function StartGunGame() game.ConsoleCommand("sbox_godmode 0\n") game.ConsoleCommand("sbox_plpldamage 0\n") game.ConsoleCommand("sbox_noclip 0\n") for k, v in pairs (player.GetAll()) do v:EmitSound("hl1/fvox/beep.wav", 100, 100) v:GodDisable() v:ChatPrint("The Gun Game has begun.") v:StripWeapons() v:Give("weapon_pistol") v:GiveAmmo(100,"pistol") end end StartGunGame() concommand.Add("Start_GunGame", StartGunGame) [/lua]
Try this [lua]hook.Add( "PlayerSpawn", "GunGame Respawn Weapons", function( ply ) ply:StripWeapons(); ply:Give( "weapon_pistol" ); ply:GiveAmmo( 100, "pistol" ); end ); function EndGunGame() hook.Remove( "PlayerSpawn", "GunGame Respawn Weapons" ); game.ConsoleCommand( "sbox_godmode 1\n" ); game.ConsoleCommand( "sbox_plpldamage 1\n" ); game.ConsoleCommand( "sbox_noclip 1\n" ); for k, v in pairs ( player.GetAll() ) do v:EmitSound( "ambient/alarms/klaxon1.wav", 100, 100 ); v:Kill(); v:GodEnable(); v:ChatPrint( "The Gun Game has ended." ); end; end; concommand.Add( "End_GunGame", EndGunGame ); function StartGunGame() game.ConsoleCommand( "sbox_godmode 0\n" ); game.ConsoleCommand( "sbox_plpldamage 0\n" ); game.ConsoleCommand( "sbox_noclip 0\n" ); for k, v in pairs( player.GetAll() ) do v:EmitSound( "hl1/fvox/beep.wav", 100, 100 ); v:GodDisable(); v:ChatPrint( "The Gun Game has begun." ); v:StripWeapons(); v:Give( "weapon_pistol" ); v:GiveAmmo( 100, "pistol" ); end; end; concommand.Add("Start_GunGame", StartGunGame);[/lua]
[QUOTE=josh980;36372760]Try this [lua]snip[/lua][/QUOTE] No, that didn't work. Sorry. I still didn't re-spawn stripped with just a pistol and 100 ammo.
It worked on mine where are you putting the script?
[quote=Shockcom]The script is located in lua/autorun/server, just to wrap that up.[/quote]
Instead of removing the hook which won't hook itself back on, you should add a variable local Round = false Round = true if Round == true then elseif Round == false then end
[QUOTE=Shockcom;36378284]No, that didn't work. Sorry. I still didn't re-spawn stripped with just a pistol and 100 ammo.[/QUOTE] It's because he didn't call back the function: StartGunGame()
Sorry, you need to Log In to post a reply to this thread.