Jump to content

How Could Link This To A Timer And P Bar And To All Area's


Recommended Posts

Posted

Well here is my code, also how can i put all the balla area's into one without needing to make tons of functions for each area.

local ballabase = createRadarArea(2077.2470703125, -1099.728515625, -220, -180, 255,0,255, 100) 
local ballaskate = createRadarArea(1981.6513671875, -1350.298828125, -140, -130, 255,0,255, 100) 
local ballamotel = createRadarArea(2268.5859375, -1138.28515625, -100, -100, 255,0,255, 100) 
local ballashops = createRadarArea(2184.7529296875, -1108.1435546875, -110, -120, 255,0,255, 100)  
local ballahouse = createRadarArea(2176.033203125, -1224.8935546875, -100, -80, 255,0,255, 100)  
local ballahouse2 = createRadarArea(2265.5126953125, -1233.033203125, -100, -80, 255,0,255, 100)  
local ballahouse3 = createRadarArea(2261.82421875, -1297.7451171875, -100, -80, 255,0,255, 100)  
local ballahouse4 = createRadarArea(2165.7333984375, -1305.1416015625, -100, -80, 255,0,255, 100) 
  
  
function ballabase (theElement, theArea) 
    local r,g,b,a = getRadarAreaColor ( ballabase ) 
    local posX, posY = getElementPosition( theElement ) 
    local inarea = isInsideRadarArea ( ballabase, posX, posY ) 
    if ( inarea ) then 
    if getPlayerTeam(localPlayer) and getTeamName(getPlayerTeam(localPlayer)) == "Grove" or "Ballas" then 
    if r == 255 and g == 0 and b == 255 then  
    setRadarAreaColor(ballabase, 0,255,0,100) 
    setRadarAreaFlashing ( ballabase, true ) 
    else  
    setRadarAreaColor(ballabase, 255,0,255,100)   
   end 
  end 
 end 
end     
addCommandHandler("capture", ballabase) 

Posted

That should work:

local ballasAreas = 
{ 
    createRadarArea( 2077.2470703125, -1099.728515625, -220, -180, 255,0,255, 100 ), 
    createRadarArea( 1981.6513671875, -1350.298828125, -140, -130, 255,0,255, 100 ), 
    createRadarArea( 2268.5859375, -1138.28515625, -100, -100, 255,0,255, 100 ), 
    createRadarArea( 2184.7529296875, -1108.1435546875, -110, -120, 255,0,255, 100 ), 
    createRadarArea( 2176.033203125, -1224.8935546875, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2265.5126953125, -1233.033203125, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2261.82421875, -1297.7451171875, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2165.7333984375, -1305.1416015625, -100, -80, 255,0,255, 100 ); 
} 
  
