Jump to content

Yet another error "Same script"[Solved]


Captain Cody

Recommended Posts

  • Moderators

Small update on the endTheMission.

function endTheMission (truckMain,matchingDimension) 
    if matchingDimension then 
        local playerAb = getVehicleOccupant(truckMain) 
        if playerAb then 
            local playerTruckerJobData = truckerJobData[playerAb] 
            if playerTruckerJobData and playerTruckerJobData["vehicle"] == truckMain and playerTruckerJobData["marker"] == source  then -- Check if all data is correct. 
                 
                outputDebugString("endTheMission") 
                local randomMoney = (tonumber(tableMoney[randomLoc]) or 0) 
                outputChatBox ("This load got you " .. randomMoney .. "$ If you would like to continue head back to one of the trucking depos.", playerAb, 255, 255, 255, true) 
                givePlayerMoney (playerAb, randomMoney) 
                setPlayerTeam ( playerAb, NoJob ) 
                 
                ------------------ 
                -- the clean up -- 
                local trailerAb = playerTruckerJobData["trailer"] 
                local blip = playerTruckerJobData["blip"] 
                 
                --removeEventHandlers 
                removeEventHandler ("onVehicleExit", truckMain, vehicleExit) 
                removeEventHandler ("onPlayerQuit", playerAb, onQuit) 
                removeEventHandler ("onMarkerHit", source , endTheMission) 
                 
                --destroyThings 
                if isElement(trailerAb) then -- validate(if is still exist) before destroy 
                    destroyElement (trailerAb) 
                end 
                if isElement(blip) then -- validate(if is still exist) before destroy 
                    destroyElement (blip) 
                end 
                 
                destroyElement(source) -- destroy the marker, no validate needed. (element used in event, so must exist) 
                 
                destroyElement(truckMain) -- destroy the truck, no validate needed. (element used in event, so must exist) 
                 
                truckerJobData[playerAb] = nil -- clean up 
                -- the clean up -- 
                ------------------ 
            end 
        end 
    end 
end 

The onQuit function.

function onQuit () 
    local playerTruckerJobData = truckerJobData[source] 
    if playerTruckerJobData then 
        --destroyThings 
        local truckMain = playerTruckerJobData["vehicle"] 
        local trailerAb = playerTruckerJobData["trailer"] 
        local finishPoint = playerTruckerJobData["marker"] 
        local blip = playerTruckerJobData["blip"] 
  
        --removeEventHandlers 
        removeEventHandler ("onVehicleExit", truckMain, vehicleExit) 
        removeEventHandler ("onPlayerQuit", source, onQuit) 
        removeEventHandler ("onMarkerHit", finishPoint , endTheMission) 
         
        if isElement(trailerAb) then -- validate(if is still exist) before destroy 
            destroyElement (trailerAb) 
        end 
        if isElement(finishPoint) then -- validate(if is still exist) before destroy 
            destroyElement (finishPoint) 
        end 
        if isElement(blip) then -- validate(if is still exist) before destroy 
            destroyElement(blip) 
        end 
        if isElement(truckMain) then -- validate(if is still exist) before destroy 
            destroyElement(truckMain) 
        end 
        truckerJobData[source] = nil 
    end 
end 

The rest you have to do on your own. You have enough inspiration material now.

Link to comment

Here's the whole server side script, any idea what's wrong with it?

  
--//Tables and other stuff 
    tableLocationsX = {} 
    tableLocationsY = {} 
    tableLocationsZ = {} 
    trailerType = {} 
    truckerJobData = {}  
  
  
--//Cords for Blip 
    BlipX = -241.99414 
    BlipY = -226.80957 
    BlipZ = 2.1505408 
     
--//Cords for Trailer 
    TrailerX = -208.95801 
    TrailerY = -211.38281 
    TrailerZ = 1.421875 
    TrailerRotation = 0 
     
--//Cords for Blip/Marker 
    MarkerX = -227.02539 
    MarkerY = -243.80469 
    MarkerZ =  1.421875 
  
    tableMoney = {} 
  
    locationCount = 3 
     
  
  
--//Location 1 
    tableLocationsX[1] = 2253.7 
    tableLocationsY[1] = -84.0 
    tableLocationsZ[1] = 25.3 
    tableMoney[1] = 500 
    trailerType[1] = 500 
  
--//Location 2 
    tableLocationsX[2] = 1093.7 
    tableLocationsY[2] = -931.6 
    tableLocationsZ[2] = 41.9 
    tableMoney[2] = 550 
    trailerType[2] = 500 
  
