Jump to content

Busjob errors


ViRuZGamiing

Recommended Posts

Hi,

This is my code and I've got this errors:

[18:28:07] WARNING: busjob\busjob.lua:63: Bad argument @ 'getPedOccupiedVehicle' 
  
[18:28:07] WARNING: busjob\busjob.lua:64: Bad argument @ 'getElementModel' [Expe 
cted element at argument 1, got boolean] 
[18:28:07] WARNING: busjob\busjob.lua:66: Bad argument @ 'getElementData' [Expec 
ted element at argument 1, got string 'Quit'] 
[18:28:07] ERROR: busjob\busjob.lua:67: attempt to compare number with boolean 

local rootElement = getRootElement() 
local busses = {[431] = true, [437] = true} 
local busTable = { 
[1]={-2457.8000488281, 1356.8000488281, 6},[2]={-2719.1999511719, 1205, 53.599998474121},[3]={-2753.3000488281, 570.70001220703, 13.300000190735},[4]={1038.74, -1712.84, 13.4254},[5]={1037.64, -1558.29, 13.3862}, 
[6]={1061.46, -1443.02, 13.4006},[7]={1051.46, -1396.45, 13.4565},[8]={825.122, -1395.14, 13.3444},[9]={648.371, -1395.33, 13.3444},[10]={635.96, -1252.67, 17.1576}, 
[11]={554.18, -1122.47, 27.2105},[12]={238.52, -1170.34, 19.5841},[13]={-43.18, -1354.07, 11.2299},[14]={-284.8, -1642.00, 15.5116},[15]={-354.4, -1831.65, 22.2320}, 
[16]={-348.6, -2125.50, 28.3879},[17]={-174.6, -2413.64, 35.6235},[18]={-36.62, -2711.40, 42.0042},[19]={-315.0, -2800.08, 57.5757},[20]={-757.3, -2764.34, 74.7090}, 
[21]={-1141, -2850.020, 67.7570},[22]={-1569, -2742.080, 48.5795},[23]={-1966, -2547.510, 38.2349},[24]={-2191, -2370.410, 30.5065},[25]={-2212, -2264.740, 30.5055}, 
[26]={-2102, -2078.130, 63.1302},[27]={-1820, -1726.650, 29.1070},[28]={-1400, -1648.350, 45.1570},[29]={-1144, -1899.890, 77.5020},[30]={-802.3, -1785.11, 92.2070}, 
[31]={-758.6, -1454.05, 87.8020},[32]={-652.7, -1420.18, 90.4095},[33]={-572.8, -1070.35, 23.5500},[34]={-372.0, -823.054, 28.4015},[35]={-189.6, -938.291, 35.3530}, 
[36]={-55.70, -858.507, 13.7823},[37]={-113.0, -402.609, 1.10380},[38]={-221.9, 187.8397, 8.88888},[39]={-63.88, 551.1700, 9.22222},[40]={323.85, 753.2600, 6.15222}, 
[41]={740.54, 657.1210, 10.7505},[42]={1099.8, 803.8835, 10.7070},[43]={1556.6, 831.4191, 6.80807},[44]={1785.1, 798.4346, 11.2008},[45]={1605.7, 116.6938, 37.2020}, 
[46]={1701.3, -644.311, 41.8010},[47]={1635.6, -884.206, 52.5121},[48]={1798.2, -1037.61, 39.4545},[49]={2223.8, -1137.70, 25.6588},[50]={2269.0, -1209.68, 23.9119}, 
[51]={2196.8, -1382.42, 23.8575},[52]={2110.5, -1427.29, 23.8566},[53]={2002.0, -1459.51, 13.4255},[54]={1842.8, -1508.62, 13.3936},[55]={1819.2, -1865.68, 13.4469}, 
[56]={1779.7, -1917.97, 13.4165},[57]={1811.2, -1890.22, 13.4372},[58]={1798.6, -1830.07, 13.4257},[59]={1680.3, -1859.67, 13.4131},[60]={1468.2, -1869.85, 13.4074}, 
} 
  
