Okay, I've missed a few changes. So, basically, can anybody educate me on how does the new Sound playing system work? And are there any code-breaking changes that I need to be aware of?
If you want to play sounds on the client, you have to be granted the permission by the user of the chip (or yourself if you're using it). This is because the client has no idea who owns what entity, so can essentially play sounds anywhere.
In order to have your chip eligible for the permission, you also have to register (as early as possible) that you need the functionality, using permissions.register().
-- Register that the chip requires access to playing client sounds (make sure this is on the client side, not server)
permissions.register( permissions.PLAY_CLIENT_SOUNDS )
Now whenever a sound is played, the client running the script checks the permission access, and if they've granted it, the sound plays. Otherwise it (currently) silently fails to play. To grant permission rights, go into the editor, click the shield icon at the top right, and grant either to a specific chip, or all your chips by selecting yourself in the list.
Yes, I figured it out. And not silently, it told me exactly what was the reason it failed, that I needed to do permissions. The thing is, I don't think that SoundName:play() works now, or at least it doesn't work for me. Is it right? Or am I missing something?
(02-04-2016, 10:43 PM)Destinys Player Wrote: And not silently, it told me exactly what was the reason it failed, that I needed to do permissions.
It errors if you haven't registered the permission, but not if the user has not granted it. So any client that hasn't granted your chip the permission will silently fail to play the sound.
(02-04-2016, 10:43 PM)Destinys Player Wrote: The thing is, I don't think that SoundName:play() works now, or at least it doesn't work for me. Is it right? Or am I missing something?
Works for me when the permission is registered and granted. What's the problem you're getting?
03-04-2016, 02:30 PM, (This post was last modified: 03-04-2016, 02:31 PM by Destiny's Player.)
(02-04-2016, 10:43 PM)Destinys Player Wrote: The thing is, I don't think that SoundName:play() works now, or at least it doesn't work for me. Is it right? Or am I missing something?
Works for me when the permission is registered and granted. What's the problem you're getting?
It says something like "SoundName is unknown" (can't look at the exact message right now), despite it all working before. Here's the code I have.
if SERVER then
if ents.self():class() ~= "starfall_screen" then
error("Not a Starfall screen")
else
Water = nil
Energy = nil
Refinery = nil
LS = nil
Node = nil
Connect = 0
function getResourceEnts()
ShipEnts = Self:getSingleConstrainedEnts()
local i = 0
timer.create("RG",0.01,#ShipEnts,function()
i = i+1
local Cur = ShipEnts[i]
printConsole(Cur:class())
if Cur:class() == "stargazer_water_core" then
Water = Cur
Connect = Connect+1
printColor(Color(100,100,255),"Water Core Connected")
print(6-Connect.." - Connections left")
elseif Cur:class() == "stargazer_energy_core" then
Energy = Cur
Connect = Connect+1
printColor(Color(255,220,150),"Energy Core Connected")
print(6-Connect.." - Connections left")
elseif Cur:class() == "stargazer_refinement_core" then
Refinery = Cur
Connect = Connect+1
printColor(Color(100,100,150),"Refinery Core Connected")
print(6-Connect.." - Connections left")
elseif Cur:class() == "stargazer_ls_core" then
LS = Cur
Connect = Connect+1
printColor(Color(10,200,10),"Life Support Connected")
print(6-Connect.." - Connections left")
elseif Cur:class() == "stargazer_node" then
Node = Cur
Connect = Connect+1
printColor(Color(100,100,100),"Resource Node Connected")
print(6-Connect.." - Connections left")
end
end)
end
function getResourceInfo()
timer.remove("RG")
if Connect < 6 then
Pump = Water:getWirelink()["Collector"]
if Pump:isValid() then
Connect = Connect+1
printColor(Color(10,10,255),"Water Pump Connected")
print(6-Connect.." - Connections left")
end
end
if Connect == 6 then
WaterOn = Pump:getWirelink()["Active"]
else
WaterOn = 0
end
WaterCurrent = Node:getWirelink()["Water"]
WaterMax = Node:getWirelink()["Max Water"]
--printConsole("Water - ", WaterCurrent," Out of ", WaterMax)
EnergyOn = Energy:getWirelink()["Active"]
EnergyCurrent = Node:getWirelink()["Energy"]
EnergyMax = Node:getWirelink()["Max Energy"]
--printConsole("Energy - ", EnergyCurrent," Out of ", EnergyMax)
RefineryOn = Refinery:getWirelink()["Active"]
DeuteriumCurrent = Node:getWirelink()["Deuterium"]
DeuteriumMax = Node:getWirelink()["Max Deuterium"]
--printConsole("Deut - ", DeuteriumCurrent," Out of ", DeuteriumMax)
LSOn = LS:getWirelink()["Active"]
OxygenCurrent = Node:getWirelink()["Oxygen"]
OxygenMax = Node:getWirelink()["Max Oxygen"]
--printConsole("Oxygen - ", OxygenCurrent," Out of ", OxygenMax)
end
function lifeSupportToggle()
if Started == 1 then
Energy:getWirelink()["Activate"] = 1
if EnergyCurrent > 20000 then
if Connect == 6 then
Pump:getWirelink()["Activate"] = 1
end
Refinery:getWirelink()["Activate"] = 1
LS:getWirelink()["Activate"] = 1
end
elseif Started == 0 or EnergyCurrent < 1000 then
if Connect >= 6 then
Pump:getWirelink()["Activate"] = 0
end
Energy:getWirelink()["Activate"] = 0
Refinery:getWirelink()["Activate"] = 0
LS:getWirelink()["Activate"] = 0
end
end
function resourcesToClient()
net.writeTable({
WaterOn,
EnergyOn,
RefineryOn,
LSOn,
WaterCurrent,
WaterMax,
EnergyCurrent,
EnergyMax,
DeuteriumCurrent,
DeuteriumMax,
OxygenCurrent,
OxygenMax
})
end
function sendToClient()
if net.start() then
resourcesToClient()
net.broadcast()
end
end
getResourceEnts()
Started = 0
hook("net","ServerRecieve",function()
if Started == 0 then
Started = 1
printConsole("Life Support is turned on!")
else
Started = 0
printConsole("Life Support is turned off!")
end
end)
timer.create("Refr",0.5,0,function()
if Connect >= 5 then
getResourceInfo()
lifeSupportToggle()
sendToClient()
end
end)
end
end
if CLIENT then
permissions.register("PLAY_CLIENT_SOUNDS")
--Cursor Stuff
function Cursor(ply)
local CurPosX,CurPosY = render.cursorPos(ply)
if CurPosX ~= nil and CurPosY ~= nil then
return CurPosX,CurPosY
end
end
function Pointer(ply)
local CurPosX,CurPosY = render.cursorPos(ply)
render.setColor(255,255,255)
if CurPosX ~= nil and CurPosY ~= nil then
render.drawRectOutline(CurPosX-3,CurPosY-3,6,6)
render.drawRect(CurPosX-1,CurPosY-1,2,2)
end
end
function Press(ply)
return ply:keyDown(input.IN_USE)
end
--Color Stuff
function TurnedOn()
if CoresOn[1] == 1 then
WCol = {0,100,205}
else
WCol = {0,45,100}
end
if CoresOn[2] == 1 then
ECol = {205,160,0}
else
ECol = {100,75,0}
end
if CoresOn[3] == 1 then
RCol = {0,205,195}
else
RCol = {0,100,90}
end
if CoresOn[4] == 1 then
LSCol = {0,205,0}
else
LSCol = {0,100,0}
end
end
--Render Stuff
function Draw4(press,p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y,col)
local Polygon = render.createPoly({
render.vertex(p1x,p1y),
render.vertex(p2x,p2y),
render.vertex(p3x,p3y),
render.vertex(p4x,p4y)
})
if press == 1 then
render.setColor(col[1]+20,col[2]+20,col[3]+20)
else
render.setColor(col[1],col[2],col[3])
end
render.drawPoly(Polygon)
render.setColor(255,255,255)
render.drawLine(p1x,p1y,p2x,p2y)
render.drawLine(p2x,p2y,p3x,p3y)
render.drawLine(p3x,p3y,p4x,p4y)
render.drawLine(p4x,p4y,p1x,p1y)
end
function Draw6(press,p1x,p1y,p2x,p2y,p3x,p3y,p4x,p4y,p5x,p5y,p6x,p6y,col)
local Polygon = render.createPoly({
render.vertex(p1x,p1y),
render.vertex(p2x,p2y),
render.vertex(p3x,p3y),
render.vertex(p4x,p4y),
render.vertex(p5x,p5y),
render.vertex(p6x,p6y)
})
if press == 1 then
render.setColor(col[1]+20,col[2]+20,col[3]+20)
else
render.setColor(col[1],col[2],col[3])
end
render.drawPoly(Polygon)
render.setColor(255,255,255)
render.drawLine(p1x,p1y,p2x,p2y)
render.drawLine(p2x,p2y,p3x,p3y)
render.drawLine(p3x,p3y,p4x,p4y)
render.drawLine(p4x,p4y,p5x,p5y)
render.drawLine(p5x,p5y,p6x,p6y)
render.drawLine(p6x,p6y,p1x,p1y)
end
--Sound Stuff
function Beeper()
Beep:play()
timer.simple(0.2,function() Beeptop() end)
end
--Button Stuff
function Button(xpos1,ypos1,xpos2,ypos2)
local num = 0
if CurX ~= nil and CurY ~= nil then
if CurX >= xpos1 and CurX <= xpos2 then
if CurY >= ypos1 and CurY <= ypos2 then
if Used then
num = 1
Beeper()
return num
end
end
end
end
end
--Prettification Stuff
Basic = render.createFont("default",20,1000,1,1,0,0,0)
Big = render.createFont("default",50,1000,1,1,0,0,0)
Credits = render.createFont("default",10,500,0,0,0,0,0)
Beep = sounds.create(Self,"st/console/beep06.wav")
hook("net","ClientRecieve",function()
ResourcesData = net.readTable()
if ResourcesData ~= nil then
hook("render","loading",nil)
CoresOn = {ResourcesData[1], ResourcesData[2], ResourcesData[3], ResourcesData[4]}
--[[for i=1, #ResCurrent do
printConsole("Test - ", ResCurrent[i])
end]]
--[[timer.create("Test",2,0,function()
if ResourcesInfo ~= nil then
printConsole(ResourcesInfo[1], " - Water is On")
printConsole(ResourcesInfo[5], " - Is how much water we have")
end
end) ]]
hook("render","Rendering",function()
render.clear()
--Resources Text
render.setColor(255,255,255,255)
render.drawText(Basic,256,10,"WATER",render.TEXT_ALIGN_CENTER)
render.drawText(Basic,256,70,"ENERGY",render.TEXT_ALIGN_CENTER)
render.drawText(Basic,256,130,"DEUTERIUM",render.TEXT_ALIGN_CENTER)
render.drawText(Basic,256,190,"OXYGEN",render.TEXT_ALIGN_CENTER)
if ResCurrent.Water ~= nil then
TextWater = tostring(math.floor(ResCurrent.Water[1])).."/"..tostring(ResCurrent.Water[2])
render.drawText(Basic,256,35,TextWater,render.TEXT_ALIGN_CENTER)
end
if ResCurrent.Energy ~= nil then
TextEnergy = tostring(math.floor(ResCurrent.Energy[1])).."/"..tostring(ResCurrent.Energy[2])
render.drawText(Basic,256,95,TextEnergy,render.TEXT_ALIGN_CENTER)
end
if ResCurrent.Deuterium ~= nil then
TextDeut = tostring(math.floor(ResCurrent.Deuterium[1])).."/"..tostring(ResCurrent.Deuterium[2])
render.drawText(Basic,256,155,TextDeut,render.TEXT_ALIGN_CENTER)
end
if ResCurrent.Oxygen ~= nil then
TextOxygen = tostring(math.floor(ResCurrent.Oxygen[1])).."/"..tostring(ResCurrent.Oxygen[2])
render.drawText(Basic,256,215,TextOxygen,render.TEXT_ALIGN_CENTER)
end
--Cursor Debug Info
--render.drawText(Basic,10,100,tostring(CurX),render.TEXT_ALIGN_LEFT)
--render.drawText(Basic,10,120,tostring(CurY),render.TEXT_ALIGN_LEFT)
--render.drawText(Basic,10,140,tostring(Used),render.TEXT_ALIGN_LEFT)
--Everything to do with Buttons
StartBut = Button(10,250,500,500)
--Start Button
StartButCol = {150,0,0}
--Draw4(StartBut,300,100,400,100,420,120,320,120,StartButCol)
Draw6(StartBut,10,250,500,250,500,450,450,500,60,500,10,450,StartButCol)
render.drawText(Big,256,350,"START LIFE SUPPORT",render.TEXT_ALIGN_CENTER)
--Credits
CreBGCol = {120,120,120}
Draw4(0,415,499,510,499,510,510,415,510,CreBGCol)
render.drawText(Credits,509,500,"Author - The Next Decade",render.TEXT_ALIGN_RIGHT)
--Just the cursor render
Pointer(Owner)
end)
else
hook("render","loading",function()
render.clear()
render.setColor(255,255,255)
render.drawText(Big,256,246,"LOADING",render.TEXT_ALIGN_CENTER)
end)
end
end)
--Send To Server
hook("starfall_used","Used",function()
if StartBut ~= nil then
if net.start() then
--local ButString = tostring(StartBut)
--net.writeString(ButString)
net.sendToServer()
end
end
end)
end
Because you have not granted the permission to play sounds.
Go into the editor, click the shield icon at the top right, click your name, select the "Grant access to play sounds client side." option. Then try again.