-- percentage is a boolean value true/false
function adjustMonsterMaxHealthOnceOnly(target, percentage, amount)
-- confirm that it's a monster
if not isMonster(target) then
return false
end
-- confirm that the monsters health has not been adjusted previously.
local targetMaxHealth = getCreatureMaxHealth(target)
if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then
return false
end
-- calculate and adjust health
local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount
setCreatureMaxHealth(target, adjustedAmount)
-- adjust current health of target
local targetCurrentHealth =...
-- percentage is a boolean value true/false
function adjustMonsterMaxHealthOnceOnly(target, percentage, amount)
-- confirm that it's a monster
if not isMonster(target) then
return false
end
-- confirm that the monsters health has not been adjusted previously.
local targetMaxHealth = getCreatureMaxHealth(target)
if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then
return false
end
-- calculate and adjust health
local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount
setCreatureMaxHealth(target, adjustedAmount)
-- adjust current health of target
local targetCurrentHealth = getCreatureHealth(target)
if targetCurrentHealth > adjustedAmount then
doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount))
else
doCreatureAddHealth(cid, adjustedAmount)
end
return true
end
--[[
Usage
Doubling hp | 1000 -> 2000
adjustMonsterMaxHealthOnceOnly(target, true, 2)
Half hp | 1000 -> 500
adjustMonsterMaxHealthOnceOnly(target, true, 0.5)
Adding 400 hp | 1000 -> 1400
adjustMonsterMaxHealthOnceOnly(target, false, 400)
Removing 600 hp | 1000 -> 400
adjustMonsterMaxHealthOnceOnly(target, false, -600)
]]--
-- Example, doubling max hp of all summons of a character
function onCast(cid, target)
local summons = getCreatureSummons(cid)
for i = 1, #summons do
adjustMonsterMaxHealthOnceOnly(summons[i], true, 2)
end
return true
end
Untested.
Lua:-- percentage is a boolean value true/false function adjustMonsterMaxHealthOnceOnly(target, percentage, amount) -- confirm that it's a monster if not isMonster(target) then return false end -- confirm that the monsters health has not been adjusted previously. local targetMaxHealth = getCreatureMaxHealth(target) if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then return false end -- calculate and adjust health local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount setCreatureMaxHealth(target, adjustedAmount) -- adjust current health of target local targetCurrentHealth = getCreatureHealth(target) if targetCurrentHealth > adjustedAmount then doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount)) else doCreatureAddHealth(cid, adjustedAmount) end return true end
Lua:--[[ Usage Doubling hp | 1000 -> 2000 adjustMonsterMaxHealthOnceOnly(target, true, 2) Half hp | 1000 -> 500 adjustMonsterMaxHealthOnceOnly(target, true, 0.5) Adding 400 hp | 1000 -> 1400 adjustMonsterMaxHealthOnceOnly(target, false, 400) Removing 600 hp | 1000 -> 400 adjustMonsterMaxHealthOnceOnly(target, false, -600) ]]--
Lua:-- Example, doubling max hp of all summons of a character function onCast(cid, target) local summons = getCreatureSummons(cid) for i = 1, #summons do adjustMonsterMaxHealthOnceOnly(summons[i], true, 2) end return true end
23:31 You see a dragon.
Health: [1500 / 1500].
Position: [X: 1034] [Y: 1047] [Z: 6].
23:31 You see a dragon.
Health: [1500 / 1500].
Position: [X: 1036] [Y: 1045] [Z: 6].
23:32 You see a dragon.
Health: [3000 / 1500].
Position: [X: 1032] [Y: 1046] [Z: 6].
23:32 You see a dragon.
Health: [3000 / 3000].
Position: [X: 1032] [Y: 1045] [Z: 6].
23:33 You see a dragon.
Health: [1500 / 1500].
Position: [X: 1032] [Y: 1046] [Z: 6].
23:33 You see a dragon.
Health: [3000 / 3000].
Position: [X: 1032] [Y: 1045] [Z: 6].
What do i doing wrong?
before use the spell
Code:23:31 You see a dragon. Health: [1500 / 1500]. Position: [X: 1034] [Y: 1047] [Z: 6]. 23:31 You see a dragon. Health: [1500 / 1500]. Position: [X: 1036] [Y: 1045] [Z: 6].
When i use the spell
Code:23:32 You see a dragon. Health: [3000 / 1500]. Position: [X: 1032] [Y: 1046] [Z: 6]. 23:32 You see a dragon. Health: [3000 / 3000]. Position: [X: 1032] [Y: 1045] [Z: 6].
when the buff over
Code:23:33 You see a dragon. Health: [1500 / 1500]. Position: [X: 1032] [Y: 1046] [Z: 6]. 23:33 You see a dragon. Health: [3000 / 3000]. Position: [X: 1032] [Y: 1045] [Z: 6].
-- Example, doubling max hp of all summons of a character
function onCast(cid, target)
print("Script starting..")
local summons = getCreatureSummons(cid)
print("You have " .. #summons " summons.")
for i = 1, #summons do
print("Adjusting " .. getCreatureName(summons[i]) .. "'s hp. " .. i)
adjustMonsterMaxHealthOnceOnly(summons[i], true, 2)
end
print("Script ended successfully, without errors.")
return true
end
function resetMonsterMaxHealth(cid)
-- confirm that creature still exists
if not isMonster(cid) then
return true
end
-- reset maxHealth
local maxHealth = getMonsterInfo(getCreatureName(cid)).healthMax
setCreatureMaxHealth(cid, maxHealth)
-- if current health is above maximum health, reduce current health
local targetCurrentHealth = getCreatureHealth(cid)
if targetCurrentHealth > maxHealth then
doCreatureAddHealth(cid, -(targetCurrentHealth - maxHealth))
end
return true
end
-- percentage is a boolean value true/false
-- timer in seconds
function adjustMonsterMaxHealthOnceOnly(target, percentage, amount, timer)
-- confirm that it's a monster
if not isMonster(target) then
return false
end
-- confirm that the monsters health has not been adjusted previously.
local targetMaxHealth = getCreatureMaxHealth(target)
if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then
return false
end
-- calculate and adjust health
local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount
setCreatureMaxHealth(target, adjustedAmount)
-- adjust current health of target
local targetCurrentHealth = getCreatureHealth(target)
if targetCurrentHealth > adjustedAmount then
doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount))
else
doCreatureAddHealth(cid, adjustedAmount)
end
-- if timer, reset monster health after x seconds.
if timer > 0 then
addEvent(resetMonsterMaxHealth, timer * 1000, target)
end
return true
end
-- resets hp after 5 seconds
function onCast(cid, target)
local summons = getCreatureSummons(cid)
for i = 1, #summons do
adjustMonsterMaxHealthOnceOnly(summons[i], true, 2, 5)
end
return true
end
any errors?
try this and find out what prints to the console.
Lua:-- Example, doubling max hp of all summons of a character function onCast(cid, target) print("Script starting..") local summons = getCreatureSummons(cid) print("You have " .. #summons " summons.") for i = 1, #summons do print("Adjusting " .. getCreatureName(summons[i]) .. "'s hp. " .. i) adjustMonsterMaxHealthOnceOnly(summons[i], true, 2) end print("Script ended successfully, without errors.") return true end
Nvm, I see you want it to be a temporary adjustment. (aka a buff)
Try this.
Lua:function resetMonsterMaxHealth(cid) -- confirm that creature still exists if not isMonster(cid) then return true end -- reset maxHealth local maxHealth = getMonsterInfo(getCreatureName(cid)).healthMax setCreatureMaxHealth(cid, maxHealth) -- if current health is above maximum health, reduce current health local targetCurrentHealth = getCreatureHealth(cid) if targetCurrentHealth > maxHealth then doCreatureAddHealth(cid, -(targetCurrentHealth - maxHealth)) end return true end
Lua:-- percentage is a boolean value true/false -- timer in seconds function adjustMonsterMaxHealthOnceOnly(target, percentage, amount, timer) -- confirm that it's a monster if not isMonster(target) then return false end -- confirm that the monsters health has not been adjusted previously. local targetMaxHealth = getCreatureMaxHealth(target) if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then return false end -- calculate and adjust health local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount setCreatureMaxHealth(target, adjustedAmount) -- adjust current health of target local targetCurrentHealth = getCreatureHealth(target) if targetCurrentHealth > adjustedAmount then doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount)) else doCreatureAddHealth(cid, adjustedAmount) end -- if timer, reset monster health after x seconds. if timer > 0 then addEvent(resetMonsterMaxHealth, timer * 1000, target) end return true end
Lua:-- resets hp after 5 seconds function onCast(cid, target) local summons = getCreatureSummons(cid) for i = 1, #summons do adjustMonsterMaxHealthOnceOnly(summons[i], true, 2, 5) end return true end
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false)
local condition = createConditionObject(CONDITION_ATTRIBUTES)
setConditionParam(condition, CONDITION_PARAM_TICKS, 10000)
setConditionParam(condition, CONDITION_PARAM_SUBID, 69)
setConditionParam(condition, CONDITION_PARAM_STAT_MAXHEALTHPERCENT, -50)
setConditionParam(condition, CONDITION_PARAM_STAT_MAXMANAPERCENT, -50)
setConditionParam(condition, CONDITION_PARAM_BUFF, true)
setCombatCondition(combat, condition)
function resetMonsterMaxHealth(cid)
-- confirm that creature still exists
if not isMonster(cid) then
return true
end
-- reset maxHealth
local maxHealth = getMonsterInfo(getCreatureName(cid)).healthMax
setCreatureMaxHealth(cid, maxHealth)
-- if current health is above maximum health, reduce current health
local targetCurrentHealth = getCreatureHealth(cid)
if targetCurrentHealth > maxHealth then
doCreatureAddHealth(cid, -(targetCurrentHealth - maxHealth))
end
return true
end
-- percentage is a boolean value true/false
--[[
Usage
Doubling hp | 1000 -> 2000
adjustMonsterMaxHealthOnceOnly(target, true, 2)
Half hp | 1000 -> 500
adjustMonsterMaxHealthOnceOnly(target, true, 0.5)
Adding 400 hp | 1000 -> 1400
adjustMonsterMaxHealthOnceOnly(target, false, 400)
Removing 600 hp | 1000 -> 400
adjustMonsterMaxHealthOnceOnly(target, false, -600)
]]--
-- percentage is a boolean value true/false
-- timer in seconds
function adjustMonsterMaxHealthOnceOnly(target, percentage, amount, timer)
-- confirm that it's a monster
if not isMonster(target) then
return false
end
-- confirm that the monsters health has not been adjusted previously.
local targetMaxHealth = getCreatureMaxHealth(target)
if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then
return false
end
-- calculate and adjust health
local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount
setCreatureMaxHealth(target, adjustedAmount)
-- adjust current health of target
local targetCurrentHealth = getCreatureHealth(target)
if targetCurrentHealth > adjustedAmount then
doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount))
else
doCreatureAddHealth(cid, adjustedAmount)
end
-- if timer, reset monster health after x seconds.
if timer > 0 then
addEvent(resetMonsterMaxHealth, timer * 1000, target)
end
return true
end
local function checking(cid)
if isPlayer(cid) then
if not getCreatureCondition(cid, CONDITION_ATTRIBUTES, 69) then
-- back to normal
local summons = getCreatureSummons(cid)
for i = 1, #summons do
local target = summons[i]
-- rateMonsterHealth 1.5
local maxMonsterHP = getMonsterInfo(getCreatureName(target)).healthMax + (getMonsterInfo(getCreatureName(target)).healthMax / 2)
setCreatureMaxHealth(target, maxMonsterHP )
-- adjust current health of target
local targetCurrentHealth = getCreatureHealth(target)
if targetCurrentHealth > adjustedAmount then
doCreatureAddHealth(target, -(targetCurrentHealth - adjustedAmount))
else
doCreatureAddHealth(target, adjustedAmount)
end
end
setPlayerStorageValue(cid, 669, -1)
return false
end
addEvent(checking, 2000, cid)
end
end
-- Example, doubling max hp of all summons of a character
-- resets hp after 5 seconds
function onCastSpell(cid, var)
local summons = getCreatureSummons(cid)
for i = 1, #summons do
adjustMonsterMaxHealthOnceOnly(summons[i], true, 2, 5)
doSendMagicEffect(getThingPos(summons[i]), CONST_ME_MAGIC_RED)
end
doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED)
return true
end
What? noThis is it?
Code:local combat = createCombatObject() setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE) setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, false) local condition = createConditionObject(CONDITION_ATTRIBUTES) setConditionParam(condition, CONDITION_PARAM_TICKS, 10000) setConditionParam(condition, CONDITION_PARAM_SUBID, 69) setConditionParam(condition, CONDITION_PARAM_STAT_MAXHEALTHPERCENT, -50) setConditionParam(condition, CONDITION_PARAM_STAT_MAXMANAPERCENT, -50) setConditionParam(condition, CONDITION_PARAM_BUFF, true) setCombatCondition(combat, condition) function resetMonsterMaxHealth(cid) -- confirm that creature still exists if not isMonster(cid) then return true end -- reset maxHealth local maxHealth = getMonsterInfo(getCreatureName(cid)).healthMax setCreatureMaxHealth(cid, maxHealth) -- if current health is above maximum health, reduce current health local targetCurrentHealth = getCreatureHealth(cid) if targetCurrentHealth > maxHealth then doCreatureAddHealth(cid, -(targetCurrentHealth - maxHealth)) end return true end -- percentage is a boolean value true/false --[[ Usage Doubling hp | 1000 -> 2000 adjustMonsterMaxHealthOnceOnly(target, true, 2) Half hp | 1000 -> 500 adjustMonsterMaxHealthOnceOnly(target, true, 0.5) Adding 400 hp | 1000 -> 1400 adjustMonsterMaxHealthOnceOnly(target, false, 400) Removing 600 hp | 1000 -> 400 adjustMonsterMaxHealthOnceOnly(target, false, -600) ]]-- -- percentage is a boolean value true/false -- timer in seconds function adjustMonsterMaxHealthOnceOnly(target, percentage, amount, timer) -- confirm that it's a monster if not isMonster(target) then return false end -- confirm that the monsters health has not been adjusted previously. local targetMaxHealth = getCreatureMaxHealth(target) if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then return false end -- calculate and adjust health local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount setCreatureMaxHealth(target, adjustedAmount) -- adjust current health of target local targetCurrentHealth = getCreatureHealth(target) if targetCurrentHealth > adjustedAmount then doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount)) else doCreatureAddHealth(cid, adjustedAmount) end -- if timer, reset monster health after x seconds. if timer > 0 then addEvent(resetMonsterMaxHealth, timer * 1000, target) end return true end local function checking(cid) if isPlayer(cid) then if not getCreatureCondition(cid, CONDITION_ATTRIBUTES, 69) then -- back to normal local summons = getCreatureSummons(cid) for i = 1, #summons do local target = summons[i] -- rateMonsterHealth 1.5 local maxMonsterHP = getMonsterInfo(getCreatureName(target)).healthMax + (getMonsterInfo(getCreatureName(target)).healthMax / 2) setCreatureMaxHealth(target, maxMonsterHP ) -- adjust current health of target local targetCurrentHealth = getCreatureHealth(target) if targetCurrentHealth > adjustedAmount then doCreatureAddHealth(target, -(targetCurrentHealth - adjustedAmount)) else doCreatureAddHealth(target, adjustedAmount) end end setPlayerStorageValue(cid, 669, -1) return false end addEvent(checking, 2000, cid) end end -- Example, doubling max hp of all summons of a character -- resets hp after 5 seconds function onCastSpell(cid, var) local summons = getCreatureSummons(cid) for i = 1, #summons do adjustMonsterMaxHealthOnceOnly(summons[i], true, 2, 5) doSendMagicEffect(getThingPos(summons[i]), CONST_ME_MAGIC_RED) end doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_RED) return true end
Its not setting the summons health :S
local function resetMonsterMaxHealth(cid)
if not isMonster(cid) then
return true
end
local maxHealth = getMonsterInfo(getCreatureName(cid)).healthMax
setCreatureMaxHealth(cid, maxHealth)
local targetCurrentHealth = getCreatureHealth(cid)
if targetCurrentHealth > maxHealth then
doCreatureAddHealth(cid, -(targetCurrentHealth - maxHealth))
end
return true
end
local function adjustMonsterMaxHealthOnceOnly(target, percentage, amount, timer)
if not isMonster(target) then
return false
end
local targetMaxHealth = getCreatureMaxHealth(target)
if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then
return false
end
local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount
setCreatureMaxHealth(target, adjustedAmount)
local targetCurrentHealth = getCreatureHealth(target)
if targetCurrentHealth > adjustedAmount then
doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount))
else
doCreatureAddHealth(cid, adjustedAmount)
end
if timer > 0 then
addEvent(resetMonsterMaxHealth, timer * 1000, target)
end
return true
end
function onCast(cid, target)
local summons = getCreatureSummons(cid)
for i = 1, #summons do
adjustMonsterMaxHealthOnceOnly(summons[i], true, 2, 5)
end
return true
end
What? no
Literally just copy paste what I put above.
And then run as-is.
Lua:local function resetMonsterMaxHealth(cid) if not isMonster(cid) then return true end local maxHealth = getMonsterInfo(getCreatureName(cid)).healthMax setCreatureMaxHealth(cid, maxHealth) local targetCurrentHealth = getCreatureHealth(cid) if targetCurrentHealth > maxHealth then doCreatureAddHealth(cid, -(targetCurrentHealth - maxHealth)) end return true end local function adjustMonsterMaxHealthOnceOnly(target, percentage, amount, timer) if not isMonster(target) then return false end local targetMaxHealth = getCreatureMaxHealth(target) if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then return false end local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount setCreatureMaxHealth(target, adjustedAmount) local targetCurrentHealth = getCreatureHealth(target) if targetCurrentHealth > adjustedAmount then doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount)) else doCreatureAddHealth(cid, adjustedAmount) end if timer > 0 then addEvent(resetMonsterMaxHealth, timer * 1000, target) end return true end function onCast(cid, target) local summons = getCreatureSummons(cid) for i = 1, #summons do adjustMonsterMaxHealthOnceOnly(summons[i], true, 2, 5) end return true end
local function resetMonsterMaxHealth(cid)
if not isMonster(cid) then
return true
end
local maxHealth = getMonsterInfo(getCreatureName(cid)).healthMax
setCreatureMaxHealth(cid, maxHealth)
local targetCurrentHealth = getCreatureHealth(cid)
if targetCurrentHealth > maxHealth then
doCreatureAddHealth(cid, -(targetCurrentHealth - maxHealth))
end
return true
end
local function adjustMonsterMaxHealthOnceOnly(target, percentage, amount, timer)
if not isMonster(target) then
return false
end
local targetMaxHealth = getCreatureMaxHealth(target)
if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then
return false
end
local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount
setCreatureMaxHealth(target, adjustedAmount)
local targetCurrentHealth = getCreatureHealth(target)
if targetCurrentHealth > adjustedAmount then
doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount))
else
doCreatureAddHealth(cid, adjustedAmount)
end
if timer > 0 then
addEvent(resetMonsterMaxHealth, timer * 1000, target)
end
return true
end
function onCastSpell(cid, var)
print("Script starting..")
local summons = getCreatureSummons(cid)
for i = 1, #summons do
print("Adjusting " .. getCreatureName(summons[i]) .. "'s hp. " .. i)
adjustMonsterMaxHealthOnceOnly(summons[i], true, 2, 5)
end
print("Script ended successfully, without errors.")
return true
end
You gotta work with me here.Tried the copy paste then:
Code:local function resetMonsterMaxHealth(cid) if not isMonster(cid) then return true end local maxHealth = getMonsterInfo(getCreatureName(cid)).healthMax setCreatureMaxHealth(cid, maxHealth) local targetCurrentHealth = getCreatureHealth(cid) if targetCurrentHealth > maxHealth then doCreatureAddHealth(cid, -(targetCurrentHealth - maxHealth)) end return true end local function adjustMonsterMaxHealthOnceOnly(target, percentage, amount, timer) if not isMonster(target) then return false end local targetMaxHealth = getCreatureMaxHealth(target) if getMonsterInfo(getCreatureName(target)).healthMax ~= getCreatureMaxHealth(target) then return false end local adjustedAmount = percentage and targetMaxHealth * amount or targetMaxHealth + amount setCreatureMaxHealth(target, adjustedAmount) local targetCurrentHealth = getCreatureHealth(target) if targetCurrentHealth > adjustedAmount then doCreatureAddHealth(cid, -(targetCurrentHealth - adjustedAmount)) else doCreatureAddHealth(cid, adjustedAmount) end if timer > 0 then addEvent(resetMonsterMaxHealth, timer * 1000, target) end return true end function onCastSpell(cid, var) print("Script starting..") local summons = getCreatureSummons(cid) for i = 1, #summons do print("Adjusting " .. getCreatureName(summons[i]) .. "'s hp. " .. i) adjustMonsterMaxHealthOnceOnly(summons[i], true, 2, 5) end print("Script ended successfully, without errors.") return true end
The dragons still with the same health...
You gotta work with me here.
What happened in console?
Errors?
rateMonsterHealth = 1.5
local targetMaxHealth = getMonsterInfo(getCreatureName(target)).healthMax + (getMonsterInfo(getCreatureName(target)).healthMax / 2)
The problem was that i have
in my config.luaCode:rateMonsterHealth = 1.5
i just had to change to targetMaxHealth
Code:local targetMaxHealth = getMonsterInfo(getCreatureName(target)).healthMax + (getMonsterInfo(getCreatureName(target)).healthMax / 2)
There is a better way to do that?
So i can not have to get the information from config.lua
I mean, if i had to change the info on config.lua the spell will bug again :S
getConfigValue("rateMonsterHealth")
god! thank you!Lua:getConfigValue("rateMonsterHealth")