raynner Posted November 28, 2015 Share Posted November 28, 2015 (edited) Well you and a colleague we are creating a work for walkers I had done another way after posting a few more mistakes here a guy pointed me to use tables form the challenge however we found some errors similar to the previous one could help? errors ------- WARNING: trucker\server.lua:43: Bad argument @ 'getVehicleTowedByVehicle' [Expected vehicle at argument 1, got nil] WARNING: trucker\server.lua:52: Bad argument @ 'destroyElement' [Expected element at argument 1, got nil] WARNING: trucker\server.lua:53: Bad argument @ 'destroyElement' [Expected element at argument 1, got nil] WARNING: trucker\server.lua:54: Bad argument @ 'givePlayerMoney' [Expected number at argument 2, got nil] WARNING: trucker\server.lua:59: Bad argument @ 'destroyElement' [Expected element at argument 1, got nil] WARNING: trucker\server.lua:60: Bad argument @ 'destroyElement' [Expected element at argument 1, got nil] ------- jTrucker = {} local marker, blip, truck, trailer, dTruck, dTrailer function takeJob() if isPedInVehicle(source) then outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê está em um veículo, saia do mesmo.", source, 255, 255, 255, true) else marker = createMarker(2234, -2216, 12.5, "cylinder", 4, 255, 0, 0, 255, source) blip = createBlip(-64, -1134, 0.5, 53, 2, 255, 255, 255, 255, 0, 99999, source) truck = createVehicle(515, 2202, -2249, 14) trailer = createVehicle(435, 0, 0, 4) jTrucker[source] = {} pTrucker = jTrucker[source] pTrucker["blip"] = blip pTrucker["marker"] = marker pTrucker["truck"] = truck pTrucker["trailer"] = trailer pTrucker["money"] = 350 setElementRotation(pTrucker["truck"], 0, 0, -45) setElementRotation(pTrucker["trailer"], 0, 0, -45) attachTrailerToVehicle(pTrucker["truck"], pTrucker["trailer"]) warpPedIntoVehicle(source, pTrucker["truck"]) addEventHandler("onMarkerHit", pTrucker["marker"], finishJob) outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê obteve um caminhão, leve-o até a marcação.", source, 255, 255, 255, true) end end addEvent("TraB1", true) addEventHandler("TraB1", getRootElement(), takeJob) function finishJob(hitElement) if(isElement(hitElement)) and (getElementType(hitElement) == "player") then jTrucker[hitElement] = {} pTrucker = jTrucker[hitElement] if(getVehicleTowedByVehicle(pTrucker["truck"]) == pTrucker["trailer"]) then outputChatBox ("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê trouxe a carga e recebeu seu pagamento.", hitElement, 255, 255, 255, true) destroyElement(pTrucker["marker"]) destroyElement(pTrucker["blip"]) givePlayerMoney(hitElement, pTrucker["money"]) else outputChatBox ("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê não trouxe a carga, portanto, não receberá.", hitElement, 255, 255, 255, true) destroyElement(pTrucker["marker"]) destroyElement(pTrucker["blip"]) givePlayerMoney(hitElement, pTrucker["money"]) end dTruck = destroyElement(jTrucker[hitElement]["truck"]) dTrailer = destroyElement(jTrucker[hitElement]["trailer"]) if (dTruck and dTrailer) then jTrucker[hitElement]["truck"] = false jTrucker[hitElement]["trailer"] = false end end end Edited December 4, 2015 by Guest Link to comment
Moderators IIYAMA Posted November 28, 2015 Moderators Share Posted November 28, 2015 remove line 38, it overwriting something you don't want to be overwritten. Link to comment
raynner Posted November 29, 2015 Author Share Posted November 29, 2015 remove line 38, it overwriting something you don't want to be overwritten. Well my friend removed the line 38 and fix some mistakes put it this containing a single problem I could not solve tried in many ways, in the end it did not work good the error and the following is just have a player doing delivery it is perfectly more if you have 2 or more players in the same delivery cmd sends some message WARNING which are the following server.lua:37: Bad argument @ 'getVehicleTowedByVehicle' [Expected vehicle at argument 1, got boolean] server.lua:39: Bad argument @ 'destroyElement' [Expected element at argument 1] server.lua:40: Bad argument @ 'destroyElement' [Expected element at argument 1] server.lua:47: Bad argument @ 'destroyElement' [Expected element at argument 1, got boolean] server.lua:48: Bad argument @ 'destroyElement' [Expected element at argument 1, got boolean] noteit destroys them correctly elements of each player having one or more, but in order and a relevant error so how could not solve back here for help, It would be vacant if I do not feel it here when you have eg 3 in this race the first arrives he gets the number of messages and money to players who are on the run Example 3 he will take delivery of message 3 times and the money 3 times correctly note that it contains these errors and I have not made functions out of the vehicle or the server jTrucker = {} function takeJob() if isPedInVehicle(source) then outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê está em um veículo, saia do mesmo.", source, 255, 255, 255, true) else marker = createMarker(2234, -2216, 12.5, "cylinder", 4, 255, 0, 0, 255, source) blip = createBlip(-64, -1134, 0.5, 53, 2, 255, 255, 255, 255, 0, 99999, source) truck = createVehicle(515, 2202, -2249, 14) trailer = createVehicle(435, 0, 0, 4) jTrucker[source] = {} pTrucker = jTrucker[source] pTrucker["blip"] = blip pTrucker["marker"] = marker pTrucker["truck"] = truck pTrucker["trailer"] = trailer pTrucker["money"] = 350 setElementRotation(pTrucker["truck"], 0, 0, -45) setElementRotation(pTrucker["trailer"], 0, 0, -45) attachTrailerToVehicle(pTrucker["truck"], pTrucker["trailer"]) warpPedIntoVehicle(source, pTrucker["truck"]) addEventHandler("onMarkerHit", pTrucker["marker"], finishJob) outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê obteve um caminhão, leve-o até a marcação.", source, 255, 255, 255, true) end end addEvent("TraB1", true) addEventHandler("TraB1", getRootElement(), takeJob) function finishJob(hitElement) if(isElement(hitElement)) and (getElementType(hitElement) == "player") then pTrucker = jTrucker[hitElement] if(getVehicleTowedByVehicle(pTrucker["truck"]) == pTrucker["trailer"]) then outputChatBox ("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê trouxe a carga e recebeu seu pagamento.", hitElement, 255, 255, 255, true) destroyElement(pTrucker["marker"]) destroyElement(pTrucker["blip"]) givePlayerMoney(hitElement, pTrucker["money"]) else outputChatBox ("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê não trouxe a carga, portanto, não receberá.", hitElement, 255, 255, 255, true) destroyElement(pTrucker["marker"]) destroyElement(pTrucker["blip"]) end dTruck = destroyElement(pTrucker["truck"]) dTrailer = destroyElement(pTrucker["trailer"]) if (dTruck and dTrailer) then pTrucker["truck"] = false pTrucker["trailer"] = false end end end Link to comment
Moderators IIYAMA Posted November 29, 2015 Moderators Share Posted November 29, 2015 It is very important to validate data before re-using it. This can be done with the isElement function. Ones data has been stored in variable or elementData and when you are going to re-use it over time, validation is required in order to have 0 warnings/errors. And study what the word local is for, because you are using it the wrong way. Link to comment
raynner Posted November 29, 2015 Author Share Posted November 29, 2015 It is very important to validate data before re-using it. This can be done with the isElement function. Ones data has been stored in variable or elementData and when you are going to re-use it over time, validation is required in order to have 0 warnings/errors.And study what the word local is for, because you are using it the wrong way. How should I then do my friend because I swear I tried in many ways and I can not finish this job and I'm out of ideas of what to do. Link to comment
Moderators IIYAMA Posted November 29, 2015 Moderators Share Posted November 29, 2015 Validate elements if isElement(element) then -- < validate destroyElement(element) -- < destroy end Locals Local variables are active within a block. local marker = createMarker(2234, -2216, 12.5, "cylinder", 4, 255, 0, 0, 255, source) local blip = createBlip(-64, -1134, 0.5, 53, 2, 255, 255, 255, 255, 0, 99999, source) local truck = createVehicle(515, 2202, -2249, 14) local trailer = createVehicle(435, 0, 0, 4) Blocks: Functions functions functionName() local variable -- active t/m end end if elseif else if true then local variable -- active t/m elseif elseif true then local variable -- active t/m else else local variable -- active t/m end end Loops for i=1,10 do local variable -- active t/m end end You can also look here for inspiration: https://forum.multitheftauto.com/viewtopic.php?f ... 9&start=30 He had circa the same question. Link to comment
raynner Posted November 30, 2015 Author Share Posted November 30, 2015 Good Friends I've been trying to resolve the errors put the fix another appears .. this time is just about everything right at first sight however there were some errors as RemoveEventHandler .. and another who will try to explain did a second run to take a test and occurs as well, if a player is on the run 1 and another at 2, the player race 2 by accident pass above the place where is the marker of one or vise versa they receive the money and message short and as if the marker I had up to two non-visible player. I am very frustrated with what no longer do more idea what to do the last idea I had to resolve the errors had a large cut by little knowledge that in my opinion I should use the function takeJob hitElement. please check my script friends since you have more experience in the subject and see if you have any idea of this error. I'll leave the two sides script of the server and client. OBS: marker delivery on the exit road to speed up testing. Client function onClientResourceStart() truckerMarker = createMarker(2205, -2252, 12.5, "cylinder", 1.5, 255, 0, 0, 153) createBlip(2205, -2252, 12.5, 51, 1, 255, 255, 255, 255, 0, 250) end addEventHandler("onClientResourceStart", getRootElement(), onClientResourceStart) function trucker(hitPlayer) if (hitPlayer == localPlayer and source == truckerMarker) then addEventHandler("onClientRender", getRootElement(), truckerDX) addEventHandler("onClientKey", getRootElement(), pressKey) end end addEventHandler("onClientMarkerHit", getRootElement(), trucker) function truckerF(leftPlayer) if (leftPlayer == localPlayer and source == truckerMarker) then removeEventHandler("onClientRender", getRootElement(), truckerDX) removeEventHandler("onClientKey", getRootElement(), pressKey) end end addEventHandler("onClientMarkerLeave", getRootElement(), truckerF) function truckerDX() local sW,sH = guiGetScreenSize() dxDrawLine(sW*813/1280, sH*240/800, sW*813/1280, sH*569/800, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(sW*1154/1280, sH*240/800, sW*813/1280, sH*240/800, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(sW*813/1280, sH*569/800, sW*1154/1280, sH*569/800, tocolor(255, 255, 255, 255), 1, false) dxDrawLine(sW*1154/1280, sH*569/800, sW*1154/1280, sH*240/800, tocolor(255, 255, 255, 255), 1, false) dxDrawRectangle(sW*814/1280, sH*241/800, sW*340/1280, sH*328/800, tocolor(0, 0, 0, 200), false) dxDrawLine(sW*812/1280, sH*280/800, sW*1154/1280, sH*280/800, tocolor(255, 255, 255, 255), 1, false) dxDrawText("1. Carga para Las Venturas\n2. Carga para San Fierro\n3. Carga para Los Santos\n4. Carga para você HEHEHE", sW*824/1280, sH*299/800, sW*1144/1280, sH*555/800, tocolor(255, 255, 255, 255), 1.00, "sans", "left", "top", false, false, false, false, false) dxDrawLine(sW*812/1280, sH*280/800, sW*1154/1280, sH*280/800, tocolor(255, 255, 255, 255), 1, false) dxDrawText("Caminhoneiro", sW*859/1280, sH*250/800, sW*1116/1280, sH*270/800, tocolor(255, 255, 255, 255), 1, "diploma", "center", "center", false, false, false, false, false) end function pressKey(button, press) if button == "1" then triggerServerEvent("jobLS", localPlayer) removeEventHandler("onClientKey", getRootElement(), pressKey) elseif button == "2" then triggerServerEvent("jobLV", localPlayer) removeEventHandler("onClientKey", getRootElement(), pressKey) end end Server jTrucker = {} function takeJob() if isPedInVehicle(source) then outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê está em um veículo, saia do mesmo.", source, 255, 255, 255, true) else local marker = createMarker(2234, -2216, 12.5, "cylinder", 4, 255, 0, 0, 255, source) local blip = createBlip(-64, -1134, 0.5, 53, 2, 255, 255, 255, 255, 0, 99999, source) local truck = createVehicle(515, 2202, -2249, 14) local trailer = createVehicle(435, 0, 0, 4) jTrucker[source] = {} local pTrucker = jTrucker[source] pTrucker["blip"] = blip pTrucker["marker"] = marker pTrucker["truck"] = truck pTrucker["trailer"] = trailer pTrucker["money"] = 350 setElementRotation(pTrucker["truck"], 0, 0, -45) setElementRotation(pTrucker["trailer"], 0, 0, -45) attachTrailerToVehicle(pTrucker["truck"], pTrucker["trailer"]) warpPedIntoVehicle(source, pTrucker["truck"]) addEventHandler("onMarkerHit", pTrucker["marker"], finishJob) addEventHandler("onPlayerQuit", root, dElements) addEventHandler("onPlayerVehicleExit", root, dElements) outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê obteve um caminhão, leve-o até a marcação.", source, 255, 255, 255, true) end end addEvent("TraB1", true) addEventHandler("TraB1", getRootElement(), takeJob) function takeJob2() if isPedInVehicle(source) then outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê está em um veículo, saia do mesmo.", source, 255, 255, 255, true) else local marker = createMarker(2261, -2225, 12.5, "cylinder", 4, 255, 0, 0, 255, source) local blip = createBlip(2261, -2225, 12.5, 53, 2, 255, 255, 255, 255, 0, 99999, source) local truck = createVehicle(515, 2202, -2249, 14) local trailer = createVehicle(435, 0, 0, 4) jTrucker[source] = {} local pTrucker = jTrucker[source] pTrucker["blip"] = blip pTrucker["marker"] = marker pTrucker["truck"] = truck pTrucker["trailer"] = trailer pTrucker["money"] = 350 setElementRotation(pTrucker["truck"], 0, 0, -45) setElementRotation(pTrucker["trailer"], 0, 0, -45) attachTrailerToVehicle(pTrucker["truck"], pTrucker["trailer"]) warpPedIntoVehicle(source, pTrucker["truck"]) addEventHandler("onMarkerHit", pTrucker["marker"], finishJob) addEventHandler("onPlayerQuit", root, dElements) addEventHandler("onPlayerVehicleExit", root, dElements) outputChatBox("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê obteve um caminhão, leve-o até a marcação.", source, 255, 255, 255, true) end end addEvent("TraB2", true) addEventHandler("TraB2", getRootElement(), takeJob2) function finishJob(hitElement) local pTrucker = jTrucker[hitElement] if pTrucker then if (isElement(hitElement) and isElement(pTrucker["truck"]) and isElement(pTrucker["trailer"]) and getElementType(hitElement) == "player") then if (getVehicleTowedByVehicle(pTrucker["truck"]) == pTrucker["trailer"]) then outputChatBox ("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê trouxe a carga e recebeu seu pagamento.", hitElement, 255, 255, 255, true) givePlayerMoney(hitElement, pTrucker["money"]) else outputChatBox ("#CCFF00[#FFA600 ! #CCFF00] #0080FFVocê não trouxe a carga, portanto, não receberá.", hitElement, 255, 255, 255, true) end end if (isElement(pTrucker["marker"]) and isElement(pTrucker["blip"]) and isElement(pTrucker["truck"]) and isElement(pTrucker["trailer"])) then destroyElement(pTrucker["marker"]) destroyElement(pTrucker["blip"]) destroyElement(pTrucker["truck"]) destroyElement(pTrucker["trailer"]) end end end function dElements() local pTrucker = jTrucker[source] if (isElement(pTrucker["marker"]) and isElement(pTrucker["blip"]) and isElement(pTrucker["truck"]) and isElement(pTrucker["trailer"])) then destroyElement(pTrucker["marker"]) destroyElement(pTrucker["blip"]) destroyElement(pTrucker["truck"]) destroyElement(pTrucker["trailer"]) end end Link to comment
Moderators IIYAMA Posted November 30, 2015 Moderators Share Posted November 30, 2015 I do not fully understand what is wrong. If you show these conditions and actions as a schematic, I might understand it better. 1) if... 2) then .. 3) and.. Link to comment
raynner Posted November 30, 2015 Author Share Posted November 30, 2015 I do not fully understand what is wrong.If you show these conditions and actions as a schematic, I might understand it better. 1) if... 2) then .. 3) and.. Even though I'm not a script more with my experience and my friend did not understand WHAT is wrong. I remember that before I had made a table for each argument and not all together he only gave error in DestroyElement is that if I do the old way works? ex: marker = {} blip = {} truck = {} trailer = {} Link to comment
Moderators IIYAMA Posted November 30, 2015 Moderators Share Posted November 30, 2015 Doing that would make your code not very efficient. Also, ones you used a table location which you aren't going to use anymore, you have to nil it. jTrucker[source] = nil else it is still in the memory... And this is a wrong validation, because if one element isn't valid the other elements won't get destroyed. if (isElement(pTrucker["marker"]) and isElement(pTrucker["blip"]) and isElement(pTrucker["truck"]) and isElement(pTrucker["trailer"])) then destroyElement(pTrucker["marker"]) destroyElement(pTrucker["blip"]) destroyElement(pTrucker["truck"]) destroyElement(pTrucker["trailer"]) end if isElement(...) then destroyElement(...) end if isElement(...) then destroyElement(...) end if isElement(...) then destroyElement(...) end Link to comment
raynner Posted December 1, 2015 Author Share Posted December 1, 2015 if isElement(...) then destroyElement(...) end if isElement(...) then destroyElement(...) end if isElement(...) then destroyElement(...) end Friend I'm about to give up to make this script work because I am getting very upset about it I have devoted much of my time on it and every time you solve one error appears 3 new ! Link to comment
Moderators IIYAMA Posted December 1, 2015 Moderators Share Posted December 1, 2015 It is not about the errors or your end result, it is about learning to script. Ones you understand tables very well, you will be able to script much greater scripts. They are the key to let your code doing every you want. If this is too hard, you should focus more on lua than mta functions. Link to comment
raynner Posted December 1, 2015 Author Share Posted December 1, 2015 It is not about the errors or your end result, it is about learning to script. Ones you understand tables very well, you will be able to script much greater scripts. They are the key to let your code doing every you want. If this is too hard, you should focus more on lua than mta functions. I have studied the moon however I know there is something more difficult in order'm exhausted understand I start with this 9 am and stop by 3 am that this hurting me. Out estrece not understand the source of the error sooner will gain more experience and so I can finish this script. Link to comment
Moderators IIYAMA Posted December 1, 2015 Moderators Share Posted December 1, 2015 That is the spirit! Link to comment
raynner Posted December 4, 2015 Author Share Posted December 4, 2015 That is the spirit! We managed to finish the script 100% functional Link to comment
.:HyPeX:. Posted December 4, 2015 Share Posted December 4, 2015 It is not about the errors or your end result, it is about learning to script. Ones you understand tables very well, you will be able to script much greater scripts. They are the key to let your code doing every you want. If this is too hard, you should focus more on lua than mta functions. I have studied the moon however I know there is something more difficult in order'm exhausted understand I start with this 9 am and stop by 3 am that this hurting me. Out estrece not understand the source of the error sooner will gain more experience and so I can finish this script. Anyways, look over at the tutorials sub-forum, there are quite a few good ones. 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