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

TFS 0.X dual wielding conditions

Lurk

Active Member
Joined
Dec 4, 2017
Messages
336
Reaction score
48
Hi, I want my players to be able to use a special weapon alongside their normal weapons, for that I'd need my second weapon to be dual wield and their normal weapons to also be dual wield
the thing is, making their normal weapons dual wield will allow them to use 2 normal weapons together which I don't want.
This is the beggining of a code I'm trying to make

edit: new code
Lua:
function onEquip(cid, item, slot)

local slotitem = getPlayerSlotItem(cid, CONST_SLOT_LEFT) -- edite o slot
local itemid1 = 7391
local itemid2 = 7754
local itemid3 = 8849


if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
doPlayerPopupFYI(cid, "erro 1 if")
return false
elseif getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
doPlayerPopupFYI(cid, "erro 2 if")
return false
elseif getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
doPlayerPopupFYI(cid, "erro 3 if")
return false
end

return true
end
it doesn't return errors in the console but also doesn't work, in game I'm receiving the PopupFYI but the player equips it anyway, I don't know how to prevent the player from equiping the item
tfs 0.4 rev 3777
 
Last edited:
Solution
I've had this error, is lack of function in source.
Talked to him over discord, and we figured that out pretty quick.
Gave him a link to another tfs 0.4 on github, and he's going to try to use the onMoveItem function from that one and recompile source.

Dunno if it'll work, but it's worth a try. xD
I've never worked with source before, but it at least sounds like a plausible solution.

Someone who knows better then me might want to chime in, if this won't work, or requires additional changes?
Hi, I want my players to be able to use a special weapon alongside their normal weapons, for that I'd need my second weapon to be dual wield and their normal weapons to also be dual wield
the thing is, making their normal weapons dual wield will allow them to use 2 normal weapons together which I don't want.
This is the beggining of a code I'm trying to make

edit: new code
Lua:
function onEquip(cid, item, slot)

local slotitem = getPlayerSlotItem(cid, CONST_SLOT_LEFT) -- edite o slot
local itemid1 = 7391
local itemid2 = 7754
local itemid3 = 8849


if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
doPlayerPopupFYI(cid, "erro 1 if")
return false
elseif getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
doPlayerPopupFYI(cid, "erro 2 if")
return false
elseif getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
doPlayerPopupFYI(cid, "erro 3 if")
return false
end

return true
end
it doesn't return errors in the console but also doesn't work, in game I'm receiving the PopupFYI but the player equips it anyway, I don't know how to prevent the player from equiping the item
What TFS are you using?
 
tfs 0.4 rev 3777, I've also added this information to the main post, my bad
Instead of using onEquip in movements, try using 'onMoveItem' in creaturescripts.
You can check if the item is being moved to one of the hand slots, and then compare whatever you need to check.
Returning false using 'onMoveItem' will stop the item from being moved.

For whatever reason movements can't return false, because the item has already been 'moved' by the time onEquip is triggered, so returning false just doesn't accomplish anything.

---Edit---
Lua:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if toPos.x == 65535 then
        -- item is being moved to inventory area
        if toPos.y == 6 or toPos.y == 5 then
            -- item is being moved to one of the hand locations
            -- start checking whatever you want
        end
    end
    return true
end
 
Last edited:
console
Code:
[23:36:00.359] [Error - CreatureEvent::configureEvent] No valid type for creature event.onMove
[23:36:00.361] [Warning - BaseEvents::loadFromXml] Cannot configure an event

code
Lua:
function onMoveItem(cid, item, slot)

local itemid1 = 7391
local itemid2 = 7754
local itemid3 = 8849

if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
return doPlayerSendCancel (cid, "no") and false

return true
end

creaturescripts.xml
XML:
<event type="onMove" name="checkUnclear" event="script" value="checkunclear.lua"/>

I registered in login.lua as well

edit: oops nvm, it's type="moveitem". got this error in the console now
Code:
[23:38:48.071] [Error - CreatureScript Interface]
[23:38:48.072] data/creaturescripts/scripts/checkunclear.lua:onMoveItem
[23:38:48.074] Description:
[23:38:48.075] (LuaInterface::luaGetPlayerSlotItem) Player not found
 
console
Code:
[23:36:00.359] [Error - CreatureEvent::configureEvent] No valid type for creature event.onMove
[23:36:00.361] [Warning - BaseEvents::loadFromXml] Cannot configure an event

code
Lua:
function onMoveItem(cid, item, slot)

local itemid1 = 7391
local itemid2 = 7754
local itemid3 = 8849

if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
return doPlayerSendCancel (cid, "no") and false

return true
end

