Jump to content

onMarkerHit not working


Recommended Posts

When I hit a marker I want to Display "GG" in the chat.

I have got a resource which is a garage system that will have a marker. I write this code:

Marker = createMarker(1702.7998046875, -1079.2001953125, 22.89999961853, "cylinder", 2, 0, 0, 255)
local myMarker = createMarker(1702.7998046875, -1079.2001953125, 22.89999961853, 'cylinder', 2.0, 0, 0, 255, 150)

function MarkerHit( Element, matchingDimension )
    triggerClientEvent ( "onMarkerHit", getRootElement())
addEventHandler( "onMarkerHit", Marker, MarkerHit )

And when I go to the marker I created, nothing happened. But when I go to the garage system marker, that works. And the marker position in this code is not the same as the garage system marker.

Please help!!

Edited by hackermagus
Link to comment

You should always try to pin point the problem by adding output messages everywhere. Or prints, but anyway, try putting a output right after the createmarker so you know that was successfully made, then another message right before TriggerClientEvent… Wait, I don't even think you need the TriggerClientEvent line, that would keep looping forever...

Try commenting out that line and see if it works

Link to comment
Marker = createMarker(1702.7998046875, -1079.2001953125, 22.89999961853, "cylinder", 2, 0, 0, 255) -- Global variable for a marker (Probably should be local)
local myMarker = createMarker(1702.7998046875, -1079.2001953125, 22.89999961853, 'cylinder', 2.0, 0, 0, 255, 150) -- Locl variable for a marker

function MarkerHit( Element, matchingDimension )-- The function, notice the arugments as it will be useful (Element is whatever hits the marker, a player)
    -- triggerClientEvent ( "onMarkerHit", getRootElement())-- This will call MarkerHit, but we already triggered MarkerHit, so this is an infinite loop
    outputChatBox("GG",Element)-- This is our goal... By adding the Element argument, sends the message ONLY to the player that hit the marker
end -- Ends the function, easy enough

addEventHandler( "onMarkerHit", getRootElement(), MarkerHit )-- Defines that MTA-SA's onMarkerHit will be the function MarkerHit, had to change this too...

It will take some time, but you must learn in general how coding/scripting is done, try to understand what every line is doing. Use the MTA-SA Wiki for Events, Functions and such. Lua is the language MTA SA uses, will need to learn how the language operates too.  Remember, baby steps :)

Edited by ReZurrecti0n
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...