Jump to content

[HELP] Creating a marker and then add hit event


Recommended Posts

Hi,

So I am trying to do something simple again. In my experience with other coding languages, this should work. However, here it does not.
I am creating a marker near my position when entering a command. At that moment I want to bind a new hit event that triggers a function. The function does not trigger for some reason.

Is there something I am missing here?

function createTheMarker (  )
    local x, y, z = getElementPosition(localPlayer)
    local theMarker = createMarker ( x, y+5, z, "cylinder", 1.5, 255, 255, 0, 170 )
    addEventHandler( "onMarkerHit", theMarker, markerTriggered )
end
addCommandHandler ( "create", createTheMarker )

function markerTriggered (  ) 
    outputServerLog ( 'hit' )
end 

 

Thanks!

Link to post

Hello Bartje,

the problem is that you are mixing up client-side functionality with server-side functionality. You are trying to use the localPlayer global variable in a server-side script. But there is no localPlayer on the server because the server is not a game window.

Fixed script for you:

function createTheMarker ( cmdPlayer )
    local x, y, z = getElementPosition(cmdPlayer)
    local theMarker = createMarker ( x, y+5, z, "cylinder", 1.5, 255, 255, 0, 170 )
    addEventHandler( "onMarkerHit", theMarker, markerTriggered )
end
addCommandHandler ( "create", createTheMarker )

function markerTriggered (  ) 
    outputServerLog ( 'hit' )
end 

Did you know about the script debug output? If you look into the server console then it should tell you which line is at fault and maybe which function got you an error. :) 

  • Like 1
Link to post

Hi!

Oh my. This entire code was inside a client script, so it wouldn't have worked either way!😅  It is obvious now.

1 hour ago, The_GTA said:

Did you know about the script debug output? If you look into the server console then it should tell you which line is at fault and maybe which function got you an error

Didn't know about this. I thought the server console was showing all errors.

So I can start this debugging by typing for example: 'debugscript 3' in the in-game console, correct?

 

Thanks for making clear that I was mixing up client and server functionality!

Link to post
2 minutes ago, Bartje said:

So I can start this debugging by typing for example: 'debugscript 3' in the in-game console, correct?

Correct. You have be to logged-in as admin of course. This way you see both client-side errors as well as server-side errors.

Always happy to help! 😉

Edited by The_GTA
  • Thanks 1
Link to post

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