PDA

Просмотр полной версии : [FS] Простая система голода



L0ndl3m
02.05.2014, 23:23
http://www.youtube.com/watch?v=J70KsfYiBAI]

Для работы со скриптом понадобится: progressbar (в оригинальной версии ещё зачем-то zcmd приписали к инклюдам).




#include <a_samp>
#include <progress>

#define HUNGER_SUB_INTERVAL \
1000

#define HEALTH_SUB_INTERVAL \
1000

#define HUNGER_SUB_HEALTH \
5

new
PlayerBar: pHungerBar[MAX_PLAYERS],
progressBarTimer[MAX_PLAYERS],
healthBarTimer[MAX_PLAYERS],
pHunger[MAX_PLAYERS],
pHungerHealth[MAX_PLAYERS]
;

public OnFilterScriptInit();

public OnPlayerSpawn(playerid)
{
pHunger[playerid] = 100;
pHungerHealth[playerid] = 100;

pHungerBar[playerid] = CreatePlayerProgressBar(playerid, 547.5, 58.0, 59.0, 5, 0x52875AFF, 100.0);
ShowPlayerProgressBar(playerid, pHungerBar[playerid]);

SetPlayerProgressBarValue(playerid, pHungerBar[playerid], 100);
UpdatePlayerProgressBar(playerid, pHungerBar[playerid]);

progressBarTimer[playerid] = SetTimer("@__hungerBarUpdate", HUNGER_SUB_INTERVAL, 1); // Потеря голода. HUNGER_SUB_INTERVAL = (по умолчанию: 1 секунда), измените это значение на своё

return 1;
}

@__hungerBarUpdate(playerid);
@__hungerBarUpdate(playerid)
{
if(pHunger[playerid] == 0)
{
KillTimer(progressBarTimer[playerid]);
healthBarTimer[playerid] = SetTimer("@__healthBarUpdate", HEALTH_SUB_INTERVAL, 1); // Потеря здоровья. HEALTH_SUB_INTERVAL = (по умолчанию: 1 секунда), измените это значение на своё
}
else if(pHunger[playerid] > 0)
{
pHunger[playerid] -= HUNGER_SUB_HEALTH;

SetPlayerProgressBarValue(playerid, pHungerBar[playerid], pHunger[playerid]);
UpdatePlayerProgressBar(playerid, pHungerBar[playerid]);
}
}

@__healthBarUpdate(playerid);
@__healthBarUpdate(playerid)
{
new
Float: p_id_health
;

pHungerHealth[playerid] -= HUNGER_SUB_HEALTH;
SetPlayerHealth(playerid, pHungerHealth[playerid]);

if(GetPlayerHealth(playerid, p_id_health) == 0)
KillTimer(healthBarTimer[playerid]);
}



Оригинал: http://forum.sa-mp.com/showthread.php?t=510091 (http://forum.sa-mp.com/showthread.php?t=510091)
Автор: Mionee
Дополнение к коду: Londlem (http://pro-pawn.ru/member.php?2057-Londlem)

Специально для: Pro-Pawn.Ru (http://pro-pawn.ru)

Копирование данной статьи без разрешения автора запрещено!