Jump to content

Cancel createMarker


Lloyd Logan

Recommended Posts

Posted

Hey, so i made a random marker, and you drive to the marker (this marker is created randomly) and pick up the created ped. When you do the marker is destroyed. The problem is, i have 2 tables, one to pick up the ped(in the table there is co-ordinates for the random marker), the other one is where to drop the ped off. The problem i am have is that when i pick up a ped it creates another pick up ped marker. How do i cancel it creating another marker?

Team = createTeam("Taxi Driver", 0, 255, 0) 
  
busTeams = { [Team] = true } 
busVehs = { [420] = true } 
  
  
  
function enterVehicle ( thePlayer, seat, jacked ) -- when a player enters a vehicle 
    if getElementType ( thePlayer ) == "player" then 
    if ( busVehs[getElementModel ( source )] ) and ( not busTeams[getPlayerTeam( thePlayer )] ) then -- if the vehicle is one of 4 police cars, and the skin is not a police skin 
        removePedFromVehicle( thePlayer )-- force the player out of the vehicle 
        outputChatBox("Only Taxi Drivers can drive this vehicle!", thePlayer) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) 
  
markers = { } 
blips = { } 
peds = { } 
  
function inVEH(thePlayer) 
        if isPedInVehicle ( thePlayer ) then 
        if ( getElementModel ( source ) == 420 ) then 
        local x, y, z = unpack ( dropoffs [ math.random ( #dropoffs ) ] ) 
        markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 3.5, 255, 0, 0 ) 
         
        local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
        peds [ thePlayer ] = createPed( skins, x, y, z ) 
        blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
        addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 
        end 
    else 
        if ( isElement ( markers [ thePlayer ] ) ) then 
            destroyElement ( markers [ thePlayer ] ) 
        end 
        if ( isElement ( blips [ thePlayer ] ) ) then 
        destroyElement( blips [ thePlayer ] ) 
        cancelEvent() 
        end 
        end 
        end 
addEventHandler("onVehicleEnter", getRootElement(), inVEH) 
  
  
  
  
  
function warpit ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        local vehicle = getPedOccupiedVehicle ( thePlayer ) 
        if ( getElementModel ( vehicle ) == 420 ) then 
            if ( isElement ( markers [ thePlayer ] ) ) then 
                destroyElement ( markers [ thePlayer ] ) 
            if ( isElement ( blips [ thePlayer ] ) ) then 
                destroyElement( blips [ thePlayer ] ) 
            warpPedIntoVehicle ( peds [ thePlayer ], vehicle, 2 ) 
            triggerEvent ( "onPickUp", root ) 
        end 
    end 
end 
end 
end 
  
function pickMeUp () 
    if ( isElement ( markers [ thePlayer ] ) ) then 
                destroyElement ( markers [ thePlayer ] ) 
            end 
            if ( isElement ( blips [ thePlayer ] ) ) then 
                destroyElement( blips [ thePlayer ] ) 
            end 
    end 
addEvent("onPickUp", true) 
addEventHandler("onPickUp", root, pickMeUp) 

Posted
You are saying that a random marker is generated again because the ped enters the vehicle, that's what I got at least.

So, i create a random marker for the player to pick a ped up at, this marker is random

Then, When the player hit the marker the ped is warped into the veh then the DROP OFF marker is displayed, problem is I don't know how to stop it creating another PICK UP marker aswell.

Posted
I told you on my first post, check if the element that entered the vehicle is a player.
getElementType 

I dont that, What i mean is, the player is already in the vehicle , it IS creating the DROP OFF marker, but it is also creating the PICK UP MARKER, Which shouldn't be made until the DROPOFF marker has been hit.

Posted
Team = createTeam("Taxi Driver", 0, 255, 0) 
  
busTeams = { [Team] = true } 
busVehs = { [420] = true } 
  
  
  
function enterVehicle ( thePlayer, seat, jacked ) -- when a player enters a vehicle 
    if getElementType ( thePlayer ) == "player" then 
    if ( busVehs[getElementModel ( source )] ) and ( not busTeams[getPlayerTeam( thePlayer )] ) then -- if the vehicle is one of 4 police cars, and the skin is not a police skin 
        removePedFromVehicle( thePlayer )-- force the player out of the vehicle 
        outputChatBox("Only Taxi Drivers can drive this vehicle!", thePlayer) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) 
  
markers = { } 
blips = { } 
peds = { } 
  
function inVEH ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        if ( getElementModel ( source ) == 420 ) then 
            local x, y, z = unpack ( dropoffs [ math.random ( #dropoffs ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 3.5, 255, 0, 0 ) 
            local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
            peds [ thePlayer ] = createPed( skins, x, y, z ) 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 
        end 
    else 
        if ( isElement ( markers [ thePlayer ] ) ) then 
            destroyElement ( markers [ thePlayer ] ) 
        end 
        if ( isElement ( blips [ thePlayer ] ) ) then 
            destroyElement( blips [ thePlayer ] ) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), inVEH ) 
  
function warpit ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        local vehicle = getPedOccupiedVehicle ( thePlayer ) 
        if ( getElementModel ( vehicle ) == 420 ) then 
            warpPedIntoVehicle ( peds [ thePlayer ], vehicle, 2 ) 
            pickMeUp ( thePlayer ) 
        end 
    end 
end 
  
function pickMeUp ( thePlayer ) 
    if ( isElement ( markers [ thePlayer ] ) ) then 
        destroyElement ( markers [ thePlayer ] ) 
    end 
    if ( isElement ( blips [ thePlayer ] ) ) then 
        destroyElement( blips [ thePlayer ] ) 
    end 
end 

Posted

Can I quickly ask, is getElementsByType all you added in there?

And yes it works! How then would get it, after the dropoff has been made, to create another pickup marker?

And again Thank You!

Posted

I changed some other things.

To do that, you need to do the same as in "inVEH" function, destroy first marker/blip, create new random one and attach the event handler of "onMarkerHit" to function "pickMeUp".

Posted
I changed some other things.

To do that, you need to do the same as in "inVEH" function, destroy first marker/blip, create new random one and attach the event handler of "onMarkerHit" to function "pickMeUp".

Thanks, I will try that now Castillo.

Posted
I changed some other things.

To do that, you need to do the same as in "inVEH" function, destroy first marker/blip, create new random one and attach the event handler of "onMarkerHit" to function "pickMeUp".

It says Bad argument at 2, expected element got nil, markers [ thePlayer ] is the element of the marker, yes?

function dropoff( thePlayer ) 
     if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then  
        if ( getElementModel ( source ) == 420 ) then 
    local x, y, z = unpack ( sss [ math.random ( #sss ) ] ) 
        markers [ thePlayer ] = createMarker ( x, y, z - 1, "cylinder", 3.5, 255, 0, 0 ) 
        blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
        if ( isElement ( markers [ thePlayer ] ) ) then 
            destroyElement ( markers [ thePlayer ] ) 
        end 
        if ( isElement ( blips [ thePlayer ] ) ) then 
            destroyElement( blips [ thePlayer ] ) 
            end 
        end 
    end 
end 
addEvent("onMarkerHit", true) 
addEventHandler("onMarkerHit", markers [ thePlayer ], dropoff) 

Posted

I'm sorry Castillo, I'm so confused, I attempted what you said and,

local pickups = { 
[1]={ 2060.7685546875, -1941.1181640625, 13.14103603363 }, 
[2]={ 2114.5068359375, -1611.302734375, 13.167269706726 }, 
[3]={ 1932.9521484375, -1776.1259765625, 13.16081237793 }, 
[4]={ 1057.41796875, -1568.4853515625, 13.166387557983 } 
}  
  
local dropoffs = { 
  
[1]={ 1965.54296875 , -1883.013671875, 13.160305023193 }, 
[2]={ 1467.3916015625, -1736.419921875, 13.242918014526 }, 
[3]={ 2376.1064453125, -1728.4091796875, 13.162055015564 }, 
[4]={ 1066.5029296875, -1200.86328125, 18.405519485474 } 
} 
  
local pedCus = { 
[1]={ 9 }, 
[2]={ 10 }, 
[3]={ 14 }, 
[4]={ 15 }, 
[5]={ 37 } 
} 
  
  
Team = createTeam("Taxi Driver", 0, 255, 0) 
  
busTeams = { [Team] = true } 
busVehs = { [420] = true } 
  
function enterVehicle ( thePlayer, seat, jacked ) -- when a player enters a vehicle 
    if getElementType ( thePlayer ) == "player" then 
    if ( busVehs[getElementModel ( source )] ) and ( not busTeams[getPlayerTeam( thePlayer )] ) then -- if the vehicle is one of 4 police cars, and the skin is not a police skin 
        removePedFromVehicle( thePlayer )-- force the player out of the vehicle 
        outputChatBox("Only Taxi Drivers can drive this vehicle!", thePlayer) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) 
  
markers = { } 
blips = { } 
peds = { } 
  
  
  
function inVEH ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then  
        if ( getElementModel ( source ) == 420 ) then 
            local x, y, z = unpack ( pickups [ math.random ( #pickups ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 3.5, 255, 0, 0 ) 
            local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
            peds [ thePlayer ] = createPed( skins, x, y, z ) 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
           addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 
           addEventHandler ( "onMarkerHit", markers [ thePlayer ], dropoff ) 
        end 
    else 
        if ( isElement ( markers [ thePlayer ] ) ) then 
            destroyElement ( markers [ thePlayer ] ) 
        end 
        if ( isElement ( blips [ thePlayer ] ) ) then 
            destroyElement( blips [ thePlayer ] ) 
            triggerEvent("onMarkerHit", root, dropoff) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), inVEH ) 
  
  
function warpit ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        local vehicle = getPedOccupiedVehicle ( thePlayer ) 
        if ( getElementModel ( vehicle ) == 420 ) then 
            warpPedIntoVehicle ( peds [ thePlayer ], vehicle, 2 ) 
            pickMeUp ( thePlayer ) 
        end 
    end 
end 
  
  
 function dropoff( thePlayer ) 
        if ( getElementModel ( source ) == 420 ) then 
        local x, y, z = unpack ( dropoff [ math.random ( #dropoff ) ] ) 
        markers [ thePlayer ] = createMarker ( x, y, z - 1, "cylinder", 3.5, 255, 0, 0 ) 
        blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            end 
        end 
addEvent("onMarkerHit", true) 
  
     
  
function pickMeUp ( thePlayer ) 
    if ( isElement ( markers [ thePlayer ] ) ) then 
        destroyElement ( markers [ thePlayer ] ) 
    end 
    if ( isElement ( blips [ thePlayer ] ) ) then 
        destroyElement( blips [ thePlayer ] ) 
        end 
    end 

Posted
local pickups = { 
[1]={ 2060.7685546875, -1941.1181640625, 13.14103603363 }, 
[2]={ 2114.5068359375, -1611.302734375, 13.167269706726 }, 
[3]={ 1932.9521484375, -1776.1259765625, 13.16081237793 }, 
[4]={ 1057.41796875, -1568.4853515625, 13.166387557983 } 
} 
  
local dropoffs = { 
  
[1]={ 1965.54296875 , -1883.013671875, 13.160305023193 }, 
[2]={ 1467.3916015625, -1736.419921875, 13.242918014526 }, 
[3]={ 2376.1064453125, -1728.4091796875, 13.162055015564 }, 
[4]={ 1066.5029296875, -1200.86328125, 18.405519485474 } 
} 
  
local pedCus = { 
[1]={ 9 }, 
[2]={ 10 }, 
[3]={ 14 }, 
[4]={ 15 }, 
[5]={ 37 } 
} 
  
  
Team = createTeam("Taxi Driver", 0, 255, 0) 
  
busTeams = { [Team] = true } 
busVehs = { [420] = true } 
  
function enterVehicle ( thePlayer, seat, jacked ) -- when a player enters a vehicle 
    if getElementType ( thePlayer ) == "player" then 
    if ( busVehs[getElementModel ( source )] ) and ( not busTeams[getPlayerTeam( thePlayer )] ) then -- if the vehicle is one of 4 police cars, and the skin is not a police skin 
        removePedFromVehicle( thePlayer )-- force the player out of the vehicle 
        outputChatBox("Only Taxi Drivers can drive this vehicle!", thePlayer) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) 
  
markers = { } 
blips = { } 
peds = { } 
  
function inVEH ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        if ( getElementModel ( source ) == 420 ) then 
            local x, y, z = unpack ( pickups [ math.random ( #pickups ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 3.5, 255, 0, 0 ) 
            local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
            peds [ thePlayer ] = createPed( skins, x, y, z ) 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 
        end 
    else 
        if ( isElement ( markers [ thePlayer ] ) ) then 
            destroyElement ( markers [ thePlayer ] ) 
        end 
        if ( isElement ( blips [ thePlayer ] ) ) then 
            destroyElement( blips [ thePlayer ] ) 
            triggerEvent("onMarkerHit", root, dropoff) 
        end 
    end 
end 
addEventHandler ( "onVehicleEnter", getRootElement(), inVEH ) 
  
function warpit ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        local vehicle = getPedOccupiedVehicle ( thePlayer ) 
        if ( getElementModel ( vehicle ) == 420 ) then 
            warpPedIntoVehicle ( peds [ thePlayer ], vehicle, 2 ) 
            if ( isElement ( markers [ thePlayer ] ) ) then 
                destroyElement ( markers [ thePlayer ] ) 
            end 
            if ( isElement ( blips [ thePlayer ] ) ) then 
                destroyElement( blips [ thePlayer ] ) 
            end 
            local x, y, z = unpack ( dropoff [ math.random ( #dropoff ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z - 1, "cylinder", 3.5, 255, 0, 0 ) 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            addEventHandler ( "onMarkerHit", markers [ thePlayer ], pickMeUp ) 
        end 
    end 
end 
  
function pickMeUp ( thePlayer ) 
    if ( getElementType ( thePlayer ) == "player" and isPedInVehicle ( thePlayer ) ) then 
        if ( isElement ( markers [ thePlayer ] ) ) then 
            destroyElement ( markers [ thePlayer ] ) 
        end 
        if ( isElement ( blips [ thePlayer ] ) ) then 
            destroyElement( blips [ thePlayer ] ) 
        end 
        if ( isElement ( peds [ thePlayer ] ) ) then 
            destroyElement ( peds [ thePlayer ] ) 
        end 
        outputChatBox ( "Destination reached.", thePlayer ) 
    end 
end 

Posted
You can create a function instead, and execute it when they enter the vehicle, and when they finish delivery.

If i have created my function how would I execute it when they enter the vehicle the finish the job?

Posted

This would be the main function:

function startJob ( thePlayer ) 
    -- Code here 
end 

And you would need to put your random marker generation inside it, then execute startJob passing 'thePlayer' argument from 'onVehicleEnter' and 'onMarkerHit'.

Posted
            local x, y, z = unpack ( pickups [ math.random ( #pickups ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 3.5, 255, 0, 0 ) 
            local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
            peds [ thePlayer ] = createPed( skins, x, y, z ) 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 

That's what it has to go inside startJob function.

Posted (edited)
            local x, y, z = unpack ( pickups [ math.random ( #pickups ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 3.5, 255, 0, 0 ) 
            local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
            peds [ thePlayer ] = createPed( skins, x, y, z ) 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 

That's what it has to go inside startJob function.

You must have the Utmost patience with people.

Do I remove

  
           local x, y, z = unpack ( pickups [ math.random ( #pickups ) ] ) 
            markers [ thePlayer ] = createMarker ( x, y, z, "cylinder", 3.5, 255, 0, 0 ) 
            local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) 
            peds [ thePlayer ] = createPed( skins, x, y, z ) 
            blips [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
            addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 

From my other functions?

Edited by Guest

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