function onThink(interval, lastExecution)
for _, cid in pairs(getPlayersOnline()) do
if getPlayerFood(cid) == 0 then
doCreatureAddHealth(cid, -10)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You are starving.")
end
end
return true
end
global eventOmg thanks limos, btw where do i put that script?
edit: in functions i guess...
Code:function onThink(interval, lastExecution) for _, cid in pairs(getPlayersOnline()) do if getPlayerFood(cid) == 0 then doCreatureAddHealth(cid, -10) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You are starving.") end end return true end
<?xml version="1.0" encoding="UTF-8"?>
<globalevents>
<globalevent name="save" interval="900" script="save.lua"/>
<globalevent name="starving" interval="900" script="starving.lua"/>
<globalevent name="clean" interval="7200" script="clean.lua"/>
</globalevents>
Not really performance friendly. Probably the best way would be to add starving condition when regeneration condition ends in sources or editing food script to add starving (addEvent) after player feed time, also checking it onLogin.
getPlayersOnline()
getPlayersOnlineList()
[27/01/2015 20:19:53] Lua Script Error: [GlobalEvent Interface]
[27/01/2015 20:19:53] data/globalevents/scripts/starving.lua:onThink
[27/01/2015 20:19:53] data/globalevents/scripts/starving.lua:2: attempt to call global 'getPlayersOnlineList' (a nil value)
[27/01/2015 20:19:53] stack traceback:
[27/01/2015 20:19:53] data/globalevents/scripts/starving.lua:2: in function <data/globalevents/scripts/starving.lua:1>
[27/01/2015 20:19:53] [Error - GlobalEvents::onThink] Couldn't execute event: starving
That is indeed a better idea.Not really performance friendly. Probably the best way would be to add starving condition when regeneration condition ends in sources or editing food script to add starving (addEvent) after player feed time, also checking it onLogin.
function doPlayerStarve(cid)
if isPlayer(cid) == FALSE or getPlayerFood(cid) > 0 then
return TRUE
end
doCreatureAddHealth(cid, -10)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You are starving.")
addEvent(doPlayerStarve, 60 * 1000, cid)
return TRUE
end
addEvent(doPlayerStarve, 60 * 1000, cid)
addEvent(doPlayerStarve, (getPlayerFood(cid) + 60) * 1000, cid)
function onLogin(cid)
registerCreatureEvent(cid, "PlayerDeath")
addEvent(doPlayerStarve, 60 * 1000, cid)
return TRUE
end
function doPlayerStarve(cid)
if not isPlayer(cid) or getPlayerFood(cid) > 0 then
return true
end
doCreatureAddHealth(cid, -10)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You are starving.")
addEvent(doPlayerStarve, 60 * 1000, cid)
return true
end
function doPlayerGiveItem(cid, itemid, count, charges)
local hasCharges = (isItemRune(itemid) == TRUE or isItemFluidContainer(itemid) == TRUE)
if(hasCharges and charges == nil) then
charges = 1
end
while count > 0 do
local tempcount = 1
if(hasCharges) then
tempcount = charges
end
end
local MAX_FOOD = 1200
function onUse(cid, item, frompos, item2, topos)
if (item.itemid == 6280) then
doPlayerSay(cid, "Blewing out the candle.", 1)
doTransformItem(item.uid, item.itemid - 1)
doSendMagicEffect(frompos, CONST_ME_POFF)
return TRUE
end
if FOODS[item.itemid] == nil then
return FALSE
end
local size = FOODS[item.itemid][1]
local sound = FOODS[item.itemid][2]
if (getPlayerFood(cid) + size > MAX_FOOD) then
doPlayerSendCancel(cid, "You are full.")
return TRUE
end
doPlayerFeed(cid, size)
doRemoveItem(item.uid, 1)
doPlayerSay(cid, sound, 1)
doCreatureSay(cid, sound, TALKTYPE_MONSTER_SAY)
addEvent(doPlayerStarve, (getPlayerFood(cid) + 60) * 1000, cid)
return TRUE
end
function onLogin(cid)
registerCreatureEvent(cid, "PlayerDeath")
addEvent(doPlayerStarve, 60 * 1000, cid)
return TRUE
end
function.lua
Code:function doPlayerStarve(cid) if isPlayer(cid) == FALSE or getPlayerFood(cid) > 0 then return TRUE end doCreatureAddHealth(cid, -10) doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "You are starving.") addEvent(doPlayerStarve, 60 * 1000, cid) return TRUE end