Jump to content

help with car[RP]


huyjvguyen

Recommended Posts

i want make a marker when player hit this marker, they will have a car , and setimer destroy car when they exit car, if thePlayer enter car , script will killtimer desroy. this is my code

markers = {} 
markers[1] = createMarker( 1923.009765625, 1242.271484375, 62.886322021484, "cylinder", 1, 255, 255, 0, 200) 
--markers[2] = createMarker(-709, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
  
vehicle ={} 
  
function onMarkerHitGiveVehicle(hitPlayer) 
  
  
if getElementType(hitPlayer) == "player"  then 
if (isElement(vehicle[hitPlayer])) then 
  
outputChatBox("You did took a car", hitPlayer) 
else 
local x, y, z = getElementPosition(hitPlayer) 
vehicle[hitPlayer] = createVehicle(514,x,y,z) 
setElementData(hitPlayer,"car",Vehicle[hitPlayer]) 
warpPedIntoVehicle(hitPlayer,vehicle[hitPlayer]) 
addEventHandler("onVehicleExit", getRootElement(),destime) 
addEventHandler("onVehicleEnter", getRootElement(),killtime) 
         end 
      end 
   end 
  
  
function des(player, veh) 
local veh = getElementData(player ,"car") 
if veh then 
destroyElement(veh) 
end 
end 
function destime() 
kill = setTimer(onMarkerHitGiveVehicle, 5000,1) 
outputChatBox("Get in car in 10s or the car will be destroyed",hitPlayer) 
end 
function killtime() 
killTimer(kill) 
outputChatBox("Pls don't get out the car",hitPlayer) 
end 
addEventHandler("onMarkerHit",getRootElement(),onMarkerHitGiveVehicle) 

Link to comment

i think that my build is an advance

markers = { 
createMarker( 1923.009765625, 1242.271484375, 62.886322021484, "cylinder", 1, 255, 255, 0, 200), 
--createMarker(-709, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
} 
vehicle ={} 
function onMarkerHitGiveVehicle(hitPlayer) 
    if getElementType(hitPlayer) == "player"  then 
        if (isElement(vehicle[hitPlayer])) then  
        outputChatBox("You did took a car", hitPlayer) 
        else 
        local x, y, z = getElementPosition(hitPlayer) 
        vehicle[hitPlayer] = createVehicle(514,x,y,z) 
        setElementData(hitPlayer,"car",Vehicle[hitPlayer]) 
        warpPedIntoVehicle(hitPlayer,vehicle[hitPlayer]) 
        addEventHandler("onVehicleExit", hitPlayer,destime) 
        addEventHandler("onVehicleEnter", hitPlayer,killtime) 
        end 
    end 
end 
  
  
function des(player, veh) 
local veh = getElementData(player ,"car") 
if veh then 
destroyElement(veh) 
end 
end 
function destime() 
kill = setTimer( 
    function (hitPlayer) 
    local veh = vehicle[hitPlayer] 
    local seat = getPedOccupiedVehicleSeat(hitPlayer) 
        if veh and seat == 0 then 
        destroyElement(veh) 
        outputChatBox("Veh destroyed", hitPlayer, 255,0,0,true) 
        end 
    end 
, 10000,1, hitPlayer) 
outputChatBox("Get in car in 10s or the car will be destroyed",hitPlayer) 
end 
function killtime() 
killTimer(kill) 
outputChatBox("Pls don't get out the car",hitPlayer) 
end 
addEventHandler("onMarkerHit",root,onMarkerHitGiveVehicle) 

Link to comment
i think that my build is an advance
markers = { 
createMarker( 1923.009765625, 1242.271484375, 62.886322021484, "cylinder", 1, 255, 255, 0, 200), 
--createMarker(-709, 966, 12, "cylinder", 1, 255, 255, 0, 200) 
} 
vehicle ={} 
function onMarkerHitGiveVehicle(hitPlayer) 
    if getElementType(hitPlayer) == "player"  then 
        if (isElement(vehicle[hitPlayer])) then  
        outputChatBox("You did took a car", hitPlayer) 
        else 
        local x, y, z = getElementPosition(hitPlayer) 
        vehicle[hitPlayer] = createVehicle(514,x,y,z) 
        setElementData(hitPlayer,"car",Vehicle[hitPlayer]) 
        warpPedIntoVehicle(hitPlayer,vehicle[hitPlayer]) 
        addEventHandler("onVehicleExit", hitPlayer,destime) 
        addEventHandler("onVehicleEnter", hitPlayer,killtime) 
        end 
    end 
end 
  
  
function des(player, veh) 
local veh = getElementData(player ,"car") 
if veh then 
destroyElement(veh) 
end 
end 
function destime() 
kill = setTimer( 
    function (hitPlayer) 
    local veh = vehicle[hitPlayer] 
    local seat = getPedOccupiedVehicleSeat(hitPlayer) 
        if veh and seat == 0 then 
        destroyElement(veh) 
        outputChatBox("Veh destroyed", hitPlayer, 255,0,0,true) 
        end 
    end 
, 10000,1, hitPlayer) 
outputChatBox("Get in car in 10s or the car will be destroyed",hitPlayer) 
end 
function killtime() 
killTimer(kill) 
outputChatBox("Pls don't get out the car",hitPlayer) 
end 
addEventHandler("onMarkerHit",root,onMarkerHitGiveVehicle) 

addEventHandler("onMarkerHit",root,onMarkerHitGiveVehicle)

And when he creates another marker from another script to do something else, the action will still be taken. You're calling a global argument to classify all elements with such corresponding data, in this case, markers. Why not use the table for the required data, define such and unpack or use a loop within a function onResourceStart to add the hit handler and give the data? That'll be even more advanced, your way is still vulnerable.

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