progressbar timer
#1

Hy!

The progressbar timer dosent work please help!

code:

PHP код:
dcmd_text(playerid,params[])
{
    
#pragma unused params
     
varastamine[playerid] = CreateProgressBar(532.00372.00103.5011.19, -86100.0);
    
ShowProgressBarForPlayer(playeridvarastamine[playerid]);
    
SetProgressBarValue(varastamine[playerid], 10.0);
    
UpdateProgressBar(varastamine[playerid], playerid);
     
SetTimer("Textdrawnaita"1000false);
    return 
1;

PHP код:
public Textdrawnaita(playerid)
{
    
ShowProgressBarForPlayer(playeridvarastamine[playerid]);
    
SetProgressBarValue(varastamine[playerid], 20.0);
    
UpdateProgressBar(varastamine[playerid], playerid);
    
SetTimer("Textdrawnaita2"2500true);

Reply
#2

please help!
Reply
#3

pawn Код:
SetTimer("Textdrawnaita", 1000, false);
to
pawn Код:
SetTimerEx("Textdrawnaita", 1000, false, "i", playerid);
.. and so on
pawn Код:
SetTimer("Textdrawnaita2", 2500, true);
to
pawn Код:
SetTimerEx("Textdrawnaita2", 2500, true, "i", playerid);
Reply
#4

What on earth are you trying to do? I mean, from an experienced coder point-of-view, your code appears to not have much purpose.

I'm not too smooth with PAWNO and I have no idea where those progress bar natives and I've got no documentation on it to go on, but here's an example of a more useful application:
PHP код:
// change the declaration depending on use...
new ProgressTargets[MAX_PLAYERS];
stock UpdatePlayerProgressBar(playerid)
{
    
// do a little update
    
UpdateProgressBar(varastamine[playerid], playerid);
}
stock ShowPlayerProgressBar(playerid
{
    
// must use CreateProgressBar
    
varastamine[playerid] = CreateProgressBar(320.0220.0__0xFFFFFFFF100.0)
    
// start with 0 per-cent, maybe?
    
SetProgressBarValue(varastamine[playerid], 0.0);
    
// show to player
    
ShowProgressBarForPlayer(playeridvarastamine[playerid]);
    
UpdatePlayerProgressBar(playerid);
    
    
// a timer is not based on "progress", unless your progress is the transit of time and even so, will not update smothly
    //SetTimer("Textdrawnaita2", 2500, true); 
    
    // this is a much smoother way to keep track of progress. store the current and target values:
    
ProgressCurrents[playerid] = GetTickCount();
    
ProgressTargets[playerid] = 3000;
}
// recommendation: use OnPlayerUpdate for ANYTHING which has to run constantly for any one player
public OnPlayerUpdate(int pid)
{
    
// not sure how PAWN allocates this, but in C in-function static vars are stored globally, but can only be accessed within the current scope - they keep their value after the function ends and are great for function-specific variables
    
static nLastUpdateTime[MAX_PLAYERS];
    
    new 
Float:diff float(GetTickCount() - nLastUpdateTime[pid]);
    
floatabs(diff);   // just in case, say, the player has been on for over 24 days (fail-safe)
    
    // The following if will return true every 100 milliseconds the player is online (higher - better server performance, lower - better script performance)
    
if((diff >= 100.0)
    {
        
// --BEGIN PROGRESS UPDATE CODE--
        // This is what actually gets the progress to 'prog'. This is the major part to change (other than the basic use of vars in this code - it's an example only)
        
diff float(ProgressTargets[pid] - GetTickCount());
        
floatabs(diff);    // again, fixes issues with integer limits and GetTickCount with relative integral values
        // (important algorithm) - divide the current by the total and multiply by the percentage limit
        
new prog floatround((diff ProgressTargets[pid]) * 100.0floatround_floor);
        
        
// keep it within percentage boundaries
        
if(prog 100prog 100;
        else if(
prog <= 0prog 0;
        
        
// set the new progress
        
SetProgressBarValue(baridprog);
        
// finally, update
        
UpdatePlayerProgressBar(pid);
        
        
// --END PROGRESS UPDATE CODE--
        
        // set the update time of this player to the current time
        
nLastUpdateTime[pid] = GetTickCount();
    }
    return 
0;   // change this to 1 if you use OnPlayerUpdate in other scripts (I've never needed it)

Untested. As I said I'm not a PAWN coder, I prefer C++. This code is based on quick online lookups and on-the-spot coding and is just intended as a demonstration. In other words, don't do what I see most PAWN coders doing and just copy'n'paste'n'adapt. Using a var[MAX_PLAYERS] array for every single different player-related property is down-right ridiculous, yet I see it in so many scripts. I would suggest looking for better ways to do a similar thing and keeping related data together.
Reply
#5

thanks for help
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)