Jump to content

Hello, I need a hand here I want that when the user dies or leaves the vehicle is destroyed but not .. happens already I put the function and nothing someone helps me in the error that I have?


Akranes123

Recommended Posts

local blip = createBlip ( 89.8653, -269.70767, 1.278, 58 )
local jobped = createPed ( 202, 122.80000305176, -296.20001220703, 1.6000000238419, 90.0041198 )
local getjobmarker = createMarker ( 122.69999694824, -294.29998779297, 0.60000002384186, "cylinder", 3, 255, 255, 0, 85 )
local destinations =
{
    { 1456, 2877.8999023438, 9.8000001907349 };
    { 2850.1000976563, 1209.8000488281, 9.6999998092651 };
    { 2827.1000976563, 1383.5, 9.8000001907349 };
    { 2495.5, 2773.3000488281, 9.8000001907349 };
    { -2130.6999511719, -80.099998474121, 34.299999237061 };
    { -2643.6000976563, 1373, 5.9000000953674 };
    { -2747.1000976563, -280, 6 };
    {  2339.97876, 2036.61914, 10.42309 };
    {  1069.39612, 1226.58252, 10.23718 };
}


function unpackDestinations ()
    return unpack ( destinations [ math.random ( #destinations ) ] )
end

addEventHandler("onResourceStart",getjobmarker,
function(p) 
    if p == lp and not isPedInVehicle(lp) then 
        guiSetVisible(getjobmarker,true) 
        showCursor(true) 
    end 
end)
-- Trucker Job GUI -- 
sx,sy = guiGetScreenSize()
lp = getLocalPlayer()
mr = math.random(1,2)
jobwindow = guiCreateWindow(360, 190, 333, 388, "Trucker Job", false)
guiWindowSetSizable(jobwindow, false)
guiSetAlpha(jobwindow, 1.00)
memo = guiCreateMemo(9, 18, 314, 224, "Hola, para ser un camionero debes hacer clic en el botón de aceptar a continuación, cuando aceptas el trabajo, debes ir al camión ubicado en el radar, cuando llegues, recibirás dinero. Si quiere dejar este trabajo, primero debe tener el trabajo, luego volver al marcador del trabajo del camionero y hará clic en el botón Salir del trabajo. Buena suerte.", false, jobwindow)
label1 = guiCreateLabel(4, 273, 329, 15, "________________________________________________________", false, jobwindow)
label = guiCreateLabel(10, 246, 252, 17, "ToRnix~|nR", false, jobwindow)
guiSetFont(label, "default-bold-small")
takebutton = guiCreateButton(14, 315, 140, 42, "Accept", false, jobwindow)
guiSetProperty(takebutton, "NormalTextColour", "FFAAAAAA")
cancbutton = guiCreateButton(180, 315, 137, 42, "Close", false, jobwindow)
guiSetProperty(cancbutton, "NormalTextColour", "FFAAAAAA")  
guiSetVisible (jobwindow,false)
guiMemoSetReadOnly(memo,true)
guiWindowSetMovable (jobwindow,true )
guiWindowSetSizable (jobwindow,false )
-- The Continue or Not Gui --
sx, sy = guiGetScreenSize()
lp = getLocalPlayer()
mr = math.random(1,2)
destinationwindow = guiCreateWindow(327, 219, 339, 365, "Trucker Job", false)
guiSetAlpha(destinationwindow, 1.00)
destinationmemo = guiCreateMemo(9, 18, 320, 227, "Oye, entonces con este gui, puedes elegir si quieres continuar con el trabajo del camionero o no, es tu elección,  :)", false, destinationwindow)
label1 = guiCreateLabel(9, 250, 283, 25, "¿Quieres continuar con el trabajo de camionero ?", false, destinationwindow)
guiSetFont(label1, "default-bold-small")
label2 = guiCreateLabel(0, 275, 334, 21, "_____________________________________________________________________", false, destinationwindow)
continue = guiCreateButton(17, 309, 138, 37, "Continue", false, destinationwindow)
guiSetProperty(continue, "NormalTextColour", "FFAAAAAA")
close = guiCreateButton(192, 308, 127, 38, "Close", false, destinationwindow)
guiSetProperty(close, "NormalTextColour", "FFAAAAAA")  
guiMemoSetReadOnly(destinationmemo, true)
guiWindowSetSizable(destinationwindow, false)
guiWindowSetMovable(destinationwindow, true)
guiSetVisible (destinationwindow, false)
--
addEventHandler("onClientGUIClick",jobwindow,
function(b,thePlayer)
    if b == "left" then
        if source == takebutton then
            outputChatBox ("Ahora eres camionero",255,255,0, true)
            outputChatBox ("Ahora vuelve al marcador para ir a trabajar",0,255,0, true)
            guiSetVisible(jobwindow,false)
            guiSetVisible(takebutton,false)
            triggerServerEvent ( "doSomething", lp)
            showCursor(false)
            --
            onduty = guiCreateButton(14, 288, 303, 27, "Go On Duty", false, jobwindow)
            guiSetProperty(onduty, "NormalTextColour", "FFAAAAAA")    
            --
            quitbutton = guiCreateButton(14, 315, 140, 42, "Quit", false, jobwindow)
            guiSetProperty(quitbutton, "NormalTextColour", "FFAAAAAA")
            --
            end
        end
    end
)

addEventHandler("onClientGUIClick",jobwindow,
function(b,thePlayer)
    if b == "left" then
        if source == cancbutton then
        guiSetVisible(jobwindow,false)
        showCursor(false)
    end
  end
end)

addEventHandler("onClientGUIClick",jobwindow,
function(b,thePlayer)
    if b == "left" then
        if source == quitbutton then
        outputChatBox ("Ya no eres camionero",255,0,0, true)
        guiSetVisible(jobwindow,false)
        guiSetVisible(quitbutton,false)
        guiSetVisible(onduty,false)
        guiSetVisible(offduty,false)
        guiSetVisible(cancbutton,true)
        guiSetVisible(takebutton,true)
        triggerServerEvent ( "doSomethin", lp)
        showCursor(false)
        destroyElement ( truckerMarker )
        destroyElement ( truckerBlip )
    end
  end
end)
    
addEventHandler("onClientGUIClick",jobwindow,
function(b,thePlayer)
    if b == "left" then
        if source == onduty then
        outputChatBox ("Ahora está de servicio, regrese en el marcador para irse de servicio",source,0,255,0, true)
        triggerServerEvent ( "HaveTruckerJob", lp)
        triggerServerEvent ( "sum", lp)
        guiSetVisible(jobwindow,false)
        guiSetVisible(quitbutton,true)
        guiSetVisible(takebutton,false)
        guiSetVisible(offduty,true)
        guiSetVisible(onduty,false)
        guiSetVisible(cancbutton,true)
        showCursor(false)
        --
        offduty = guiCreateButton(14, 288, 303, 27, "Salir de servicio", false, jobwindow)
        guiSetProperty(offduty, "NormalTextColour", "FFAAAAAA")
        --
        end
    end
end)

addEventHandler("onClientGUIClick",jobwindow,
function(b,thePlayer)
    if b == "left" then
        if source == offduty then
        outputChatBox ("Ahora estás fuera de servicio, regresa en el marcador para ir a trabajar",source,255,0,0, true)
        guiSetVisible(jobwindow,false)
        guiSetVisible(quitbutton,true)
        guiSetVisible(takebutton,false)
        guiSetVisible(offduty,false)
        guiSetVisible(onduty,true)
        guiSetVisible(cancbutton,true)
        showCursor(false)
        destroyElement ( truckerMarker )
        destroyElement ( truckerBlip )
        end
    end
end)
        
addEventHandler("onClientMarkerHit",getjobmarker,
    function(p)
        if p == lp and not isPedInVehicle(lp) then
            guiSetVisible(jobwindow,true)
            showCursor(true)
        end
    end
)

addEvent("HaveTruckerJob", true)
function createDestinations ()
    x, y, z = unpackDestinations ()
    truckerMarker = createMarker ( x, y, z, "cylinder", 3, 255, 51, 102, 85, localPlayer )
    truckerBlip = createBlipAttachedTo ( truckerMarker, 51,nil, nil, nil, nil, nil, nil, nil, localPlayer )
end
addEventHandler ( "HaveTruckerJob", root, createDestinations )

addEventHandler ( "onClientMarkerHit", root,
    function ( hitElement )
        if source == truckerMarker and localPlayer == hitElement  then
        local vehicle = getPedOccupiedVehicle ( localPlayer )
        if vehicle and getElementModel(vehicle) == 514 then
            triggerServerEvent ( "givePlayerPay", localPlayer )
            destroyElement ( truckerMarker )
 
            if isElement(truckerBlip) then -- very important
            destroyElement ( truckerBlip )
end
 
            guiSetVisible(destinationwindow,true)
            showCursor(true)
            triggerEvent ( "createTruckerEvent", localPlayer )
        end
    end
end)

addEventHandler ( "onClientPedDamage", resourceRoot,
    function ()
        cancelEvent ()
    end
)

function exitforcar ( )
     if isElement(truckerBlip) then -- very important
            destroyElement ( truckerBlip )
    end

    if isElement(truckerMarker) then
            destroyElement ( truckerMarker )
    end
end
addEventHandler ( "onClientPlayerVehicleExit", root, exitforcar )
-------------------------------
function wastedd ( )
    
     if isElement(truckerBlip) then -- very important
            destroyElement ( truckerBlip )
    end

    if isElement(truckerMarker) then
            destroyElement ( truckerMarker )
    end
end
addEventHandler ( "OnClientPlayerWasted", getRootElement(), wastedd )

-- Destination Functions --
    
addEventHandler("onClientGUIClick",destinationwindow,
function(b,thePlayer)
    if b == "left" then
        if source == continue then
            x, y, z = unpackDestinations ()
            truckerMarker = createMarker ( x, y, z, "cylinder", 3, 255, 51, 102, 85, localPlayer )
            truckerBlip = createBlipAttachedTo ( truckerMarker, 51,nil, nil, nil, nil, nil, nil, nil, localPlayer )
            guiSetVisible(destinationwindow,false)
            showCursor(false)
            elseif source == close then
            guiSetVisible(destinationwindow,false)
            showCursor(false)
        end
    end
end)
Link to comment
(Sorry if my English came out "wrong" I'm Brazilian and I don't speak fluent)
The problem I found there was:
In this roadmap I do not see any createVehicle soon the onClientPlayerVehicleExit will be called when you leave any vehicle, you should make a comparison if the source that has chained the event is the truck
Example:
Truck = createVehicle (523,x,y,z)

function exitforcar (Vehicle)
  if Vehicle == Truck then
     if isElement(truckerBlip) then destroyElement ( truckerBlip ) end
     if isElement(truckerMarker) then destroyElement ( truckerMarker ) end
  end
end
addEventHandler ( "onClientPlayerVehicleExit", root, exitforcar )
Edited by W4LK1NG
Link to comment
car = {}
car[1] = createVehicle(411, x, y, z) -- Example

Markers = {}
Markers[1] = createMarker(z, y, z, "cylinder", 1.5, 255, 255, 0) --Example
Blips = {}
Blips[1] = createBlipAttachedTo(Markers[1], 54) -- Example

function exitforcar (player, seat)
	if(getElementModel(source) == 411) then
		if player == localPlayer and seat == 0 then
			for i, v in ipairs(car)do
				if isElement(v)then
					destroyElement(v)
				end
			end	
			for i, maker in ipairs(Markers)do
				if isElement(maker)then
					destroyElement(maker)
				end
			end	
			for i, blip in ipairs(Blips)do
				if isElement(blip) then
					destroyElement(blip)
				end	
			end	
		end	
	end		
end
addEventHandler ("onClientVehicleExit", root, exitforcar )

 

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