Jump to content

MTA job-script question


Animan99

Recommended Posts

Hello guys! I need help. I am writing a simple marker-job, and it is working fine. My problem is, when i hit the last marker, the job is over. I mean, i want to do, that when i hit the last marker and earn money, then the code begins again from the start. (i hope you understand, i am pretty bad at english :) ) so, i made an example code, because my whole job script is way to complicated to understand (for me, not you) and it is easier if you explain it for this code. (i googled it found nothing.)

Here is my example code:

(client side)

marker1 = createMarker(1213.9326171875, -1340.8984375, 13.571063995361, "cylinder", 2, 255, 0, 0, 150) 
marker2 = createMarker(1214.1376953125, -1309.7197265625, 13.557456016541, "cylinder", 2, 255, 0, 0, 150) 
marker3 = createMarker(1214.1376953125, -1309.7197265625, 13.557456016541, "cylinder", 2, 255, 0, 0, 150) 
  
function hit1 (thePlayer) 
    if thePlayer == getLocalPlayer() then 
        destroyElement(marker1) 
    end 
end 
  
function hit2 (thePlayer) 
    if thePlayer == getLocalPlayer() then 
        destroyElement(marker2) 
    end 
end 
  
function hit3 (thePlayer) 
    if thePlayer == getLocalPlayer() then 
        -- then the code starts again from the beginning. 
    end 
end 
  
addEventHandler("onClientMarkerHit", marker1, hit1) 
addEventHandler("onClientMarkerHit", marker2, hit2) 
addEventHandler("onClientMarkerHit", marker3, hit3) 
  

so, if i am hit the third marker, i want the whole script starts from the beginning, so there will be 1st and 2nd marker visible, hope you understand, and you can help me, Thanks.

Link to comment

Try this i didn't test it.

local thirdMarker = false 
local MarkersTable = {} 
  
local Markers = { 
{1213.9326171875, -1340.8984375, 13.571063995361}, -- Marker 1  
{1214.1376953125, -1309.7197265625, 13.557456016541}, -- Marker 2  
{1214.1376953125, -1309.7197265625, 13.557456016541,true}, -- Marker 3  
} 
  
function CreateMarkers() 
    for i=1,#Markers do 
            local x, y, z = Markers[i][1], Markers[i][2], Markers[i][3] 
            local theMarker = createMarker ( x, y, z , "cylinder", 2, 255, 0, 0, 150) 
            table.insert (MarkersTable, theMarker ) 
            if Markers[i][4] then  
            thirdMarker = true 
            end 
        addEventHandler ( "onClientMarkerHit", theMarker, MarkersEvent, false ) 
    end 
end  
addEventHandler("onClientResourceStart",resourceRoot,CreateMarkers) 
  
function MarkersEvent (thePlayer,matchDim) 
    if matchDim and thePlayer == getLocalPlayer() then 
     if isThirdMarker ( source ) then  
      for i , v in ipairs(MarkersTable) do  
        destroyElement(v) 
            CreateMarkers() -- then the code starts again from the beginning. 
            end  
        else 
            destroyElement(source) 
        end 
    end 
end  
  
function isThirdMarker ( theMarker ) 
    for i, v in ipairs (MarkersTable) do 
        if ( v == theMarker ) and thirdMarker then 
            return true 
        end 
    end 
    return false 
end 

Link to comment
local mMarkers = {} 
local lastMarker 
local Markers = { 
{1213.9326171875, -1340.8984375, 13.571063995361}, 
{1214.1376953125, -1309.7197265625, 13.557456016541}, 
{1214.1376953125, -1309.7197265625, 13.557456016541} -- The last marker 
} 
  
  
function createMarkers() 
mMarkers = {} 
lastMarker = nil 
    for i=1,#Markers do 
    local x,y,z = unpack(Markers[i]) 
    local marker = createMarker(x,y,z,"cylinder",2,255,0,0,150) 
        if i == #Markers then 
        lastMarker = marker 
        end 
    mMarkers[marker] = true 
    end 
end 
addEventHandler("onClientResourceStart",resourceRoot,createMarkers) 
  
addEventHandler("onClientMarkerHit",root, 
function(element) 
    if mMarkers[source] then 
        if source == lastMarker then 
        outputChatBox("This is the last marker",element) 
        destroyElement(source) 
        createMarkers() 
        else 
        destroyElement(source) 
        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...