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

Need a script that only player that use item x may pass

1268995

Member
Joined
Sep 9, 2010
Messages
422
Reaction score
13
Hello, i need a script that only people with item x, may pass on some door.. Is that possible? @Limos
 
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.
 
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.

My server are 8.6, so my distro are... 0.3.6 or 0.4, idk ... >.<
 
Try this make sure to put the item used in arrow slot or it wont work :)
Code:
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
 
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
Code:
<movevent type="StepIn" actionid="45001" event="script" value="need_item_to_pass_door.lua"/>
data/movements/scripts/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. :D
 
Last edited:
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
Code:
<movevent type="StepIn" actionid="45001" event="script" value="need_item_to_pass_door.lua"/>
data/movements/scripts/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. :D

But also work, for example, with itens like equips? i mean, shield, armor, legs that i am wearing?
 
But also work, for example, with itens like equips? i mean, shield, armor, legs that i am wearing?
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
 
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

You should edit the original post with the right code: if config.removeitem == yes then -- righ

Anyway, thanks, i will test and tell u if works!!!!
 
Last edited: 35 minutes ago
1268995, 12 minutes ago

I already did. :p
 
Back
Top