--//Location3 
    tableLocationsX[3] = -47.3 
    tableLocationsY[3] = -1137.5 
    tableLocationsZ[3] = 0.07 
    tableMoney[3] = 500 
    trailerType[3] = 500 
     
function startScript () 
    StartBlip = createBlip (MarkerX , MarkerY , MarkerZ , 42 ) 
    setBlipVisibleDistance(StartBlip, 220) 
    addEvent( "startTheMission", true ) 
    rootElement = getRootElement() 
    addEventHandler ("startTheMission", rootElement, startMission) 
    TruckDriverAA = getTeamFromName("Trucker") 
    NoJob = getTeamFromName("Unemployed") 
end 
  
function startMission ()  
--Pick up Trailer and start job marker  
    markerAAB = createMarker ( MarkerX , MarkerY , MarkerZ ) 
    addEventHandler ("onMarkerHit", markerAAB, startMissionAAA) 
end 
  
function startMissionAAA ( hitElement ) 
if getElementType ( hitElement ) == "vehicle" and getVehicleOccupant ( hitElement ) 
    then 
        local truckMain = hitElement 
         playerAb = getVehicleOccupant ( hitElement ) 
            truckerJobData[playerAb] = {} 
            local playerTruckerJobData = truckerJobData[playerAb] 
            local TrailerAb = createVehicle (435, TrailerX, TrailerY, TrailerZ, 0, TrailerRotation, trailerType[randomLoc]) 
            setVehicleVariant (TrailerAb, 5, 0) 
            attachTrailerToVehicle ( truckMain, TrailerAb ) 
            setPlayerTeam ( playerAb, TruckDriverAA ) 
            destroyElement (markerAAB) 
            
            --Location stuff-- 
            local randomLoc = math.random (1, locationCount) 
            local finishPoint = createMarker (tableLocationsX[randomLoc], tableLocationsY[randomLoc], tableLocationsZ[randomLoc], "cylinder", 3, 0, 200, 55, 255, playerAb) 
            local blip = createBlip (tableLocationsX[randomLoc], tableLocationsY[randomLoc], tableLocationsZ[randomLoc], 0, 2, 255, 0, 0, 255, 0, 10000, playerAb) 
            --Chat Stuff-- 
            outputChatBox ("Drive to the red blip on the map", playerAb, 255, 255, 255, true) 
            --addEventHandlers 
            addEventHandler ("onVehicleExit", truckMain, vehicleExit) 
            addEventHandler ("onMarkerHit", finishPoint , endTheMission) 
            addEventHandler ("onPlayerQuit", playerAb, onQuit) 
            --Add the stuff into table-- 
            playerTruckerJobData["vehicle"] = truckMain 
            playerTruckerJobData["blip"] = blip 
            playerTruckerJobData["marker"] = finishPoint 
            playerTruckerJobData["trailer"] = TrailerAb 
        else 
            return false 
        end 
    end 
  
function destroyVehicle () 
    if destroyTimer then 
        local playerTruckerJobData = truckerJobData[source] 
        if playerTruckerJobData then 
            --destroyThings 
            local truckMain = playerTruckerJobData["vehicle"] 
            local trailerAb = playerTruckerJobData["trailer"] 
            local finishPoint = playerTruckerJobData["marker"] 
            local blip = playerTruckerJobData["blip"] 
      
            --removeEventHandlers 
            removeEventHandler ("onVehicleExit", truckMain, vehicleExit) 
            removeEventHandler ("onPlayerQuit", source, onQuit) 
            removeEventHandler ("onMarkerHit", finishPoint , endTheMission) 
            
            if isElement(trailerAb) then -- validate(if is still exist) before destroy 
                destroyElement (trailerAb) 
            end 
            if isElement(finishPoint) then -- validate(if is still exist) before destroy 
                destroyElement (finishPoint) 
            end 
            if isElement(blip) then -- validate(if is still exist) before destroy 
                destroyElement(blip) 
            end 
            if isElement(truckMain) then -- validate(if is still exist) before destroy 
                destroyElement(truckMain) 
            end 
            truckerJobData[source] = nil 
        end 
    end 
    end 
         
function vehicleExit (PlayerAb) 
local playerTruckerJobData = truckerJobData[player] 
if playerTruckerJobData then 
--destroyThings 
local truckMain = playerTruckerJobData["vehicle"] 
if source == truckMain then 
outputChatBox ("Go back to the truck within a minute", PlayerAb, 255, 255, 255, true) 
destroyTimer = setTimer (destroyVehicle, 600000, 1) 
addEventHandler ("onVehicleEnter", truckMain, destrTimer) 
        else 
        return false 
    end 
end 
end 
  
