Hi all!
Yes im a LUA noob, but im trying to learn.
The idea is to give ranked players a weapon on spawn each round. Like a bonus for the regular playes.
this is what I've made so far, but i keep getting the error:
[CODE]Lua 4: function arguments expected near '=='[/CODE]
Here is my script:
[lua]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile ("weaponspawn.lua")
end
if CLIENT then
local function GiveWeapon(ply)
if ply:IsUserGroup = ("regular") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("moderator") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("admin") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("janitor") then
ply:Give(weapon_deagle)
end
[/lua]
The whole script should be server-side, and you have a space after AddCSLuaFile.
[QUOTE=Assault_Trooper;38890345]The whole script should be server-side, and you have a space after AddCSLuaFile.[/QUOTE]
fixed both.
Still same error.
[lua]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile("weaponspawn.lua")
local function GiveWeapon(ply)
if ply:IsUserGroup == ("regular") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("moderator") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("admin") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("janitor") then
ply:Give(weapon_deagle)
end
end
[/lua]
[lua]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile("weaponspawn.lua")
end
local function GiveWeapon(ply)
if ply:IsUserGroup("regular") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup("moderator") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup("admin") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup("janitor") then
ply:Give(weapon_deagle)
end
end
[/lua]
Take a look at [URL="http://wiki.garrysmod.com/page/Classes/Player/IsUserGroup"]this[/URL]
[QUOTE=Fr3d_;38890527][lua]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile("weaponspawn.lua")
end
local function GiveWeapon(ply)
if ply:IsUserGroup("regular") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup("moderator") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup("admin") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup("janitor") then
ply:Give(weapon_deagle)
end
end
[/lua]
Take a look at [URL="http://wiki.garrysmod.com/page/Classes/Player/IsUserGroup"]this[/URL][/QUOTE]
Thanks for your reply!
The script does not return any errors now, sp thats a good sign.
but the script is not working either.
I believe i maybe need to add a line to say that this is suppose to happen each round.
i know that there is a hook(?) that goes something like PlayerInitialSpawn, wich is when a player first joins the server i think.
Is there something similar but at round start? and where can i find such hooks?
[URL="http://wiki.garrysmod.com/page/Hooks"]Hooks[/URL]
[URL="http://wiki.garrysmod.com/page/hook"]Hook library[/URL]
I hope you figure it out, also I do not think that you need to send the .lua to the clients as they won't be using it.
player.Give() is a serverside function afaik
[LUA]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile("weaponspawn.lua")
end
local function giveWeapon(ply)
if ply:IsUserGroup("regular") then
ply:Give(weapon_zm_revolver)
elseif ply:IsUserGroup("moderator") then
ply:Give(weapon_zm_revolver)
elseif ply:IsUserGroup("admin") then
ply:Give(weapon_zm_revolver)
elseif ply:IsUserGroup("janitor") then
ply:Give(weapon_zm_revolver)
end
end
hook.Add("playerInitialSpawn", "giverankedWeapon", giveWeapon)
[/LUA]
Changed it up to work with TTT
[QUOTE=DrJenkins;38890998][LUA]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile("weaponspawn.lua")
end
local function giveWeapon(ply)
if ply:IsUserGroup("regular") then
ply:Give(weapon_zm_revolver)
elseif ply:IsUserGroup("moderator") then
ply:Give(weapon_zm_revolver)
elseif ply:IsUserGroup("admin") then
ply:Give(weapon_zm_revolver)
elseif ply:IsUserGroup("janitor") then
ply:Give(weapon_zm_revolver)
end
end
hook.Add("playerInitialSpawn", "giverankedWeapon", giveWeapon)
[/LUA]
Changed it up to work with TTT[/QUOTE]
Might want to put those weapons in quotes.
I didn't think they were needed for ply:Give() ?
[QUOTE=DrJenkins;38891141]I didn't think they were needed for ply:Give() ?[/QUOTE]
And the hook needs to be a capital letter. Well, now you're just giving a nil variable...
If you are running ULX use the following code otherwise replace ply:CheckGroup with ply:IsUserGroup("regular")
[LUA]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile("weaponspawn.lua")
end
local function giveWeapon(ply)
if ply:CheckGroup("regular") or ply:CheckGroup("moderator") or ply:CheckGroup("admin") or ply:IsUserGroup("janitor") then
ply:Give("weapon_zm_revolver")
end
end
hook.Add("PlayerLoadout", "giverankedWeapon", giveWeapon)
[/LUA]
oh and if moderator, admin, and janitor inherit from regular all you need is the check for regular.
Thanks for many good respones :)
[QUOTE=centran;38891409]If you are running ULX use the following code otherwise replace ply:CheckGroup with ply:IsUserGroup("regular")
[/QUOTE]
Isnt IsUserGroup for ULX?
[QUOTE=zapha;38891909]Thanks for many good respones :)
Isnt IsUserGroup for ULX?[/QUOTE]
No, it's for the users.txt in the settings folder, which is a GMod default thing. You might've confused it with GetUserGroup, which is for ULX.
[QUOTE=Assault_Trooper;38892879]No, it's for the users.txt in the settings folder, which is a GMod default thing. You might've confused it with GetUserGroup, which is for ULX.[/QUOTE]
ok. Im using ULX.
so should it be
[lua]
if ply:IsUserGroup("regular") then
[/lua]
or
[lua]
if ply:CheckGroup("regular") then
[/lua]
[QUOTE]if ply:IsUserGroup("regular") then[/QUOTE]
nobody has noticed yet?
ply:Give() needs a string.
ex: ply:Give("weapon_zm_revolver")
You need those quotes.
[QUOTE=zapha;38893127]ok. Im using ULX.
so should it be
[lua]
if ply:IsUserGroup("regular") then
[/lua]
it is
or
[lua]
if ply:CheckGroup("regular") then
[/lua][/QUOTE]
It is this for ULX
[lua]
if ply:CheckGroup("regular") then
[/lua]
The code I posted above should work.
[LUA]
function giveWeapon( ply )
if ply:Team() == 1 then
if ply:IsUserGroup("regular") or ply:IsUserGroup("moderator") or ply:IsUserGroup("admin") or ply:IsUserGroup("janitor") then
ply:Give("weapon_zm_revolver")
end
end
end
hook.Add("PlayerSpawn", "giverankedWeapon", giveWeapon)
[/LUA]
This will give them a weapon when they start, this is before the round starts, so they can always throw it away and find a new one before the round starts!
[QUOTE=centran;38891409]If you are running ULX use the following code otherwise replace ply:CheckGroup with ply:IsUserGroup("regular")
[LUA]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile("weaponspawn.lua")
end
local function giveWeapon(ply)
if ply:CheckGroup("regular") or ply:CheckGroup("moderator") or ply:CheckGroup("admin") or ply:IsUserGroup("janitor") then
ply:Give("weapon_zm_revolver")
end
end
hook.Add("PlayerLoadout", "giverankedWeapon", giveWeapon)
[/LUA]
oh and if moderator, admin, and janitor inherit from regular all you need is the check for regular.[/QUOTE]
Works like a charm, Thank you very much, and thank you to everyone else that have contributed!
I still have 2 questions though.
1) if i want to add some ammo to the weapon of choice, should it then be like this?
[lua]
ply:Give("item_ammo_revolver_ttt")
[/lua]
after the functions "then" and with some sort of amount? number maybe?
2) if i want to change it so that for instance mods spawn with an AK, and regulars with a deagle can i then do this?
[lua]
if SERVER then
AddCSLuaFile("weaponspawn.lua")
end
local function giveWeapon(ply)
if ply:CheckGroup("moderator") then
ply:Give("ttt_weapon_ak47")
elseif ply:CheckGroup("regular") then
ply:Give("weapon_zm_revolver")
end
end
hook.Add("PlayerLoadout", "giverankedWeapon", giveWeapon)
[/lua]
[QUOTE]
1) if i want to add some ammo to the weapon of choice, should it then be like this?
ply:Give("item_ammo_revolver_ttt") and with some sort of amount? number maybe?[/QUOTE]
You have to get the ammo type and the amount after you give the waepon:
e.g. ply:GiveAmmo("AlyxGun",16)
This is for the Deagle.. I think..
[QUOTE]
2) if i want to change it so that for instance mods spawn with an AK, and regulars with a deagle can i then do this?
[/quote]
[lua]
function giveWeapon( ply )
if ply:Team() == 1 then
if ply:IsUserGroup("regular") then
ply:Give("weapon_zm_revolver")
elseif ply:IsUserGroup("moderator") then
ply:Give("weapon_ttt_ak47") --or whatever the AK47 code is.. <.<
end
end
end
hook.Add("PlayerSpawn", "giverankedWeapon", giveWeapon)
[/lua]
[QUOTE=Archemyde;38894679]nobody has noticed yet?[/QUOTE]
[QUOTE=Assault_Trooper;38891089]Might want to put those weapons in quotes.[/QUOTE]
[QUOTE=brickyross;38898144]You have to get the ammo type and the amount after you give the waepon:
e.g. ply:GiveAmmo("AlyxGun",16)
This is for the Deagle.. I think..
[lua]
function giveWeapon( ply )
if ply:Team() == 1 then
if ply:IsUserGroup("regular") then
ply:Give("weapon_zm_revolver")
elseif ply:IsUserGroup("moderator") then
ply:Give("weapon_ttt_ak47") --or whatever the AK47 code is.. <.<
end
end
end
hook.Add("PlayerSpawn", "giverankedWeapon", giveWeapon)
[/lua][/QUOTE]
Thank you!
I will test this and report back :)
If I wanted to use this where would I put it?
init.lua would work
Where is that located?
[QUOTE=zapha;38890313]Hi all!
Yes im a LUA noob, but im trying to learn.
The idea is to give ranked players a weapon on spawn each round. Like a bonus for the regular playes.
this is what I've made so far, but i keep getting the error:
[CODE]Lua 4: function arguments expected near '=='[/CODE]
Here is my script:
[lua]
if SERVER then // This is where the init.lua stuff goes.
//This makes sure clients download the file
AddCSLuaFile ("weaponspawn.lua")
end
if CLIENT then
local function GiveWeapon(ply)
if ply:IsUserGroup = ("regular") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("moderator") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("admin") then
ply:Give(weapon_deagle)
elseif ply:IsUserGroup == ("janitor") then
ply:Give(weapon_deagle)
end
[/lua][/QUOTE]
zapha you can also buy lua books from the lua website to learn alot about lua coding. they also have a pirtate version of lua coding book on thepiratebay :)
[QUOTE=GlenSH;39358829]Where is that located?[/QUOTE]
I know this is old but where is the file located ever find out?
Can anyone PLEASE help me out? I am in dire need of a script very similar to this, but instead of for TTT, its for a Sandbox Server I manage. Here's what I'd like:
A Script that gives certain ranks of players (Clients, Regulars, Mods, etc) an assortment of weapons (m9k) each time they spawn in. So if a player gets killed and respawns, they get their weapons back because of the script, instead of having to respawn them each time. I've imputted the above scripts into a lua file and edited the weapon and rank variables, but they just don't seem to work at all
Here's what I have
if SERVER then AddCSLuaFile("weaponspawn.lua")
end
local function giveWeapon( ply )
if ply:IsUserGroup("servermanager") then
ply:Give("m9k_colt1911")
end
end
end
hook.Add("PlayerSpawn", "giverankedWeapon", giveWeapon)
Your syntax is wrong, you need to get a lua lexer.
Not tested:
[lua]
//lua/autorun/server
local TTT_WB = {
["servermanager"] = {"m9k_colt1911"},
["specialguest"] = {"weapon_zm_revolver", "weapon_ttt_m16"}
}
hook.Add("PlayerSpawn", "TTT_WB.PlayerSpawn", function(ply)
local benefits = TTT_WB[ply:GetNWString("usergroup")]
if !benefits then return end
for k,v in ipairs(benefits) do
if ply:CanCarryWeapon(v) then
ply:Give(v)
end
end
end)
[/lua]
[QUOTE=brandonj4;42435132]Your syntax is wrong, you need to get a lua lexer.
Not tested:
[lua]
//lua/autorun/server
local TTT_WB = {
["servermanager"] = {"m9k_colt1911"},
["specialguest"] = {"weapon_zm_revolver", "weapon_ttt_m16"}
}
hook.Add("PlayerSpawn", "TTT_WB.PlayerSpawn", function(ply)
local benefits = TTT_WB[ply:GetNWString("usergroup")]
if !benefits then return end
for k,v in ipairs(benefits) do
if ply:CanCarryWeapon(v) then
ply:Give(v)
end
end
end)
[/lua][/QUOTE]
Going to test right now, though mind you the server is SANDBOX, not TTT, but testing otherwise
Sorry, you need to Log In to post a reply to this thread.