createBlip(-2063.5, 1371.0999755859, 7.0999999046326, 51, 2, 0, 0, 0, 255, 0, 50000) 
  
function getNewBusLocation(thePlayer, ID) 
local x, y, z = busTable[ID][1], busTable[ID][2], busTable[ID][3] 
triggerClientEvent(thePlayer,"bus_set_location",thePlayer,x,y,z) 
end 
  
function busJob(thePlayer) 
    local theVehicle = getPedOccupiedVehicle (thePlayer) 
    local id = getElementModel(theVehicle) 
    if id == 431 or id == 437 then 
        local x, y, z = getNewBusLocation(thePlayer, 1) 
        setElementData(thePlayer,"buszp",0) 
        setElementData(thePlayer,"busData",1) 
    else 
    end 
end 
addEventHandler("onVehicleEnter",rootElement,busJob) 
  
function busStart(thePlayer) 
    local theVehicle = getPedOccupiedVehicle (thePlayer) 
    local id = getElementModel(theVehicle) 
    if id == 431 or id == 437 then 
        outputChatBox("You started bus job!", thePlayer, 255, 255, 0) 
    end 
end 
addEventHandler("onVehicleEnter",rootElement,busStart) 
  
addEvent("bus_finish",true) 
addEventHandler("bus_finish",rootElement, 
function (client) 
if not isPedInVehicle(client) then return end 
if not busses[getElementModel(getPedOccupiedVehicle(client))] then return end 
local zarp = getElementData(client, "buszp") 
local money = math.random(10,20) 
setElementData(client, "buszp", zarp + money) 
if #busTable == tonumber(getElementData(client,"busData")) then 
setElementData(client,"busData",1) 
else 
setElementData(client,"busData",tonumber(getElementData(client,"busData"))+1) 
end 
getNewBusLocation(client, tonumber(getElementData(client,"busData"))) 
end) 
  
function giveMoney(thePlayer) 
    local theVehicle = getPedOccupiedVehicle (thePlayer) 
    local id = getElementModel(theVehicle) 
    if id == 431 or 437 then 
        local gpm = getElementData(thePlayer, "buszp") 
        if ((gpm) > 0 ) then 
            givePlayerMoney(thePlayer, tonumber(gpm)) 
            outputChatBox("You've earned " .. gpm .. "$", thePlayer, 0, 140, 240) 
            setElementData(thePlayer, "buszp", 0) 
        end 
    end 
end 
addEventHandler("onVehicleExit", rootElement, giveMoney) 
addEventHandler("onPlayerQuit", rootElement, giveMoney) 

This is my favorite script and the best one i've ever made bcuz i'm a noob and it worked and never got errors before.

Link to comment
[19:13:40] ERROR: busjob\busjob_c.lua:1: attempt to call global 'getLocalPlayer' (a nil value) 

busjob_c.lua

local thePlayer = getLocalPlayer() 
local rootElement = getRootElement() 
local marker = nil 
local blip = nil 
  
addEvent("bus_set_location",true) 
addEventHandler("bus_set_location",rootElement, 
function (x, y, z) 
marker = createMarker(tostring(x), tostring(y), tostring(z)-1, "checkpoint", 4.0, 0, 0, 255, 255) 
blip = createBlipAttachedTo( marker, 56, 3, 0, 0, 255, 255 ) 
addEventHandler("onClientMarkerHit",marker,onBusStopHit) 
end) 
  
function onBusStopHit(hitPlayer) 
if not hitPlayer == thePlayer then return end 
triggerServerEvent("bus_finish",thePlayer,thePlayer) 
if isElement(blip) then destroyElement(blip) end 
if isElement(marker) then 
removeEventHandler("onClientMarkerHit",marker,onBusStopHit) 
destroyElement(marker)  
  end 
