How can I script such an item? I would like to make an item that adds mana and hitpoints when equipped, and when de-equipped, removes the added points. I'm using TFS 0.3.6
Thanks!
Thanks!
Code:<attribute key="maxhealthpoints" value="1000" /> <attribute key="maxmanapoints" value="1000" />
I added:Item registered in movements.xml?
<movevent type="Equip" itemid="12644" slot="shield" event="function" value="onEquipItem"/>
<movevent type="DeEquip" itemid="12644" slot="shield" event="function" value="onDeEquipItem"/>
<movevent type="Equip" itemid="yourID" event="script" value="YourScript.lua"/>
<movevent type="Dequip" itemid="yourID" event="script" value="YourScript.lua"/>
I think you have to run a script, when it is equipped, add it to movements.xml:
HTML:<movevent type="Equip" itemid="yourID" event="script" value="YourScript.lua"/> <movevent type="Dequip" itemid="yourID" event="script" value="YourScript.lua"/>
I dont know if this can work tho.
Anyway, you need to run a lua script when the item is equipped, directly from an XML is no option.
Sorry, there was a while between typing, and watching this thread! Didn't notice there where replies
I can't think of a way to incready capacity right now.
To add mana and hp already works, just add the attribute in the xml and register the item in movements.xml, but I want to know the attribute that I must use to add capacity when equipped.
local storage = XXXX
function getPlayerCap(cid)
local test = db.getResult("SELECT `cap` FROM `players` WHERE `id` = " .. getPlayerGUID(cid))
if test:getID() ~= false then
local cap = test:getDataInt("cap")
test:free()
return cap
end
return false
end
function onEquip(cid, item, slot)
if getPlayerStorageValue(cid, storage) < 1 then
doPlayerSetMaxCapacity(cid, (getPlayerCap(cid) + extracap))
end
return true
end
function onDeEquip(cid, item, slot)
if getPlayerStorageValue(cid, storage) > 0 then
doPlayerSetMaxCapacity(cid, (getPlayerCap(cid) - extracap))
end
return true
end
<movevent type="Equip" itemid="XXX" slot="feet" event="script" value="yourscriptname.lua"/>
<movevent type="DeEquip" itemid="XXX" slot="feet" event="script" value="yourscriptname.lua"/>
Not tested, is just an idea:
Code:local extracap = 9000 function getPlayerCap(cid) query = db.getResult("SELECT `cap` FROM `players` WHERE `player_id` = '" .. getPlayerGUID(cid) .. "';") if(query:getID() < 1) then return nil end cap = query:getDataInt("cap") query:free() return cap end function onEquip(cid, item, slot) doPlayerSetMaxCapacity(cid, (getPlayerCap(cid) + extracap)) return true end function onDeEquip(cid, item, slot) doPlayerSetMaxCapacity(cid, (getPlayerCap(cid) - extracap)) return true end
BTW you should add storages and maybe some exhaust.
@Edit: And you have to change your movements.xml to something like that:
Code:<movevent type="Equip" itemid="XXX" slot="feet" event="script" value="yourscriptname.lua"/> <movevent type="DeEquip" itemid="XXX" slot="feet" event="script" value="yourscriptname.lua"/>
[31/10/2013 11:34:57] [Error - MoveEvents Interface]
[31/10/2013 11:34:57] data/movements/scripts/cap.lua:onEquip
[31/10/2013 11:34:57] Description:
[31/10/2013 11:34:57] data/movements/scripts/cap.lua:14: attempt to perform arithmetic on a nil value
[31/10/2013 11:34:57] stack traceback:
[31/10/2013 11:34:57] data/movements/scripts/cap.lua:14: in function <data/movements/scripts/cap.lua:13>
[31/10/2013 11:34:57] mysql_real_query(): SELECT `cap` FROM `players` WHERE `player_id` = '9'; - MYSQL ERROR: Unknown column 'player_id' in 'where clause' (1054)
[31/10/2013 11:33:14] [Error - MoveEvents Interface]
[31/10/2013 11:33:14] data/movements/scripts/cap.lua:onDeEquip
[31/10/2013 11:33:14] Description:
[31/10/2013 11:33:14] data/movements/scripts/cap.lua:19: attempt to perform arithmetic on a nil value
[31/10/2013 11:33:14] stack traceback:
[31/10/2013 11:33:14] data/movements/scripts/cap.lua:19: in function <data/movements/scripts/cap.lua:18>
Fixes the MySQL error
Code:db.getResult("SELECT `cap` FROM `players` WHERE `id` = " .. getPlayerGUID(cid))
function getPlayerCap(cid)
local test = db.getResult("SELECT `cap` FROM `players` WHERE `id` = " .. getPlayerGUID(cid))
if test:getID() ~= false then
local cap = test:getDataInt("cap")
test:free()
return cap
end
return false
end
I don't think it will work properly tbhCode:function getPlayerCap(cid) local test = db.getResult("SELECT `cap` FROM `players` WHERE `id` = " .. getPlayerGUID(cid)) if test:getID() ~= false then local cap = test:getDataInt("cap") test:free() return cap end return false end