ULX

Author Topic: LUA request  (Read 6433 times)

0 Members and 1 Guest are viewing this topic.

Offline Michael

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
LUA request
« on: May 28, 2013, 01:16:03 AM »
I've searched for hours, and cannot code LUA to save my life.

Im looking for a script, or something that i can implement to have like an into song for specific users that join my server, namely admins.
I'm half asleep at the moment, lol so i dont know if i make sense.

Like me, and two other people would have specific sounds when we enter the server.

Can that even be done?

Offline Michael

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: LUA request
« Reply #1 on: May 28, 2013, 01:17:13 AM »
Im sorry, i should specify. Its for a Gmod server (TTT)

Offline Michael

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: LUA request
« Reply #2 on: May 28, 2013, 04:16:00 AM »
ORRR better yet. is there a way i can addapt this code to ONLY work with one user? then i /should/ be able to use more than one application of this code for the other users...


 
Code: [Select]
-- Simple lua script written by Ayv, feel free to edit it! :D --
resource.AddFile("sound/admin_alert.mp3")

if SERVER then
     AddCSLuaFile("autorun/admin_alert.lua")

end

function AdminAlert( pl )
if pl:IsAdmin() 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 )

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: LUA request
« Reply #3 on: May 28, 2013, 05:15:39 AM »
This is a very basic script. Try starting with a Lua tutorial such as this, then flex your Lua muscles by trying to figure this out on your own. :)
Experiencing God's grace one day at a time.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: LUA request
« Reply #4 on: May 28, 2013, 08:12:58 AM »
Completely untested... if the script you posted works then this should work too...

Add the SteamIDs of the people you want this to chime in for in the table (the first line in the AdminAlert function..

Code: [Select]
-- Simple lua script written by Ayv, feel free to edit it! :D --
resource.AddFile("sound/admin_alert.mp3")

if SERVER then
     AddCSLuaFile("autorun/admin_alert.lua")

end

function AdminAlert( pl )
local admins = { "STEAM_0:1:12345678", "STEAM_0:1:9876543" }
for _, v in pairs( admins ) do
if pl:SteamID() == v then
for _, v2 in pairs(player.GetAll()) do
v2:PrintMessage(HUD_PRINTCENTER,"Admin has joined the server!")
v2:ConCommand("play admin_alert.mp3")
end
end
end
end
hook.Add( "PlayerInitialSpawn", "playerInitialSpawn", AdminAlert )






--You should still try and learn though. There is no reason why any server operator should not be able to make simple modifications to little scripts like this on his/her own. Learning a little lua WILL be what sets you and your server(s) apart from the other 9999 servers out there running the same gamemode as you.

Offline Michael

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: LUA request
« Reply #5 on: May 28, 2013, 09:38:37 AM »
I have full intentions on learning lua, ahaha i just wanted a quick fix, for instance now i know that you can use your steam ID:P

Offline Michael

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: LUA request
« Reply #6 on: May 28, 2013, 02:41:21 PM »
Also, even when the audio file gets downloaded to the client, it doesnt work.. steam says that its not there. well, steams console.

Offline Michael

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: LUA request
« Reply #7 on: May 28, 2013, 04:07:30 PM »
is there any way i could adapt that script to allow for different admins having different songs

Offline JamminR

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 8096
  • Karma: 390
  • Sertafide Ulysses Jenius
    • Team Ulysses [ULib/ULX, other fine releases]
Re: LUA request
« Reply #8 on: May 28, 2013, 07:36:24 PM »
Absolutely.
Research advanced tables. :)
Your admins table could easily store a sound for each admin.
Be wary though, I'm not sure if PlayerInitialspawn hooks on each map change.
I'd be annoyed if 1) as a player, hearing the beginning stutter of 5 songs start playing because 5 admins were on when the map changed.
2) as an admin, another admins sound played more often than mine because they always managed to join seconds after I did.

Also...sometimes, joining a server and NOT being announced is a good thing... I wouldn't always want to join and be recognized.
Sometimes, stealth mode administration allows you to see things that might not normally take place, even among fellow admins.
"Though a program be but three lines long, someday it will have to be maintained." -- The Tao of Programming

Offline Michael

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: LUA request
« Reply #9 on: May 28, 2013, 10:45:40 PM »
Hahah i know next to nothing about lua. XD my friend has a very basic understanding of it. I tried looking up advanced tables but quite honestly i cannot make sense of it.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: LUA request
« Reply #10 on: May 28, 2013, 11:59:57 PM »
Try this..

Code: [Select]
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 )

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.

Offline Michael

  • Newbie
  • *
  • Posts: 8
  • Karma: 0
Re: LUA request
« Reply #11 on: May 29, 2013, 11:59:36 AM »
I plugged that in and got immediate LUA errors.

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

Offline Joseph

  • Newbie
  • *
  • Posts: 1
  • Karma: 0
Re: LUA request
« Reply #12 on: May 30, 2013, 09:10:13 PM »
I am his friend with limited LUA experience I have changed the code, to
Code: [Select]
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 )

Now we are getting an error of
Quote
attempt to call field a nil value
« Last Edit: May 30, 2013, 09:16:03 PM by Joseph »

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: LUA request
« Reply #13 on: May 30, 2013, 09:57:35 PM »
in the table, don't include the sound/, it's assumed in the code below. That might be what's causing your errors.

Offline skillz

  • Newbie
  • *
  • Posts: 29
  • Karma: 1
Re: LUA request
« Reply #14 on: June 02, 2013, 04:04:17 AM »
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.