[Include] stamina (control each player stamina)
#1

STAMINA

This include allows you to control player's stamina, You can make fat skins get tired faster than slim skins etc...
How to include:

Код:
#define FILTERSCRIPT 
#define STAMINA_UPDATE_TIME //you can set you'r own update time by defining STAMINA_UPDATE_TIME before including stamina
#include <a_samp>
#include <stamina> //req y_hooks and foreach

//and you must add this callback: or you will get error.

public OnPlayerOutOfStamina(playerid)
{

    return 1;
}
Functions:

Код:
native SetPlayerStamina(playerid, Float:stamina);
native SetPlayerStaminaSubVal(playerid, Float:sub_val);
native GetPlayerStamina(playerid, &Float:stamina);
native GetPlayerStaminaSubVal(playerid);
Callbacks:

Код:
OnPlayerOutOfStamina(playerid)
Example:

1. make tired animation

PHP код:
#include <a_samp>
#include <stamina>
public OnPlayerOutOfStamina(playerid)
{
    
ApplyAnimation(playerid"PED""IDLE_tired"4.10110STAMINA_UPDATE_TIME*51);
    return 
1;

2. Player health decrease just like in GTA 5

PHP код:
#include <a_samp>
#include <stamina>
public OnPlayerOutOfStamina(playerid
{
    new 
Float:hp;
    
GetPlayerHealth(playeridhp); 
    
SetPlayerHealth(playeridhp-1.5);
    return 
1;

Video: https://www.youtube.com/watch?v=Zo8doDuZ6J4

Github: Click here

Download: Click here

requires:

y_hooks & foreach

Bugs:

If you find any bugs please report.


Credits:

SA-MP team - a_samp
****** - y_hooks & foreach
Lokii - stamina
Reply
#2

Looks good, but your are calling functions inside iterator, if you replace with variable directly should be more optimized.
Example: GetPlayerStamina > Line: 92
Reply
#3

Quote:
Originally Posted by Injury
Посмотреть сообщение
Looks good, but your are calling functions inside iterator, if you replace with variable directly should be more optimized.
Example: GetPlayerStamina > Line: 92
How else am i supposed to get players stamina? i cannot get players stamina outside the loop
Reply
#4

Код:
public es_StaminaUpdate()
{
    new animlib[32], animname[32];
    foreach(new i : Player)
    {
        GetAnimationName(GetPlayerAnimationIndex(i), animlib, 32, animname, 32);
        if(!strcmp("SWIM_CRAWL", animname, true) || !strcmp("SWIM_UNDER", animname, true))
            continue;

        if(GetSpeed(i) > 18.0)
        {
            if(g_PlayerStamina[i]> 0.0)
            {
                SetPlayerStamina(i, g_PlayerStamina[i]-g_SubStamina[i]);
            }
            else
            {
                OnPlayerOutOfStamina(i);
            }
        }
        else
        {
            if(g_PlayerStamina[i] < 100.0)
            {
                SetPlayerStamina(i, g_PlayerStamina[i]+g_SubStamina[i]);
            }
        }
    }
    return 1;
}
Reply
#5

Quote:
Originally Posted by Injury
Посмотреть сообщение
Код:
public es_StaminaUpdate()
{
    new animlib[32], animname[32];
    foreach(new i : Player)
    {
        GetAnimationName(GetPlayerAnimationIndex(i), animlib, 32, animname, 32);
        if(!strcmp("SWIM_CRAWL", animname, true) || !strcmp("SWIM_UNDER", animname, true))
            continue;

        if(GetSpeed(i) > 18.0)
        {
            if(g_PlayerStamina[i]> 0.0)
            {
                SetPlayerStamina(i, g_PlayerStamina[i]-g_SubStamina[i]);
            }
            else
            {
                OnPlayerOutOfStamina(i);
            }
        }
        else
        {
            if(g_PlayerStamina[i] < 100.0)
            {
                SetPlayerStamina(i, g_PlayerStamina[i]+g_SubStamina[i]);
            }
        }
    }
    return 1;
}
Ohh right sorry i was thinking you meant:

Код:
GetPlayerStamina(i);
foreach(new i : Player)
anyway updated
Reply
#6

Tried to add this like a blank nothing happend

Set Stamina to 100

create a commande to get my stamina run like 5 sec and still get 100

Can you provide us a exemple like the one on the video?
Reply
#7

PHP код:
#include <a_samp>
#include <stamina>
#include <progress2>
#include <zcmd>

new sbtime[MAX_PLAYERS];
new 
PlayerBar:StaminaBar[MAX_PLAYERS];

public 
OnPlayerConnect(playerid)
{
    if(
IsPlayerNPC(playerid)) return 1;
    
StaminaBar[playerid] = CreatePlayerProgressBar(playerid547.030.063.05.00xFFFFFFFF100.0BAR_DIRECTION_RIGHT0x000000FF);
    
ShowPlayerProgressBar(playeridStaminaBar[playerid]);
    return 
1;
}

public 
OnPlayerDisconnect(playeridreason)
{
    if(
IsPlayerNPC(playerid)) return 1;
    
DestroyPlayerProgressBar(playeridStaminaBar[playerid]);
    return 
1;
}

public 
OnPlayerOutOfStamina(playerid)
{
    
ApplyAnimation(playerid"PED""IDLE_tired"4.10110STAMINA_UPDATE_TIME*51);
    return 
1;
}

CMD:sub(playeridparams[])
{
    
SetPlayerStaminaSubVal(playeridstrval(params));
    return 
1;
}

public 
OnPlayerUpdate(playerid)
{
    new 
Float:stamina;
    if(!
IsPlayerNPC(playerid))
    {
        if(
sbtime[playerid] != gettime())
        {
            
GetPlayerStamina(playeridstamina);
            
SetPlayerProgressBarValue(playeridStaminaBar[playerid], stamina);
            
sbtime[playerid] = gettime();
        }
    }
    return 
1;

Reply
#8

Mah man rep!
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)