Jump to content

Server-side and Client-side


Cronoss

Recommended Posts

Hello Everybody, I need help with this specific function in client-side

The main script (/bloquear function) it's in server-side, I know playSound3D must be in Client-Side but I don't know how to connect them, because in server side the script look like this:

addCommandHandler("bloquear", function(player,cmd) 
	local acc = player:getAccount()
	local owner = acc:getName()
	local vehicle = getNearestVehicle(player,5) or Ped.getOccupiedVehicle(player)
	if (vehicle:getData("vehicles:owner") == owner) then
		setPlayerVehicleLocked(player, vehicle)
	else
		player:outputChat("", 255, 0, 0)
	end
end)

function setPlayerVehicleLocked(player, vehicle)
	local vehname = vehicle:getName()
	if (vehicle:getData("vehicles:locked") == 1) then
		vehicle:setData("vehicles:locked", 0)
		vehicle:setLocked(false)
		player:outputChat("> Desbloqueaste tu "..vehname..".", 233, 24, 189)
		connection:exec("UPDATE vehicles SET locked=? WHERE id=? AND owner=?", 0, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner"))
	elseif (vehicle:getData("vehicles:locked") == 0) then
		vehicle:setData("vehicles:locked", 1)
		vehicle:setLocked(true)
		player:outputChat("> Bloqueaste tu "..vehname..".", 233, 24, 189)
		connection:exec("UPDATE vehicles SET locked=? WHERE id=? AND owner=?", 1, vehicle:getData("vehicles:id"), vehicle:getData("vehicles:owner"))
	end
end

And in Client side looks like this:

local x, y, z = client:getPosition()

function sonidoBloq()
local bloqueo = playSound3D( "sonidoBloq.mp3", x, y, z, false )
setSoundMaxDistance(bloqueo,10)
end
addEventHandler(???)

When I try to connect them, with "callClientFunction" or any variant of it, the resource stop working and hides every vehicle. It only happens with the playsound, I've tried making another client-side functions and works, but with this simply It doesn't work :(

 

Link to comment
local x, y, z = getElementPosition(localPlayer) -- get player position

function sonidoBloq()
local bloqueo = playSound3D("sonidoBloq.mp3", x, y, z, false)
setSoundMaxDistance(bloqueo, 10)
end
addEvent("playSound", true)  -- add event with name "playSound" or whatever you want
addEventHandler("playSound", root, sonidoBloq) -- add event listener 

create an event on the client side to play the sound

you can use triggerClientEvent to call this on server side
triggerClientEvent(player, "playSound", player)

 

Edited by Burak5312
  • Like 1
Link to comment

yes it's possible you can call it with triggerClientEvent likewise

triggerClientEvent(player, "playSound", player)

but be careful with the player parameter because it will change based on where it is called.

 

As an example, here I made 3 parameters as posX, posY, posZ.

function sonidoBloq(posX, posY, posZ)
local bloqueo = playSound3D("sonidoBloq.mp3", posX, posY, posZ, false)
setSoundMaxDistance(bloqueo, 10)
end
addEvent("playSound", true)  -- add event with name "playSound" or whatever you want
addEventHandler("playSound", root, sonidoBloq) -- add event listener 

 

you can run it on the server side with triggerClientEvent in the same way, but here we will need to add 3 x, y, z coordinates as an extra, so we can play the sound in the coordinates we want.

triggerClientEvent(player, "playSound", player, 0, 50, 3) -- play sound 0,50,3 coordinates

 

Edited by Burak5312
  • Like 1
Link to comment
function sonidoBloq()
local x, y, z = getElementPosition(localPlayer) -- get player position
local bloqueo = playSound3D("sonidoBloq.mp3", x, y, z, false)
setSoundMaxDistance(bloqueo, 10)
end
addEvent("playSound", true)  -- add event with name "playSound" or whatever you want
addEventHandler("playSound", root, sonidoBloq) -- add event listener 

hmmm can you try to enclose the getElementPosition in a function?

Edited by Burak5312
  • Like 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...