Jump to content

[HELP] Server triggered clientside event, but event is not added clienside


MarbleXeno

Recommended Posts

I'm trying to make simple job. When player hit the marker

this error pops up in debuscript 3. I'm just learning Lua 

and I don't know how to fix this error.

Error: Server triggered clientside event, createGui, but event is not added clientside

 

meta.xml

<meta>
    <script src="server.Lua" type="server" />
    <script src="client.Lua" type="client" />
</meta>

 

client.Lua

local gui = {}
 
okno = guiCreateWindow(0.350.260.160.45"Praca GAZECIARZ"true)
guiWindowSetSizable(okno, false)
guiSetVisible(okno, false)
 
button = guiCreateButton(0.160.560.730.39""true, okno)
 
addEvent("createGui"true)
 
function openGui()
    outputChatBox("Test2")
    guiSetVisible(okno, false)
end
addEventHandler("createGui", resourceRoot, openGui)

 

server.Lua

function createSomeMarker()
    createMarker(-244275434"cylinder"2)
end
addEventHandler("onResourceStart"root, createSomeMarker)
 
function markerCollision (markerHit, matchingDimension)
    if matchingDimension then
        outputChatBox("Test1")
        triggerClientEvent("createGui", resourceRoot)
    end
end
addEventHandler("onPlayerMarkerHit"root, markerCollision)

 

Thanks for the help!

Link to comment

 

9 hours ago, ReZurrecti0n said:

Instead of root or resourceRoot, try just using getRootElement() instead, for example:

 

 

I did as you said, now I get exactly the same error in debuscript 3 but this time when we enter the gui marker it will show up. I don't know what the problem is now.

 

server.Lua

function createSomeMarker()
    createMarker(-244275434"cylinder"2)
end
addEventHandler("onResourceStart"getRootElement(), createSomeMarker)
 
function markerCollision (markerHit, matchingDimension)
    if matchingDimension then
        outputChatBox("Test1")
        triggerClientEvent("createGui", resourceRoot)
    end
end
addEventHandler("onPlayerMarkerHit"getRootElement(), markerCollision)

 

client.Lua

local gui = {}
 
okno = guiCreateWindow(0.350.260.160.45"Praca GAZECIARZ"true)
guiWindowSetSizable(okno, false)
guiSetVisible(okno, false)
showCursor(falsefalse)
 
button = guiCreateButton(0.160.560.730.39""true, okno)
 
addEvent("createGui"true)
function OpenGui()
    outputChatBox("Test2")
    guiSetVisible(okno, true)
    showCursor(truetrue)
end
addEventHandler("createGui"getRootElement(), OpenGui)

 

When we enter the marker:

https://imgur.com/a/xvek0fx

Link to comment
46 minutes ago, ReZurrecti0n said:

Strange, it does reach the event, thus you get the "test2" outputchatbox for it...

It is saying expected Element at Argument 2, but getting a Function

Well, maybe if you fix the showCursor(false) and showCursor(true)

Error is showing up only when resource is starting. 
I think the problem is that the computer reads the code from the top down, and something can't be loaded. The code works, so I'm leaving this problem for now.
Edited by MarbleXeno
Link to comment

Maybe the client file wasn't downloaded and run yet when the server attempted the triggerClientEvent. But after it finishes downloading and running the client file, it all works... A solution to this is starting your server from the onClientResourceStart event on your client side file. Once that event triggers, then you could just use triggerServerEvent to spawn in your player in etc.

Oh, but you may want to make sure it only triggers once, so just do a quick resource check, I'll give a full example of what I mean:

function ClientResourceStart(resource)
 if(getResourceName(resource)=="EXAMPLE")then
  triggerServerEvent("SomeFunction",localPlayer)
 end
  
addEventHandler("onClientResourceStart",getRootElement(),ClientResourceStart)

Where as "SomeFunction" would be a custom function created server side with all your starting player code and whatnot

Edited by ReZurrecti0n
Link to comment
addEvent("createGui", true)

function guiFunction()
okno = guiCreateWindow(0.35, 0.26, 0.16, 0.45, "Praca GAZECIARZ", true)
guiWindowSetSizable(okno, false)
 
button = guiCreateButton(0.16, 0.56, 0.73, 0.39, "", true, okno)
end
 
function openGui()
if not isElement(okno) then
guiFunction()
showCursor(true)
guiSetInputMode("no_binds_when_editing")
elseif isElement(okno) then
guiSetVisible(okno, not guiGetVisible(okno))
showCursor(not isCursorShowing())
guiSetInputMode("no_binds_when_editing")
end
end
addEventHandler("createGui", getRootElement(), openGui)
local jobMarker = createMarker(-2442, 754, 34, "cylinder", 2)
 
addEventHandler("onMarkerHit", jobMarker, function(hitElement, matchingDimension)
if isElement(hitElement) and getElementType(hitElement) == "player" and not getPedOccupiedVehicle(hitElement) then -- checks if element exists, if is player, and not inside a car
if matchingDimension then -- if both player and marker are on the same dimension --
triggerClientEvent(hitElement, "createGui", hitElement)
end
end
end)

Fixed your code, not tested but should work. If you want some help understanding this, you can PM me and I'll be glad to help you.

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...