Hey,
I'm looking for a simple script to add player's to a ULX user group when they join the server if their Steam name contains a specified string (and adding them to a default group if they change their name back) - but I don't know where to start. How would I go about doing this?
[QUOTE=Kevlon;49188102][img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/GM/PlayerInitialSpawn]GM/PlayerInitialSpawn[/url][/QUOTE]
thanks for getting me on the right track. However, I've encountered a lua error that I'm not sure what to do with:[CODE]if string.find(str, "|QIG|") then
RunConsoleCommand ("ulx tsay", str .. "has been added to the Community Member group for having |QIG| in their name!");
containsqig = true
else
containsqig = false
end
if containsqig = true then
RunConsoleCommand("ulx adduser", str, "CommunityMember")
elseif containsqig = false then
RunConsoleCommand("ulx adduser", str, "user")
end[/CODE]
Error code: 'then' expected near '='
the line in question is "if containsqig = true then"
[lua]if containsqig = true then
to
if containsqig == true then
Or even more
if containsqig then[/lua]
[CODE]function GAMEMODE:PlayerInitialSpawn( ply )
print( ply:GetName().." joined the server.\n" )
str = Player:GetName()
if string.find(str, "|QIG|") then
containsqig = true
RunConsoleCommand ("ulx", "tsay", ply:Nick() .. "has been added to the Community Member group for having |QIG| in their name!")
else
containsqig = false
end
if containsqig then
RunConsoleCommand("ulx", "adduser", ply:Nick(), "CommunityMember")
elseif containsqig == false and ply:IsUserGroup("user") then
RunConsoleCommand("ulx", "adduser", ply:Nick(), "user")
end
if ply:IsUserGroup ("superadmin") or
ply:IsUserGroup ("admin") or
ply:IsUserGroup ("Council") or
ply:IsUserGroup ("manager") or
ply:IsUserGroup ("CommunityMember") or
ply:IsUserGroup ("SilverVIP") or
ply:IsUserGroup ("operator") or
ply:IsUserGroup ("Dev") or
ply:IsUserGroup ("GoldVIP") or
ply:IsUserGroup ("DiamondVIP")
then return false
end
end[/CODE]
Error code: attempt to index global 'Player' (a function value)
Change
[CODE]str = Player:GetName() [/CODE]
to
[CODE]str = ply:GetName()[/CODE]
with the above fix: [CODE]line 1: attempt to index global 'GAMEMODE' (a nil value)
stack traceback:
t.lua:1: in main chunk
[C]: ?[/CODE]
[CODE]hook.Add( "PlayerInitialSpawn", "useAhook", function()
print( ply:GetName().." joined the server.\n" )
str = Player:GetName()
if string.find(str, "|QIG|") then
containsqig = true
RunConsoleCommand ("ulx", "tsay", ply:Nick() .. "has been added to the Community Member group for having |QIG| in their name!")
else
containsqig = false
end
if containsqig then
RunConsoleCommand("ulx", "adduser", ply:Nick(), "CommunityMember")
elseif containsqig == false and ply:IsUserGroup("user") then
RunConsoleCommand("ulx", "adduser", ply:Nick(), "user")
end
if ply:IsUserGroup ("superadmin") or
ply:IsUserGroup ("admin") or
ply:IsUserGroup ("Council") or
ply:IsUserGroup ("manager") or
ply:IsUserGroup ("CommunityMember") or
ply:IsUserGroup ("SilverVIP") or
ply:IsUserGroup ("operator") or
ply:IsUserGroup ("Dev") or
ply:IsUserGroup ("GoldVIP") or
ply:IsUserGroup ("DiamondVIP")
then return false
end
end )[/CODE]
Try that.
[QUOTE=boxvader;49189157][CODE]hook.Add( "PlayerInitialSpawn", "useAhook", function()
print( ply:GetName().." joined the server.\n" )
str = Player:GetName()
if string.find(str, "|QIG|") then
containsqig = true
RunConsoleCommand ("ulx", "tsay", ply:Nick() .. "has been added to the Community Member group for having |QIG| in their name!")
else
containsqig = false
end
if containsqig then
RunConsoleCommand("ulx", "adduser", ply:Nick(), "CommunityMember")
elseif containsqig == false and ply:IsUserGroup("user") then
RunConsoleCommand("ulx", "adduser", ply:Nick(), "user")
end
if ply:IsUserGroup ("superadmin") or
ply:IsUserGroup ("admin") or
ply:IsUserGroup ("Council") or
ply:IsUserGroup ("manager") or
ply:IsUserGroup ("CommunityMember") or
ply:IsUserGroup ("SilverVIP") or
ply:IsUserGroup ("operator") or
ply:IsUserGroup ("Dev") or
ply:IsUserGroup ("GoldVIP") or
ply:IsUserGroup ("DiamondVIP")
then return false
end
end )[/CODE]
Try that.[/QUOTE]
[CODE]line 1: attempt to index global 'hook' (a nil value)
stack traceback:
t.lua:1: in main chunk
[C]: ?[/CODE]
[lua]
hook.Add("PlayerInitialSpawn", "DoShit", function(ply)
if not ply:GetUserGroup() == "user" then return end
local name = ply:Nick()
print(name.." has joined the server.")
if string.find(name, "|QIG|") then
RunConsoleCommand ("ulx", "tsay", name.." has been added to the Community Member group for having |QIG| in their name!")
RunConsoleCommand("ulx", "adduser", ply:Nick(), "CommunityMember")
end
end)[/lua]
I couldn't stand the spaghetti code for another second. I wrote this from my phone so the formatting might be messed up.
[QUOTE=YourStalker;49189314][lua]
hook.Add("PlayerInitialSpawn", "DoShit", function(ply)
if not ply:GetUserGroup() == "user" then return end
local name = Player:Nick()
print(name.." has joined the server.")
if string.find(name, "|QIG|") then
RunConsoleCommand ("ulx", "tsay", name.." has been added to the Community Member group for having |QIG| in their name!")
RunConsoleCommand("ulx", "adduser", ply:Nick(), "CommunityMember")
end
end)[/lua]
I couldn't stand the spaghetti code for another second. I wrote this from my phone so the formatting might be messed up.[/QUOTE]
[CODE][ERROR] addons/djmuz/lua/autorun/server/qigcommemberauto.lua:4: attempt to index global 'Player' (a function value)
1. fn - addons/djmuz/lua/autorun/server/qigcommemberauto.lua:4
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179[/CODE]
[QUOTE=djmuz;49189839][CODE][ERROR] addons/djmuz/lua/autorun/server/qigcommemberauto.lua:4: attempt to index global 'Player' (a function value)
1. fn - addons/djmuz/lua/autorun/server/qigcommemberauto.lua:4
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179[/CODE][/QUOTE]
[CODE]hook.Add("PlayerInitialSpawn", "DoShit", function(ply)
if not ply:GetUserGroup() == "user" then return end
local name = ply:Nick()
print(name.." has joined the server.")
if string.find(name, "|QIG|") then
RunConsoleCommand ("ulx", "tsay", name.." has been added to the Community Member group for having |QIG| in their name!")
RunConsoleCommand("ulx", "adduser", name, "CommunityMember")
end
end)[/CODE]
[QUOTE=djmuz;49189839][CODE][ERROR] addons/djmuz/lua/autorun/server/qigcommemberauto.lua:4: attempt to index global 'Player' (a function value)
1. fn - addons/djmuz/lua/autorun/server/qigcommemberauto.lua:4
2. unknown - addons/ulib/lua/ulib/shared/hook.lua:179[/CODE][/QUOTE]
Not trying to sound like an asshole but you should learn to fix small errors like this yourself. Here is how the errors in gmod work.
name/of/file/containing/error.lua:Line number where the error is: description of the error
1. Stack trace.
With the error you got it was saying Player isn't the actual player entity. In fact, Player is the name of an already existing function found here [img]http://wiki.garrysmod.com/favicon.ico[/img] [url=http://wiki.garrysmod.com/page/Global/Player]Global.Player[/url]. That is why it says (a function value) but it was expecting a player entity, not a function. Up top in the function you see that we defined ply as the player entity in the hook.Add function.
Sorry, you need to Log In to post a reply to this thread.