Jump to content

I am new to Mtasa scripting.


scolen

Recommended Posts

getJobMarker = createMarker(872.03754, -29.07278, 62.3000, "cylinder", 1.0, 0, 255, 255, 255, getRootElement())
ped = createPed(159, 872.92389, -27.08743, 63.94565, 160)
setPedFrozen(ped, true)
blip = createBlipAttachedTo(getJobMarker, 56)

function hitMarkerWindow()
    window = guiCreateWindow(0.35, 0.35, 0.35, 0.30, "wood job", true)
    memo = guiCreateMemo(0.10, 0.20, 0.80, 0.4, "this is wood cutting job", true, window)
    accept = guiCreateButton(0.10, 0.75, 0.22, 0.14, "Accept Job", true, window)
    leave = guiCreateButton(0.35, 0.75, 0.22, 0.14, "Leave Job", true, window)
    close = guiCreateButton(0.60, 0.75, 0.22, 0.14, "Close", true, window)
    showCursor(true)
    guiMemoSetReadOnly(memo, true)
end

addEventHandler("onClientMarkerHit", getJobMarker, hitMarkerWindow)

function clientClick()
    if source == close then 
        guiSetVisible(window, false)
        showCursor(false)
        triggerServerEvent("cancelButton", resourceRoot, localPlayer)
    elseif source == accept then
        guiSetVisible(window, false)
        showCursor(false)
        triggerServerEvent("acceptWoodJob", resourceRoot, localPlayer)
    elseif source == leave then 
        guiSetVisible(window, false)
        showCursor(false)
        triggerServerEvent("leaveJob", resourceRoot, localPlayer)

    end
end

addEventHandler("onClientGUIClick", root,  clientClick)

 

Link to comment
9 hours ago, Ciastuuś said:

What's your problem?

The script works fine. It loads the marker, the gui is loaded, all buttons in it work and trigger.

If a player hits this marker, every player on the same server will start working. What I want to do is to make it work only for the player who hits the marker. How to fix this?

Link to comment

addEventHandler("onClientMarkerHit", getJobMarker, hitMarkerWindow)

-- should be changed to


addEventHandler("onClientMarkerHit", getJobMarker, function(hitPlayer, matchingDimension)
    if (hitPlayer == localPlayer and matchingDimension) then
      hitMarkerWindow()
    end
  end
)

This protects the window from being created when any element hits the marker, instead only triggering if the element that hits the marker is the client that is running this client-side script.

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