AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Global Timer variable mismatch (https://forums.alliedmods.net/showthread.php?t=295131)

iNvectus 03-17-2017 05:26

Global Timer variable mismatch
 
Hello.Recently, Ive been trying to do a duel system, yeah, I have done it, it works, but it has one feature that I want to implement into it that is getting some off values.I want to know where am I making a mistake.Here is the part of the code:

Note: Difference is declared as new Float: Difference; not as array.

PHP Code:

public fwdUse(entid

       if(!
g_bUserRacing[id])
        return 
PLUGIN_CONTINUE
   
  
new target[33
  
peventpev_targettargetsizeof target 
   
  if( 
equalitarget"counter_start" ) || equalitarget"clockstartbutton" ) || equalitarget"firsttimerelay" ) ) 
  { 
    
g_fHisTime[id] = get_gametime()
    
g_fHisTime[g_iAsker[id]] = get_gametime()
  } 
  else if( 
equalitarget"counter_off" ) || equalitarget"clockstopbutton" ) || equalitarget"clockstop" ) ) 
  { 
    new 
szBuffer[64];
    
get_user_name(idszBuffer63)
    
    
g_fHisTime[id] = get_gametime() - g_fHisTime[id];
    
g_fHisTime[g_iAsker[id]] = get_gametime() - g_fHisTime[g_iAsker[id]];
    
    if(
g_fHisTime[id] > g_fHisTime[g_iAsker[id]])
    {
        
Difference g_fHisTime[id] - g_fHisTime[g_iAsker[id]];
        
show_finish_message(idg_fHisTime[id])
    }else
    {
        
Difference g_fHisTime[g_iAsker[id]] - g_fHisTime[id];
        
show_finish_message(idg_fHisTime[g_iAsker[id]]);
    }
    
    
ColorChat(idRED"[%s] ^x01You won! :]"g_szPrefix);
    
ColorChat(g_iAsker[id], RED"[%s] ^x01You lost! :F"g_szPrefix);
    
    
g_bUserRacing[id] = false;
    
g_bUserRacing[g_iAsker[id]] = false;
    
    
g_fHisTime[id] = 0.0
    g_fHisTime
[g_iAsker[id]] = 0.0
    
    g_iAsker
[g_iAsker[id]] = 0;
    
g_iAsker[id] = 0;
  } 
   
  return 
FMRES_IGNORED
}


public 
show_finish_message(idFloat:dueltime)
{
    new 
name[32]
    new 
imin,isec,ims
    imin 
floatround(dueltime 60.0floatround_floor)
    
isec floatround(dueltime imin 60.0,floatround_floor)
    
ims floatround( ( dueltime - ( imin 60.0 isec ) ) * 100.0floatround_floor )
    
get_user_name(idname31);
    
    
//Difference
    
new dmindsecdms;
    
dmin floatround(Difference 60.0floatround_floor)
    
dsec floatround(Difference dmin 60.0floatround_floor)
    
dms floatround((Difference - (dmin 60.0 dsec)) * 100.0floatround_floor)
    
    
ColorChat(0RED"[%s]^x04 %s^x01 won the duel with time ^x04 %02i:%02i.%02i^x01[^x03 Difference: ^x04%02i:%02i.%02i^x01 ] Congratulations!"g_szPrefixnameiminisecimsdmindsecdms)


The problem lies here: When two players are dueling and if the first one finishes, it shows this chat message:
Quote:

[Kreedz Duels] unnamed won the duel with time 01:40.69(Difference: 00:00.00)
Any ideas?

jimaway 03-17-2017 07:32

Re: Global Timer variable mismatch
 
you start counting the time for both players at the same time
Code:

g_fHisTime[id] = get_gametime()
    g_fHisTime[g_iAsker[id]] = get_gametime()

that's why they both have same time stored when first player finishes


All times are GMT -4. The time now is 17:49.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.