• Vote in May Mapping Competition to select a winner!
  • 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!

Storage for equip actionid

sakero

New Member
Joined
Oct 21, 2010
Messages
28
Best answers
1
Reaction score
3
Hello,

I need: when equipping "x" sword for example with actionid "9191" obtain
Code:
self: setStorageValue (8345, 1)
I Have this: in event / script / Player function Player:eek:nMoveItem(item, count, fromPosition, toPosition, fromCylinder, toCylinder)


Code:
 if item:getActionId() == 9191 and self:getStorageValue(8345) == -1 then
        if toPosition.y ==  6 then
            self:setStorageValue(8345, 1)
            return true
        end
    end
   
        if item:getActionId() == 9191 and self:getStorageValue(8345) == 1 then
                if toPosition.x ~= CONTAINER_POSITION or toPosition.y == CONST_SLOT_BACKPACK then
            self:setStorageValue(8345, -1)
            return true
        end
    end

The problem is:
when I move item to the floor and there is something the storage is changed, and the sword is still equipped

PD: Sry my english.
 
Last edited:

Sttorm

New Member
Joined
Apr 25, 2019
Messages
4
Best answers
0
Reaction score
2
@sakero it's practical to use movements
Lua:
local storage = 8345
local action_id = 9191

function onEquip(player, item, slot)
    if item:getActionId() == action_id then
        self:setStorageValue(storage, 1)
        return true
    end
end

function onDeEquip(player, item, slot)
    if item:getActionId() == action_id then
        self:setStorageValue(storage, 0)
        return true
    end
end
 
OP
S

sakero

New Member
Joined
Oct 21, 2010
Messages
28
Best answers
1
Reaction score
3
I can't test now. But i can register actionid for onequip and ondequip un movements?
I want use for different items
 

Sttorm

New Member
Joined
Apr 25, 2019
Messages
4
Best answers
0
Reaction score
2
@sakero All items that have this id action will have this effect.
 

Apollos

Dude who does stuff
Joined
Apr 22, 2009
Messages
756
Best answers
114
Reaction score
520
Location
United States
@sakero it's practical to use movements
Lua:
local storage = 8345
local action_id = 9191

function onEquip(player, item, slot)
    if item:getActionId() == action_id then
        self:setStorageValue(storage, 1)
        return true
    end
end

function onDeEquip(player, item, slot)
    if item:getActionId() == action_id then
        self:setStorageValue(storage, 0)
        return true
    end
end
You need to use player instead of self here. Also I'm not 100% with onEquip/onDeEquip sure but you may just be able to register the action id in movements.xml instead of the itemid so you can exclude the getActionId check within.

I can't test now. But i can register actionid for onequip and ondequip un movements?
I want use for different items
I think it may be better to just check slots of player when needed instead of setting storages every time, for example:

Lua:
for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
    local slot_item = player:getSlotItem(i)
    if slot_item and slot_item.actionid == 9191 then
        -- do your stuff
        break
    end
end
Or if you only need to check one slot, like how your only checking CONST_SLOT_LEFT in your onMove attempt you can do this:
Lua:
local slot_item = player:getSlotItem(CONST_SLOT_LEFT)
if slot_item and slot_item.actionid == 9191 then
    -- do your stuff
end
 

Sttorm

New Member
Joined
Apr 25, 2019
Messages
4
Best answers
0
Reaction score
2
@Apollos Thank you! I do not have much experience with this version of TFS, even more that I do not speak English and use translator

@sakero

XML:
    <movevent event="Equip" actionid="9191" slot="ring" script="item.lua" />
    <movevent event="DeEquip" actionid="9191" slot="ring" script="item.lua" />
Lua:
local storage = 8345
local action_id = 9191

function onEquip(player, item, slot)
    player:setStorageValue(storage, 1)
    return true
end

function onDeEquip(player, item, slot)
    player:setStorageValue(storage, 0)
    return true
end
 
OP
S

sakero

New Member
Joined
Oct 21, 2010
Messages
28
Best answers
1
Reaction score
3
@Apollos Thank you! I do not have much experience with this version of TFS, even more that I do not speak English and use translator

@sakero

XML:
    <movevent event="Equip" actionid="9191" slot="ring" script="item.lua" />
    <movevent event="DeEquip" actionid="9191" slot="ring" script="item.lua" />
Lua:
local storage = 8345
local action_id = 9191

function onEquip(player, item, slot)
    player:setStorageValue(storage, 1)
    return true
end

function onDeEquip(player, item, slot)
    player:setStorageValue(storage, 0)
    return true
end
Its dont work, I think it does not work register actionid in movements.

You need to use player instead of self here. Also I'm not 100% with onEquip/onDeEquip sure but you may just be able to register the action id in movements.xml instead of the itemid so you can exclude the getActionId check within.


I think it may be better to just check slots of player when needed instead of setting storages every time, for example:

Lua:
for i = CONST_SLOT_FIRST, CONST_SLOT_LAST do
    local slot_item = player:getSlotItem(i)
    if slot_item and slot_item.actionid == 9191 then
        -- do your stuff
        break
    end
end
Or if you only need to check one slot, like how your only checking CONST_SLOT_LEFT in your onMove attempt you can do this:
Lua:
local slot_item = player:getSlotItem(CONST_SLOT_LEFT)
if slot_item and slot_item.actionid == 9191 then
    -- do your stuff
end
Nice, it worked, different but it worked

thanks to both.
 
Top