Jump to content

[Help]destroyElement..Tables


raynner

Recommended Posts

Hello good friends came to ask your help as I am with some mistakes and really tried everything within my knowledge moon more could not solve however identified some errors.

Well for starters I'm working on a trucker's job and he has a marker hit the player passes choose where you want to lead the charge. (if necessary see the Client-side report.)

server

cabineTrab = { } 
trailerTrab = { } 
markerEntrega = { } 
blipEntrega = { } 
money1 = { } 
----------------- 
function Saida1() 
        if isPedInVehicle(source) then 
                outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê Já Esta Com Um Veiculo, Venha Sem Um Vaiculo Em Posse", source, 255, 255, 255, true) 
        else 
                local x, y, z = getElementPosition(source) 
                cabineTrab[source] = createVehicle(515 , x - 5, y, z +1) 
                trailerTrab[source] = createVehicle(435, 0, 0, 4) 
                setElementRotation(cabineTrab[source],0,0,0 -45) 
                setElementRotation(trailerTrab[source],0,0,0 -45) 
                attachTrailerToVehicle(cabineTrab[source], trailerTrab[source]) 
                warpPedIntoVehicle(source, cabineTrab[source]) 
                money1[source] = 350 
                markerEntrega[source] = createMarker(-64, -1134, 0.5, "cylinder", 4, 255, 0, 0, 255, source) 
                blipEntrega[source] = createBlip(-64, -1134, 0.5, 53, 2, 255, 255, 255, 255, 0, 99999, source) 
                outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê Obteve Um Caminhão e Uma Carga Entrege No Ponto Marcado No Mapa.", source, 255, 255, 255, true) 
                ----- 
                addEventHandler("onMarkerHit", markerEntrega[source], Chegada) 
                addEventHandler("onVehicleExit", getRootElement(), ExitVehicle) 
                addEventHandler("onPlayerQuit", getRootElement(), onQuit) 
        end 
end   
addEvent( "TraB1", true ) 
addEventHandler( "TraB1", root, Saida1 ) 
------------------  
function Chegada(hitElement) 
     if (isElement(hitElement)) and (getElementType (hitElement) == "player") then 
        if(getVehicleTowedByVehicle(cabineTrab[hitElement] ) == trailerTrab[hitElement]) then 
                outputChatBox ("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê Trouxe a Carga e Recebeu Seu Pagamento.", hitElement, 255, 255, 255, true) 
                d1CabineC = destroyElement( cabineTrab[hitElement] ) 
                d1TrailerC = destroyElement( trailerTrab[hitElement] ) 
                destroyElement ( markerEntrega[hitElement] ) 
                destroyElement ( blipEntrega[hitElement] ) 
                givePlayerMoney ( hitElement, money1[hitElement] ) 
                ---- 
                removeEventHandler ("onVehicleExit", getRootElement(), Chegada) 
                removeEventHandler ("onVehicleExit", getRootElement(), ExitVehicle) 
                removeEventHandler ("onPlayerQuit", getRootElement(), onQuit) 
                if (d1CabineC and d1TrailerC) then 
                    cabineTrab[hitElement] = false 
                    trailerTrab[hitElement] = false 
                end 
        else 
                outputChatBox ("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê Não Trouxe  a Carga e Não Recebera Pela Viagem.", hitElement, 255, 255, 255, true) 
                d01CabineC = destroyElement( cabineTrab[hitElement] ) 
                d01TrailerC = destroyElement( trailerTrab[hitElement] ) 
                destroyElement ( markerEntrega[hitElement] ) 
                destroyElement ( blipEntrega[hitElement] ) 
                ---- 
                removeEventHandler ("onVehicleExit", getRootElement(), Chegada) 
                removeEventHandler ("onVehicleExit", getRootElement(), ExitVehicle) 
                removeEventHandler ("onPlayerQuit", getRootElement(), onQuit) 
                if (d01CabineC and d01TrailerC) then 
                    cabineTrab[hitElement] = false 
                    trailerTrab[hitElement] = false 
                end 
        end 
    else 
        return false 
    end 
