SA-MP Forums Archive
Progress bar - 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: Progress bar (/showthread.php?tid=483785)



Progress bar - cnoopers - 27.12.2013

how to give value to bar, and check it that may some functions?
dont refer me here but this dont say me much.


Re: Progress bar - xVIP3Rx - 27.12.2013

pawn Код:
SetProgressBarValue(barid, GetProgressBarValue(barid)+value); // To increase the value
pawn Код:
GetProgressBarValue(barid); // To get the current value



Re: Progress bar - cnoopers - 27.12.2013

okay, so can i get value, for example 10? concr if i got 10 value, give me given weapn?


Re: Progress bar - xVIP3Rx - 27.12.2013

I didn't understand that very well but I'll try to describe it all in a little code
pawn Код:
SetProgressBarValue(barid, 25); // Now the value is 25
SetProgressBarValue(barid, GetProgressBarValue(barid)+10); // Now the value will be 25+10=35
new Float:Value = GetProgressBarValue(barid); // That will return 35 ( Value = 35 )



Re: Progress bar - cnoopers - 27.12.2013

what happened?

Код:
public OnGameModeInit()
{
    new Bar:tired = CreateProgressBar(500.00, 103.00, 105.50, 4.50, -202116097, 100.0);

	return 1;
}

new TTired[MAX_PLAYERS];

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    TTired[playerid] = SetTimerEx("Tired", 9000, true, "i", playerid);
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    KillTimer(TTired[playerid]);
    return 1;
}

forward Tired();
public Tired()
{
    SetProgressBarValue(Bar:tired, GetProgressBarValue(barid)+1);
}
Код:
warning 204: symbol is assigned a value that is never used: "tired"
error 017: undefined symbol "tired"



Re: Progress bar - xVIP3Rx - 27.12.2013

Here you go, Just improved/fixed it for you..
pawn Код:
new Bar:tired[MAX_PLAYERS] = {INVALID_BAR_ID, ...};
new TTired[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    tired[playerid] = CreateProgressBar(500.00, 103.00, 105.50, 4.50, -202116097, 100.0);
    return 1;
}

public OnPlayerEnterVehicle(playerid, vehicleid, ispassenger)
{
    ShowProgressBarForPlayer(playerid, tired[playerid]);
    TTired[playerid] = SetTimerEx("Tired", 9000, true, "i", playerid);
    return 1;
}

public OnPlayerExitVehicle(playerid, vehicleid)
{
    KillTimer(TTired[playerid]);
    return 1;
}

forward Tired(playerid);
public Tired(playerid)
{
    SetProgressBarValue(tired[playerid], GetProgressBarValue(tired[playerid])+1);
    return 1;
}
Note: I don't suggest using OnPlayerExitVehicle because :
1. OnPlayerEnterVehicle is called when a player starts to enter a vehicle, meaning the player is not in vehicle yet at the time this callback is called."
2. OnPlayerExitVehicle Not called if the player falls off a bike or is removed from a vehicle by other means such as using SetPlayerPos.

And use OnPlayerStateChange instead
Another code using "OnPlayerStateChange"
pawn Код:
new Bar:tired[MAX_PLAYERS] = {INVALID_BAR_ID, ...};
new TTired[MAX_PLAYERS];

public OnPlayerConnect(playerid)
{
    tired[playerid] = CreateProgressBar(500.00, 103.00, 105.50, 4.50, -202116097, 100.0);
    return 1;
}

public OnPlayerStateChange(playerid, newstate, oldstate)
{
    if(newstate == PLAYER_STATE_DRIVER || newstate == PLAYER_STATE_PASSENGER) // Player entered a vehicle as a driver or a passenger
    {
        ShowProgressBarForPlayer(playerid, tired[playerid]);
        TTired[playerid] = SetTimerEx("Tired", 9000, true, "i", playerid);
    }
    else if(oldstate == PLAYER_STATE_DRIVER || oldstate == PLAYER_STATE_PASSENGER) // Player Exited a vehicle and he  was a driver or a passenger
    {
        KillTimer(TTired[playerid]);
    }
    return 1;
}

forward Tired(playerid);
public Tired(playerid)
{
    SetProgressBarValue(tired[playerid], GetProgressBarValue(tired[playerid])+1);
    return 1;
}



Re: Progress bar - cnoopers - 27.12.2013

wait. when player join to the game, progress be create. thats wrong, becas thats be to many.


Re: Progress bar - cnoopers - 27.12.2013

anyone help me?


Re: Progress bar - xVIP3Rx - 27.12.2013

So when you want to create it ?


Re: Progress bar - cnoopers - 27.12.2013

i seems in ongamemodeinit, but i cant suppose.
Sooo.. if this bar is create when player join to the server, so i have to destroy it when hes disconnected. right?