function destrTimer (thePlayer) 
local playerTruckerJobData = truckerJobData[player] 
if playerTruckerJobData then 
 --destroyThings 
local truckMain = playerTruckerJobData["vehicle"] 
    if source == truckMain and thePlayer == playerAb then 
        local team = getPlayerTeam (thePlayer) 
        if getTeamName (team) == "Other" or getTeamName (team) == "Police" then 
            return false 
        else 
            killTimer (destroyTimer) 
            removeEventHandler ("onVehicleEnter", truckMain, destrTimer) 
            setVehicleLocked (truckMain, true) 
        end 
        else 
        return false 
    end 
end 
end 
  
    function onQuit () 
        local playerTruckerJobData = truckerJobData[source] 
        if playerTruckerJobData then 
            --destroyThings 
            local truckMain = playerTruckerJobData["vehicle"] 
            local trailerAb = playerTruckerJobData["trailer"] 
            local finishPoint = playerTruckerJobData["marker"] 
            local blip = playerTruckerJobData["blip"] 
      
            --removeEventHandlers 
            removeEventHandler ("onVehicleExit", truckMain, vehicleExit) 
            removeEventHandler ("onPlayerQuit", source, onQuit) 
            removeEventHandler ("onMarkerHit", finishPoint , endTheMission) 
            
            if isElement(trailerAb) then -- validate(if is still exist) before destroy 
                destroyElement (trailerAb) 
            end 
            if isElement(finishPoint) then -- validate(if is still exist) before destroy 
                destroyElement (finishPoint) 
            end 
            if isElement(blip) then -- validate(if is still exist) before destroy 
                destroyElement(blip) 
            end 
            if isElement(truckMain) then -- validate(if is still exist) before destroy 
                destroyElement(truckMain) 
            end 
            truckerJobData[source] = nil 
        end 
    end 
  
       function endTheMission ( hitElement )  
       if getElementType ( hitElement ) == "Vehicle" 
       then 
       local playerAbb = getVehicleOccupant ( hitElement ) 
       local playerTruckerJobData = truckerJobData[playerAbb] 
       local truckMain = playerTruckerJobData["vehicle"] 
        if getElementType ( hitElement ) == "truckMain" then 
                if playerTruckerJobData and playerTruckerJobData["marker"] == source  then -- Check if all data is correct. 
                    outputDebugString("endTheMission") 
                    local randomMoney = (tonumber(tableMoney[randomLoc])) 
                    outputChatBox ("This load got you " .. randomMoney .. "$ If you would like to continue head back to one of the trucking depos.", playerAbb, 255, 255, 255, true) 
                    givePlayerMoney (playerAbb, randomMoney) 
                    setPlayerTeam ( playerAbb, NoJob ) 
                    
                    ------------------ 
                    -- the clean up -- 
                    local trailerAb = playerTruckerJobData["trailer"] 
                    local blip = playerTruckerJobData["blip"] 
                    
                    --removeEventHandlers 
                    removeEventHandler ("onVehicleExit", truckMain, vehicleExit) 
                    removeEventHandler ("onPlayerQuit", playerAb, onQuit) 
                    removeEventHandler ("onMarkerHit", source , endTheMission) 
                    
                    --destroyThings 
                    if isElement(trailerAb) then -- validate(if is still exist) before destroy 
                        destroyElement (trailerAb) 
                    end 
                    if isElement(blip) then -- validate(if is still exist) before destroy 
                        destroyElement (blip) 
                    end 
                    
                    destroyElement(source) -- destroy the marker, no validate needed. (element used in event, so must exist) 
                    
                    
                    truckerJobData[playerAb] = nil -- clean up 
                    -- the clean up -- 
                    ------------------ 
                end 
            end 
        end 
    end 
  
  
addEventHandler ("onResourceStart", getResourceRootElement(getThisResource()), startScript) 

-- Client side button push creates marker--

--Person hits marker in vehicle "Truck"--

--It detects the truck and player--

--Attaches trailer to the truck--

--Delivery blip and marker apear--

--Person delivers trailer to location--

--It gives the player cash, then removes trailer, blip, marker etc.

----Debug script = attempt to index local "PlayerTruckJobData (A nil Value)

Link to comment

That worked, but do you know the issue with the on vehicle leave --

"All the script that's connected to on vehicle leave"

