• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Lua Bonus HP

norrow

Member
Joined
Dec 16, 2012
Messages
129
Reaction score
7
Location
Poland
Hi needs of an item which increases the player 15% of life in 15 minutes and after use is changed to a different item. TFS 0.3.6 please help
 
Code:
local conditionstate = {}

local function doPlayerAddHealthGeneration(cid, amount, state, seconds, rtime)
     if not isPlayer(cid) then
         conditionstate[cid] = nil
         return true
     end
     if state == 0 then
       rtime = rtime * 60 / seconds
     end
     state = state + 1
     if state <= rtime then
         doCreatureAddHealth(cid, amount)
         doSendMagicEffect(getCreaturePosition(cid), CONST_ME_MAGIC_BLUE)
         addEvent(doPlayerAddHealthGeneration, seconds * 1000, cid, amount, state, seconds, rtime)
     else
         conditionstate[cid] = nil
     end
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
     if not conditionstate[cid] then
         doPlayerAddHealthGeneration(cid, math.ceil(getCreatureMaxHealth(cid) * 0.15), 0, 2, 15)
         conditionstate[cid] = 1
         doTransformItem(item.uid, 2112)
     else
         doPlayerSendCancel(cid, "You are already using this item.")
     end
     return true
end
Not sure how exactly you want it to work, but you can change it here.
Code:
doPlayerAddHealthGeneration(cid, math.ceil(getCreatureMaxHealth(cid) * 0.15), 0, 2, 15)
The values stand for the parameters you see here.
Code:
doPlayerAddHealthGeneration(cid, amount, state, seconds, rtime)
amount is how much the player heals (atm it's 15% of someones max health), seconds is how fast (after how many seconds it heals again) and rtime is for how long, atm it's for 15 min.


If it should add 15% maxhealth for 15 min you can just use a condition instead, so without conditionstate and doPlayerAddHealthGeneration and use: if not getCreatureCondition(cid, CONDITION_ATTRIBUTES, 2) then instead of if not conditionstate then.

Add the condition instead of the function.
Code:
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_BUFF, true)
setConditionParam(condition, CONDITION_PARAM_SUBID, 2)
setConditionParam(condition, CONDITION_PARAM_STAT_MAXHEALTHPERCENT, 115)
setConditionParam(condition, CONDITION_PARAM_TICKS, 15 * 60 * 1000)
Then if the player doesn't have the condition, add the condition to the player.
Code:
doAddCondition(cid, condition)
 
Back
Top