04.06.2014, 17:29
(
Last edited by Jay_Dixon; 07/06/2014 at 11:10 PM.
)
Right, so. Here, I have possibly the most simple thing you'll ever make. Could be great for RP servers as well. So lets get started shall we?
so, we'll be using ZCMD for this tutorial. If you use string compare or dcmd, I honestly highly recommend you upgrade to ZCMD, it's the best command processor in my honest opinion. Although everyone's entitled to their own.
We'll start by adding the 2 includes that we'll need.
Next, we'll define how much HP you'll lose when you're hungry, and how long until you're hungry
Next we'll create the forward for the timer.
As for the 2 array's we'll be using
Right, so next we'll want to create the timer, for when that person would be hungry, and all that lovely stuff. So to do that, we'll need to create a timer. You'll want to put it under OnPlayerSpawn, so that it starts the hunger counter everytime the player spawns.
Ok, so now we have the timer made, and going, now we need to create the result of when they get hungry.
Next up, we'll create the command for it. Normally I'd have it locked to food places, but for this tutorial, I'll just make it so that you can use it anywhere.
And that's my tutorial for a simple hunger system. If you liked it feel free to comment and/or rep. Or tell me opinions and how I'd be able to improve for future tutorials, as this was my first tutorial ever so I realize it may not be the best, but who says there's no room for improvement right?
so, we'll be using ZCMD for this tutorial. If you use string compare or dcmd, I honestly highly recommend you upgrade to ZCMD, it's the best command processor in my honest opinion. Although everyone's entitled to their own.
We'll start by adding the 2 includes that we'll need.
pawn Code:
#include <a_samp>//This is required
#include <zcmd>//CMD: ability
pawn Code:
#undef MAX_PLAYERS // |
#define MAX_PLAYERS 50 //Change this to your player slot amount |
#define needFoodTimer 10000 //Edit this value to change the timer, now = 10 mins |
#define losingHealth 5 //The HP the player will lose
#define COLOR_LIGHTRED 0xFF6347AA //Lets not forget the colors!
#define COLOR_LIGHTGREEN 0x7CFC00AA
pawn Code:
forward needFood(playerid);
pawn Code:
new firstSpawn[MAX_PLAYERS];
new Float:curHealth[MAX_PLAYERS];
pawn Code:
public OnPlayerSpawn(playerid) {
firstSpawn[playerid] += 1;//This is for when they spawn
new Float:Health;//This is the float we'll need to detect current health
GetPlayerHealth(playerid, Health);//This is to get their health
curHealth[playerid] = Health;//Same for above
if(firstSpawn[playerid] == 1)//This is for when we start the timer
SetTimerEx("needFood",needFoodTimer,1,"i", playerid);//Lets start the timer shall we?
return 1;
}
pawn Code:
public needFood(playerid) {
new Float:Health;
GetPlayerHealth(playerid, Health);
if(curHealth[playerid] >= health) {
SendClientMessage(playerid, COLOR_LIGHTRED, "You start to feel hungry!");
SetPlayerHealth(playerid,Health-losingHealth);
curHealth[playerid] = Health-5;//This is to take the health away
} else {
curHealth[playerid] = health;
}
}
pawn Code:
CMD:eat(playerid) {
SetPlayerHealth(playerid, 100);
SetTimerEx("needFood",needFoodTimer,1,"i",playerid);//Now that the players eaten, we'll reset the timer
SendClientMessage(playerid, COLOR_LIGHTGREEN, "You are no longer hungry");
return 1;
}