• 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!

Solved Issue with movement onEquip [TFS 1.1]

Danten

New Member
Joined
Jun 2, 2015
Messages
7
Reaction score
0
Hello! Im trying to create a script for when equipping an armor, you end up with 1hp and get extra mana. I know it's possible to do in items.xml however it doesn't give the desired effect when the item is removed. Which is that i want it to return to the hp/mana before equipping the item.

The script send the deEquip message, but nothing is really happening during the equip. All help would be appreciated.

This is what i've come up with so far...
Code:
local hp = Combat()
hp:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, 1)
hp:setParameter(CONDITION_PARAM_SUBID, 1)
local mana = Combat()
mana:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTS, 1)
mana:setParameter(CONDITION_PARAM_SUBID, 500)
function onEquip(cid, item, slot)
if getPlayerSlotItem(cid, slot).itemid == item.itemid then
local player = Player(cid)
player:addCondition(hp)
player:addCondition(mana)
player:setStorageValue(101703, 1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "on")
end
return true
end
function onDeEquip(cid, item, slot)
local player = Player(cid)
player:removeCondition(hp)
player:removeCondition(mana)
player:setStorageValue(101703, -1)
doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "off")
return true
end
 
Solution
try this out, make sure to add the logout function to creaturescripts, register it in creaturescripts.xml & login.lua
Lua:
local mana = Condition(CONDITION_ATTRIBUTES)
mana:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, 20)
mana:setParameter(CONDITION_PARAM_TICKS, -1)

decreasedHp = {}

function onEquip(cid, item, slot)
    local player = Player(cid)
    if player:getSlotItem(slot).itemid == item.itemid then
        decreasedHp[player:getGuid()] = player:getMaxHealth()
        player:setMaxHealth(1)
        player:addCondition(mana)
        player:setStorageValue(101703, 1)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "on")
    end
    return true
end

function onDeEquip(cid, item, slot)
    local player =...
try this out
Lua:
local hp = Combat()
hp:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, 1)
hp:setParameter(CONDITION_PARAM_SUBID, 1)
hp:setParameter(CONDITION_PARAM_TICKS, -1)

local mana = Combat()
mana:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTS, 1)
mana:setParameter(CONDITION_PARAM_SUBID, 500)
mana:setParameter(CONDITION_PARAM_TICKS, -1)

function onEquip(cid, item, slot)
    local player = Player(cid)
    if player:getSlotItem(slot).itemid == item.itemid then
        player:addCondition(hp)
        player:addCondition(mana)
        player:setStorageValue(101703, 1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "on")
    end
    return true
end

function onDeEquip(cid, item, slot)
    local player = Player(cid)
    player:removeCondition(hp)
    player:removeCondition(mana)
    player:setStorageValue(101703, -1)
    doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "off")
    return true
end
 
try this out

Thanks for the quick response, however still it only display the "debug" for off. And the statchanges doesn't appear.

Also this is in my movement.xml shouldn't be any issue there?
Code:
    <movevent event="Equip" itemid="21725" slot="armor" function="onEquipItem" />   
   <movevent event="Equip" itemid="21725" slot="armor" script="cii.lua" />
   <movevent event="DeEquip" itemid="21725" slot="armor" script="cii.lua" />
 
Thanks for the quick response, however still it only display the "debug" for off. And the statchanges doesn't appear.

Also this is in my movement.xml shouldn't be any issue there?
Code:
    <movevent event="Equip" itemid="21725" slot="armor" function="onEquipItem" />  
   <movevent event="Equip" itemid="21725" slot="armor" script="cii.lua" />
   <movevent event="DeEquip" itemid="21725" slot="armor" script="cii.lua" />
remove the line with the function="onEquipItem" since it's not needed
 
It showed that other problems was appearing, such as addCondition crashes the server or I end up getting "Segmentation fault". Know any reason behind this?

Also changed a small bit of the code to be able to get the debug message to work
Code:
function onEquip(cid, item, slot)
    local player = Player(cid)

local slots = getPlayerSlotItem(cid, slot )
    if slots.itemid ~= item.itemid then
        return true
    end

        player:addCondition(hp)
        player:addCondition(mana)
        player:setStorageValue(101703, 1)
        doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "on")
    return true
end
 
ah it was still combats instead of conditions
Lua:
local hp = Condition(CONDITION_ATTRIBUTES)
hp:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, 1)
hp:setParameter(CONDITION_PARAM_SUBID, 1)
hp:setParameter(CONDITION_PARAM_TICKS, -1)

