General > Developers Corner

LUA request

<< < (3/4) > >>

MrPresident:
Try this..


--- Code: ---resource.AddFile("sound/admin_alert.mp3")

function AdminAlert( pl )
local advancedtable = { "STEAM_0:1:1234567" = "admin_alert.mp3", "STEAM_0:1:9876543" = "admin_alert.mp3" }

for k, v in pairs( advancedtable ) do
if pl:SteamID() == k then

if not ULib.fileExists( "sound/" .. v ) then
ULib.tsayError( pl, "That sound doesn't exist on the server!", true )
return
end
umsg.Start( "ulib_sound" )
umsg.String( Sound( v ) )
umsg.End()

ULib.tsay(_, "Admin (" .. pl:Nick() .. ") has joined the server!")
end
end

end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", AdminAlert )

--- End code ---

Untested...

If you want to add more admins, just do it like the example. "STEAMID" = "sound file". Separate each entry with a comma.

edit: Also, I have taken the liberty to rewrite most of this to use ULib; It makes things 100% easier and I assume you have it installed.

Michael:
I plugged that in and got immediate LUA errors.


--- Code: ---[error] addons/alert/lua/alert.lua:4: '}' expected near '='
1. unknown - addons/alert/lua/autorun/alert.lua:0
--- End code ---

Joseph:
I am his friend with limited LUA experience I have changed the code, to
--- Code: ---resource.AddFile("sound/admin_alert.mp3")
resource.AddFile("sound/29083.wav")
resource.AddFile("sound/joealert.wav")

function AdminAlert( pl )
advancedtable = {["STEAM_0:1:408646469"]  = "sound/29083.wav",  ["STEAM_021221127"] = "sound/joealert.wav" }

for k, v in pairs( advancedtable ) do
if pl:SteamID() == k then

if not ULib.fileExists( "sound/" .. v ) then
ULib.tsayError( pl, "That sound doesn't exist on the server!", true )
return
end
umsg.Start( "ulib_sound" )
umsg.String( Sound( v ) )
umsg.End()

ULib.tsay(_, "Admin (" .. pl:Nick() .. ") has joined the server!")
end
end

end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", AdminAlert )
--- End code ---

Now we are getting an error of

--- Quote ---attempt to call field a nil value
--- End quote ---

MrPresident:
in the table, don't include the sound/, it's assumed in the code below. That might be what's causing your errors.

skillz:
If you're new to lua and you do intend on learning it, its well worth getting a good editor, preferably one with syntax highlighting. I use sublime text 2, i think you have to pay but if you don't, you get reminders to pay every now and then. Regardless it might be worth getting a linter of some kind, it will check through your code for syntax errors and will highlight the error and the line the error occurred. Just thought i would mention this because using notepad or something equivalent not only takes forever but its soul destroying :). Good luck.

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version