function destroyVehicle () 
    if destroyTimer then 
        local playerTruckerJobData = truckerJobData[source] 
        if playerTruckerJobData then 
            --destroyThings 
            local truckMain = playerTruckerJobData["vehicle"] 
            local trailerAb = playerTruckerJobData["trailer"] 
            local finishPoint = playerTruckerJobData["marker"] 
            local blip = playerTruckerJobData["blip"] 
      
            --removeEventHandlers 
            removeEventHandler ("onVehicleExit", truckMain, vehicleExit) 
            removeEventHandler ("onPlayerQuit", source, onQuit) 
            removeEventHandler ("onMarkerHit", finishPoint , endTheMission) 
            
            if isElement(trailerAb) then -- validate(if is still exist) before destroy 
                destroyElement (trailerAb) 
            end 
            if isElement(finishPoint) then -- validate(if is still exist) before destroy 
                destroyElement (finishPoint) 
            end 
            if isElement(blip) then -- validate(if is still exist) before destroy 
                destroyElement(blip) 
            end 
            if isElement(truckMain) then -- validate(if is still exist) before destroy 
                destroyElement(truckMain) 
            end 
            truckerJobData[source] = nil 
            end 
        end 
    end 
         
function vehicleExit (PlayerAb) 
local playerTruckerJobData = truckerJobData[player] 
if playerTruckerJobData then 
--destroyThings 
local truckMain = playerTruckerJobData["vehicle"] 
if source == truckMain then 
outputChatBox ("Go back to the truck within a minute", PlayerAb, 255, 255, 255, true) 
destroyTimer = setTimer (destroyVehicle, 600000, 1) 
addEventHandler ("onVehicleEnter", truckMain, destrTimer) 
        else 
        return false 
    end 
end 
end 
  
function destrTimer (thePlayer) 
local playerTruckerJobData = truckerJobData[player] 
if playerTruckerJobData then 
 --destroyThings 
local truckMain = playerTruckerJobData["vehicle"] 
    if source == truckMain and thePlayer == playerAb then 
        local team = getPlayerTeam (thePlayer) 
        if getTeamName (team) == "Other" or getTeamName (team) == "Police" then 
            return false 
        else 
            killTimer (destroyTimer) 
            removeEventHandler ("onVehicleEnter", truckMain, destrTimer) 
            setVehicleLocked (truckMain, true) 
        end 
        else 
        return false 
    end 
end 
end 

Link to comment
  • Moderators

Typo:

function vehicleExit (PlayerAb) 
local playerTruckerJobData = truckerJobData[player] 
function vehicleExit (PlayerAb) 
local playerTruckerJobData = truckerJobData[PlayerAb] 

Add argument of the player.

destroyTimer = setTimer (destroyVehicle, 600000, 1) 
local destroyTimer = setTimer (destroyVehicle, 600000, 1,PlayerAb) 

insert the timer >destroyTimer< into playerTruckerJobData.

playerTruckerJobData["timer"] = destroyTimer 

So every player has his own timer.

Timers don't support a source element, replace like this:

function destroyVehicle (PlayerAb) 
-- 
local playerTruckerJobData = truckerJobData[PlayerAb] 
-- 
removeEventHandler ("onPlayerQuit", PlayerAb, onQuit) 
-- 
truckerJobData[PlayerAb] = nil 
  

How do I get this PlayerAb there? Like this:

local destroyTimer = setTimer (destroyVehicle, 600000, 1,[color=#FF0000]PlayerAb[/color]) 

function destroyVehicle ([color=#FF0000]PlayerAb[/color]) 

Link to comment

Or so I thought

function destroyVehicle (PlayerAb) 
        local playerTruckerJobData = truckerJobData[playerAb] 
            --destroyThings 
            local truckMain = playerTruckerJobData["vehicle"] 
            local trailerAb = playerTruckerJobData["trailer"] 
            local finishPoint = playerTruckerJobData["marker"] 
            local blip = playerTruckerJobData["blip"] 
            --removeEventHandlers 
            removeEventHandler ("onVehicleExit", truckMain, vehicleExit) 
            removeEventHandler ("onPlayerQuit", playerAb, onQuit) 
            removeEventHandler ("onMarkerHit", finishPoint , endTheMission) 
            destroyElement (trailerAb) 
            destroyElement (finishPoint) 
            destroyElement(blip) 
            truckerJobData[playerAb] = nil 
        end 
    end 
end 

Gives me debug, expected -> End of script at line "125" the end of this.

Link to comment

ok that fixed it, but another question how would I go about adding money to the total pay if the mission were illegal

here's what defines if he did legal mission or not -

when he enters the Illegal marker

playerTruckerJobData["Illegal"] = true 

Here's what increases the pay

local payaddon = if playerTruckerJobData["Illegal"] = true then 5000 else 0 

Did not do the increase pay right, but I'm not sure how to accually do it.

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