end 
  
addEventHandler("onClientVehicleExit",rootElement, 
function () 
if isElement(marker) then 
removeEventHandler("onClientMarkerHit",marker,onBusStopHit) 
destroyElement(marker)  
end 
if isElement(blip) then destroyElement(blip) end 
end) 

Link to comment

How can I add this to my code and is it correct? ;

-- Client

function setFrozen(thePlayer) 
 if getPedOccupiedVehicle ( thePlayer ) then 
  local playerVehicle = getPlayerOccupiedVehicle ( thePlayer ) 
  setElementFrozen ( playerVehicle ) 
 end 
end 
  
setTimer(setFrozen, 5000) 
addEventHandler("onClientMarkerHit", setFrozen) 

-- Server

function destroyBus 
 destroyElement(theVehicle) 
end 
  
addEventHandler("onVehicleExit", destroyBus) 

Link to comment

Is 'theVehicle' defined server side? Client side should work if you change it a little bit. The timer should be like this: setTimer(function, interval, executes). You did not define execution ( how many times you want the timer to start over and over again. 0 = infinite) and:

setElementFrozen(playerVehicle, true) 

If you created the marker inside a function, then place the client side thing you posted into the same function.

EDIT: use

getPedOccupiedVehicle 

instead of:

getPlayerOccupiedVehicle 

Both of them works, but the first one is more generic, the second one is an old function.

Link to comment

Edited:

function setFrozen(thePlayer) 
 local theVehicle = getPedOccupiedVehicle (thePlayer) 
 if getPedOccupiedVehicle ( thePlayer ) then 
  local playerVehicle = getPzsOccupiedVehicle ( thePlayer ) 
  setElementFrozen (theVehicle, true) 
 end 
end 
  
setTimer(setFrozen, 5000, 1) 
addEventHandler("onClientMarkerHit", setFrozen) 

and the client is busjob_c.lua some posts above and I didn't use a function but marker = createMarker to create one.

Link to comment

EDIT:

function setFrozen(thePlayer) 
    local theVehicle = getPedOccupiedVehicle (thePlayer) 
        if getPedOccupiedVehicle ( thePlayer ) then 
        local playerVehicle = getPedOccupiedVehicle ( thePlayer ) 
        setElementFrozen (theVehicle, true) 
        end 
end 
  
setTimer(setFrozen, 5000, 1) 
addEventHandler("onClientMarkerHit", marker, setFrozen) 

Link to comment

You know, the timer should be inside your function... try this;

