Jump to content

markerHit and markerLeave


pa3ck

Recommended Posts

Hello there, I'm making a little job ( I'm bored ) and was wondering if I could simplify my code, but I could not find a way. Here is the code:

  
marker1 = createMarker (2363.59326, -1667.18665, 12.6, "cylinder", 0.8, 0, 255, 0) 
  
marker2 = createMarker (2363.97681, -1650.78491, 12.6, "cylinder", 0.8, 0, 255, 0) 
  
marker3 = createMarker (2383.69360, -1667.21069, 12.6,  "cylinder", 0.8, 0, 255, 0) 
  
marker4 = createMarker (2395.30908 ,-1650.56726, 12.6,  "cylinder", 0.8, 0, 255, 0) 
  
marker5 = createMarker (2408.49097, -1667.32104, 12.6, "cylinder", 0.8, 0, 255, 0) 
  
marker6 = createMarker (2415.36792, -1650.27344, 12.9, "cylinder", 0.8, 0, 255, 0) 
  
addEventHandler('onClientMarkerHit', marker1, function(hitPlayer) 
    if hitPlayer == getLocalPlayer() then 
    hitMarker = setTimer(function() outputChatBox('You got your money.') givePlayerMoney(hitPlayer, 500) destroyElement(marker1) end, 5000, 1) 
    end 
end) 
  
addEventHandler('onClientMarkerLeave', marker1, function(leavingPlayer) 
    if leavingPlayer == getLocalPlayer() and isTimer(hitMarker) then 
        outputChatBox('Wait a few seconds please!') 
        killTimer(hitMarker) 
    end 
end) 
  

I don't want to write a 'onClientMarkerHit' function for each of the markers, is there anyway to do this? I don't know if you get what I'm trying to say here.

Link to comment

not tested

and you should give the player money on serverside!

      
    local marker1 = createMarker (2363.59326, -1667.18665, 12.6, "cylinder", 0.8, 0, 255, 0) 
    local marker2 = createMarker (2363.97681, -1650.78491, 12.6, "cylinder", 0.8, 0, 255, 0) 
    local marker3 = createMarker (2383.69360, -1667.21069, 12.6,  "cylinder", 0.8, 0, 255, 0) 
    local marker4 = createMarker (2395.30908 ,-1650.56726, 12.6,  "cylinder", 0.8, 0, 255, 0) 
    local marker5 = createMarker (2408.49097, -1667.32104, 12.6, "cylinder", 0.8, 0, 255, 0) 
    local marker6 = createMarker (2415.36792, -1650.27344, 12.9, "cylinder", 0.8, 0, 255, 0) 
    local hitmarker = nil 
      
    addEventHandler('onClientMarkerHit', resourceRoot, function(hitPlayer) 
        if hitPlayer == localPlayer then 
                if source == marker1 then 
                     hitMarker = setTimer(function() outputChatBox('You got your money.') givePlayerMoney(hitPlayer, 500) destroyElement(marker1) end, 5000, 1) 
               elseif source == marker2 then --ADD THIS FOR EVERY MARKER AND IF YOU WANNA DO THE SAME FOR ALL YOU DONT NEED WHAT MARKER IS HIT, BECAUSE THIS ONLY WORKS THEN FOR MARKERS CREATED BY THIS RESOURCE 
               end 
        end 
    end) 
      
      

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