TheGamingMann Posted May 19, 2014 Share Posted May 19, 2014 (edited) Hello. So I am simply getting an error that is saying bad argument. I have tried many things to sort this out and have not solved the issue yet. Code below. c_load.lua: function loadHandler(button, state) if button == "left" and state == "up" then local row, col = guiGridListGetSelectedItem(glistLoadList) local startpos = guiGridListGetItemData(glistLoadList, row, 2) local endpos = guiGridListGetItemData(glistLoadList, row, 3) local cash = guiGridListGetItemData(glistLoadList, row, 4) if row and col and row ~= -1 and col ~=-1 then startx, starty, startz = unpack(startpos) endx, endy, endz = unpack(endpos) cash = unpack(cash) createLoadStart() end end end function createLoadStart() startMarker = createMarker(startx, starty, startz, "checkpoint", 7) startBlip = createBlip(startx, starty, startz, 0, 2, 0, 0, 255) hideLoad() end function startLoading() local vehicle = getPedOccupiedVehicle(localPlayer) if isElementWithinMarker(localPlayer, startMarker) then if vehicle then if (getElementModel(vehicle)) == 403 or (getElementModel(vehicle)) == 515 or (getElementModel(vehicle)) == 514 then trailer = createVehicle(435, -99, -57, 3.5, 0, 0, 167) guiSetText(lblLoading, "Loading...") guiSetVisible(lblLoading, true) attachTrailerToVehicle(vehicle, trailer) setElementFrozen(vehicle, true) setTimer(function () guiSetVisible(lblLoading, false) setElementFrozen(vehicle, false) end, 10*1000, 1) destroyElement(startMarker) destroyElement(startBlip) endMarker = createMarker(endx, endy, endz, "checkpoint", 7) endBlip = createBlip(endx, endy, endz, 0, 2, 255, 0, 0) end else outputChatBox("You need to be in some sort of 18 Wheeler to take a job.", localPlayer) end else outputChatBox("You need to be in the load marker to get the trailer.", localPlayer) end end addCommandHandler("load", startLoading) function startUnLoading() local person = localPlayer local vehicle = getPedOccupiedVehicle(localPlayer) if isElementWithinMarker(localPlayer, endMarker) then if vehicle then if getVehicleTowingVehicle(trailer) == vehicle then guiSetText(lblLoading, "Unloading...") guiSetVisible(lblLoading, true) setElementFrozen(vehicle, true) setTimer(function () guiSetVisible(lblLoading, false) setElementFrozen(vehicle, false) detachTrailerFromVehicle(vehicle) destroyElement(trailer) end, 10*1000, 1) destroyElement(endMarker) destroyElement(endBlip) triggerServerEvent("finishRoute", localPlayer, person, cash) end end else outputChatBox("You need to be in the unload marker to unload the trailer.", localPlayer) end end addCommandHandler("unload", startUnLoading) s_load.lua: function finishLoad(person, cash) givePlayerMoney(person, tonumber(cash)) end addEvent("finishRoute", true) addEventHandler("finishRoute", root, finishLoad) Thanks in advance guys. Edited May 19, 2014 by Guest Link to comment
xXMADEXx Posted May 19, 2014 Share Posted May 19, 2014 Try to use this (client): function loadHandler(button, state) if button == "left" and state == "up" then local row, col = guiGridListGetSelectedItem(glistLoadList) local startpos = guiGridListGetItemData(glistLoadList, row, 2) local endpos = guiGridListGetItemData(glistLoadList, row, 3) local cash_ = guiGridListGetItemData(glistLoadList, row, 4) if row and col and row ~= -1 and col ~=-1 then startx, starty, startz = unpack(startpos) endx, endy, endz = unpack(endpos) cash = unpack(cash_) createLoadStart() end end end function createLoadStart() startMarker = createMarker(startx, starty, startz, "checkpoint", 7) startBlip = createBlip(startx, starty, startz, 0, 2, 0, 0, 255) hideLoad() end function startLoading() local vehicle = getPedOccupiedVehicle(localPlayer) if isElementWithinMarker(localPlayer, startMarker) then if vehicle then if (getElementModel(vehicle)) == 403 or (getElementModel(vehicle)) == 515 or (getElementModel(vehicle)) == 514 then trailer = createVehicle(435, -99, -57, 3.5, 0, 0, 167) guiSetText(lblLoading, "Loading...") guiSetVisible(lblLoading, true) attachTrailerToVehicle(vehicle, trailer) setElementFrozen(vehicle, true) setTimer(function () guiSetVisible(lblLoading, false) setElementFrozen(vehicle, false) end, 10*1000, 1) destroyElement(startMarker) destroyElement(startBlip) endMarker = createMarker(endx, endy, endz, "checkpoint", 7) endBlip = createBlip(endx, endy, endz, 0, 2, 255, 0, 0) end else outputChatBox("You need to be in some sort of 18 Wheeler to take a job.", localPlayer) end else outputChatBox("You need to be in the load marker to get the trailer.", localPlayer) end end addCommandHandler("load", startLoading) function startUnLoading() local person = localPlayer local vehicle = getPedOccupiedVehicle(localPlayer) if isElementWithinMarker(localPlayer, endMarker) then if vehicle then if getVehicleTowingVehicle(trailer) == vehicle then guiSetText(lblLoading, "Unloading...") guiSetVisible(lblLoading, true) setElementFrozen(vehicle, true) setTimer(function () guiSetVisible(lblLoading, false) setElementFrozen(vehicle, false) detachTrailerFromVehicle(vehicle) destroyElement(trailer) end, 10*1000, 1) destroyElement(endMarker) destroyElement(endBlip) triggerServerEvent("finishRoute", localPlayer, person, cash) end end else outputChatBox("You need to be in the unload marker to unload the trailer.", localPlayer) end end addCommandHandler("unload", startUnLoading) and if it still isn't working, put this for the server side and tell me the results: function finishLoad(person, cash) outputChatBox ( tostring ( cash ) ) givePlayerMoney(person, tonumber(cash)) end addEvent("finishRoute", true) addEventHandler("finishRoute", root, finishLoad) Link to comment
TheGamingMann Posted May 19, 2014 Author Share Posted May 19, 2014 Okay... It worked.. I guess the issue was that the "cash" variable wasn't in a string format so it was not converting correctly. It now works and I changed the code a little so it does not output to the chat. Thanks man. 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