addEventHandler ( "onClientMarkerHit", marker, 
    function ( hitElement ) 
        if ( hitElement == getLocalPlayer() ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if ( vehicle ) then 
                setElementFrozen ( vehicle, true ); 
                setTimer ( function() 
                            setElementFrozen ( vehicle, false ); 
                            end, 5000, 1 ); 
            end 
        end 
    end 
); 

Link to comment

I'll post the full script here so you get a good overview

Meta.xml

    "Viruz" name="busjob"  version="1.0" type="script"/> 
    

busjob.lua

local rootElement = getRootElement() 
local busses = {[431] = true, [437] = true} 
local busTable = { 
[1]={-2457.8000488281, 1356.8000488281, 6},[2]={-2719.1999511719, 1205, 53.599998474121},[3]={-2753.3000488281, 570.70001220703, 13.300000190735},[4]={-2856, 380.20001220703, 3.2999999523163},[5]={-2811.1999511719, 61.799999237061, 6}, 
[6]={-2423.1999511719, 126.69999694824, 34},[7]={-2254.5, 297.20001220703, 34.099998474121},[8]={825.122, -1395.14, 13.3444},[9]={648.371, -1395.33, 13.3444},[10]={635.96, -1252.67, 17.1576}, 
[11]={554.18, -1122.47, 27.2105},[12]={238.52, -1170.34, 19.5841},[13]={-43.18, -1354.07, 11.2299},[14]={-284.8, -1642.00, 15.5116},[15]={-354.4, -1831.65, 22.2320}, 
[16]={-348.6, -2125.50, 28.3879},[17]={-174.6, -2413.64, 35.6235},[18]={-36.62, -2711.40, 42.0042},[19]={-315.0, -2800.08, 57.5757},[20]={-757.3, -2764.34, 74.7090}, 
[21]={-1141, -2850.020, 67.7570},[22]={-1569, -2742.080, 48.5795},[23]={-1966, -2547.510, 38.2349},[24]={-2191, -2370.410, 30.5065},[25]={-2212, -2264.740, 30.5055}, 
[26]={-2102, -2078.130, 63.1302},[27]={-1820, -1726.650, 29.1070},[28]={-1400, -1648.350, 45.1570},[29]={-1144, -1899.890, 77.5020},[30]={-802.3, -1785.11, 92.2070}, 
[31]={-758.6, -1454.05, 87.8020},[32]={-652.7, -1420.18, 90.4095},[33]={-572.8, -1070.35, 23.5500},[34]={-372.0, -823.054, 28.4015},[35]={-189.6, -938.291, 35.3530}, 
[36]={-55.70, -858.507, 13.7823},[37]={-113.0, -402.609, 1.10380},[38]={-221.9, 187.8397, 8.88888},[39]={-63.88, 551.1700, 9.22222},[40]={323.85, 753.2600, 6.15222}, 
[41]={740.54, 657.1210, 10.7505},[42]={1099.8, 803.8835, 10.7070},[43]={1556.6, 831.4191, 6.80807},[44]={1785.1, 798.4346, 11.2008},[45]={1605.7, 116.6938, 37.2020}, 
[46]={1701.3, -644.311, 41.8010},[47]={1635.6, -884.206, 52.5121},[48]={1798.2, -1037.61, 39.4545},[49]={2223.8, -1137.70, 25.6588},[50]={2269.0, -1209.68, 23.9119}, 
[51]={2196.8, -1382.42, 23.8575},[52]={2110.5, -1427.29, 23.8566},[53]={2002.0, -1459.51, 13.4255},[54]={1842.8, -1508.62, 13.3936},[55]={1819.2, -1865.68, 13.4469}, 
[56]={1779.7, -1917.97, 13.4165},[57]={1811.2, -1890.22, 13.4372},[58]={1798.6, -1830.07, 13.4257},[59]={1680.3, -1859.67, 13.4131},[60]={1468.2, -1869.85, 13.4074}, 
} 
  
createBlip(-2063.5, 1371.0999755859, 7.0999999046326, 51, 2, 0, 0, 0, 255, 0, 50000) 
  
function getNewBusLocation(thePlayer, ID) 
local x, y, z = busTable[ID][1], busTable[ID][2], busTable[ID][3] 
triggerClientEvent(thePlayer,"bus_set_location",thePlayer,x,y,z) 
end 
  
function busJob(thePlayer) 
    local theVehicle = getPedOccupiedVehicle (thePlayer) 
    local id = getElementModel(theVehicle) 
    if id == 431 or id == 437 then 
        local x, y, z = getNewBusLocation(thePlayer, 1) 
        setElementData(thePlayer,"buszp",0) 
        setElementData(thePlayer,"busData",1) 
    else 
    end 
end 
addEventHandler("onVehicleEnter",rootElement,busJob) 
  
function busStart(thePlayer) 
    local theVehicle = getPedOccupiedVehicle (thePlayer) 
    local id = getElementModel(theVehicle) 
    if id == 431 or id == 437 then 
        outputChatBox("You started bus job!", thePlayer, 255, 255, 0) 
    end 
end 
addEventHandler("onVehicleEnter",rootElement,busStart) 
  
addEvent("bus_finish",true) 
addEventHandler("bus_finish",rootElement, 
function (client) 
if not isPedInVehicle(client) then return end 
if not busses[getElementModel(getPedOccupiedVehicle(client))] then return end 
local zarp = getElementData(client, "buszp") 
local money = math.random(10,20) 
setElementData(client, "buszp", zarp + money) 
if #busTable == tonumber(getElementData(client,"busData")) then 
setElementData(client,"busData",1) 
else 
setElementData(client,"busData",tonumber(getElementData(client,"busData"))+1) 
end 
getNewBusLocation(client, tonumber(getElementData(client,"busData"))) 
end) 
  
function giveMoney(thePlayer) 
    local theVehicle = getPedOccupiedVehicle (thePlayer) 
    local id = getElementModel(theVehicle) 
    if id == 431 or 437 then 
        local gpm = getElementData(thePlayer, "buszp") 
        if ((gpm) > 0 ) then 
            givePlayerMoney(thePlayer, tonumber(gpm)) 
            outputChatBox("You've earned " .. gpm .. "€", thePlayer, 0, 140, 240) 
            setElementData(thePlayer, "buszp", 0) 
        end 
    end 
end 
addEventHandler("onVehicleStartExit", rootElement, giveMoney) 
addEventHandler("onPlayerQuit", rootElement, giveMoney) 

busjob_c.lua

local thePlayer = getLocalPlayer() 
local rootElement = getRootElement() 
local marker = nil 
local blip = nil 
  
addEvent("bus_set_location",true) 
addEventHandler("bus_set_location",rootElement, 
function (x, y, z) 
marker = createMarker(tostring(x), tostring(y), tostring(z)-1, "checkpoint", 4, 0, 155, 255, 30) 
blip = createBlipAttachedTo( marker, 56, 3, 0, 0, 255, 255 ) 
addEventHandler("onClientMarkerHit",marker,onBusStopHit) 
end) 
  
function onBusStopHit(hitPlayer) 
if not hitPlayer == thePlayer then return end 
triggerServerEvent("bus_finish",thePlayer,thePlayer) 
if isElement(blip) then destroyElement(blip) end 
if isElement(marker) then 
removeEventHandler("onClientMarkerHit",marker,onBusStopHit) 
destroyElement(marker)  
  end 
end 
  
addEventHandler("onClientVehicleExit",rootElement, 
function () 
if isElement(marker) then 
removeEventHandler("onClientMarkerHit",marker,onBusStopHit) 
destroyElement(marker)  
end 
if isElement(blip) then destroyElement(blip) end 
end) 
  
-- Freeze 
addEventHandler ( "onClientMarkerHit", marker, 
    function ( hitElement ) 
        if ( hitElement == getLocalPlayer() ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if ( vehicle ) then 
                setElementFrozen ( vehicle, true ); 
                setTimer ( function() 
                            setElementFrozen ( vehicle, false ); 
                            end, 5000, 1 ); 
            end 
        end 
    end 
); 

No Console Errors, debugscript 3 is in the image (only one error)

mta-screen2013-11-0612-58-15.png

The things that need to happen but don't happen are:

• Destroy the bus on Exit.

• On ClientMarkerHit the bus should freeze for 5 seconds and won't be able to drive.

Link to comment
You know, the timer should be inside your function... try this;
addEventHandler ( "onClientMarkerHit", marker, 
    function ( hitElement ) 
        if ( hitElement == getLocalPlayer() ) then 
            local vehicle = getPedOccupiedVehicle ( hitElement ) 
            if ( vehicle ) then 
                setElementFrozen ( vehicle, true ); 
                setTimer ( function() 
                            setElementFrozen ( vehicle, false ); 
                            end, 5000, 1 ); 
            end 
        end 
    end 
); 

That code should work, for the other one try this:

addEventHandler('onClientVehicleExit', getRootElement(), function(thePlayer, seat) 
    destroyElement(source) 
end) 

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