Jump to content

action for client


Recommended Posts

--client
function w1()
w1 = guiCreateWindow((sW - 419) / 2, (sH - 165) / 2, 280, 310, "W1", false)
w1btn1 = guiCreateButton ( 5, 25, 120, 25, "btn1", false, w1)
addEventHandler("onClientGUIClick",w1btn1,j1client0,false)
end

function j1client0()
triggerServerEvent("j1server",localPlayer)
destroyElement(w1)
showCursor(false)
end

function j1client()
playSoundFrontEnd(1)
end
addEvent("j1client", true)
addEventHandler("j1client", root, j1client)

--server
function j1server()
local car1 = createVehicle (408, 0, 0, 0, 0, 0, 0, "car1", 0, 0, 0)
j1server2()
end
addEvent("j1server",true)
addEventHandler("j1server",root,j1server)

function j1server2()
local x,y,z = 0, 0, 0
triggerClientEvent("j1client",source, x,y,z)
end
addEvent("j1server2",true)
addEventHandler("j1server2",root,j1server2)

Everything works as intended, with the exception of 1 nuance. The sound happens for everyone on the server, but need only for the player who presses the button. How to fix it?

Link to comment
12 minutes ago, Cronoss said:

Could you show how you are calling those events? (server-side part)

@CronossI showed the code with which I call these functions in the first post

I mean how to do it. I press the button and using the function "j1client0" which removes the window and calls the server function "j1server" , here in the code I just called another server function("j1server2"), with the line:
 

j1server2()

and here the function should transfer the coordinates to the client side "j1client" and the sound also works, using the line:
 

playSoundFrontEnd(1)

 

Maybe I didn’t use the logic correctly somewhere, but everything seems to work as it should, except for a nuance, the sound is heard by all players, and I want to do it only for the player who presses the button

Link to comment

Maybe adding this parameter? I had the same problem when I was testing some scripts in my server, this was the problem for me


--server
function j1server2()
local x,y,z = 0, 0, 0
triggerClientEvent(source, "j1client",source, x,y,z) --This
end
addEvent("j1server2",true)
addEventHandler("j1server2",root,j1server2)

Also, I don't get why you add events to these functions if you are not gonna call them before with another function like "triggerServerEvent" or something like that, this should work exactly like you want:

--server
function j1server()
local car1 = createVehicle (408, 0, 0, 0, 0, 0, 0, "car1", 0, 0, 0)
j1server2()
end
addEvent("j1server",true) --------------------It is necessary here
addEventHandler("j1server",root,j1server)

function j1server2() 
local x,y,z = 0, 0, 0
triggerClientEvent("j1client",source, x,y,z)
end
addEventHandler("j1server2",root,j1server2)

Another solution for me should be:

--Client

--Your 1st function blabla...

function j1client0()
triggerServerEvent("j1server",getLocalPlayer(), getLocalPlayer()) --Add this
destroyElement(w1)
showCursor(false)
end

--Server
function j1server(player)
local car1 = createVehicle (408, 0, 0, 0, 0, 0, 0, "car1", 0, 0, 0)
--You could add the whole function j1server2, idk why you separate these functions
triggerClientEvent(player, "j1client",
    player, x,y,z) 
end
addEvent("j1server", true)
addEventHandler("j1server",root,j1server)

 

Edited by Cronoss
  • 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...