Sasu Posted February 27, 2013 Share Posted February 27, 2013 function robar() for k, i in ipairs( getPlayersInTeam( getTeamFromName( "Criminal" ) ) ) do if isElementWithinMarker( i, bankMarker ) then for k, v in ipairs(getElementsByType('player')) do if v > 5 then outputChatBox("Esto es un test", i, 255, 0, 0) else outputChatBox("Se nesecitan mas de 5 criminales", i, 0, 255, 0) end end end end end addEventHandler("onMarkerHit", bankMarker, robar) I have a error on Debug: attempt to compare number with nil Link to comment
Castillo Posted February 27, 2013 Share Posted February 27, 2013 You are trying to compare "v" which is a player element to a number. Link to comment
Sasu Posted February 27, 2013 Author Share Posted February 27, 2013 You are trying to compare "v" which is a player element to a number. And... What should I do? Link to comment
Castillo Posted February 27, 2013 Share Posted February 27, 2013 You are trying to count all the criminals inside the marker? Link to comment
Sasu Posted February 28, 2013 Author Share Posted February 28, 2013 You are trying to count all the criminals inside the marker? I am trying to count 5 five criminals inside the marker to start de rob. Link to comment
Moderators IIYAMA Posted February 28, 2013 Moderators Share Posted February 28, 2013 (edited) Not tested: function robar() local count = 0 for k, i in ipairs( getPlayersInTeam( getTeamFromName( "Criminal" ) ) ) do if isElementWithinMarker( i, bankMarker ) then count = count +1 end end if count > 5 then outputChatBox("Esto es un test", count, 255, 0, 0) else outputChatBox("Se nesecitan mas de 5 criminales", count, 0, 255, 0) end end addEventHandler("onMarkerHit", bankMarker, robar) Edited February 28, 2013 by Guest Link to comment
Sasu Posted February 28, 2013 Author Share Posted February 28, 2013 Note tested: function robar() local count = 0 for k, i in ipairs( getPlayersInTeam( getTeamFromName( "Criminal" ) ) ) do if isElementWithinMarker( i, bankMarker ) then count = count +1 end end if count > 5 then outputChatBox("Esto es un test", count, 255, 0, 0) else outputChatBox("Se nesecitan mas de 5 criminales", count, 0, 255, 0) end end addEventHandler("onMarkerHit", bankMarker, robar) Thx it works =) Link to comment
Moderators IIYAMA Posted February 28, 2013 Moderators Share Posted February 28, 2013 np. Link to comment
Sasu Posted February 28, 2013 Author Share Posted February 28, 2013 Well, I use it to make a script of the bank rob. function robar() local count = 0 for k, i in ipairs( getPlayersInTeam( getTeamFromName( "Criminal" ) ) ) do if isElementWithinMarker( i, bankMarker ) then count = count +1 end end if count > 1 then outputChatBox("El robo comenzara en 30 segundos", count, 255, 0, 0) setTimer( function (source) setPlayerWantedLevel ( source, 6 ) outputChatBox("Estan robando el Banco de LS", getRootElement(), 255, 0, 0, false) outputChatBox("Espera 5 minutos para escapar y conseguir el dinero", source, 255, 0, 0, false) setElementData(source, "Occupation", "Robando") setElementData(source, "mfbankrob", "Robando") setTimer( function (thePlayer) local bolsadinero = createObject ( 1550, 355.664, 174.16, 1008.38 ) setElementInterior( bolsadinero, 3, 355.664, 174.16, 1008.38 ) local dinero = createMarker( 355.664, 174.16, 1007, "cylinder", 2, 255, 0, 0, 50 ) setElementInterior( dinero, 3, 355.664, 174.16, 1007) addEventHandler("onMarkerHit", dinero, function (hitElement) if (getElementData(hitElement, "mfbankrob", true) == "Robando") then setElementData(thePlayer, "mfbankrob", "Robado") outputChatBox("Rapido!! Sal de la zona del robo para ganar el dinero!", hitElement, 0, 200, 0, false) end end ) end , 2000, 1 ) end , 1000, 1 ) else outputChatBox("Se nesecitan mas de 5 criminales", count, 0, 255, 0) end end addEventHandler("onMarkerHit", bankMarker, robar) Error on debug 3: WARNING: bankrob.lua:16: Bad argument @ setPlayerWantedLevel WARNING: bankrob.lua:19: Bad argumen @ setElementData[Expected element at argument 1, got nil] WARNING: bankrob.lua:20: Bad argument @ setElementData[Expected element at argument 1, got nil] Can you help me? Link to comment
Castillo Posted February 28, 2013 Share Posted February 28, 2013 You aren't passing "source" argument to your function. Link to comment
Moderators IIYAMA Posted March 1, 2013 Moderators Share Posted March 1, 2013 Listen to solidsnake, check always what the parameters are. Also what the source is. Important --> https://wiki.multitheftauto.com/wiki/OnMarkerHit Parameters = (hitElement,dimension)element hitElement, bool matchingDimension hitElement: The element that hit the marker matchingDimension: True if the element is in the same dimension as the marker he hit Source The source of this event is the marker that got hit by the element. function robar(element) local count = 0 if not "player" == getElementType(element) then -- always check. return end local player = element for k, i in ipairs( getPlayersInTeam( getTeamFromName( "Criminal" ) ) ) do if isElementWithinMarker( i, bankMarker ) then count = count +1 end end if count > 1 then outputChatBox("El robo comenzara en 30 segundos", count, 255, 0, 0) setTimer( function (player) setPlayerWantedLevel ( player, 6 ) outputChatBox("Estan robando el Banco de LS", getRootElement(), 255, 0, 0, false) outputChatBox("Espera 5 minutos para escapar y conseguir el dinero", player, 255, 0, 0, false) setElementData(player, "Occupation", "Robando") setElementData(player, "mfbankrob", "Robando") setTimer( function ()-- thePlayer = nil (not def), you already have "player" local bolsadinero = createObject ( 1550, 355.664, 174.16, 1008.38 ) setElementInterior( bolsadinero, 3, 355.664, 174.16, 1008.38 ) local dinero = createMarker( 355.664, 174.16, 1007, "cylinder", 2, 255, 0, 0, 50 ) setElementInterior( dinero, 3, 355.664, 174.16, 1007) addEventHandler("onMarkerHit", dinero, function (hitElement) if (getElementData(hitElement, "mfbankrob", true) == "Robando") then setElementData(player, "mfbankrob", "Robado")-- not to much outputChatBox("Rapido!! Sal de la zona del robo para ganar el dinero!", hitElement, 0, 200, 0, false) end end ) end , 2000, 1 ) end , 1000, 1 ) else outputChatBox("Se nesecitan mas de 5 criminales", count, 0, 255, 0) end end addEventHandler("onMarkerHit", bankMarker, robar) 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