Jump to content

Players


Sasu

Recommended Posts

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
  • Moderators

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 by Guest
Link to comment
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

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? :S

Link to comment
  • Moderators

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

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