local exhausted_seconds = 5*60
local exhausted_storagevalue = 7485
local klucz = 75005
function onUse(cid, item, frompos, item2, topos)
if(os.time() > getPlayerStorageValue(cid, exhausted_storagevalue)) then
spanie = getPlayerStorageValue(cid, klucz)
doCreatureSetNoMove(cid, true)
doSendMagicEffect(frompos, CONST_ME_SLEEP)
setPlayerStorageValue(cid, klucz, 0)
addEvent(sleep,500, cid)
doRemoveItem(item.uid, 1)
setPlayerStorageValue(cid, exhausted_storagevalue, os.time() + exhausted_seconds)
else
timeleft = getPlayerStorageValue(cid, exhausted_storagevalue)-os.time()
if timeleft >= 60 then
min1 = timeleft/60
min = math.floor(min1)
sec1 = timeleft-min*60
sec = math.floor(sec1)
doPlayerSendTextMessage(cid, 19, "You need to wait "..min.." minutes and "..sec.." second.")
elseif timeleft < 60 then
doPlayerSendTextMessage(cid, 19, "You need to wait "..timeleft.." second.")
end
end
end
function sleep(cid)
maxzycie = getCreatureMaxHealth(cid)
zycie = getCreatureHealth(cid)
maxmana = getCreatureMaxMana(cid)
mana = getCreatureMana(cid)
if zycie < maxzycie then
if getPlayerStorageValue(cid, klucz) < 20 then
setPlayerStorageValue(cid, klucz, getPlayerStorageValue(cid, klucz)+1)
doSendMagicEffect(getPlayerPosition(cid), CONST_ME_SLEEP)
doCreatureAddHealth(cid, 0.005*maxzycie)
doSendAnimatedText(getPlayerPosition(cid), 0.005*maxzycie, TEXTCOLOR_LIGHTGREEN)
doCreatureAddMana(cid, 0.005*maxmana)
doSendAnimatedText(getPlayerPosition(cid), 0.005*maxmana, TEXTCOLOR_LIGHTBLUE)
addEvent(sleep,500, cid)
else
doCreatureSetNoMove(cid, false)
doSendAnimatedText(getPlayerPosition(cid), "WAKE UP", TEXTCOLOR_LIGHTBLUE)
setPlayerStorageValue(cid, klucz, -1)
end
else
doCreatureSetNoMove(cid, false)
doSendAnimatedText(getPlayerPosition(cid), "WAKE UP", TEXTCOLOR_LIGHTBLUE)
setPlayerStorageValue(cid, klucz, -1)
end
end