• Help with a LUA Code!
    32 replies, posted
I have a server, with SGRP, but I've managed to break the gamemode (I added 3 more new jobs), the server console says there is a error in sv_player.lua, with this code: [code]function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return local team == ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") [/code] Any help would be great, Thanks! [highlight](User was banned for this post ("Undescriptive thread title; wrong forum" - mahalis))[/highlight]
When i was making a gamemode, i made it ply:Give( "weapon_ar2" ) for instance, with spaces. Try that.
[QUOTE=bsp-reviews;17534053]When i was making a gamemode, i made it ply:Give( "weapon_ar2" ) for instance, with spaces. Try that.[/QUOTE] Don't be so dumb. [editline]06:54PM[/editline] [QUOTE=Norway174;17534017]I have a server, with SGRP, but I've managed to break the gamemode (I added 3 more new jobs), the server console says there is a error in sv_player.lua, with this code: [code]function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return local team == ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") [/code] Any help would be great, Thanks![/QUOTE] Don't return. Returning "leaps" to the end of the function. Only return if you want to do that (Or make the function equal to a value)
What? He can return what he wants here... he misses an end After the return thats all. And a end to close the function...
He also have == ( is equal to ) where he is only supposed to use one =.
it's not that, it's the "local" This is the Error from my server [code] StargateRP\gamemode\sv_player.lua:527: unexpected symbol near 'local' [/code] it's something to do with "local team == ply:Team( )" And that sentence is sentence number 527 in Notepad++
Read my message.
I tryed with one, still failed, but I try again if you want to :) Edit: Nope, sorry, still failed.
[QUOTE=Norway174;17534449]I tryed with one, still failed, but I try again if you want to :)[/QUOTE] Try everything we said. There is a lot wrong with your code.
[code] function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return end local team == ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") end [/code]
Thanks, I've made the code like this: [code] function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return end local team = ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") [/code] And then server now gives me this Error: [code] StargateRP\gamemode\sv_player.lua:756: 'end' expected (to close 'function' at line 524) near '<eof>' [/code] No idea what '<eof>' means, and at line 756, that's the last line, and there is a "end" there... And thanks for the help so far, just a little more, and this great gamemode will work again :P
[QUOTE=Norway174;17534828]Thanks, I've made the code like this: [code] function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return end local team = ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") [/code] And then server now gives me this Error: [code] StargateRP\gamemode\sv_player.lua:756: 'end' expected (to close 'function' at line 524) near '<eof>' [/code] No idea what '<eof>' means, and at line 756, that's the last line, and there is a "end" there... And thanks for the help so far, just a little more, and this great gamemode will work again :P[/QUOTE] EOF is "End of file" This means you didn't end the function.
[QUOTE=rute;17534718][code] function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return end local team == ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") end [/code][/QUOTE] with 2 "=="? I is that the problem? Capsu said it had to be one "=" Edit: Ok, I've tryed with "==", now the console said [code] StargateRP\gamemode\sv_player.lua:527: unexpected symbol near '==' [/code]
[QUOTE=Norway174;17534866]with 2 "=="? I is that the problem? Capsu said it had to be one "=" Edit: Ok, I've tryed with "==", now the console said [code] StargateRP\gamemode\sv_player.lua:527: unexpected symbol near '==' [/code][/QUOTE] He was talking shit (The poster of the code you are using). Use "=" for making something equal to something, and "==" for comparing two variables - are they equivalent to each other?
So EOF is End of File? But it has a end. and Rute, I can't have a end after "ply:Give ("gmod_camera")", it's more after that, but that has nothing to do with it, that I'm sure of...
Perhaps you need another end?
But then the other in Playerloadout won't work? [editline]06:50PM[/editline] if I set it up like this, does that change anything, or won't it be any diffrence? [code] function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return end local team = ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") end [/code] There are more under here... But that shouldn't be the problem, that wasn't the problem before atleast.
[QUOTE=Norway174;17535157]But then the other in Playerloadout won't work? [editline]06:50PM[/editline] if I set it up like this, does that change anything, or won't it be any diffrence? [code] function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return end local team = ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") end [/code] There are more under here... But that shouldn't be the problem, that wasn't the problem before atleast.[/QUOTE] You can't have multiple GM:PlayerLoadout functions. Use if statements instead.
[QUOTE=Retirsch;17534856]EOF is "End of file" This means you didn't end the function.[/QUOTE] WHAT? End of Function*
it worked, but now I have some other problems... lol Server console: [code] StargateRP\gamemode\sv_player.lua:533: attempt to index global 'CfgVars' (a nil value) [/code] and line 533 in sv_player.lua is [code] if (CfgVars["toolgun"] == 1 or Admins[ply:SteamID()] or Tool[ply:SteamID()]) then [/code] and the rest for that line is [code] local team = ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") end if (CfgVars["toolgun"] == 1 or Admins[ply:SteamID()] or Tool[ply:SteamID()]) then ply:Give("gmod_tool") end if (CfgVars["physgun"] == 1 or Admins[ply:SteamID()] or Phys[ply:SteamID()]) then ply:Give("weapon_physgun") end[/code] Plase some more help? :D
God... Just post the WHole function plus the other ones around!...
[QUOTE=commander204;17535329]WHAT? End of Function*[/QUOTE] No.
Code Removed! PRIVATE! lol, Thanks for all the help!
[lua]function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return end local team = ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") if (CfgVars["toolgun"] == 1 or Admins[ply:SteamID()] or Tool[ply:SteamID()]) then ply:Give("gmod_tool") end if (CfgVars["physgun"] == 1 or Admins[ply:SteamID()] or Phys[ply:SteamID()]) then ply:Give("weapon_physgun") end if (team == 20 or team == 21 or team == 22 or team == 23 or team == 42 or team == 44 or team == 24 or team == 25 or team == 26 or team == 27 or Admins[ply:SteamID()]) then ply:Give("door_ram") end if (team == 20 or team == 21 or team == 22 or team == 23 or team == 24 or team == 25 or team == 42 or team == 44 or team == 26 or team == 27 or team == 3 or Admins[ply:SteamID()]) then ply:Give("weapon_gdo") end -- O'Neill if (team == 20) then ply:Give("p90_sg") ply:Give("beretta_sg") ply:Give("sg_mp5") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("stunstick") ply:GiveAmmo(100, "Pistol") ply:GiveAmmo(500, "smg") -- Carter elseif (team == 21) then ply:GiveAmmo(100, "Pistol") ply:GiveAmmo(500, "smg") ply:Give("sg_mp5") ply:Give("p90_sg") ply:Give("weapon_zat") ply:Give("lockpick") ply:Give("beretta_sg") -- Jackson elseif (team == 22) then ply:GiveAmmo(500, "Pistol") ply:Give("beretta_sg") ply:Give("cse_eq_smokegrenade") ply:Give("weapon_zat") -- Teal'c elseif (team == 23) then ply:GiveAmmo(100, "Pistol") ply:Give("weapon_staff") ply:Give("weapon_zat") ply:Give("gacgoa_sg") -- Soldier elseif (team == 24) then ply:Give("p90_sg") ply:Give("beretta_sg") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("stunstick") ply:GiveAmmo(200, "Pistol") ply:GiveAmmo(500, "smg") -- Mitchell elseif (team == 25) then ply:Give("p90_sg") ply:Give("beretta_sg") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("weapon_grenade") ply:Give("stunstick") ply:GiveAmmo(20, "Pistol") ply:GiveAmmo(500, "smg") -- Vala elseif (team == 26) then ply:Give("weapon_zat") ply:Give("beretta_sg") ply:Give("p90_sg") ply:GiveAmmo(200, "Pistol") -- Dr. Lam elseif (team == 27) then ply:Give("med_kit") ply:Give("beretta_sg") ply:GiveAmmo(20, "Pistol") -- General elseif (team == 28) then ply:GiveAmmo(28, "Pistol") ply:Give("beretta_sg") ply:Give("weapon_annabelle") -- Goauld elseif (team == 40) then ply:GiveAmmo(1, "Pistol") ply:Give("lockpick") ply:Give("weapon_hand_device") ply:Give("weapon_staff") -- Anubis elseif ( team == 41 ) then ply:Give( "weapon_iron_man" ) ply:Give( "weapon_hand_device" ) -- Jaffa elseif (team == 50) then ply:Give("weapon_zat") ply:Give("gacgoa_sg") ply:Give("ring_caller") ply:Give("weapon_staff") ply:GiveAmmo(1, "Pistol") -- Bra'Tac elseif (team == 51) then ply:Give("weapon_staff") ply:Give("weapon_zat") ply:Give("gacgoa_sg") ply:Give("ring_caller") ply:Give("weapon_gdo") ply:GiveAmmo(1, "Pistol") -- Free Jaffa elseif (team == 52) then ply:Give("p90_sg") ply:Give("weapon_staff") ply:Give("weapon_zat") ply:Give("ring_caller") ply:GiveAmmo(1, "Pistol") -- Personal Guard elseif (team == 53) then ply:Give("weapon_staff") ply:Give("weapon_zat") ply:Give("ring_caller") ply:GiveAmmo(1, "Pistol") -- Tok'ra elseif (team == 60) then ply:GiveAmmo(1, "Pistol") ply:Give("weapon_zat") ply:Give("weapon_ringcaller") -- Jacob + Selmak elseif (team == 61) then ply:GiveAmmo(1, "Pistol") ply:Give("weapon_zat") ply:Give("weapon_ringcaller") ply:Give("weapon_gdo") ply:Give("weapon_zar") -- Sodan Warrior elseif (team == 70) then ply:Give("weapon_staff") ply:Give("sodan_cloak") -- Lord Hi Kon elseif (team == 71) then ply:Give("weapon_staff") ply:Give("sodan_cloak") -- Ancient elseif (team == 80) then ply:Give("weapon_ancient") ply:Give("weapon_ringcaller") ply:Give("weapon_teleport") -- Major John if (team == 42) then ply:Give("p90_sg") ply:Give("beretta_sg") ply:Give("sg_mp5") ply:Give("weapon_zat") ply:Give("lockpick") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("stunstick") ply:GiveAmmo(1000, "Pistol") ply:GiveAmmo(1000, "smg") -- Lord Op elseif (team == 43) then ply:Give("weapon_zat") ply:Give("gacgoa_sg") ply:Give("ring_caller") ply:Give("weapon_staff") ply:Give( "weapon_hand_device" ) ply:GiveAmmo(1, "Pistol") -- Pvt. Bull elseif (team == 44) then ply:GiveAmmo(1000, "Pistol") ply:GiveAmmo(1000, "smg") ply:Give("sg_mp5") ply:Give("p90_sg") ply:Give("weapon_zat") ply:Give("lockpick") ply:Give("beretta_sg") ply:Give("lockpick") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("stunstick") end end[/lua] Try that.
[QUOTE=Retirsch;17535529][code]function GM:PlayerLoadout(ply) if (ply:GetTable().Arrested) then return end local team = ply:Team() ply:Give("keys") ply:Give("weapon_physcannon") ply:Give("gmod_camera") if (CfgVars["toolgun"] == 1 or Admins[ply:SteamID()] or Tool[ply:SteamID()]) then ply:Give("gmod_tool") end if (CfgVars["physgun"] == 1 or Admins[ply:SteamID()] or Phys[ply:SteamID()]) then ply:Give("weapon_physgun") end if (team == 20 or team == 21 or team == 22 or team == 23 or team == 42 or team == 44 or team == 24 or team == 25 or team == 26 or team == 27 or Admins[ply:SteamID()]) then ply:Give("door_ram") end if (team == 20 or team == 21 or team == 22 or team == 23 or team == 24 or team == 25 or team == 42 or team == 44 or team == 26 or team == 27 or team == 3 or Admins[ply:SteamID()]) then ply:Give("weapon_gdo") end -- O'Neill if (team == 20) then ply:Give("p90_sg") ply:Give("beretta_sg") ply:Give("sg_mp5") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("stunstick") ply:GiveAmmo(100, "Pistol") ply:GiveAmmo(500, "smg") -- Carter elseif (team == 21) then ply:GiveAmmo(100, "Pistol") ply:GiveAmmo(500, "smg") ply:Give("sg_mp5") ply:Give("p90_sg") ply:Give("weapon_zat") ply:Give("lockpick") ply:Give("beretta_sg") -- Jackson elseif (team == 22) then ply:GiveAmmo(500, "Pistol") ply:Give("beretta_sg") ply:Give("cse_eq_smokegrenade") ply:Give("weapon_zat") -- Teal'c elseif (team == 23) then ply:GiveAmmo(100, "Pistol") ply:Give("weapon_staff") ply:Give("weapon_zat") ply:Give("gacgoa_sg") -- Soldier elseif (team == 24) then ply:Give("p90_sg") ply:Give("beretta_sg") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("stunstick") ply:GiveAmmo(200, "Pistol") ply:GiveAmmo(500, "smg") -- Mitchell elseif (team == 25) then ply:Give("p90_sg") ply:Give("beretta_sg") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("weapon_grenade") ply:Give("stunstick") ply:GiveAmmo(20, "Pistol") ply:GiveAmmo(500, "smg") -- Vala elseif (team == 26) then ply:Give("weapon_zat") ply:Give("beretta_sg") ply:Give("p90_sg") ply:GiveAmmo(200, "Pistol") -- Dr. Lam elseif (team == 27) then ply:Give("med_kit") ply:Give("beretta_sg") ply:GiveAmmo(20, "Pistol") -- General elseif (team == 28) then ply:GiveAmmo(28, "Pistol") ply:Give("beretta_sg") ply:Give("weapon_annabelle") -- Goauld elseif (team == 40) then ply:GiveAmmo(1, "Pistol") ply:Give("lockpick") ply:Give("weapon_hand_device") ply:Give("weapon_staff") -- Anubis elseif ( team == 41 ) then ply:Give( "weapon_iron_man" ) ply:Give( "weapon_hand_device" ) -- Jaffa elseif (team == 50) then ply:Give("weapon_zat") ply:Give("gacgoa_sg") ply:Give("ring_caller") ply:Give("weapon_staff") ply:GiveAmmo(1, "Pistol") -- Bra'Tac elseif (team == 51) then ply:Give("weapon_staff") ply:Give("weapon_zat") ply:Give("gacgoa_sg") ply:Give("ring_caller") ply:Give("weapon_gdo") ply:GiveAmmo(1, "Pistol") -- Free Jaffa elseif (team == 52) then ply:Give("p90_sg") ply:Give("weapon_staff") ply:Give("weapon_zat") ply:Give("ring_caller") ply:GiveAmmo(1, "Pistol") -- Personal Guard elseif (team == 53) then ply:Give("weapon_staff") ply:Give("weapon_zat") ply:Give("ring_caller") ply:GiveAmmo(1, "Pistol") -- Tok'ra elseif (team == 60) then ply:GiveAmmo(1, "Pistol") ply:Give("weapon_zat") ply:Give("weapon_ringcaller") -- Jacob + Selmak elseif (team == 61) then ply:GiveAmmo(1, "Pistol") ply:Give("weapon_zat") ply:Give("weapon_ringcaller") ply:Give("weapon_gdo") ply:Give("weapon_zar") -- Sodan Warrior elseif (team == 70) then ply:Give("weapon_staff") ply:Give("sodan_cloak") -- Lord Hi Kon elseif (team == 71) then ply:Give("weapon_staff") ply:Give("sodan_cloak") -- Ancient elseif (team == 80) then ply:Give("weapon_ancient") ply:Give("weapon_ringcaller") ply:Give("weapon_teleport") -- Major John if (team == 42) then ply:Give("p90_sg") ply:Give("beretta_sg") ply:Give("sg_mp5") ply:Give("weapon_zat") ply:Give("lockpick") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("stunstick") ply:GiveAmmo(1000, "Pistol") ply:GiveAmmo(1000, "smg") -- Lord Op elseif (team == 43) then ply:Give("weapon_zat") ply:Give("gacgoa_sg") ply:Give("ring_caller") ply:Give("weapon_staff") ply:Give( "weapon_hand_device" ) ply:GiveAmmo(1, "Pistol") -- Pvt. Bull elseif (team == 44) then ply:GiveAmmo(1000, "Pistol") ply:GiveAmmo(1000, "smg") ply:Give("sg_mp5") ply:Give("p90_sg") ply:Give("weapon_zat") ply:Give("lockpick") ply:Give("beretta_sg") ply:Give("lockpick") ply:Give("arrest_stick") ply:Give("unarrest_stick") ply:Give("stunstick") end end[/code] Try that.[/QUOTE] ok, thanks. And btw, I can't see it if you uses [lua]. Use [code] please. [editline]07:29PM[/editline] Now the console says [code] StargateRP\gamemode\sv_player.lua:754: 'end' expected (to close 'function' at line 524) near '<eof>' [/code]
Have you ever heard of tables? Research into tables in lua, you can optimize/make the code easier to read 10x.
[QUOTE=thomasfn;17536955]Have you ever heard of tables? Research into tables in lua, you can optimize/make the code easier to read 10x.[/QUOTE] No? Tables? What tables?
The evil kind. You know, the ones that actually help you do stuff easier. [editline]09:11PM[/editline] Wait, let me guess, the Tables are a lie.
[QUOTE=thomasfn;17537066]The evil kind. You know, the ones that actually help you do stuff easier. [editline]09:11PM[/editline] Wait, let me guess, the Tables are a lie.[/QUOTE] I think LUA hates me :/ So Tables can help me with this problem? [editline]08:34PM[/editline] Any idea where I can find this mighty Table?
[QUOTE=commander204;17535329]WHAT? End of Function*[/QUOTE] [url]http://en.wikipedia.org/wiki/End-of-file[/url] [QUOTE=Norway174;17537265]I think LUA hates me :/ So Tables can help me with this problem? [editline]08:34PM[/editline] Any idea where I can find this mighty Table?[/QUOTE] [url]http://lua-users.org/wiki/TablesTutorial[/url]
Sorry, you need to Log In to post a reply to this thread.