Jump to content

[HELP]Trigger Event


DiGiTal

Recommended Posts

Hi, it's a turf system. i created the progress bar in the client. i want once a player joined a zone of turf it will trigger the client for to show the bar.but it didn't work.         triggerEvent ( "drawed", root)
                    triggerEvent ( "started", root)   
those are. drawed= for to draw the progress bar, started= for to start it.  Thanks

Client:


local screenW, screenH = guiGetScreenSize() 
a = backgroundRectangle,progressRectangle,progressText
  
-- Assign a local variable to know if it is currently drawing or not. 
local isCurrentlyDrawing = false 
-- Variable for telling the script whether the timer is active or not. 
local progressTimer = false 
-- The total and current progress, this should always be between 0-100. 
local totalProgress = 0 
-- Math for converting the width. Originally the relative size to the screen was 2.575. So when totalProgress is at 100, renderProgress will be at 2.575. This will display the progress bar as full. 
local renderProgress = (totalProgress/100)/2.575 
  
function startDrawing() 
    -- Check if it is currently not drawing the rectangle. 
    if(isCurrentlyDrawing == false) then 
        -- Add the event handler to the function containing the drawings. 
        addEventHandler("onClientRender", getRootElement(), stuffToDraw) 
        -- Change the variable to true since you are now drawing it with every frame. 
        isCurrentlyDrawing = true 
    -- Check if it is currently drawing the rectangle. 
    elseif(isCurrentlyDrawing == true) then 
        -- If it is drawing, then remove the event handler. This will stop drawing the rectangle. 
        removeEventHandler("onClientRender", getRootElement(), stuffToDraw) 
        -- And change the variable back to false, since you're no longer drawing. 
        isCurrentlyDrawing = false 
    end 
end 
addEventHandler( "drawed", root, startDrawing )
addEvent ( "drawed", true )

function startTheProgress() 
    -- Check so the timer isn't already running. 
    if(progressTimer == false) then 
        -- Change the variable, you know the drill about those from now on.  
        progressTimer = true 
        -- Start the timer, and assign it a variable so it can be killed later. 
        theTimer = setTimer(function() 
            -- Increase the totalProgress with a random value between 0 to 10. 
            local randomProgress = math.random(0, 10) 
            -- Increase the totalProgress with the returned integer from above. 
            totalProgress = totalProgress+randomProgress 
            -- For debugging, will out put the random number and total progress in the format of randomNumber(totalProgress). 
            outputChatBox(tostring(randomProgress).."("..tostring(totalProgress)..")") 
            -- Update the renderProgress variable. 
            renderProgress = (totalProgress/100)/2.575 
            -- Check if the totalProgress becomes equal to or greater than 100. 
            if(totalProgress >= 100) then 
                -- Set the total progress to 100, in case it became greater than 100. This is to prevent the actual progress bar from becoming wider than the background. 
                totalProgress = 100 
                -- Update the renderProgress variable, since you change totalProgress above. 
                renderProgress = (totalProgress/100)/2.575 
                -- Update the timer variable. 
                progressTimer = false 
                -- Message to tell you that the progress became greater than or equal to 100. 
                outputChatBox("Progress greater than or equal to 100, killed timer.") 
                -- Kill the timer so it doesn't keep running. 
                killTimer(theTimer) 
						destroyElement(a)

            end 
        end, 120000, 1) 
    else 
        outputChatBox("Already progressing!") 
    end 
end 
addEvent ( "started", true )
addEventHandler( "started", root, startTheProgress )
  
function stuffToDraw() 
    -- Add the drawings you want in here. Do note that this code will be run with every frame. So 30-60 times PER SECOND. Be careful when using other code attached to onClientRender and onClientPreRender. 
    backgroundRectangle = dxDrawRectangle(screenW/3.0, screenH/1.4, screenW/2.5, screenH/15.0, tocolor(0, 0, 0, 110)) 
    progressRectangle = dxDrawRectangle(screenW/2.95, screenH/1.38, screenW*renderProgress, screenH/22, tocolor(30,144,255, 255)) 
    progressText = dxDrawText("Gang War: ("..totalProgress.."%)", screenW/2.15, screenH/1.37, screenW/2.575, screenH/22, tocolor(255, 255, 255, 255), 1) 
end 

Server:


local turfElement = {}
local turfTimer = {}
local checkComplete = false

local messages = {
 [1] = "Turf System by Sasuke* was started correctly!",
 [2] = "This territory already belongs to %s",
 [3] = "You enter into de %s's turf zone. Wait untill it's 100% and win 4000$",
 [4] = "[GANG ZONE]This Territor",
 [5] = "Congratulations. +4000$",
 [6] = "If you don't come back within 20s, you won't capture the turf",
 [7] = "You couldn't capture the turf because of absence"
 }
addEventHandler ( "onColShapeHit", root,
 function ( player )
  if turfElement[source] and source == turfElement[source][1] then
   local turf,area,id = unpack( turfElement[source] )
   local playerGang = getElementData ( player, "gang" )
   local turfGang = executeSQLQuery("SELECT GangOwner FROM Turf_System WHERE Turfs=?", "Turf["..tostring(id).."]" )
   if ( turfGang[1].GangOwner == playerGang ) then
	exports.joinq:showText( messages[2]:format( turfGang[1].GangOwner or "None" ), player, 0, 255, 0, false )
   else
    local playerGang = getElementData ( player, "gang" )
    setElementData( source, "warTurf", playerGang )
    if ( isTimer ( turfTimer[source][1] ) ) then
     if isTimer( turfTimer[source][2] ) then killTimer( turfTimer[source][2] ) end 
     return 
    end
    if ( playerGang ) then
     local r, g, b = unpack ( getGangColor ( playerGang ) )
     -- local r, g, b = 255, 255, 255
     setRadarAreaFlashing ( area, true )
     if turfGang[1].GangOwner ~= "Nadie" then
	triggerEvent ( "drawed", root)
	triggerEvent ( "started", root)	
	exports.joinq:showText( "You enter into de %s's turf zone. Wait untill it's 100% and win 4000$", player, 0, 255, 0, false )
     else
	exports.joinq:showText( messages[4], player, 0, 255, 0, false )
     end
     
     turfTimer[source][1] = setTimer (
      function ( )
       local players = getGangPlayersInTurf ( turf, playerGang )
       setRadarAreaColor ( area, tonumber(r), tonumber(g), tonumber(b), 175 )
       for _, player in ipairs ( players ) do
     exports.joinq:showText( messages[5], player, 0, 255, 0, false )
		triggerEvent ("onTakeTurf", root)
        givePlayerMoney ( player, 4000 )
        executeSQLQuery("UPDATE Turf_System SET GangOwner=?,r=?,g=?,b=? WHERE Turfs=?", playerGang, tonumber(r), tonumber(g), tonumber(b), "Turf["..tostring(id).."]" )
        -- setElementData ( turf, "getTurfGang", playerGang )
       end
       setRadarAreaFlashing ( area, false )
      end
     ,120000, 1)
    end
   end
  end
 end
)

 

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