creaturescripts.xml
XML:
<event type="onMove" name="checkUnclear" event="script" value="checkunclear.lua"/>

I registered in login.lua as well
Try below. And yes, register in login.lua as well.
XML:
<event type="moveitem" name="checkUnclear" event="script" value="checkunclear.lua"/>
Lua:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
    if toPos.x == 65535 then
        print("item is being moved to inventory area")
        if toPos.y == 6 or toPos.y == 5 then
            print("item is being moved to one of the hand locations")
            -- start checking whatever you want
        end
    end
    return true
end
 
Now I can't remove any item from my hands or backpack
Code:
[23:43:21.709] [Error - CreatureScript Interface]
[23:43:21.711] data/creaturescripts/scripts/checkunclear.lua:onMoveItem
[23:43:21.715] Description:
[23:43:21.716] data/creaturescripts/scripts/checkunclear.lua:5: attempt to index local 'toPos' (a nil value)
[23:43:21.718] stack traceback:
[23:43:21.719]  data/creaturescripts/scripts/checkunclear.lua:5: in function <data/creaturescripts/scripts/checkunclear.lua:1>

code:
Lua:
function onMoveItem(cid, item, count, toContainer, fromContainer, fromPos, toPos)
local itemid1 = 7391
local itemid2 = 7754
local itemid3 = 8849
    if toPos.x == 65535 then
        print("item is being moved to inventory area")
        if toPosition.y == 6 or toPosition.y == 5 then
            print("item is being moved to one of the hand locations")
            if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
                return doPlayerSendCancel (cid, "failr") and false
            end
        end
    end
    return true
end
 
I've had this error, is lack of function in source.
Talked to him over discord, and we figured that out pretty quick.
Gave him a link to another tfs 0.4 on github, and he's going to try to use the onMoveItem function from that one and recompile source.

Dunno if it'll work, but it's worth a try. xD
I've never worked with source before, but it at least sounds like a plausible solution.

Someone who knows better then me might want to chime in, if this won't work, or requires additional changes?
 
Solution
I'm getting this error trying to compile with his moveitem tho
Code:
Creating library C:\Users\gabriel60020111\Desktop\HIGH RATE\src\vc10\x64\Release\theforgottenserver.lib and object C:\Users\gabriel60020111\Desktop\HIGH RATE\src\vc10\x64\Release\theforgottenserver.exp
1>game.obj : error LNK2001: unresolved external symbol "public: unsigned int __cdecl CreatureEvents::executeMoveItems(class Creature *,class Item *,class Position const &,class Position const &)" (?executeMoveItems@CreatureEvents@@QEAAIPEAVCreature@@PEAVItem@@AEBVPosition@@2@Z)
1>C:\Users\gabriel60020111\Desktop\HIGH RATE\src\vc10\x64\Release\theforgottenserver.exe : fatal error LNK1120: 1 unresolved externals
 
 
is the one I have already
this one gave me some errors as well
and about the last one, I can't find most of the stuff he points to..

edit: I believe the problem is the check I'm using. When I have the code
Lua:
function onMoveItem(moveItem, frompos, position, cid)
local itemid1 = 7391
local itemid2 = 7754
local itemid3 = 8849
    --if position.x == 65535 then
       -- print("item is being moved to inventory area")
        --if position == 6 or position == 5 then
           -- print("item is being moved to one of the hand locations")
            if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3  and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 and getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
                return doPlayerSendCancel (cid, "failr") and false
            end
        --end
    --end
    return true
end
and just one of the weapons I've listed, I can move anything anywhere, but if I have 2 of them equiped I can never move anything anywhere. I need to check if the guy has one of the weapons i either hand and then prevent him from equiping, not prevent him from moving stuff if he has 2 weapons equiped

I think the script would have to be something like
Lua:
function onMoveItem(moveItem, frompos, position, cid)
local itemid1 = 7391
local itemid2 = 7754
local itemid3 = 8849

            if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 then
                if tryingToMoveShitToRightHand.itemid == itemid1 or ... then
                    return doPlayerSendCancel (cid, "failr") and false
                end
            end

    return true
end

edit again:
I fucking did it! on movements
Lua:
function onEquip(cid, item, slot)

local itemid1 = 7391
local itemid2 = 7754
local itemid3 = 8849

    if getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_LEFT).itemid == itemid3 or getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid1 or getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid2 or getPlayerSlotItem(cid, CONST_SLOT_RIGHT).itemid == itemid3 then
        return doPlayerSendCancel (cid, "fail") and false
    end

    return true
end
I'll give the best answer to Xikini for the earlier help and the disposition to even go to discord to try figure it out
 
Last edited:
Back
Top