[lua]resource.AddFile("sound/admin_alert.mp3")
if SERVER then
AddCSLuaFile("autorun/admin_alert.lua")
end
function AdminAlert( pl )
if pl:IsUserGroup("owner","admin1","admin2","admin3","admin4") then
for k, v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTCENTER,"Admin has joined the server!")
v:ConCommand("play admin_alert.mp3")
end
end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", AdminAlert )
[/lua]
This is a script that I edited and I use, but for some reason it does not work, it doesn't display any errors or anything it just doesn't work.
Please someone help me.
bump, can anyone explain me what's wrong with it?
AFAIK you can only use IsUserGroup with a single string argument.
Alright gonna test it.
EDIT:
Well I changed the code to this:
[lua]resource.AddFile("sound/donator.mp3")
if SERVER then
AddCSLuaFile("autorun/donator_alert.lua")
end
function AdminAlert( pl )
if pl:IsUserGroup("donator") then
for k, v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTCENTER,"Donator has joined the server!")
v:ConCommand("play donator.mp3")
end
end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", AdminAlert )[/lua]
It is downloading the sound and everything but still isn't palying or showing the text.
Is play donator.mp3 in the server files where did you put the sound?
sound is placed in /sounds folder, as it should be, but it isn't showing the text also. Perhaps it isn't finding the group from ulx admin ?
EDIT:
I can play the sound file by using playsound trought ulx menu, so it is downloaded to all players.
There is nothing wrong with pl:IsUserGroup, it is rather HUD_PRINTCENTER. It works well with HUD_PRINTTALK though. Try putting a timer on HUD_PRINTCENTER, see if that works!
The player hasn't loaded completely in on InitialPlayerSpawn, there is something weird about HUD_PRINTCENTER.
Okay changed the HUD_PRINTCENTER to HUD_PRINTTALK and it fixed the problem, don't know why or how, but it did.
Haha strange..
New problem, since I have more than one usergroup that I want to have the sound, and I couldn't add more than one usergroup, I made separate files.
2 files Owner.lua and Donator.lua
[lua]resource.AddFile("sound/donator.mp3")
if SERVER then
AddCSLuaFile("autorun/donator.lua")
end
function AdminAlert( pl )
if pl:IsUserGroup("donator") then
for k, v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTTALK,"Donator has joined the server!")
v:ConCommand("play donator.mp3")
end
end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", AdminAlert )[/lua]
This script is not working. when I join with this group nothing happens.
[lua]resource.AddFile("sound/admin_alert.mp3")
if SERVER then
AddCSLuaFile("autorun/owner.lua")
end
function AdminAlert( pl )
if pl:IsUserGroup("owner") then
for k, v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTTALK,"Owner has joined the server!")
v:ConCommand("play admin_alert.mp3")
end
end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", AdminAlert )[/lua]
This script is working, when I join it plays the sound and prints the message.
Is it that I cannot make seperate files for these? Only 1 will work?
[QUOTE=krikus62;41991775]New problem, since I have more than one usergroup that I want to have the sound, and I couldn't add more than one usergroup, I made separate files.
2 files Owner.lua and Donator.lua
[lua]
function AdminAlert( pl ) .....[/lua]
Is it that I cannot make seperate files for these? Only 1 will work?[/QUOTE]
Your files are creating what is called 'global' functions. Since they have the same name, only 1 of those functions will exist.
To avoid this, put 'local' in front of your function definition.
[lua]local function AdminAlert( pl ) ............[/lua]
EDIT:
Also, your hooks need unique names, they are both called "playerInitialSpawn"
MOAR EDIT:
This is what it would look like in one file.
[lua]if SERVER then
resource.AddFile("sound/donator.mp3")
resource.AddFile("sound/admin_alert.mp3")
AddCSLuaFile() --by not entering a filename it will just send the current file which is what we want
local function SpecialAlert( pl )
if pl:IsUserGroup("donator") then
for k, v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTTALK,"Donator has joined the server!")
v:ConCommand("play donator.mp3")
end
elseif pl:IsUserGroup("owner") then
for k, v in pairs(player.GetAll()) do
v:PrintMessage(HUD_PRINTTALK,"Owner has joined the server!")
v:ConCommand("play admin_alert.mp3")
end
end
end
hook.Add( "PlayerInitialSpawn", "Check Player Rank on Spawn", SpecialAlert )
end[/lua]
EDIT:
Currently this is all serverside code so i've wrapped it all inside if SERVER, and there is really no need for the AddCSLuaFile().
Yea I am quite new so I am learning lua slowly. I thought that it might be something the same function, but I didn't think it required such huge edit.
Anyway thank you it is working now perfectly.
Sorry, you need to Log In to post a reply to this thread.