addCommandHandler( 'capture', 
    function( player, command ) 
        local hitAreas = { } 
        local posX, posY = getElementPosition( player ); 
        for _,v in pairs( ballasArea ) do 
            if( isInsideRadarArea( v, posX, posY ) ) then 
                table.insert( hitAreas, v ); 
            end 
        end 
         
        if( #hitAreas == 1 ) then 
            if(  
            getPlayerTeam( player ) and  
            getTeamName( getPlayerTeam( player ) ) == 'Grove' or  
            getTeamName( getPlayerTeam( player ) ) == 'Ballas'  
            ) then 
                local r, g, b, a = getRadarAreaColor( hitAreas[1] ); 
                if( r == 255 and g == 0 and b == 255 ) then 
                    setRadarAreaColor( hitAreas[1], 0, 255, 0, 100 ); 
                    setRadarAreaFlashing( hitAreas[1], true ); 
                else 
                    setRadarAreaColor( hitAreas[1], 255, 0, 255, 100 ); 
                end 
            end 
        end 
    end 
) 

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

You can create a progress bar and determine the progress every 150ms, for example:

progressBar = guiCreateProgressBar(x, y, width, height, true, nil) 
setTimer(guiProgressBarSetProgress, 150, 0, progressBar, guiProgressBarGetProgress, progressBar+2) 
    if (progress == 100) then 
        ... 
    end 

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
You can create a progress bar and determine the progress every 150ms, for example:
progressBar = guiCreateProgressBar(x, y, width, height, true, nil) 
setTimer(guiProgressBarSetProgress, 150, 0, progressBar, guiProgressBarGetProgress, progressBar+2) 
    if (progress == 100) then 
        ... 
    end 

local progressBar = guiCreateProgressBar( x, y, width, height, true, nil ); 
  
progressTimer = setTimer(  
    function( ) 
        guiProgressBarSetProgress( progressBar, guiProgressBarGetProgress( progressBar ) + 5 ); 
        if( guiProgressBarGetProgress( progressBar ) == 100 ) then 
            killTimer( progressTimer ); 
        end 
    end, 
1000, 0 ); 

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

Posted

Oh, I forgot to set the variable 'progress'.

You're right it is this form is correct.

Please do not PM me with scripting related question nor support, use the forums instead.

Posted
That should work:
local ballasAreas = 
{ 
    createRadarArea( 2077.2470703125, -1099.728515625, -220, -180, 255,0,255, 100 ), 
    createRadarArea( 1981.6513671875, -1350.298828125, -140, -130, 255,0,255, 100 ), 
    createRadarArea( 2268.5859375, -1138.28515625, -100, -100, 255,0,255, 100 ), 
    createRadarArea( 2184.7529296875, -1108.1435546875, -110, -120, 255,0,255, 100 ), 
    createRadarArea( 2176.033203125, -1224.8935546875, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2265.5126953125, -1233.033203125, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2261.82421875, -1297.7451171875, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2165.7333984375, -1305.1416015625, -100, -80, 255,0,255, 100 ); 
} 
  
addCommandHandler( 'capture', 
    function( player, command ) 
        local hitAreas = { } 
        local posX, posY = getElementPosition( player ); 
        for _,v in pairs( ballasArea ) do 
            if( isInsideRadarArea( v, posX, posY ) ) then 
                table.insert( hitAreas, v ); 
            end 
        end 
         
        if( #hitAreas == 1 ) then 
            if(  
            getPlayerTeam( player ) and  
            getTeamName( getPlayerTeam( player ) ) == 'Grove' or  
            getTeamName( getPlayerTeam( player ) ) == 'Ballas'  
            ) then 
                local r, g, b, a = getRadarAreaColor( hitAreas[1] ); 
                if( r == 255 and g == 0 and b == 255 ) then 
                    setRadarAreaColor( hitAreas[1], 0, 255, 0, 100 ); 
                    setRadarAreaFlashing( hitAreas[1], true ); 
                else 
                    setRadarAreaColor( hitAreas[1], 255, 0, 255, 100 ); 
                end 
            end 
        end 
    end 
) 

Ok here is my script

Client:

  
local progressBar = guiCreateProgressBar(501,54,334,35,false); 
  
progressTimer = setTimer(progresstimer,1000, 0 ); 
    function progresstimer( ) 
        guiProgressBarSetProgress( progressBar, guiProgressBarGetProgress( progressBar ) + 5 ); 
        if( guiProgressBarGetProgress( progressBar ) == 100 ) then 
            killTimer( progressTimer ); 
        end 
    end, 
     
function hideall() 
    guiSetVisible(progessBar, false) 
end 
addEventHandler("onClientResourceStart", resourceRoot, hideall) 
  
  
addEvent("takeover:gui") 
addEventHandler("takeover:gui", getRootElement(), 
function () 
    addEventHandler("onClientRender",root,territorytakeover) 
end) 
  
function territorytakeover() 
    dxDrawText("Territory Takeover",546.0,22.0,771.0,53.0,tocolor(255,0,0,255),1.0,"pricedown","left","top",false,false,false) 
end 
  
function capturearea() 
    triggerEvent("takeover:gui", getRootElement()) 
    if( guiProgressBarGetProgress( progressBar ) == 100 ) then 
    triggerServerEvent("takeover:complete", getRootElement()) 
    end 
end 
addCommandHandler("capture", capturearea) 
  

Server:

local ballasAreas = 
{ 
    createRadarArea( 2077.2470703125, -1099.728515625, -220, -180, 255,0,255, 100 ), 
    createRadarArea( 1981.6513671875, -1350.298828125, -140, -130, 255,0,255, 100 ), 
    createRadarArea( 2268.5859375, -1138.28515625, -100, -100, 255,0,255, 100 ), 
    createRadarArea( 2184.7529296875, -1108.1435546875, -110, -120, 255,0,255, 100 ), 
    createRadarArea( 2176.033203125, -1224.8935546875, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2265.5126953125, -1233.033203125, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2261.82421875, -1297.7451171875, -100, -80, 255,0,255, 100 ), 
    createRadarArea( 2165.7333984375, -1305.1416015625, -100, -80, 255,0,255, 100 ); 
} 
  
addEvent("takeover:complete") 
addEventHandler("takeover:complete",getRootElement(), 
    function( player, command ) 
        local hitAreas = { } 
        local posX, posY = getElementPosition( player ); 
        for _,v in pairs( ballasArea ) do 
            if( isInsideRadarArea( v, posX, posY ) ) then 
                table.insert( hitAreas, v ); 
            end 
        end 
        
        if( #hitAreas == 1 ) then 
            if( 
            getPlayerTeam( player ) and 
            getTeamName( getPlayerTeam( player ) ) == 'Grove' or 
            getTeamName( getPlayerTeam( player ) ) == 'Ballas' 
            ) then 
                local r, g, b, a = getRadarAreaColor( hitAreas[1] ); 
                if( r == 255 and g == 0 and b == 255 ) then 
                    setRadarAreaColor( hitAreas[1], 0, 255, 0, 100 ); 
                    setRadarAreaFlashing( hitAreas[1], true ); 
                else 
                    setRadarAreaColor( hitAreas[1], 255, 0, 255, 100 ); 
                end 
            end 
        end 
    end 
) 

Guest Guest4401
Posted

@michael1230

triggerServerEvent("takeover:complete", getRootElement()) 

You are never passing a player or command argument.

addEvent("takeover:complete") 
addEventHandler("takeover:complete",getRootElement(), 
    function( player, command ) 
  
    end 
) 

player and command will be nil obviously.

Learn how to pass arguments triggerServerEvent.

Posted
@michael1230
triggerServerEvent("takeover:complete", getRootElement()) 

You are never passing a player or command argument.

addEvent("takeover:complete") 
addEventHandler("takeover:complete",getRootElement(), 
    function( player, command ) 
  
    end 
) 

player and command will be nil obviously.

Learn how to pass arguments triggerServerEvent.

How can i learn this?

Guest Guest4401
Posted
@michael1230
triggerServerEvent("takeover:complete", getRootElement()) 

You are never passing a player or command argument.

addEvent("takeover:complete") 
addEventHandler("takeover:complete",getRootElement(), 
    function( player, command ) 
  
    end 
) 

player and command will be nil obviously.

Learn how to pass arguments triggerServerEvent.

How can i learn this?

If you want to learn, then click this link and read it:

https://wiki.multitheftauto.com/wiki/triggerServerEvent

If you don't want to learn, then wait for someone to make the code and give you.

Posted
@michael1230
triggerServerEvent("takeover:complete", getRootElement()) 

You are never passing a player or command argument.

addEvent("takeover:complete") 
addEventHandler("takeover:complete",getRootElement(), 
    function( player, command ) 
  
    end 
) 

player and command will be nil obviously.

Learn how to pass arguments triggerServerEvent.

How can i learn this?

If you want to learn, then click this link and read it:

https://wiki.multitheftauto.com/wiki/triggerServerEvent

If you don't want to learn, then wait for someone to make the code and give you.

Mate im trying :/

Edit: Could you tell me what section to read cause i have read the first huge paragraph and it does'nt say anything about passing arguments it just tell me what i can pass.

Posted
@michael1230
triggerServerEvent("takeover:complete", getRootElement()) 

You are never passing a player or command argument.

addEvent("takeover:complete") 
addEventHandler("takeover:complete",getRootElement(), 
    function( player, command ) 
  
    end 
) 

player and command will be nil obviously.

Learn how to pass arguments triggerServerEvent.

How can i learn this?

If you want to learn, then click this link and read it:

https://wiki.multitheftauto.com/wiki/triggerServerEvent

If you don't want to learn, then wait for someone to make the code and give you.

Will this work?

  
local localPlayer = getLocalPlayer() 
  
function capturearea() 
    triggerEvent("takeover:gui", getRootElement()) 
    if( guiProgressBarGetProgress( progressBar ) == 100 ) then 
    triggerServerEvent("takeover:complete", getRootElement(), localPlayer, command) 
    end 
end 
addCommandHandler("capture", capturearea) 

Posted

Man, the command /capture is when you start capturing the territory, not to when the capture is done.

"[...] If you don’t love it, if you’re not having fun doing it, you don’t really love it, you’re going to give up." - Steve Jobs, 2007

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