Lloyd Logan Posted January 23, 2013 Share Posted January 23, 2013 Hi, How do i make it so that when a player leaves the vehicle an element is destroyed? The preoblem is I have created the marker and blip within another function, and I want them to be there. So i can't use onVehicleExit. Any Ideas? function inVEH() if ( getElementModel ( source ) == 420 ) then local x, y, z = unpack ( dropoffs [ math.random ( #dropoffs ) ] ) callum = createMarker ( x, y, z, "cylinder", 1.5, 255, 0, 0 ) john = createBlipAttachedTo ( callum, 41 ) else destroyElement(callum) destroyElement(john) end end addEventHandler("onVehicleEnter", getRootElement(), inVEH) Link to comment
Castillo Posted January 23, 2013 Share Posted January 23, 2013 markers = { } blips = { } function inVEH ( player ) if ( getElementModel ( source ) == 420 ) then local x, y, z = unpack ( dropoffs [ math.random ( #dropoffs ) ] ) markers [ player ] = createMarker ( x, y, z, "cylinder", 1.5, 255, 0, 0 ) blips [ player ] = createBlipAttachedTo ( markers [ player ], 41 ) else if ( isElement ( markers [ player ] ) ) then destroyElement ( markers [ player ] ) end if ( isElement ( blips [ player ] ) ) then destroyElement ( blips [ player ] ) end end end addEventHandler ( "onVehicleEnter", getRootElement(), inVEH ) function outVEH ( player ) if ( getElementModel ( source ) == 420 ) then if ( isElement ( markers [ player ] ) ) then destroyElement ( markers [ player ] ) end if ( isElement ( blips [ player ] ) ) then destroyElement ( blips [ player ] ) end end end addEventHandler ( "onVehicleExit", getRootElement(), outVEH ) Link to comment
Lloyd Logan Posted January 23, 2013 Author Share Posted January 23, 2013 markers = { } blips = { } function inVEH ( player ) if ( getElementModel ( source ) == 420 ) then local x, y, z = unpack ( dropoffs [ math.random ( #dropoffs ) ] ) markers [ player ] = createMarker ( x, y, z, "cylinder", 1.5, 255, 0, 0 ) blips [ player ] = createBlipAttachedTo ( markers [ player ], 41 ) else if ( isElement ( markers [ player ] ) ) then destroyElement ( markers [ player ] ) end if ( isElement ( blips [ player ] ) ) then destroyElement ( blips [ player ] ) end end end addEventHandler ( "onVehicleEnter", getRootElement(), inVEH ) function outVEH ( player ) if ( getElementModel ( source ) == 420 ) then if ( isElement ( markers [ player ] ) ) then destroyElement ( markers [ player ] ) end if ( isElement ( blips [ player ] ) ) then destroyElement ( blips [ player ] ) end end end addEventHandler ( "onVehicleExit", getRootElement(), outVEH ) Thanks so much Castillo! Link to comment
Lloyd Logan Posted January 24, 2013 Author Share Posted January 24, 2013 markers = { } blips = { } function inVEH ( player ) if ( getElementModel ( source ) == 420 ) then local x, y, z = unpack ( dropoffs [ math.random ( #dropoffs ) ] ) markers [ player ] = createMarker ( x, y, z, "cylinder", 1.5, 255, 0, 0 ) blips [ player ] = createBlipAttachedTo ( markers [ player ], 41 ) else if ( isElement ( markers [ player ] ) ) then destroyElement ( markers [ player ] ) end if ( isElement ( blips [ player ] ) ) then destroyElement ( blips [ player ] ) end end end addEventHandler ( "onVehicleEnter", getRootElement(), inVEH ) function outVEH ( player ) if ( getElementModel ( source ) == 420 ) then if ( isElement ( markers [ player ] ) ) then destroyElement ( markers [ player ] ) end if ( isElement ( blips [ player ] ) ) then destroyElement ( blips [ player ] ) end end end addEventHandler ( "onVehicleExit", getRootElement(), outVEH ) Can I ask what the blips = { } markers = { } mean? I don't understand them or them in the script? Thanks Lloyd Link to comment
Castillo Posted January 24, 2013 Share Posted January 24, 2013 These are tables, later used to store the marker elements using player as table index. Link to comment
Lloyd Logan Posted January 24, 2013 Author Share Posted January 24, 2013 These are tables, later used to store the marker elements using player as table index. Ahh okay, thanks! Link to comment
Lloyd Logan Posted January 24, 2013 Author Share Posted January 24, 2013 These are tables, later used to store the marker elements using player as table index. I done this... server markers = { } blip = { } function inVEH(thePlayer) if isPedInVehicle ( thePlayer ) then if ( getElementModel ( source ) == 420 ) then local x, y, z = unpack ( dropoffs [ math.random ( #dropoffs ) ] ) markers [ player ] = createMarker ( x, y, z, "cylinder", 3.5, 255, 0, 0 ) local skins = unpack ( pedCus [ math.random ( #pedCus ) ] ) createPed( skins, x, y, z ) blip [ player ] = createBlipAttachedTo ( markers, 41 ) else destroyElement( markers [ player ] ) destroyElement( john [ player ] ) end end end addEventHandler("onVehicleEnter", getRootElement(), inVEH) And it says 48 table index is nil Link to comment
Castillo Posted January 24, 2013 Share Posted January 24, 2013 There's no table called "john". Link to comment
Lloyd Logan Posted January 24, 2013 Author Share Posted January 24, 2013 There's no table called "john". ..Here is what I've done now, the very last line, how to i get the random marker when it is hit? 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 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 ( 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, warpit ) Link to comment
Castillo Posted January 24, 2013 Share Posted January 24, 2013 I don't really understand what do you want. addEventHandler ( "onMarkerHit", markers, warpit ) should be after the marker is created, but with the player index, like: markers [ player ] Link to comment
Lloyd Logan Posted January 24, 2013 Author Share Posted January 24, 2013 I don't really understand what do you want. addEventHandler ( "onMarkerHit", markers, warpit ) should be after the marker is created, but with the player index, like: markers [ player ] Thats what i done, addEventHandler("onMarkerHit", markers [ player ], warpit) But it says that it expected element, got table, i want the random marker that was created in the table.. When that is hit, any sense of what I am on about? Link to comment
Castillo Posted January 24, 2013 Share Posted January 24, 2013 Post the full script ( don't use spoiler, it annoys me ). Link to comment
Lloyd Logan Posted January 24, 2013 Author Share Posted January 24, 2013 Don't use spoiler, it annoys me. Haha! I tried to do that for your own good, . Just in case yu didn't want to keep scrolling and scrolling 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 ( 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 ( pickups [ math.random ( #pickups ) ] ) 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, warpit ) It's an extremely simple question I am trying to ask, but I just don't know how to put it. Link to comment
Castillo Posted January 24, 2013 Share Posted January 24, 2013 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 = { 9, 10, 14, 15, 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 = { } peds = { } function inVEH(thePlayer) if 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 ) addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) local skin = unpack ( pedCus [ math.random ( #pedCus ) ] ) peds [ thePlayer ] = createPed( skin, 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 ( 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 ] ) end if ( isElement ( blips [ thePlayer ] ) ) then destroyElement( blips [ thePlayer ] ) end warpPedIntoVehicle ( peds [ thePlayer ], vehicle, 2 ) end end end Link to comment
Lloyd Logan Posted January 24, 2013 Author Share Posted January 24, 2013 Okay, see that very last function, I wan't that so it is onMarkerHit, is triggered when, (if you look back I created a random marker), that marker is hit, Problem is it is in a table and in a different function Link to comment
Castillo Posted January 24, 2013 Share Posted January 24, 2013 I really don't get anything of what you said. Link to comment
Lloyd Logan Posted January 24, 2013 Author Share Posted January 24, 2013 I really don't get anything of what you said. Shit! Right, I created a table of markers 1. the i done this marker = { } 2. i then made a random marker from the marker table and now it is in marker = { } 3. the marker is now created in function createmarker 4. but i want to do onMarkerHit of the random marker but the marker i created is in a different function (createmarker)( see 2. and 3.) 5. Now i do onMarkerHit but how do i get the random marker that was created? Your normal one would be castillo = createMarker(blah) addEventHandler("onMarkerHit", castillo --the marker, (thefunctionhere) But my marker was create randomly and is in a table, how do i get what was created and put it into the onMarkerHit? Link to comment
Castillo Posted January 24, 2013 Share Posted January 24, 2013 But I already added the event handler attached to the random marker created, just after createMarker you can see: addEventHandler ( "onMarkerHit", markers [ thePlayer ], warpit ) 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