SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Filterscripts > Includes

Reply
 
Thread Tools Display Modes
Old 25/02/2019, 10:48 AM   #1
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 359
Reputation: 87
Default stamina (control each player stamina)


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:

Code:
#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:

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

Code:
OnPlayerOutOfStamina(playerid)
Example:

1. make tired animation

PHP Code:
#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 Code:
#include <a_samp>
#include <stamina>

public OnPlayerOutOfStamina(playerid
{
    new 
Float:hp;
    
GetPlayerHealth(playeridhp); 
    
SetPlayerHealth(playeridhp-1.5);
    return 
1;

Video: https://www.*******.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
Attached Files
File Type: zip stamina.zip (1.1 KB, 31 views)

Last edited by Lokii; 15/10/2019 at 08:22 AM.
Lokii is offline   Reply With Quote
Old 25/02/2019, 12:55 PM   #2
Injury
Big Clucker
 
Injury's Avatar
 
Join Date: Nov 2016
Location: Brazil - SP
Posts: 102
Reputation: 24
Default Re: stamina (control each player stamina)

Looks good, but your are calling functions inside iterator, if you replace with variable directly should be more optimized.
Example: GetPlayerStamina > Line: 92
Injury is offline   Reply With Quote
Old 25/02/2019, 01:15 PM   #3
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 359
Reputation: 87
Default Re: stamina (control each player stamina)

Quote:
Originally Posted by Injury View Post
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
Lokii is offline   Reply With Quote
Old 25/02/2019, 01:38 PM   #4
Injury
Big Clucker
 
Injury's Avatar
 
Join Date: Nov 2016
Location: Brazil - SP
Posts: 102
Reputation: 24
Default Re: stamina (control each player stamina)

Code:
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;
}
Injury is offline   Reply With Quote
Old 25/02/2019, 01:49 PM   #5
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 359
Reputation: 87
Default Re: stamina (control each player stamina)

Quote:
Originally Posted by Injury View Post
Code:
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:

Code:
GetPlayerStamina(i);
foreach(new i : Player)
anyway updated
Lokii is offline   Reply With Quote
Old 28/02/2019, 07:30 AM   #6
tysanio
Big Clucker
 
tysanio's Avatar
 
Join Date: May 2012
Location: At my House Duh..
Posts: 125
Reputation: 17
Default Re: stamina (control each player stamina)

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?
__________________

Did i ever tell you the définitions of insanity?
tysanio is offline   Reply With Quote
Old 28/02/2019, 01:33 PM   #7
Lokii
Huge Clucker
 
Join Date: Sep 2017
Posts: 359
Reputation: 87
Default Re: stamina (control each player stamina)

PHP Code:
#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;

Lokii is offline   Reply With Quote
Old 28/02/2019, 03:52 PM   #8
tysanio
Big Clucker
 
tysanio's Avatar
 
Join Date: May 2012
Location: At my House Duh..
Posts: 125
Reputation: 17
Default Re: stamina (control each player stamina)

Mah man rep!
__________________

Did i ever tell you the définitions of insanity?
tysanio is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
PAYDAY SA:MP - Armour, Health & Stamina Preview #1 TheSlenderman Screenshots and Videos 4 18/02/2019 08:35 AM
[Pedido] Stamina UzumakiNaruto Português/Portuguese 3 27/05/2014 08:26 PM
How do I reset a player's stamina? AaronKillz Scripting Help 10 17/03/2013 01:13 PM
Stamina? Celson General 2 20/02/2011 03:45 PM
Max Stamina ViperSniper Help Archive 0 21/01/2011 06:47 AM


All times are GMT. The time now is 11:29 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.