• Requesting simpel admin command: Client sound play
    10 replies, posted
So basically the thing i want is a script i could have on my server to let admins type in the console e.g client_playsound "Player Name" "Sound path (gmod/gmod/sound/starts here...)" I alredy got a global sound play system, but i want this system so i could play sounds on just one player insted of everyone.
[lua]function ClientSound( player, command, args) soundtarget = PlayerFind(args[1]) if soundtarget:IsPlayer() then soundtarget:EmitSound(args[2]) end end concommand.Add( "client_playsound", ClientSound ) function PlayerFind(name) for I,P in pairs( player.GetAll() ) do if string.find(P:Nick():lower() ,name) then return P end end end [/lua]
Thanks alot! Also, how do i make it admin only? So its: client_playsound "nickname" "sound path" ?
I would put it in shared, you can add isadmin to check for admin status [lua] function ClientSound( player, command, args) if player:IsAdmin() then soundtarget = PlayerFind(args[1]) if soundtarget:IsPlayer() then soundtarget:EmitSound(args[2]) end end end concommand.Add( "client_playsound", ClientSound ) [/lua] and yes its client_playsound "nickname" "sound path" (without quotes)
gamemode\shared.lua:124] attempt to index global 'soundtarget' (a nil value)
which line is that?
if soundtarget:IsPlayer() then
did you add [lua] function PlayerFind(name) for I,P in pairs( player.GetAll() ) do if string.find(P:Nick():lower() ,name) then return P end end end [/lua] ?
Yeah, I added it under function ClientSound In shared.lua
Try putting it in init.lua
Just function ClientSound or both?
Sorry, you need to Log In to post a reply to this thread.