Hi there
I have been trying to make a script for my hl2 darkrp server to create a dispatch radio that emits from the MPF just like in hl2 but I really can't get the emitsound to work and i've been trying for the last few days to get this to work.
It's probably me just being stupid or just missing something but can someone take a look at this lua for me and point out what's wrong with it.
I was using surface.playsound to emit the sound but ofcourse this just does it client side but i would like this to be emitted from the player so others nearby can hear it.
[code]
policeRadio = {}
policeRadio.setTime = 15
policeRadio.cops = {
"Civil Protection",
"Civil Protection Overwatch",
"Civil Protection Medic"
}
policeRadio.turn = {
"npc/combine_soldier/vo/off1.wav",
"npc/combine_soldier/vo/off2.wav",
"npc/combine_soldier/vo/off3.wav",
"npc/metropolice/vo/off4.wav"
}
policeRadio.quotes = {
"npc/metropolice/vo/anyonepickup647e.wav",
"npc/metropolice/vo/atcheckpoint.wav",
"npc/metropolice/vo/blockisholdingcohesive.wav",
"npc/metropolice/vo/catchthatbliponstabilization.wav",
"npc/metropolice/vo/checkformiscount.wav",
"npc/metropolice/vo/clearno647no10-107.wav",
"npc/metropolice/vo/code100.wav",
"npc/metropolice/vo/code7.wav",
"npc/metropolice/vo/control100percent.wav",
"npc/metropolice/vo/dismountinghardpoint.wav",
"npc/metropolice/vo/hardpointscanning.wav",
"npc/metropolice/vo/highpriorityregion.wav",
"npc/metropolice/vo/innoculate.wav",
"npc/metropolice/vo/inpositionathardpoint.wav",
"npc/metropolice/vo/inpositiononeready.wav",
"npc/metropolice/vo/ivegot408hereatlocation.wav",
"npc/metropolice/vo/localcptreportstatus.wav",
"npc/metropolice/vo/looseparasitics.wav",
"npc/metropolice/vo/movingtohardpoint.wav",
"npc/metropolice/vo/nocontact.wav",
"npc/metropolice/vo/novisualonupi.wav",
"npc/metropolice/vo/patrol.wav",
"npc/metropolice/vo/pickingupnoncorplexindy.wav",
"npc/metropolice/vo/possible404here.wav",
"npc/metropolice/vo/stillgetting647e.wav",
"npc/metropolice/vo/terminalrestrictionzone.wav",
"npc/metropolice/vo/unitis10-65.wav",
"npc/metropolice/vo/unitis10-8standingby.wav",
"npc/metropolice/vo/visceratorisoffgrid.wav",
"npc/metropolice/vo/chuckle.wav",
"npc/metropolice/vo/clearandcode100.wav",
"npc/metropolice/vo/get11-44inboundcleaningup.wav",
"npc/metropolice/vo/gota10-107sendairwatch.wav",
"npc/metropolice/vo/protectioncomplete.wav",
"npc/metropolice/vo/ptatlocationreport.wav",
"npc/metropolice/vo/ptgoagain.wav",
"npc/metropolice/vo/cauterize.wav",
"npc/metropolice/vo/classifyasdbthisblockready.wav",
"npc/metropolice/vo/cpbolforthat243.wav",
"npc/metropolice/vo/non-taggedviromeshere.wav",
"npc/metropolice/vo/possible10-103alerttagunits.wav",
"npc/metropolice/vo/possible647erequestairwatch.wav",
"npc/metropolice/vo/preparefor1015.wav",
"npc/metropolice/vo/proceedtocheckpoints.wav",
"npc/metropolice/vo/readytoamputate.wav",
"npc/metropolice/vo/requestsecondaryviscerator.wav",
"npc/metropolice/vo/teaminpositionadvance.wav",
"npc/overwatch/radiovoice/accomplicesoperating.wav",
"npc/overwatch/radiovoice/airwatchcopiesnoactivity.wav",
"npc/overwatch/radiovoice/airwatchreportspossiblemiscount.wav",
"npc/overwatch/radiovoice/allteamsrespondcode3.wav",
"npc/overwatch/radiovoice/allunitsdeliverterminalverdict.wav",
"npc/overwatch/radiovoice/completesentencingatwill.wav",
"npc/overwatch/radiovoice/disengaged647e.wav",
"npc/overwatch/radiovoice/disturbancemental10-103m.wav",
"npc/overwatch/radiovoice/failuretotreatoutbreak.wav",
"npc/overwatch/radiovoice/illegalinoperation63s.wav",
"npc/overwatch/radiovoice/illegalcarrying95.wav",
"npc/overwatch/radiovoice/incitingpopucide.wav",
"npc/overwatch/radiovoice/investigateandreport.wav",
"npc/overwatch/radiovoice/leadersreportratios.wav",
"npc/overwatch/radiovoice/level5anticivilactivity.wav",
"npc/overwatch/radiovoice/lockdownlocationsacrificecode.wav",
"npc/overwatch/radiovoice/lostbiosignalforunit.wav",
"npc/overwatch/radiovoice/politistablizationmarginal.wav",
"npc/overwatch/radiovoice/posession69.wav",
"npc/overwatch/radiovoice/preparevisualdownload.wav",
"npc/overwatch/radiovoice/publicnoncompliance507.wav",
"npc/overwatch/radiovoice/recalibratesocioscan.wav",
"npc/overwatch/radiovoice/recievingconflictingdata.wav",
"npc/overwatch/radiovoice/reinforcementteamscode3.wav",
"npc/overwatch/radiovoice/reminder100credits.wav",
"npc/overwatch/radiovoice/remindermemoryreplacement.wav",
"npc/overwatch/radiovoice/reporton.wav",
"npc/overwatch/radiovoice/reportplease.wav",
"npc/overwatch/radiovoice/resistingpacification148.wav",
"npc/overwatch/radiovoice/restrictedincursioninprogress.wav",
"npc/overwatch/radiovoice/rewardnotice.wav",
"npc/overwatch/radiovoice/socialfractureinprogress.wav",
"npc/overwatch/radiovoice/sociostabilizationrestored.wav",
"npc/overwatch/radiovoice/statuson243suspect.wav",
"npc/overwatch/radiovoice/switchtotac5reporttocp.wav",
"npc/overwatch/radiovoice/teamsreportstatus.wav",
"npc/overwatch/radiovoice/youarejudgedguilty.wav",
"npc/overwatch/radiovoice/youarechargedwithterminal.wav"
}
function randomPoliceRadioSounds()
if policeRadio.setTime < 5 then
policeRadio.setTime = 5
end
if table.HasValue(policeRadio.cops, team.GetName(LocalPlayer():Team())) then
randomQuoteChoice = table.Random(policeRadio.quotes)
randomTurnChoice = table.Random(policeRadio.turn)
self:EmitSound(randomTurnChoice)
timer.Simple(SoundDuration(randomTurnChoice), function() self:EmitSound(randomQuoteChoice) end)
timer.Simple(SoundDuration(randomQuoteChoice) +SoundDuration(randomTurnChoice), function() self:EmitSound(randomTurnChoice) end)
end
end
timer.Create("startRandomPoliceRadio", policeRadio.setTime, 0, randomPoliceRadioSounds)
[/code]
If someone could fix my stupid issue that would be very appreciated.
You're calling emit sound on non-defined [b]self[/]?
So what needs changing? i'm not good with lua so i'm pretty lost at this point.
Just change
[CODE]
self:EmitSound(randomTurnChoice)
[/CODE]
To emit it from a player, e.g.
[CODE]
LocalPlayer():EmitSound(randomTurnChoice)
[/CODE]
Also, if this code is clientside, EmitSound doesn't get broadcast to other players when played, so you may as well do this instead:
[CODE]
surface.PlaySound(randomTurnChoice)
[/CODE]
[editline]7th August 2016[/editline]
Oh, I didn't read the part about you wanting it to be heard by ALL players. In that case, you'll have to run that script serverside, and change the randomPoliceRadioSounds function to be something like this:
[CODE]
function randomPoliceRadioSounds()
if policeRadio.setTime < 5 then
policeRadio.setTime = 5
end
local randomplayer = table.Random( player.GetHumans() )
if table.HasValue(policeRadio.cops, team.GetName(randomplayer)) then
randomQuoteChoice = table.Random(policeRadio.quotes)
randomTurnChoice = table.Random(policeRadio.turn)
randomplayer:EmitSound(randomTurnChoice)
timer.Simple(SoundDuration(randomTurnChoice), function()
randomplayer:EmitSound(randomQuoteChoice) end)
timer.Simple(SoundDuration(randomQuoteChoice) +SoundDuration(randomTurnChoice), function()
randomplayer:EmitSound(randomTurnChoice) end)
end
end
[/CODE]
Note I haven't tested that and it probably just spams sounds constantly but you get the idea- just change randomplayer to be whatever player you want
[QUOTE=MPan1;50841718]Just change
[CODE]
self:EmitSound(randomTurnChoice)
[/CODE]
To emit it from a player, e.g.
[CODE]
LocalPlayer():EmitSound(randomTurnChoice)
[/CODE]
Also, if this code is clientside, EmitSound doesn't get broadcast to other players when played, so you may as well do this instead:
[CODE]
surface.PlaySound(randomTurnChoice)
[/CODE]
[editline]7th August 2016[/editline]
Oh, I didn't read the part about you wanting it to be heard by ALL players. In that case, you'll have to run that script serverside, and change the randomPoliceRadioSounds function to be something like this:
[CODE]
function randomPoliceRadioSounds()
if policeRadio.setTime < 5 then
policeRadio.setTime = 5
end
local randomplayer = table.Random( player.GetHumans() )
if table.HasValue(policeRadio.cops, team.GetName(randomplayer)) then
randomQuoteChoice = table.Random(policeRadio.quotes)
randomTurnChoice = table.Random(policeRadio.turn)
randomplayer:EmitSound(randomTurnChoice)
timer.Simple(SoundDuration(randomTurnChoice), function()
randomplayer:EmitSound(randomQuoteChoice) end)
timer.Simple(SoundDuration(randomQuoteChoice) +SoundDuration(randomTurnChoice), function()
randomplayer:EmitSound(randomTurnChoice) end)
end
end
[/CODE]
Note I haven't tested that and it probably just spams sounds constantly but you get the idea- just change randomplayer to be whatever player you want[/QUOTE]
The Idea is that is plays from all cp's on the RP but this may be a better way of actually implementing it I'll give it a go.
Thanks a bunch mate.
[editline]7th August 2016[/editline]
Ah dammit I made the changes you suggested and i just can't seem to get it working at all.
when i used
[code] surface.PlaySound(randomTurnChoice) [/code]
it plays for the client but if i change it to the suggested code
[code] local randomplayer = table.Random( player.GetHumans() ) [/code]
or
[code] local randomply = table.Random(player.GetAll()) [/code]
It just doesn't run at all no errors so i can't debug the problem.
anyone got any ideas as to why this doesn't work?
Final code being uses which doesn't work
[code]
function randomPoliceRadioSounds()
if policeRadio.setTime < 5 then
policeRadio.setTime = 5
end
local randomply = table.Random(player.GetAll())
if table.HasValue(policeRadio.cops, team.GetName(randomply)) then
randomQuoteChoice = table.Random(policeRadio.quotes)
randomTurnChoice = table.Random(policeRadio.turn)
randomply:EmitSound(randomTurnChoice)
timer.Simple(SoundDuration(randomTurnChoice), function() randomply:EmitSound(randomQuoteChoice) end)
timer.Simple(SoundDuration(randomQuoteChoice) +SoundDuration(randomTurnChoice), function() randomply:EmitSound(randomTurnChoice) end)
end
end
end
timer.Create("startRandomPoliceRadio", policeRadio.setTime, 0, randomPoliceRadioSounds)
[/code]
Sorry, you need to Log In to post a reply to this thread.