• 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 Making an item add mana points an health points when equipped?

dominique120

Science & Reason
Senator
Premium User
Joined
Jun 16, 2013
Messages
3,881
Solutions
3
Reaction score
1,043
Location
Númenor
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!
 
Item registered in movements.xml?
I added:
Code:
    <movevent type="Equip" itemid="12644" slot="shield" event="function" value="onEquipItem"/>
    <movevent type="DeEquip" itemid="12644" slot="shield" event="function" value="onDeEquipItem"/>

and it works now, thanks!
 
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.
 
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.

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.
 
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.

I know that there is a function that sets maximum capacity, but I dont know how I would use it. I would have to set capacity, then re set it.
 
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.

You need to make a script on movements for that one, using the following function:
doPlayerSetMaxCapacity(cid, cap)
 
Not tested, is just an idea:

Code:
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

Fixed by Ninja.

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"/>
 
Last edited:
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"/>

I get all sorts of errors with this script, when equiping, de equiping...

Code:
[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>

Code:
[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)

Code:
[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>

I think they are caused by the mysql error.

*EDIT* I fised the mysql error, now it looks for 'id' instead of 'player_id'. but I still get the errors
 
Last edited:
Fixes the MySQL error
Code:
db.getResult("SELECT `cap` FROM `players` WHERE `id` = " .. getPlayerGUID(cid))
 
Code:
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 tbh :p
 
Code:
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 tbh :p

It works! Thanks guys!! :)
 
Back
Top