end 
----------------------------------------------------------------------------------- 
function ExitVehicle(hitElement) 
    if (isElement(hitElement)) and (getElementType (hitElement) == "player") then 
        d2Cabine = destroyElement( cabineTrab[hitElement] ) 
        d2Trailer = destroyElement( trailerTrab[hitElement] ) 
        destroyElement ( markerEntrega[hitElement] ) 
        destroyElement ( blipEntrega[hitElement] ) 
        --- 
        removeEventHandler ("onVehicleExit", getRootElement(), Chegada) 
        removeEventHandler ("onVehicleExit", getRootElement(), ExitVehicle) 
        removeEventHandler ("onPlayerQuit", getRootElement(), onQuit) 
        if (d2Cabine and d2Trailer) then 
                cabineTrab[hitElement] = false 
                trailerTrab[hitElement] = false 
        end 
    else 
        return false 
    end 
end 
------- 
function onQuit() 
    if isElement(cabineTrab[source]) then 
        destroyElement ( cabineTrab[source] ) 
        destroyElement ( trailerTrab[source] ) 
        destroyElement ( markerEntrega[source] ) 
        destroyElement ( blipEntrega[source] ) 
        --- 
        removeEventHandler ("onVehicleExit", getRootElement(), Chegada) 
        removeEventHandler ("onVehicleExit", getRootElement(), ExitVehicle) 
        removeEventHandler ("onPlayerQuit", getRootElement(), onQuit) 
    end 
end 

mistakes that I have received in my cmd (Lines: 35,36,37,38 :Bad argument @ 'destroyElement' [Expected element at argument 1])

error I've noticed in test: this missing element specified removeEventHandler(.....).

Edited by Guest
Link to comment

Create tables

here's a guide I got while creating my trucking script.

For managing multiply data you need to use tables.

For example you start a job for a player.

    truckerJobData = {} -- declare on top of your script. 

When you start this job, you do this:

    truckerJobData[player] = {} 

You use the player as key of the table. Which is between the brackets > [ ].

The next step is to redeclare the table in a variable of choice: (this is just a method I like to use)

    local playerTruckerJobData = truckerJobData[player] 

After redeclaring the variable that gives access to the empty table, you are going to collect and create the data of the job. This can be the: truck, trailer, blip and marker.

  
  
    local finisha = createMarker (tableLocationsX[randomLoc], tableLocationsY[randomLoc], tableLocationsZ[randomLoc], "cylinder", 3, 0, 200, 55, 255, hitElementa) 
    local blip = createBlip (tableLocationsX[randomLoc], tableLocationsY[randomLoc], tableLocationsZ[randomLoc], 0, 2, 255, 0, 0, 255, 0, 10000, hitElementa) 
    local truckM = createVehicle(514, -715, 963, 12) 
    local trailer = createVehicle ( 435, 0, 0, 4 ) 

And the last step is to insert the required data of the job, inside your empty table.

    playerTruckerJobData["blip"] = blip 
    playerTruckerJobData["marker"] = finisha 
    playerTruckerJobData["truck"] =  truckM 
    playerTruckerJobData["trailer"] = trailer 

There are a few ways to do it, but try first this one, because it is easy to read.

Ones you did that, you can access your: trailers, trucks, blips and markers very easy.

The only thing you need to do is knowing the player/(player-userdata).

To access your trailer and destroy it, example:

   local playerTruckerJobData = truckerJobData[player] 
      
    if playerTruckerJobData then -- if the player have any job data then ... 
      
    local trailer = playerTruckerJobData["trailer"] -- then get the trailer element. 
      
    if isElement(trailer) then -- check if the trailer still does exist in the MTA world. 
    destroyElement(trailer) -- destroy the trailer. 
    end 
      
    end 

Replace what you need. But there's a basic guide from IIYAMA

Link to comment
Create tables

here's a guide I got while creating my trucking script.

For managing multiply data you need to use tables.

For example you start a job for a player.

Well somehow I made the incorrect use of tables? or not

and exchange [hitElement] by, hitElement does not work

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