local mana = Condition(CONDITION_ATTRIBUTES)
mana:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTS, 1)
mana:setParameter(CONDITION_PARAM_SUBID, 500)
mana:setParameter(CONDITION_PARAM_TICKS, -1)

function onEquip(cid, item, slot)
    local player = Player(cid)
    if player:getSlotItem(slot).itemid == item.itemid then
        player:addCondition(hp)
        player:addCondition(mana)
        player:setStorageValue(101703, 1)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "on")
    end
    return true
end

function onDeEquip(cid, item, slot)
    local player = Player(cid)
    player:removeCondition(hp)
    player:removeCondition(mana)
    player:setStorageValue(101703, -1)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "off")
    return true
end
 
ah it was still combats instead of conditions
Lua:
local hp = Condition(CONDITION_ATTRIBUTES)
hp:setParameter(CONDITION_PARAM_STAT_MAXHITPOINTS, 1)
hp:setParameter(CONDITION_PARAM_SUBID, 1)
hp:setParameter(CONDITION_PARAM_TICKS, -1)

local mana = Condition(CONDITION_ATTRIBUTES)
mana:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTS, 1)
mana:setParameter(CONDITION_PARAM_SUBID, 500)
mana:setParameter(CONDITION_PARAM_TICKS, -1)

function onEquip(cid, item, slot)
    local player = Player(cid)
    if player:getSlotItem(slot).itemid == item.itemid then
        player:addCondition(hp)
        player:addCondition(mana)
        player:setStorageValue(101703, 1)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "on")
    end
    return true
end

function onDeEquip(cid, item, slot)
    local player = Player(cid)
    player:removeCondition(hp)
    player:removeCondition(mana)
    player:setStorageValue(101703, -1)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "off")
    return true
end

That worked alot better! However the desired effect of the item to set you max hp to 1, isn't really working. Or isn't this working with conditions and rather need to be scripted like setMaxHealth? And if so, how do i manage to fetch the Current maxhp of the player?
 
That worked alot better! However the desired effect of the item to set you max hp to 1, isn't really working. Or isn't this working with conditions and rather need to be scripted like setMaxHealth? And if so, how do i manage to fetch the Current maxhp of the player?
it should work o.o
are you wanting it to increase max hp by 1? or set max hp to 1?
you can fetch the current max health by player:getMaxHealth()
 
I want it to set the max hp to 1 and increase the max mana with like 20% or something ( I know it's supposed to be Maxmanapercent, but just wanted the script to work with the basics first)

Working on a item that allows you to use permanent manashield with increased mana, while wearing it!
 
try this out, make sure to add the logout function to creaturescripts, register it in creaturescripts.xml & login.lua
Lua:
local mana = Condition(CONDITION_ATTRIBUTES)
mana:setParameter(CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, 20)
mana:setParameter(CONDITION_PARAM_TICKS, -1)

decreasedHp = {}

function onEquip(cid, item, slot)
    local player = Player(cid)
    if player:getSlotItem(slot).itemid == item.itemid then
        decreasedHp[player:getGuid()] = player:getMaxHealth()
        player:setMaxHealth(1)
        player:addCondition(mana)
        player:setStorageValue(101703, 1)
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "on")
    end
    return true
end

function onDeEquip(cid, item, slot)
    local player = Player(cid)
    local guid = player:getGuid()
    player:setMaxHealth(decreasedHp[guid])
    decreasedHp[guid] = nil
    player:addHealth(player:getMaxHealth())
    player:removeCondition(mana)
    player:setStorageValue(101703, -1)
    player:sendTextMessage(MESSAGE_STATUS_CONSOLE_ORANGE, "off")
    return true
end

function onLogout(cid)
    local player = Player(cid)
    local guid = player:getGuid()
    if decreasedHp[guid] then
        player:setMaxHealth(decreasedHp[guid])
        decreasedHp[guid] = nil
    end
    return true
end
 
Last edited:
Solution
Works like a charm with the hp, the mana increase doesn't occur for some reason, but i suppose it's just to code it like you did with the hp? Seems like there is some issues with conditions for some reason...
 
Works like a charm with the hp, the mana increase doesn't occur for some reason, but i suppose it's just to code it like you did with the hp? Seems like there is some issues with conditions for some reason...
ah thats my bad
change the condition param to this CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT
 
Back
Top