Jump to content

route


AlphaMark

Recommended Posts

Create an table filled with positions for data, then add an eventHandler that uses 'onMarkerHit', get the source ( which marker has been hit ) of the function and check its position in the table. Then select the next entry out of your table and use 'createMarker' to create the next marker. after you created the next marker, give the player some cash.

Link to comment
local currentIndex = 1 
local route = 
    { 
        { 0, 0, 0 }, 
        { 0, 0, 1 }, 
        { 0, 0, 2 }, 
        { 0, 0, 3 }, 
        { 0, 0, 4 }, 
    } 
  
marker = createMarker ( unpack ( route [ currentIndex ] ) ) 
  
addEventHandler ( "onMarkerHit", root, 
    function ( ) 
        if ( source == marker ) then 
            currentIndex = ( currentIndex + 1 ) 
            destroyElement ( marker ) 
            marker = nil 
            marker = createMarker ( unpack ( route [ currentIndex ] ) ) 
        end 
    end 
) 

Link to comment

Server

  
local jobMarker = createMarker(10, 10, 3, 'cylinder', 1, 0, 255, 0, 255) 
local jobBlip = createBlipAttachedTo(jobMarker, 41) 
local sweeperTeam = createTeam("Sweeper", 255, 0, 0) 
local joblessTeam = createTeam("Unemployed", 123, 123, 123) 
  
function GetSweeperJob(hitElement, matchingDimension) 
    if getElementData(hitElement, "Occupation") ~= "Sweeper" then 
        triggerClientEvent("SweepWindow", hitElement) 
    else 
        outputChatBox("You already are a sweeper!", hitElement, 255, 0, 0) 
    end 
end 
addEventHandler("onMarkerHit", jobMarker, GetSweeperJob) 
         
function GiveSweeperJob(client) 
    setPlayerSkin(client, 264) 
    setPlayerTeam(client, getTeamFromName("Sweeper")) 
    setElementData(client, "Occupation", "Sweeper") 
    setElementData(client, "hasSweepMarker", "no") 
    outputChatBox("You are now a sweeper!", client, 255, 0, 0) 
end 
addEvent("GiveSweeperJob", true) 
addEventHandler("GiveSweeperJob", getRootElement(), GiveSweeperJob) 
  
function resignSweeperJob(thePlayer, cmd) 
    if (getElementData(thePlayer, "Occupation") == "Sweeper") then 
        setPlayerSkin(thePlayer, math.random(1,287)) 
        setPlayerTeam(thePlayer, getTeamFromName("Unemployed")) 
        setElementData(thePlayer, "Occupation", "Unemployed") 
        outputChatBox("You resigned as sweeper!", thePlayer, 255, 0, 0) 
    elseif getElementData(thePlayer, "Occupation") == "Unemployed" then 
        outputChatBox("You are already Unemployed!", thePlayer, 255, 0, 0) 
    end 
end 
addCommandHandler("resign", resignSweeperJob) 
  
function SweepEnter(theVehicle, seat, jacked) 
    local id = getElementModel ( theVehicle ) 
    if id == 574 then 
    outputChatBox("You are now sweeping!", thePlayer, 255, 0, 0) 
    triggerClientEvent("SweepRoute", source) 
    end 
end 
addEventHandler ( "onPlayerVehicleEnter", getRootElement(), SweepEnter ) 
  
  
local currentIndex = 1 
local route = 
    { 
        { 0, 0, 0 }, 
        { 0, 0, 1 }, 
        { 0, 0, 2 }, 
        { 0, 0, 3 }, 
        { 0, 0, 4 } 
    } 
  
marker = createMarker ( unpack ( route [ currentIndex ] ) ) 
  
addEventHandler ( "onMarkerHit", root, 
    function ( ) 
        if ( source == marker ) then 
            currentIndex = ( currentIndex + 1 ) 
            destroyElement ( marker ) 
            marker = nil 
            marker = createMarker ( unpack ( route [ currentIndex ] ) ) 
            end 
    end 
) 
  

Client

  
  
  
function centerWindow(center_window) 
    local screenW,screenH=guiGetScreenSize() 
    local windowW,windowH=guiGetSize(center_window,false) 
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2 
    guiSetPosition(center_window,x,y,false) 
end 
  
function JobWindow() 
    jobWdw = guiCreateWindow(638, 266, 597, 655, "SANGSweeper", false) 
    guiWindowSetSizable(jobWdw, false) 
    takejobBtn = guiCreateButton(378, 131, 190, 78, "Take Job", false, jobWdw) 
    closeBtn = guiCreateButton(378, 524, 190, 78, "Close", false, jobWdw) 
end 
  
function showJobWindow() 
    JobWindow() 
    if (jobWdw ~= nil) then 
        guiSetVisible(jobWdw, true) 
        guiSetInputEnabled(true) 
        showCursor(true) 
        centerWindow(jobWdw) 
    end 
end 
addEvent("SweepWindow", true) 
addEventHandler("SweepWindow", getRootElement(), showJobWindow) 
  
