FSXTim Posted April 28, 2012 Share Posted April 28, 2012 (edited) Hello, I have some problems with this script. When I hit a marker, the marker is still there (not destroyed) and there is no new marker (should create a new marker). busicon = createPickup ( 1637.7, -1128.4, 23.9, 3, 1239, 1, 99 ) function busJobIconHit ( player ) triggerClientEvent ( player, "infobox_start", getRootElement(), "Tippe /drivebus, um\nals Busfahrer\nzu arbeiten.", 5000, 200, 200, 0 ) end addEventHandler ( "onPickupHit", busicon, busJobIconHit ) function destroy1 ( player ) destroyElement( Marker1 ) Marker2 = createMarker ( 1580.0999755859, -1150.5, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker1, destroy1 ) addEventHandler( "onMarkerHit", Marker2, destroy2 ) end function destroy2 ( player ) destroyElement( Marker2 ) Marker3 = createMarker ( 1548.5, -1049.9000244141, 22.60000038147, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker2, destroy2 ) addEventHandler( "onMarkerHit", Marker3, destroy3 ) end function destroy3 ( player ) destroyElement( Marker3 ) Marker4 = createMarker ( 1426.3000488281, -1029.0999755859, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker3, destroy3 ) addEventHandler( "onMarkerHit", Marker4, destroy4 ) end function destroy4 ( player ) destroyElement( Marker4 ) Marker5 = createMarker ( 1351.0999755859, -1052.1999511719, 25.60000038147, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker4, destroy4 ) addEventHandler( "onMarkerHit", Marker5, destroy5 ) end function destroy5 ( player ) destroyElement( Marker5 ) Marker6 = createMarker ( 1338.3000488281, -1120.5, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker5, destroy5 ) addEventHandler( "onMarkerHit", Marker6, destroy6 ) end function destroy6 ( player ) destroyElement( Marker6 ) Marker7 = createMarker ( 1337.5, -1255, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker6, destroy6 ) addEventHandler( "onMarkerHit", Marker7, destroy7 ) end function destroy7 ( player ) destroyElement( Marker7 ) Marker8 = createMarker ( 1337.9000244141, -1374.5999755859, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker7, destroy7 ) addEventHandler( "onMarkerHit", Marker8, destroy8 ) end function destroy8 ( player ) destroyElement( Marker8 ) Marker9 = createMarker ( 1355.1999511719, -1375.4000244141, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker8, destroy8 ) addEventHandler( "onMarkerHit", Marker9, destroy9 ) end function destroy9 ( player ) destroyElement( Marker9 ) Marker10 = createMarker ( 1365.5, -1408.1999511719, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker9, destroy9 ) addEventHandler( "onMarkerHit", Marker10, destroy10 ) end function destroy10 ( player ) destroyElement( Marker10 ) Marker11= createMarker ( 1486.4000244141, -1445.6999511719, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker10, destroy10 ) addEventHandler( "onMarkerHit", Marker11, destroy11 ) end function destroy11 ( player ) destroyElement( Marker11 ) Marker12 = createMarker ( 1608, -1431, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker11, destroy11 ) addEventHandler( "onMarkerHit", Marker12, destroy12 ) end function destroy12 ( player ) destroyElement( Marker12 ) Marker13 = createMarker ( 1627.4000244141, -1308.4000244141, 15.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker12, destroy12 ) addEventHandler( "onMarkerHit", Marker13, destroy13 ) end function destroy13 ( player ) destroyElement( Marker13 ) Marker14 = createMarker ( 1720, -1256.8000488281, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker13, destroy13 ) addEventHandler( "onMarkerHit", Marker14, destroy14 ) end function destroy14 ( player ) destroyElement( Marker14 ) Marker15 = createMarker ( 1695.6999511719, -1156.0999755859, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker14, destroy14 ) addEventHandler( "onMarkerHit", Marker15, destroy15 ) end function destroy15 ( player ) destroyElement( Marker15 ) Marker16 = createMarker ( 1637.5999755859, -1144.0999755859, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker15, destroy15 ) addEventHandler( "onMarkerHit", Marker16, destroy16 ) end function destroy16 ( player ) destroyElement( Marker16 ) dbSetElementData ( player, "money", dbGetElementData ( player, "money" ) + 150 ) outputChatBox ( "Du hast den Job erfolgreich abgeschlossen! Als Belohnung erhälst du 150$!", player, 0, 255, 0 ) removeEventHandler( "onMarkerHit", Marker16, destroy16 ) if isElement ( veh ) then local model = getElementModel ( veh ) if model == 431 then destroyElement ( veh ) end end addEventHandler( "onMarkerHit", Marker16, destroy16 ) end function drivebus ( player ) local x, y, z = getElementPosition ( player ) if getDistanceBetweenPoints3D ( x, y, z, 1637.7, -1128.4, 24.0 ) <= 5 then if tonumber ( vioGetElementData ( player, "lkwlicense" ) ) == 1 then veh = createVehicle ( 431, 1637.7, -1132.4, 23.9, 0, 0, 180 ) warpPedIntoVehicle ( player, veh ) Marker1 = createMarker ( 1623.0999755859, -1156.5, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) else outputChatBox ( "Du brauchst einen LKW-Führerschein!", player, 255, 0, 0) end else outputChatBox ( "Du bist nicht beim Busparkplatz!", player, 255, 0, 0 ) end end addCommandHandler ( "drivebus", drivebus ) Can anybody helf me? Edited April 28, 2012 by Guest Link to comment
Xeno Posted April 28, 2012 Share Posted April 28, 2012 Where is Marker1 being created? I don't see it at all... Its also better AND easier to make the coods in a table, but its up to you, I personally find tables extremely hard. Link to comment
FSXTim Posted April 28, 2012 Author Share Posted April 28, 2012 Yes, thank you for your tip! Here is Marker 1 being created, sorry, I forgot that. function drivebus ( player ) local x, y, z = getElementPosition ( player ) if getDistanceBetweenPoints3D ( x, y, z, 1637.7, -1128.4, 24.0 ) <= 5 then if tonumber ( dbGetElementData ( player, "lkwlicense" ) ) == 1 then veh = createVehicle ( 431, 1637.7, -1132.4, 23.9, 0, 0, 180 ) warpPedIntoVehicle ( player, veh ) Marker1 = createMarker ( 1623.0999755859, -1156.5, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) else outputChatBox ( "Du brauchst einen LKW-Führerschein!", player, 255, 0, 0) end else outputChatBox ( "Du bist nicht beim Busparkplatz!", player, 255, 0, 0 ) end end addCommandHandler ( "drivebus", drivebus ) But there is nothing wrong, isn't it? There are no errors in the console. Link to comment
Jaysds1 Posted April 28, 2012 Share Posted April 28, 2012 try this: busicon = createPickup ( 1637.7, -1128.4, 23.9, 3, 1239, 1, 99 ) addCommandHandler ( "drivebus",function( player ) local x, y, z = getElementPosition ( player ) if getDistanceBetweenPoints3D ( x, y, z, 1637.7, -1128.4, 24.0 ) <= 5 then if tonumber ( getElementData ( player, "lkwlicense" ) ) == 1 then veh = createVehicle ( 431, 1637.7, -1132.4, 23.9, 0, 0, 180 ) warpPedIntoVehicle ( player, veh ) Marker1 = createMarker ( 1623.0999755859, -1156.5, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) addEventHandler( "onMarkerHit", Marker1, destroy1 ) else outputChatBox ( "Du brauchst einen LKW-Führerschein!", player, 255, 0, 0) end else outputChatBox ( "Du bist nicht beim Busparkplatz!", player, 255, 0, 0 ) end end) addEventHandler ( "onPickupHit", busicon,function( player ) triggerClientEvent ( player, "infobox_start", getRootElement(), "Tippe /drivebus, um\nals Busfahrer\nzu arbeiten.", 5000, 200, 200, 0 ) end) function destroy1 ( player ) destroyElement( Marker1 ) Marker2 = createMarker ( 1580.0999755859, -1150.5, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker1, destroy1 ) addEventHandler( "onMarkerHit", Marker2, destroy2 ) end function destroy2 ( player ) destroyElement( Marker2 ) Marker3 = createMarker ( 1548.5, -1049.9000244141, 22.60000038147, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker2, destroy2 ) addEventHandler( "onMarkerHit", Marker3, destroy3 ) end function destroy3 ( player ) destroyElement( Marker3 ) Marker4 = createMarker ( 1426.3000488281, -1029.0999755859, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker3, destroy3 ) addEventHandler( "onMarkerHit", Marker4, destroy4 ) end function destroy4 ( player ) destroyElement( Marker4 ) Marker5 = createMarker ( 1351.0999755859, -1052.1999511719, 25.60000038147, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker4, destroy4 ) addEventHandler( "onMarkerHit", Marker5, destroy5 ) end function destroy5 ( player ) destroyElement( Marker5 ) Marker6 = createMarker ( 1338.3000488281, -1120.5, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker5, destroy5 ) addEventHandler( "onMarkerHit", Marker6, destroy6 ) end function destroy6 ( player ) destroyElement( Marker6 ) Marker7 = createMarker ( 1337.5, -1255, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker6, destroy6 ) addEventHandler( "onMarkerHit", Marker7, destroy7 ) end function destroy7 ( player ) destroyElement( Marker7 ) Marker8 = createMarker ( 1337.9000244141, -1374.5999755859, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker7, destroy7 ) addEventHandler( "onMarkerHit", Marker8, destroy8 ) end function destroy8 ( player ) destroyElement( Marker8 ) Marker9 = createMarker ( 1355.1999511719, -1375.4000244141, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker8, destroy8 ) addEventHandler( "onMarkerHit", Marker9, destroy9 ) end function destroy9 ( player ) destroyElement( Marker9 ) Marker10 = createMarker ( 1365.5, -1408.1999511719, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker9, destroy9 ) addEventHandler( "onMarkerHit", Marker10, destroy10 ) end function destroy10 ( player ) destroyElement( Marker10 ) Marker11= createMarker ( 1486.4000244141, -1445.6999511719, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker10, destroy10 ) addEventHandler( "onMarkerHit", Marker11, destroy11 ) end function destroy11 ( player ) destroyElement( Marker11 ) Marker12 = createMarker ( 1608, -1431, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker11, destroy11 ) addEventHandler( "onMarkerHit", Marker12, destroy12 ) end function destroy12 ( player ) destroyElement( Marker12 ) Marker13 = createMarker ( 1627.4000244141, -1308.4000244141, 15.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker12, destroy12 ) addEventHandler( "onMarkerHit", Marker13, destroy13 ) end function destroy13 ( player ) destroyElement( Marker13 ) Marker14 = createMarker ( 1720, -1256.8000488281, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker13, destroy13 ) addEventHandler( "onMarkerHit", Marker14, destroy14 ) end function destroy14 ( player ) destroyElement( Marker14 ) Marker15 = createMarker ( 1695.6999511719, -1156.0999755859, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker14, destroy14 ) addEventHandler( "onMarkerHit", Marker15, destroy15 ) end function destroy15 ( player ) destroyElement( Marker15 ) Marker16 = createMarker ( 1637.5999755859, -1144.0999755859, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker15, destroy15 ) addEventHandler( "onMarkerHit", Marker16, destroy16 ) end function destroy16 ( player ) destroyElement( Marker16 ) dbSetElementData ( player, "money", dbGetElementData ( player, "money" ) + 150 ) outputChatBox ( "Du hast den Job erfolgreich abgeschlossen! Als Belohnung erhälst du 150$!", player, 0, 255, 0 ) removeEventHandler( "onMarkerHit", Marker16, destroy16 ) if isElement ( veh ) then local model = getElementModel ( veh ) if model == 431 then destroyElement ( veh ) end end addEventHandler( "onMarkerHit", Marker16, destroy16 ) end You forgot to add the handler to the marker. Link to comment
Kenix Posted April 29, 2012 Share Posted April 29, 2012 Also use warpPedIntoVehicle with timer. Link to comment
FSXTim Posted April 29, 2012 Author Share Posted April 29, 2012 @Jaysds1 It's working now. Thank you! Maybe you can helfp me again. When a player left the game or exit the vehicle, then the job end and all markers + the bus will be destroyed. Link to comment
Jaysds1 Posted April 29, 2012 Share Posted April 29, 2012 @Jaysds1It's working now. Thank you! Maybe you can helfp me again. When a player left the game or exit the vehicle, then the job end and all markers + the bus will be destroyed. try this: busicon = createPickup ( 1637.7, -1128.4, 23.9, 3, 1239, 1, 99 ) addCommandHandler ( "drivebus",function( player ) local x, y, z = getElementPosition ( player ) if getDistanceBetweenPoints3D ( x, y, z, 1637.7, -1128.4, 24.0 ) <= 5 then if tonumber ( getElementData ( player, "lkwlicense" ) ) == 1 then veh = createVehicle ( 431, 1637.7, -1132.4, 23.9, 0, 0, 180 ) warpPedIntoVehicle ( player, veh ) Marker1 = createMarker ( 1623.0999755859, -1156.5, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) addEventHandler( "onMarkerHit", Marker1, destroy1 ) addEventHandler("onPlayerQuit",root,destroy) else outputChatBox ( "Du brauchst einen LKW-Führerschein!", player, 255, 0, 0) end else outputChatBox ( "Du bist nicht beim Busparkplatz!", player, 255, 0, 0 ) end end) addEventHandler ( "onPickupHit", busicon,function( player ) triggerClientEvent ( player, "infobox_start", getRootElement(), "Tippe /drivebus, um\nals Busfahrer\nzu arbeiten.", 5000, 200, 200, 0 ) end) function destroy1 ( player ) destroyElement( Marker1 ) Marker2 = createMarker ( 1580.0999755859, -1150.5, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker1, destroy1 ) addEventHandler( "onMarkerHit", Marker2, destroy2 ) end function destroy2 ( player ) destroyElement( Marker2 ) Marker3 = createMarker ( 1548.5, -1049.9000244141, 22.60000038147, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker2, destroy2 ) addEventHandler( "onMarkerHit", Marker3, destroy3 ) end function destroy3 ( player ) destroyElement( Marker3 ) Marker4 = createMarker ( 1426.3000488281, -1029.0999755859, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker3, destroy3 ) addEventHandler( "onMarkerHit", Marker4, destroy4 ) addEventHandler("onPlayerQuit",root,destroy,Marker4) end function destroy4 ( player ) destroyElement( Marker4 ) Marker5 = createMarker ( 1351.0999755859, -1052.1999511719, 25.60000038147, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker4, destroy4 ) addEventHandler( "onMarkerHit", Marker5, destroy5 ) end function destroy5 ( player ) destroyElement( Marker5 ) Marker6 = createMarker ( 1338.3000488281, -1120.5, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker5, destroy5 ) addEventHandler( "onMarkerHit", Marker6, destroy6 ) end function destroy6 ( player ) destroyElement( Marker6 ) Marker7 = createMarker ( 1337.5, -1255, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker6, destroy6 ) addEventHandler( "onMarkerHit", Marker7, destroy7 ) end function destroy7 ( player ) destroyElement( Marker7 ) Marker8 = createMarker ( 1337.9000244141, -1374.5999755859, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker7, destroy7 ) addEventHandler( "onMarkerHit", Marker8, destroy8 ) end function destroy8 ( player ) destroyElement( Marker8 ) Marker9 = createMarker ( 1355.1999511719, -1375.4000244141, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker8, destroy8 ) addEventHandler( "onMarkerHit", Marker9, destroy9 ) end function destroy9 ( player ) destroyElement( Marker9 ) Marker10 = createMarker ( 1365.5, -1408.1999511719, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker9, destroy9 ) addEventHandler( "onMarkerHit", Marker10, destroy10 ) end function destroy10 ( player ) destroyElement( Marker10 ) Marker11= createMarker ( 1486.4000244141, -1445.6999511719, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker10, destroy10 ) addEventHandler( "onMarkerHit", Marker11, destroy11 ) end function destroy11 ( player ) destroyElement( Marker11 ) Marker12 = createMarker ( 1608, -1431, 12.39999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker11, destroy11 ) addEventHandler( "onMarkerHit", Marker12, destroy12 ) end function destroy12 ( player ) destroyElement( Marker12 ) Marker13 = createMarker ( 1627.4000244141, -1308.4000244141, 15.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker12, destroy12 ) addEventHandler( "onMarkerHit", Marker13, destroy13 ) end function destroy13 ( player ) destroyElement( Marker13 ) Marker14 = createMarker ( 1720, -1256.8000488281, 12.5, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker13, destroy13 ) addEventHandler( "onMarkerHit", Marker14, destroy14 ) end function destroy14 ( player ) destroyElement( Marker14 ) Marker15 = createMarker ( 1695.6999511719, -1156.0999755859, 22.700000762939, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker14, destroy14 ) addEventHandler( "onMarkerHit", Marker15, destroy15 ) end function destroy15 ( player ) destroyElement( Marker15 ) Marker16 = createMarker ( 1637.5999755859, -1144.0999755859, 22.89999961853, "cylinder", 2.5, 150, 10, 10, 125 ) removeEventHandler( "onMarkerHit", Marker15, destroy15 ) addEventHandler( "onMarkerHit", Marker16, destroy16 ) end function destroy16 ( player ) destroyElement( Marker16 ) dbSetElementData ( player, "money", dbGetElementData ( player, "money" ) + 150 ) outputChatBox ( "Du hast den Job erfolgreich abgeschlossen! Als Belohnung erhälst du 150$!", player, 0, 255, 0 ) removeEventHandler( "onMarkerHit", Marker16, destroy16 ) removeEventHandler("onPlayerQuit",root,destroy) if isElement ( veh ) then local model = getElementModel ( veh ) if model == 431 then destroyElement ( veh ) end end addEventHandler( "onMarkerHit", Marker16, destroy16 ) end function destroy() local marker = {Marker1,Marker2,Marker3,Marker4,Marker5,Marker6,Marker7,Marker8,Marker9,Marker10,Marker11,Marker12,Marker13,Marker14,Marker15,Marker16} for i,v in pairs(marker)do if(isElement(v))then destroyElement(v) destroyElemnt(veh) end end end 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