Nandonalt
New Member
- Joined
- Aug 4, 2008
- Messages
- 29
- Reaction score
- 0
Hello, i made this hunger system for my RPG OTServer. It's very simple
You can configure the way you want in the lua. The scripts may be a little long because i'm old school and i do not know alot of the actual scripting :mellow:
I also posted this on other forum.
I made it and tested in The Forgotten Server 0.3.6 (8.54).
TFS Mod
As Frankfarmer said, a mod would be better. Then i made the mod
Just extract the attached file in yours mods folder. The config is in scripts/hungersystem/config.lua.
The command for checking the hunger % is "/hunger"
How to config the interval of adding 1% hunger to all players:
But you need to do this:
-------------
Manual Way
Make a file called "checkhunger.lua" in the folder creaturescripts/scripts, and add this:
Now go to your onLogin script and add this inside the function:
Open the creaturescripts.xml file and add:
Now go to the actions/scripts folder and find a file called food.lua. As i said before, i made this using TFS, so the food system may be different.
After:
Add:
We are coming to the end! Go to globalevents/scripts and make a file called givehunger.lua, and add this:
And add this to globalevents.xml. INTERVAL is the interval between adding 1% hunger to all players online (in seconds):
OPTIONAL: An talkaction that says how much hungry the player is.
Make a file called hunger.lua in talkactions/scripts, add this:
And talkactions.xml:
You are ready! I have changed this script to put it here(i made it configurable), so if there is any errors please report. And english is not my native language so... yeah.
You can configure the way you want in the lua. The scripts may be a little long because i'm old school and i do not know alot of the actual scripting :mellow:
I also posted this on other forum.
I made it and tested in The Forgotten Server 0.3.6 (8.54).
TFS Mod
As Frankfarmer said, a mod would be better. Then i made the mod
Just extract the attached file in yours mods folder. The config is in scripts/hungersystem/config.lua.
The command for checking the hunger % is "/hunger"
How to config the interval of adding 1% hunger to all players:
After you extracted, go to yours mods folder and open hungersystem.xml and find this:
Where is "interval=2" change the "2" to the interval you want(in seconds, Ex: 1 minute -> interval="60"Code:<globalevent name="GiveHunger" interval="2" event="script" value="hungersystem/globalevents.lua"/>
But you need to do this:
Go to the actions/scripts folder and find a file called food.lua. As i said before, i made this using TFS, so the food system may be different.
After:
Add:Code:doRemoveItem(item.uid, 1)
Code:------ Put the same storage that you wrote on your config file :) hunger___storage = 5544 ----------- setPlayerStorageValue(cid,hunger___storage,getPlayerStorageValue(cid,hunger___storage)-food[1])
-------------
Manual Way
Make a file called "checkhunger.lua" in the folder creaturescripts/scripts, and add this:
Code:
function onThink(cid, interval)
------------------- Hunger System by Nandonalt
----------- Hunger System Config
-- Hunger Storage Value
hunger_storage = 5544
-- Hunger % that the player will start to say he's hungry (1 - 99).
hunger_scream = 95
-- Put 0 to player die if hunger is 100%, or 1 to change his hp to 1.
hunger_die = 0
-- Put inside the " " what the player will say if he is hungry.
hunger_say1 = "I'm Hungry!!"
-- Put inside the " " what the player will say when reaches 100% hunger.
hunger_say2 = "<Dying of Starvation>"
----- Script Below
storage = getPlayerStorageValue(cid,hunger_storage)
if storage < 0 then
setPlayerStorageValue(cid,hunger_storage,0)
elseif storage > 100 then
setPlayerStorageValue(cid,hunger_storage,100)
elseif storage >= hunger_scream and storage <= 99 then
doCreatureSay(cid,hunger_say1,TALKTYPE_ORANGE_1)
elseif storage >= 100 then
setPlayerStorageValue(cid,hunger_storage,0)
doCreatureSay(cid,hunger_say2,TALKTYPE_ORANGE_1)
health = getCreatureHealth(cid)-hunger_die
doCreatureAddHealth(cid,-health)
end
return 1
end
Now go to your onLogin script and add this inside the function:
Code:
------ Put the same storage as checkhunger.lua
hunger__storage = 5544
-----------
registerCreatureEvent(cid, "Hunger")
if getPlayerStorageValue(cid,hunger__storage) == -1 then
setPlayerStorageValue(cid,hunger__storage, 0)
else
end
Open the creaturescripts.xml file and add:
Code:
<event type="think" name="Hunger" event="script" value="checkhunger.lua"/>
Now go to the actions/scripts folder and find a file called food.lua. As i said before, i made this using TFS, so the food system may be different.
After:
Code:
doRemoveItem(item.uid, 1)
Code:
------ Put the same storage as checkhunger.lua
hunger___storage = 5544
----------- setPlayerStorageValue(cid,hunger___storage,getPlayerStorageValue(cid,hunger___storage)-food[1])
We are coming to the end! Go to globalevents/scripts and make a file called givehunger.lua, and add this:
Code:
function onThink(cid, item, fromPosition, toPosition)
------- Hunger System by Nandonalt
--- Put the same storage as checkhunger.lua
hungerstorage = 5544
-------------
for _, name in ipairs(getOnlinePlayers()) do
local player = getPlayerByName(name)
setPlayerStorageValue(player,hungerstorage,getPlayerStorageValue(player,hungerstorage)+1)
end
return 1
end
And add this to globalevents.xml. INTERVAL is the interval between adding 1% hunger to all players online (in seconds):
Code:
<globalevent name="givehunger" interval="30" event="script" value="givehunger.lua"/>
OPTIONAL: An talkaction that says how much hungry the player is.
Make a file called hunger.lua in talkactions/scripts, add this:
Code:
function onSay(cid, words, param)
------- Hunger System by Nandonalt
---- Change 5544 to the same storage that you wrote on checkhunger.lua
storage = getPlayerStorageValue(cid,5544)
doPlayerSendCancel(cid,"Hunger percent: "..storage.."%.")
return 1
end
And talkactions.xml:
Code:
<talkaction words="/hunger" event="script" value="hunger.lua"/>
You are ready! I have changed this script to put it here(i made it configurable), so if there is any errors please report. And english is not my native language so... yeah.
Attachments
-
Hunger System - By Nandonalt.rar1.7 KB · Views: 53 · VirusTotal
Last edited: