Jump to content

events issue


Chaos

Recommended Posts

hi, i have issue with events sometimes when last player standing the reward will give both last one and another one was dead before or the same player himself in event like:

in dm event it had 2 winners

someone called Lesly ( the last standing)

and another one called samsulee

who died at 5th place

reward will give to them both in the same time

can i set timer or something can fix this, any idea ?

>

  
  
  
function thisEventFunctions.OnPlayerWasted ( _, killer ) 
    local plrs = EventCore.GetPlayersInEvent ( ) 
    local winner = nil 
    if ( table.len ( plrs ) == 0 ) then 
        winner = source 
    elseif ( table.len ( plrs ) == 1 ) then 
        for i, v in pairs ( plrs ) do 
            winner = v 
        end 
    end 
    if winner then 
        EventCore.WinPlayerEvent ( winner ) 
    end 
end 
addEventHandler ( "onPlayerWasted", root, thisEventFunctions.OnPlayerWasted ) 
  

Link to comment
  
local theRealWinner -- nil for now 
  
function thisEventFunctions.OnPlayerWasted ( _, killer ) 
    local plrs = EventCore.GetPlayersInEvent ( ) 
    local winner = nil 
    if ( table.len ( plrs ) == 0 ) and theRealWinner ~= source then -- if the last player standing has already received the reward then don't give it to him again 
        winner = source 
    elseif ( table.len ( plrs ) == 1 ) then 
            winner = plrs [1]     
            theRealWinner = winner  
        end 
    end 
    if winner then 
        EventCore.WinPlayerEvent ( winner ) 
    end 
end 
addEventHandler ( "onPlayerWasted", root, thisEventFunctions.OnPlayerWasted ) 

if this doesn't work then there must be a flaw in EventCore.GetPlayersInEvent ( ) function. Make sure that you are not using element data to get alive player.

Link to comment

fair enough but i made a script for quit is that will working fine?

  
function onQuit() 
    local c = EventCore.GetPlayersInEvent ( ) 
    if ( #c == 1 ) then 
     for i, v in pairs ( c ) do 
      EventCore.WinPlayerEvent ( v ) 
      break 
     end 
    end 
    end 
  

Link to comment
fair enough but i made a script for quit is that will working fine?

Yep but you're using bad technique there. Here:

  
function onQuit() 
    local c = EventCore.GetPlayersInEvent ( ) 
    if ( #c == 1 ) then 
      theRealWinner = c[1] 
      EventCore.WinPlayerEvent ( c[1] ) 
       
    end 
    end 

Also I did a small fix there of my own code:

  
local theRealWinner -- nil for now 
  
function thisEventFunctions.OnPlayerWasted ( _, killer ) 
    local plrs = EventCore.GetPlayersInEvent ( ) 
    local winner = nil 
    if ( table.len ( plrs ) == 0 ) and theRealWinner ~= source then -- if the last player standing has already received the reward then don't give it to him again 
        winner = source 
theRealWinner =nil 
    elseif ( table.len ( plrs ) == 1 ) then 
            winner = plrs [1]     
            theRealWinner = winner 
        end 
    end 
    if winner then 
        EventCore.WinPlayerEvent ( winner ) 
    end 
end 
addEventHandler ( "onPlayerWasted", root, thisEventFunctions.OnPlayerWasted ) 

Link to comment
Last code it worked fine. Last question how can i convert time to mins and secs like 300000 mili secs to 4:59 > 4:58 ... and times should including zero beside one number 4:09 > 4:08...

You mean you want to check which time variable has more time passed/eplased? If that's the case then you can simply check it with milliseconds before converting them to string format.

If you meant string time format then you can use a function:

  
-- I'm using this function since many years. I took this from coronalabs forum. 
local function mstostr(   newfresh ) 
local floor = math.floor 
  
local ms = floor(newfresh % 1000) 
local hundredths = floor(ms / 10) 
local seconds = floor(newfresh / 1000) 
local minutes = floor(seconds / 60);   seconds = floor(seconds % 60) 
return string.format("%02d:%02d", minutes, seconds) 
  
end 
  
  
  

Usage:

local str =mstostr (  milliSeCondsHERE ) 

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