progressbar timer - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: progressbar timer (
/showthread.php?tid=466963)
progressbar timer -
romka - 30.09.2013
Hy!
The progressbar timer dosent work please help!
code:
PHP код:
dcmd_text(playerid,params[])
{
#pragma unused params
varastamine[playerid] = CreateProgressBar(532.00, 372.00, 103.50, 11.19, -86, 100.0);
ShowProgressBarForPlayer(playerid, varastamine[playerid]);
SetProgressBarValue(varastamine[playerid], 10.0);
UpdateProgressBar(varastamine[playerid], playerid);
SetTimer("Textdrawnaita", 1000, false);
return 1;
}
PHP код:
public Textdrawnaita(playerid)
{
ShowProgressBarForPlayer(playerid, varastamine[playerid]);
SetProgressBarValue(varastamine[playerid], 20.0);
UpdateProgressBar(varastamine[playerid], playerid);
SetTimer("Textdrawnaita2", 2500, true);
}
Re: progressbar timer -
romka - 30.09.2013
please help!
Re: progressbar timer -
-Prodigy- - 30.09.2013
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);
Re: progressbar timer -
Deji - 30.09.2013
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.0, 220.0, _, _, 0xFFFFFFFF, 100.0)
// start with 0 per-cent, maybe?
SetProgressBarValue(varastamine[playerid], 0.0);
// show to player
ShowProgressBarForPlayer(playerid, varastamine[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.0, floatround_floor);
// keep it within percentage boundaries
if(prog > 100) prog = 100;
else if(prog <= 0) prog = 0;
// set the new progress
SetProgressBarValue(barid, prog);
// 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.
Re: progressbar timer -
romka - 30.09.2013
thanks for help