<action actionid="1234" script="doorthing.lua" />
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if player:getItemCount(2400) >= 1 then
return true
end
return false
end
https://otland.net/threads/board-rules-for-requests.113384/
Good place to start.
This is very possible and probably already exists, but you should consider posting some information as per the thread I posted above.
Basically, if I was doing this for TFS 1.x I would do something like this:
the door:
set door actionid in map editor to 1234
actions.xml
Code:<action actionid="1234" script="doorthing.lua" />
doorthing.lua
Code:function onUse(player, item, fromPosition, target, toPosition, isHotkey) if player:getItemCount(2400) >= 1 then return true end return false end
However if you're not using TFS 1.x then this isn't going to work. Post your distro and this can easily be adapted to it.
local THEID = 2160 --2160 is id for crystal coin. make sure item is in arrow slot!--
function onUse(cid, item, fromPosition, itemEx, toPosition)
local doorPosition = {x = toPosition.x, y = toPosition.y, z = toPosition.z, stackpos = STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE}
local doorCreature = getThingfromPos(doorPosition)
if isInArray(questDoors, item.itemid) == TRUE then
if getPlayerSlotItem(cid, CONST_SLOT_AMMO).itemid == THEID then
doTransformItem(item.uid, item.itemid + 1)
doTeleportThing(cid, toPosition, TRUE)
else
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You need a special item in ammunition slot to pass!")
end
return TRUE
end
return FALSE
end
<movevent type="StepIn" actionid="45001" event="script" value="need_item_to_pass_door.lua"/>
local config = {
itemid = 2666, -- meat
count = 4, -- how many required.
removeitem = yes, -- yes/no to remove items from player when they pass
}
function onStepIn(cid, item, fromPos, item2, toPos)
if getPlayerItemCount(cid, config.itemid) >= config.count then
if config.removeitem == yes then
doPlayerRemoveItem(cid, config.itemid, config.count)
else
return true
end
else
doTeleportThing(cid, fromPos)
doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You require ".. config.count .." ".. getItemNameById(config.itemid) .." to pass.")
end
return true
end
An alternative is to make a movement script for the tile of the door.
People will be able to open the door, but will be unable to pass through the door unless they have the correct item.
data/movements/movements.xml
data/movements/scripts/need_item_to_pass_door.luaCode:<movevent type="StepIn" actionid="45001" event="script" value="need_item_to_pass_door.lua"/>
Code:local config = { itemid = 2666, -- meat count = 4, -- how many required. removeitem = yes, -- yes/no to remove items from player when they pass } function onStepIn(cid, item, fromPos, item2, toPos) if getPlayerItemCount(cid, config.itemid) >= config.count then if config.removeitem = yes then doPlayerRemoveItem(cid, config.itemid, config.count) else return true end else doTeleportThing(cid, fromPos) doPlayerSendTextMessage(cid, MESSAGE_INFO_DESCR, "You require ".. config.count .." ".. getItemNameById(config.itemid) .." to pass.") end return true end
Just different ways to do things.
All of them work, and all of them have their uses.
Yes, it will also check players equipment slots for items.But also work, for example, with itens like equips? i mean, shield, armor, legs that i am wearing?
if getPlayerSlotItem(cid, CONST_SLOT_AMMO).itemid == config.itemid then
CONST_SLOT_FIRST = 1
CONST_SLOT_HEAD = CONST_SLOT_FIRST
CONST_SLOT_NECKLACE = 2
CONST_SLOT_BACKPACK = 3
CONST_SLOT_ARMOR = 4
CONST_SLOT_RIGHT = 5
CONST_SLOT_LEFT = 6
CONST_SLOT_LEGS = 7
CONST_SLOT_FEET = 8
CONST_SLOT_RING = 9
CONST_SLOT_AMMO = 10
CONST_SLOT_LAST = CONST_SLOT_AMMO
if config.removeitem = yes then -- wrong
if config.removeitem == yes then -- right
Yes, it will also check players equipment slots for items.
If you want the player to be required to have the item equipped then you will need to check that particular item slot for the item.
Code:if getPlayerSlotItem(cid, CONST_SLOT_AMMO).itemid == config.itemid then
Code:CONST_SLOT_FIRST = 1 CONST_SLOT_HEAD = CONST_SLOT_FIRST CONST_SLOT_NECKLACE = 2 CONST_SLOT_BACKPACK = 3 CONST_SLOT_ARMOR = 4 CONST_SLOT_RIGHT = 5 CONST_SLOT_LEFT = 6 CONST_SLOT_LEGS = 7 CONST_SLOT_FEET = 8 CONST_SLOT_RING = 9 CONST_SLOT_AMMO = 10 CONST_SLOT_LAST = CONST_SLOT_AMMO
Also looking back through the code I posted yesterday there is a small mistake that I will edit now.
Code:if config.removeitem = yes then -- wrong
Code:if config.removeitem == yes then -- right