AWOL Posted January 5, 2019 Share Posted January 5, 2019 (edited) Hello MTA SA community i'm trying to make a anti shortcut script for a map. In this script the player is suppose to drive through all 3 CORONAS, at the very end the 4th corona will check that the player hit all 3 previous coronas. If the player some how misses on he will be denied at the end. (I'm still new to the scripting community. I understand the concept but i would l like to know what i'm missing) -Thanks local playerHitCorona = {} local coronaElement = {} coronaElement[1] = createMarker(3955.6198730469, -1604.9947509766, 56.082000732422, "corona", 15, 0, 0, 255) coronaElement[2] = createMarker(3222.6970214844, -1473.5163574219, -1.5256999731064, "corona", 40, 0, 0, 255) coronaElement[3] = createMarker(3465.4184570313, -505.55020141602, 6.6930999755859, "corona", 15, 0, 0, 255) coronaElement[4] = createMarker(3788.0246582031, -807.74267578125, 110.54779815674, "corona", 10, 0, 0, 255) -- corona before hunter pickup -- and so on addEventHandler( "onClientMarkerHit", root, MarkerHit ) function MarketHit (player) if player == localPlayer then if source == coronaElement[1] then -- you check that the player hit the first corona playerHitCorona[1] = true -- set it to true, that means that the player hit the corona elseif source == coronaElement[2] then -- same as above playerHitCorona[2] = true elseif source == coronaElement[3] then -- on this corona, you check that the player hit all previous coronas playerHitCorona[1] = true playerHitCorona[2] = true elseif source == coronaElement[4] then if playerHitCorona[1] and playerHitCorona[2] and playerHitCorona[3] then -- You forgot the IF statements -- player hit all coronas, do nothing else local veh = getPedOccupiedVehicle(localPlayer) -- You also didn't define the veh variable, vehicle wasn't going to blow outputChatBox("#ADD8E6AW#FFFFFFOL: You're not worthy") blowVehicle(veh) -- player did not hit all coronas (he made sc) , blow player end end end end ) Edited January 5, 2019 by AWOL Link to comment
Captain Cody Posted January 5, 2019 Share Posted January 5, 2019 (edited) local playerHitCorona = {} local coronaElement = {} coronaElement[1] = createMarker(3955.6198730469, -1604.9947509766, 56.082000732422, "corona", 15, 0, 0, 255) coronaElement[2] = createMarker(3222.6970214844, -1473.5163574219, -1.5256999731064, "corona", 40, 0, 0, 255) coronaElement[3] = createMarker(3465.4184570313, -505.55020141602, 6.6930999755859, "corona", 15, 0, 0, 255) coronaElement[4] = createMarker(3788.0246582031, -807.74267578125, 110.54779815674, "corona", 10, 0, 0, 255) -- corona before hunter pickup -- and so on --[[ addEventHandler( "onClientMarkerHit", root, MarkerHit ) ]]--// Defined as markerHit and before the function move to line 31 function markerHit (element)--function MarketHit (player) // Was defined as MarketHit, switched to markerHit() if element == localPlayer then --// Just switched player to element because who knows what'll go through if source == coronaElement[1] then -- you check that the player hit the first corona playerHitCorona[1] = true -- set it to true, that means that the player hit the corona elseif source == coronaElement[2] then -- same as above playerHitCorona[2] = true elseif source == coronaElement[3] then -- on this corona, you check that the player hit all previous coronas playerHitCorona[3] = true --playerHitCorona[1] = true playerHitCorona[2] = true // Set to playerHitCorona[3], used 1 and 2 before elseif source == coronaElement[4] then if playerHitCorona[1] and playerHitCorona[2] and playerHitCorona[3] then -- Correcto -- player hit all coronas, do nothing else local vehicle = getPedOccupiedVehicle(localPlayer) outputChatBox("#ADD8E6AW#FFFFFFOL: You're not worthy") blowVehicle(vehicle) end end end end --) // ) should not be there because this is in a full function addEventHandler( "onClientMarkerHit", root, markerHit )--< addEventHandler should be moved here That goes through and explains what exactly was wrong the code, I'd say mostly just typos and misunderstandings how lua works. coronaInformation = {} coronaInformation[1] = {3955.6198730469, -1604.9947509766, 56.082000732422, "corona", 15, 0, 0, 255} coronaInformation[2] = {3222.6970214844, -1473.5163574219, -1.5256999731064, "corona", 40, 0, 0, 255} coronaInformation[3] = {3465.4184570313, -505.55020141602, 6.6930999755859, "corona", 15, 0, 0, 255} coronaInformation[4] = {3788.0246582031, -807.74267578125, 110.54779815674, "corona", 10, 0, 0, 255} function prep() if not running then running = true if coronaElement then for i,v in pairs(coronaElement) do if isElement(v) then destroyElement(v) end end end playerHitCorona = {} coronaElement = {} for i,v in pairs(coronaInformation) do coronaElement[i] = createMarker(unpack(v)) end addEventHandler( "onClientMarkerHit", root, markerHit ) end end function verifyScore(count) for i=1,(count or #coronaElement) do if not playerHitCorona[i] then return false -- # If a marker was not hit then return false end end return true --# If none of the above passes, return true end function markerHit (player) if player == localPlayer then for i,v in pairs(coronaElement) do if (source == v) then if (i == 1) or verifyScore(i-1) then --# Checks if marker is 1, and if not checks if you scored the previous ones. playerHitCorona[i] = true destroyElement(v) --# Removes the marker when you hit it if (i == #coronaElement) then -- # If this is the last one, try to score doScore() end end end end end end function doScore() if verifyScore() then -- # If all markers have been hit then continue -- Score else -- If a marker was not hit then blow em to peices local veh = getPedOccupiedVehicle(localPlayer) outputChatBox("#ADD8E6AW#FFFFFFOL: You're not worthy") blowVehicle(veh) end removeEventHandler( "onClientMarkerHit", root, markerHit ) running = nil end prep() Here's 'better' way of doing it that'll allow you to place more markers in the list and still have the function work 100% (Untested) Edited January 5, 2019 by CodyJ(L) Link to comment
AWOL Posted January 5, 2019 Author Share Posted January 5, 2019 (edited) I tested both in editor and it still doesn't work Edited January 5, 2019 by AWOL Link to comment
Captain Cody Posted January 5, 2019 Share Posted January 5, 2019 Check debug, and ensure it is running client side. Link to comment
AWOL Posted January 6, 2019 Author Share Posted January 6, 2019 On 05/01/2019 at 17:03, CodyJ(L) said: Check debug, and ensure it is running client side. Sorry for the late response. This is what i get Link to comment
Captain Cody Posted January 7, 2019 Share Posted January 7, 2019 First one does not contain 50 lines second one line 50 is blank. It's something else that's messed up. Link to comment
AWOL Posted January 8, 2019 Author Share Posted January 8, 2019 Could you please help me to get it to work. I checked the lines and nothing is there, what else am i missing. Link to comment
AWOL Posted January 10, 2019 Author Share Posted January 10, 2019 Lock this topic i ain't getting the help i need. Link to comment
Captain Cody Posted January 11, 2019 Share Posted January 11, 2019 Please post the entire code (And be patient, chirst some of us have lives) Link to comment
Moderators Citizen Posted January 11, 2019 Moderators Share Posted January 11, 2019 I double checked the CodyJ's code and it should work ! The server log says the resource editor_test couldn't even start because of what looks like an unexpected chinese character in Treat.lua at line 50. Don't blame the community just because we didn't guess you messed up something without telling us (but the logs say it !). Link to comment
AWOL Posted January 11, 2019 Author Share Posted January 11, 2019 I apologize i was a little impatient. I'm not blaming nobody, what i'm saying is that i had no idea that there was a Chinese character on line 50. When i open notepad++ it's not visible. Solved Lock this topic 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