Hello, I've been trying to figure this out with no success, I made a code which is unfinished that currently has only 2 usergroups (enough for testing I guess) but none of them spawn with the desired weapon and the console doesn't show any error on it. I'm using ulx. Is there anything wrong with this?
[CODE]if (SERVER) then
AddCSLuaFile("admingunspawn.lua")
end
local function GiveWeapon( ply )
if ply:Team() == 1 then
if ply:CheckGroup("owner") then
ply:Give("weapon_ttt_pist_weagon")
elseif ply:CheckGroup("regulars") then
ply:Give("weapon_ttt_pump_shotgun")
end
end
end
[/CODE]
I still have to add more groups and stuff, I just wanted to know why it doesn't call any error on me or why it doesn't work, thanks ^.^
And yes, I'm a LUA nub.
[QUOTE=Peanutcarl;42318362]Hello, I've been trying to figure this out with no success, I made a code which is unfinished that currently has only 2 usergroups (enough for testing I guess) but none of them spawn with the desired weapon and the console doesn't show any error on it. I'm using ulx. Is there anything wrong with this?
[CODE]if (SERVER) then
AddCSLuaFile("admingunspawn.lua")
end
local function GiveWeapon( ply )
if ply:Team() == 1 then
if ply:CheckGroup("owner") then
ply:Give("weapon_ttt_pist_weagon")
elseif ply:CheckGroup("regulars") then
ply:Give("weapon_ttt_pump_shotgun")
end
end
end
[/CODE]
I still have to add more groups and stuff, I just wanted to know why it doesn't call any error on me or why it doesn't work, thanks ^.^
And yes, I'm a LUA nub.[/QUOTE]
You're not calling the function at all. It's there, but it's never used.
Add:
[lua]
hook.Add( "TTTPrepareRound", "GiveOutGuns", GiveWeapon )
[/lua]
You haven't defined ply either, it will return nil.
Do a for.. in loop ( fail example below ):
[lua]
for k,v in pairs ( player:GetAll()) do
if v:IsGroup("owner") then
give weaponx
elseif y
give weaponz
end
end
[/lua]
I have hardly used for in loops, so I don' exactly remember them
I doubt IsGroup is a function, don't use it. Just providing you with a shell.
Aight, I will add the hooks and report back to you ^^ thanks
EDIT: How can I make those loops? I got this error, now I know what you meant.
[CODE][ERROR] lua/autorun/admingunspawn.lua:6: attempt to index local 'ply' (a nil value)
1. fn - lua/autorun/admingunspawn.lua:6
2. Call - addons/ulib/lua/ulib/shared/hook.lua:183
3. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:136
4. Function - gamemodes/terrortown/gamemode/cl_init.lua:214
5. unknown - lua/includes/modules/usermessage.lua:87
[/CODE]
EDIT: My bad, was in a rush when I posted this.
[LUA]
local function GiveWeapon()
for k,v in pairs( player.GetAll() ) do // Loop through the table of players, where k (key) is the player index and v (value) is the actual entity
if v:IsUserGroup("owner") then // If the player is the usergroup
v:Give( "weapon_ttt_pist_weagon" ) // Give the player the admin gun
elseif v:IsUserGroup("regulars") then // else (if the player is not owner, check if they are a regulars - this is a continuation of the first if
v:Give( "weapon_ttt_pump_shotgun" ) // if they are, give them a shotgun
end
end
end
hook.Add( "TTTBeginRound", "GiveOutGuns", GiveWeapon ) -- Hook the function, so it is called when TTT starts the round[/LUA]
You might also want to apply it on round beginning, since some people may die in preround and lose their weapon.
[QUOTE=rejax;42322298]EDIT: My bad, was in a rush when I posted this.
[LUA]
local function GiveWeapon()
for k,v in pairs( player.GetAll() ) do // Loop through the table of players, where k (key) is the player index and v (value) is the actual entity
if v:IsUserGroup("owner") then // If the player is the usergroup
v:Give( "weapon_ttt_pist_weagon" ) // Give the player the admin gun
elseif v:IsUserGroup("regulars") then // else (if the player is not owner, check if they are a regulars - this is a continuation of the first if
v:Give( "weapon_ttt_pump_shotgun" ) // if they are, give them a shotgun
end
end
end
hook.Add( "TTTBeginRound", "GiveOutGuns", GiveWeapon ) -- Hook the function, so it is called when TTT starts the round[/LUA][/QUOTE]
Still, the script returns no errors but it won't do what it is supposed to do, excuse me if I made something wrong, I'm still learning a lot of LUA
EDIT: Error here.
[CODE]
[ERROR] lua/autorun/admingunspawn.lua:10: attempt to call method 'Give' (a nil value)
1. fn - lua/autorun/admingunspawn.lua:10
2. Call - addons/ulib/lua/ulib/shared/hook.lua:183
3. RoundStateChange - gamemodes/terrortown/gamemode/cl_init.lua:138
4. Function - gamemodes/terrortown/gamemode/cl_init.lua:214
5. unknown - lua/includes/modules/usermessage.lua:87
T[/CODE]
You're trying to run it clientside. Remove: [lua]
if (SERVER) then
AddCSLuaFile("admingunspawn.lua")
end
[/lua]
This is not needed since you're doing no clientside stuff here. Also, if this script is not in lua/autorun/server, move it there. This is all assuming that no clientside processing is going on in your script.
[QUOTE=crazyscouter;42327320]You're trying to run it clientside. Remove: [lua]
if (SERVER) then
AddCSLuaFile("admingunspawn.lua")
end
[/lua]
This is not needed since you're doing no clientside stuff here. Also, if this script is not in lua/autorun/server, move it there. This is all assuming that no clientside processing is going on in your script.[/QUOTE]
Still, same error, deleted the AddCS
What's the path to the file?
Where is the file located?
Edit: Ninja'd lol
for the lua? /lua/autorun/
Move it to lua/autorun/server see of it works there.
Sorry, you need to Log In to post a reply to this thread.