AlphaMark Posted November 13, 2013 Share Posted November 13, 2013 How do i make an route that will make you drive to certain markers after each other and that u get money for each marker? Link to comment
tosfera Posted November 13, 2013 Share Posted November 13, 2013 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
Castillo Posted November 13, 2013 Share Posted November 13, 2013 Use tables. createMarker givePlayerMoney onMarkerHit http://lua-users.org/wiki/TablesTutorial Link to comment
AlphaMark Posted November 13, 2013 Author Share Posted November 13, 2013 So i would have this? function Route local markers = { {0, 0, 3}, {2, 0, 3}, {4, 0, 3} } And then? Link to comment
Castillo Posted November 13, 2013 Share Posted November 13, 2013 Then you must define the current index the player is, and go incrementing everytime he hits the marker. Link to comment
AlphaMark Posted November 13, 2013 Author Share Posted November 13, 2013 Could you make an example? Link to comment
Castillo Posted November 13, 2013 Share Posted November 13, 2013 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
AlphaMark Posted November 13, 2013 Author Share Posted November 13, 2013 Hitting the marker wont do anything. Link to comment
AlphaMark Posted November 13, 2013 Author Share Posted November 13, 2013 I already got it working, Still thanks! Link to comment
AlphaMark Posted November 14, 2013 Author Share Posted November 14, 2013 I though i got it to work, But when u enter the marker nothing happends Link to comment
AlphaMark Posted November 14, 2013 Author Share Posted November 14, 2013 I want to make this in to an function because i want to be able to trigger it serverside Link to comment
TAPL Posted November 15, 2013 Share Posted November 15, 2013 The code is server side. Link to comment
AlphaMark Posted November 16, 2013 Author Share Posted November 16, 2013 Ah okay but now i got this error: Bad argument at #1 to 'unpack' (table expected got nil) Link to comment
TAPL Posted November 16, 2013 Share Posted November 16, 2013 The table not exist or not defined. Link to comment
Spajk Posted November 16, 2013 Share Posted November 16, 2013 Remove the comma after the last position Link to comment
AlphaMark Posted November 16, 2013 Author Share Posted November 16, 2013 (edited) Spajk, Same error Edited November 17, 2013 by Guest Link to comment
AlphaMark Posted November 16, 2013 Author Share Posted November 16, 2013 The table not exist or not defined. its defined with "local table =" Link to comment
TAPL Posted November 17, 2013 Share Posted November 17, 2013 Post the current code you use and have the error. Link to comment
AlphaMark Posted November 18, 2013 Author Share Posted November 18, 2013 The whole script? Link to comment
AlphaMark Posted November 18, 2013 Author Share Posted November 18, 2013 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
TAPL Posted November 18, 2013 Share Posted November 18, 2013 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
AlphaMark Posted November 18, 2013 Author Share Posted November 18, 2013 Nothing happends when i hit the marker, Also no errors. And only sweepers should see the marker(When they are in the sweeper vehicle) Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now