Jump to content

addEventHandler


Lloyd Logan

Recommended Posts

Hey, i made a table so i could store markers etc, then delete the table, this works fine, apart from when i get a create a random marker from a list, I donot know how to trigger it in the script?

  
local dropoffs = { 
[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 } 
}  
  
markers = { } 
  
function warpit ( hitElement ) 
    if ( hitElement == localPlayer ) then 
    if isPedInVehicle ( thePlayer ) then 
        if ( getElementModel ( source ) == 420 ) then 
                destroyElement( markers [ thePlayer ] ) 
                    local vehicle = getPedOccupiedVehicle ( source ) 
                    if ( vehicle ) then 
                    warpPedIntoVehicle ( skins, vehicle, 2 ) 
                end 
            end 
        end 
    end 
end 
addEventHandler ( "onMarkerHit", markers --this bit, warpit ) 

Link to comment

You have to add trigger event while creating your markers.

markers[1] = createMarker(dropoffs[1][1],dropoffs[1][2],dropoffs[1][3],"cylinder",2,255,0,0,125) 
addEventHandler ( "onMarkerHit", markers[1], warpit ) 

Or with a loop but then you will get all your markers created:

for i=1,4 do 
markers[i] = createMarker(dropoffs[i][1],dropoffs[i][2],dropoffs[i][3],"cylinder",2,255,0,0,125) 
addEventHandler ( "onMarkerHit", markers[i], warpit ) 
end 

Link to comment
You have to add trigger event while creating your markers.
markers[1] = createMarker(dropoffs[1][1],dropoffs[1][2],dropoffs[1][3],"cylinder",2,255,0,0,125) 
addEventHandler ( "onMarkerHit", markers[1], warpit ) 

Or with a loop but then you will get all your markers created:

for i=1,4 do 
markers[i] = createMarker(dropoffs[i][1],dropoffs[i][2],dropoffs[i][3],"cylinder",2,255,0,0,125) 
addEventHandler ( "onMarkerHit", markers[i], warpit ) 
end 

Here is my script, see if you can gather what i mean.

local dropoffs = { 
[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 sss = { 
  
[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 ( 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 
addEventHandler ( "onVehicleEnter", getRootElement(), enterVehicle ) 
  
markers = { } 
blip = { } 
vehiclees = { } 
  
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 ) ] ) 
        createPed( skins, x, y, z ) 
        blip [ thePlayer ] = createBlipAttachedTo ( markers [ thePlayer ], 41 ) 
    else 
        if ( isElement ( markers [ thePlayer ] ) ) then 
            destroyElement ( markers [ thePlayer ] ) 
        end 
        if ( isElement ( blips [ thePlayer ] ) ) then 
        destroyElement( blips [ thePlayer ] ) 
        end 
        end 
    end 
end 
addEventHandler("onVehicleEnter", getRootElement(), inVEH) 
  
  
  
  
function warpit ( hitElement ) 
    if ( hitElement == localPlayer ) then 
    if isPedInVehicle ( thePlayer ) then 
        if ( getElementModel ( source ) == 420 ) then 
                destroyElement( markers [ thePlayer ] ) 
                    local vehicle = getPedOccupiedVehicle ( source ) 
                    if ( vehicle ) then 
                    warpPedIntoVehicle ( skins, vehicle, 2 ) 
                end 
            end 
        end 
    end 
end 
addEventHandler ( "onMarkerHit", ********markers[dropoffs]******, warpit ) 

The last line, is what i mean

Link to comment

Add a handler to the event "onMarkerHit" for each marker and in the function of that event ( "onMarkerHit" ), iterate through 'markers' array and check if the marker that was hit is the one you're checking.

Example:

for key, value in pairs( markers ) do 
    if ( source == value ) then 
        --your code here 
    end 
end 

Link to comment
for key, value in pairs( markers ) do 
    if ( source == value ) then 
            if ( hitElement == localPlayer ) then 
    if isPedInVehicle ( thePlayer ) then 
        if ( getElementModel ( source ) == 420 ) then 
                destroyElement( markers [ thePlayer ] ) 
                    local vehicle = getPedOccupiedVehicle ( source ) 
                    if ( vehicle ) then 
                    warpPedIntoVehicle ( skins, vehicle, 2 ) 
    end 
end 

That?

Link to comment

You have lots of 'end' missing. And your code doesn't make sense.

if isPedInVehicle ( thePlayer ) then 

First you use 'hitElement' and now you're using 'thePlayer'?

if ( getElementModel ( source ) == 420 ) then 

'source' is the marker.

destroyElement( markers [ thePlayer ] ) 

Again using 'thePlayer'...

local vehicle = getPedOccupiedVehicle ( source ) 

Again using 'source' but 'source' is the marker, not the player.

warpPedIntoVehicle ( skins, vehicle, 2 ) 

Where is 'skins' declared?

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