function clickJobWindow(button,state) 
    if (source == takejobBtn) then 
        local client = localPlayer 
        triggerServerEvent("GiveSweeperJob", localPlayer, client) 
        guiSetVisible(jobWdw, false) 
        guiSetInputEnabled(false) 
        showCursor(false) 
    elseif (source == closeBtn) then 
        guiSetVisible(jobWdw, false) 
        guiSetInputEnabled(false) 
        showCursor(false) 
    end 
end 
  
addEventHandler("onClientGUIClick", getRootElement(), clickJobWindow) 
  

Link to comment

The reason for the error is because the index reached its limit, you have to reset it to 1 again.

Also there was some other problems i fixed, and there is event not added at client side (check line 43).

local jobMarker = createMarker(10, 10, 3, 'cylinder', 1, 0, 255, 0, 255) 
local jobBlip = createBlipAttachedTo(jobMarker, 41) 
local sweeperTeam = createTeam("Sweeper", 255, 0, 0) 
local joblessTeam = createTeam("Unemployed", 123, 123, 123) 
  
function GetSweeperJob(hitElement) 
    if getElementType(hitElement) == "player" then 
        if getElementData(hitElement, "Occupation") ~= "Sweeper" then 
            triggerClientEvent(hitElement, "SweepWindow", hitElement) 
        else 
            outputChatBox("You already are a sweeper!", hitElement, 255, 0, 0) 
        end 
    end 
end 
addEventHandler("onMarkerHit", jobMarker, GetSweeperJob) 
        
function GiveSweeperJob() 
    setElementModel(source, 264) 
    setPlayerTeam(source, getTeamFromName("Sweeper")) 
    setElementData(source, "Occupation", "Sweeper") 
    setElementData(source, "hasSweepMarker", "no") 
    outputChatBox("You are now a sweeper!", source, 255, 0, 0) 
end 
addEvent("GiveSweeperJob", true) 
addEventHandler("GiveSweeperJob", root, GiveSweeperJob) 
  
function resignSweeperJob(thePlayer) 
    if (getElementData(thePlayer, "Occupation") == "Sweeper") then 
        setElementModel(thePlayer, math.random(1,287)) 
        setPlayerTeam(thePlayer, getTeamFromName("Unemployed")) 
        setElementData(thePlayer, "Occupation", "Unemployed") 
        outputChatBox("You resigned as sweeper!", thePlayer, 255, 0, 0) 
    elseif getElementData(thePlayer, "Occupation") == "Unemployed" then 
        outputChatBox("You are already Unemployed!", thePlayer, 255, 0, 0) 
    end 
end 
addCommandHandler("resign", resignSweeperJob) 
  
function SweepEnter(theVehicle, seat, jacked) 
    local id = getElementModel(theVehicle) 
    if id == 574 then 
        outputChatBox("You are now sweeping!", source, 255, 0, 0) 
        --triggerClientEvent(source, "SweepRoute", source) 
    end 
end 
addEventHandler("onPlayerVehicleEnter", root, SweepEnter) 
  
local currentIndex = 1 
local route = 
    { 
        { 0, 0, 0 }, 
        { 0, 0, 1 }, 
        { 0, 0, 2 }, 
        { 0, 0, 3 }, 
        { 0, 0, 4 } 
    } 
  
marker = createMarker(unpack(route[currentIndex])) 
  
addEventHandler("onMarkerHit", root, 
function() 
    if (source == marker) then 
        destroyElement(marker) 
        currentIndex = (currentIndex < #route) and (currentIndex + 1) or 1 
        marker = createMarker(unpack(route[currentIndex])) 
    end 
end) 

function centerWindow(center_window) 
    local screenW,screenH=guiGetScreenSize() 
    local windowW,windowH=guiGetSize(center_window,false) 
    local x,y = (screenW-windowW)/2,(screenH-windowH)/2 
    guiSetPosition(center_window,x,y,false) 
end 
  
jobWdw = guiCreateWindow(638, 266, 597, 655, "SANGSweeper", false) 
guiWindowSetSizable(jobWdw, false) 
takejobBtn = guiCreateButton(378, 131, 190, 78, "Take Job", false, jobWdw) 
closeBtn = guiCreateButton(378, 524, 190, 78, "Close", false, jobWdw) 
guiSetVisible(jobWdw, false) 
  
function showJobWindow() 
    if (jobWdw ~= nil) then 
        guiSetVisible(jobWdw, true) 
        guiSetInputEnabled(true) 
        showCursor(true) 
        centerWindow(jobWdw) 
    end 
end 
addEvent("SweepWindow", true) 
addEventHandler("SweepWindow", root, showJobWindow) 
  
function clickJobWindow(button,state) 
    if (source == takejobBtn) then 
        triggerServerEvent("GiveSweeperJob", localPlayer) 
        guiSetVisible(jobWdw, false) 
        guiSetInputEnabled(false) 
        showCursor(false) 
    elseif (source == closeBtn) then 
        guiSetVisible(jobWdw, false) 
        guiSetInputEnabled(false) 
        showCursor(false) 
    end 
end 
addEventHandler("onClientGUIClick", guiRoot, clickJobWindow) 

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