• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Lua What i made worng? Open door if have item

warriorfrog

Active Member
Joined
Jul 29, 2015
Messages
334
Reaction score
35
I tried made it to
if door is closed

if u tried to open and have a scroll
ok, door will open and in 5 seconds it will close

else
u cant open the door

script (im not good in lua, i tried make it, cathing parts on web)
Code:
local open_door = 6258
local closed_door = 6257
local scroll_id = 1949

local function changeBack(Pos)
   doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)
end

function onUse(cid, item, frompos, item2, toPosition)
   if(itemEx.itemid == closed_door) then
     if getPlayerItemCount(cid,scroll_id) > -1 then
       doTransformItem(itemEx.uid, open_door)
       addEvent(changeBack,5000,toPosition)
     else
       doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You don't have the scroll password.")
     end
   end
end
 
Last edited:
To begin with you should always include your version of tfs. Looking at your script I'm going to guess it's 0.3.6 - 0.4
function onUse(cid, item, frompos, item2, toPosition)

cid = creature ID (I like to think of it as caller ID as if it refers to the one calling the script, makes more sense to me at least :p)
item = item you use
i̶t̶e̶m̶2̶ itemEx = the Item you use your item on

Look through everything within that function and you should be able to see what needs to be changed.

also in function changeBack(Pos) the P in "Pos" is supposed to be lowercase, but in this case you actually don't need it at all. You can leave it blank("changeBack()"). you should also define the position either within a variable or inside the function.
something like:
local door_pos = {x = 1000, y = 1000, z = 7} (change it to your doors position of course)
and then in "doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)" change Pos with door_pos
To define it inside the function it should be done like this "doTransformItem(getTileItemById({x = 1000, y = 1000, z = 7}, open_door).uid, closed_door)"
 
Actually the parameters of the interface don't matter for spelling or what they are named, for consistencies sake sure but for execution not important, as long as the data that is being passed is used appropriately.
 
I tried:
Code:
local open_door = 6258
local closed_door = 6257
local scroll_id = 1949

local function changeBack(Pos)
   doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)
end

function onUse(cid, item, frompos, item2, toPosition)
   if(item.itemid == closed_door) then
     if getPlayerItemCount(cid,scroll_id) >= 1 then
       doTransformItem(item.uid, open_door)
       addEvent(changeBack,5000,toPosition)
     else
       doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You don't have the scroll password.")
     end
   end
end

Its work, but when u dont have conditions gave msg:
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You don't have the scroll password.")
and open door, i need not open
 
Last edited:
Read Cade's post again. That'll help you a bit on the way. I don't understand the issue you're having, are you simply not able to open the door or does it always give you the message "you don't have the scroll password" or can you always open the door? Any console errors?
 
Read Cade's post again. That'll help you a bit on the way. I don't understand the issue you're having, are you simply not able to open the door or does it always give you the message "you don't have the scroll password" or can you always open the door? Any console errors?

There is no erros on console, my problem is:
if getPlayerItemCount(cid,scroll_id) >= 1 then:
work fine, open the door, and in 5 seconds close again

else:
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE, "You don't have the scroll password.")
its give msg, but door is open, i want the door not open if u dont have if getPlayerItemCount(cid,scroll_id) >= 1 then:
 
Probably means the door is in the doors actions script still. Therefore it is working 100% but it is loading two scripts when u open it.
 
Code:
Local open_door = 6258
local closed_door = 6257
local scroll_id = 1949
local function changeBack(Pos)
doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)
end

function onUse(cid, item, frompos, item2, toPosition)
if item.actionid == xxxx and if getPlayerItemCount(cid,scroll_id) >= 1 then
doTransformItem(item.uid, open_door)
addEvent(changeBack,5000,toPosition)
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"You don't have the scroll password.")
end
return true
end
In xml use door id and put actionid on door
Not tested and i use phone dont sure if work or no
 
Last edited:
return true
Code:
Local open_door = 6258
local closed_door = 6257
local scroll_id = 1949
local function changeBack(Pos)
doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)
end

function onUse(cid, item, frompos, item2, toPosition)
if item.actionid == xxxx and if getPlayerItemCount(cid,scroll_id) >= 1 then
doTransformItem(item.uid, open_door)
addEvent(changeBack,5000,toPosition)
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"You don't have the scroll password.")
end
end
In xml use action id not door id
Not tested and i use phone dont sure if work or no
Post the xml entry associated with this script.
 
There is a problem, if player stay on door, when it close he stay upside closed door

I think i will solved the problem teleporting him to 1 sqm \/
Code:
  local a = getCreaturePosition(cid)
  doTeleportThing(cid,{x=a.x,y=a.y-1,z=a.z})
Its right?

But how to check if he is upside closed door?
 
There is a problem, if player stay on door, when it close he stay upside closed door

I think i will solved the problem teleporting him to 1 sqm \/
Code:
  local a = getCreaturePosition(cid)
  doTeleportThing(cid,{x=a.x,y=a.y-1,z=a.z})
Its right?

But how to check if he is upside closed door?

You can check for a player on a position with " getThingFromPos(position).uid ".
So probably like:

local pp = getThingFromPos(position).uid

if isPlayer(pp) then
doTeleportThing(pp, destination)
end
 
Its not work

You can check for a player on a position with " getThingFromPos(position).uid ".
So probably like:

local pp = getThingFromPos(position).uid

if isPlayer(pp) then
doTeleportThing(pp, destination)
end


Code:
[15:47:27.684] [Error - Action Interface]
[15:47:27.684] In a timer event called from:
[15:47:27.684] data/actions/scripts/porta_labmino.lua:onUse
[15:47:27.684] Description:
[15:47:27.684] attempt to index a nil value
[15:47:27.684] stack traceback:
[15:47:27.684]    [C]: in function 'getThingFromPos'
[15:47:27.684]    data/actions/scripts/porta_labmino.lua:6: in function <data/actions/scripts/porta_labmino.lua:5>

Code:
local open_door = 6258
local closed_door = 6257
local scroll_id = 1949

local function changeBack(Pos)
   local pp = getThingFromPos(position).uid
   if isPlayer(pp) then
     local destination = getCreaturePosition(pp)
     doTeleportThing(pp,{x=destination.x,y=destination.y-1,z=destination.z})
   end

   doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)
end

function onUse(cid, item, frompos, item2, toPosition)
   if item.actionid == 7420 and getPlayerItemCount(cid,scroll_id) >= 1 then
     doTransformItem(item.uid, open_door)
     addEvent(changeBack,5000,toPosition)
   else
     doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"You don't have the scroll password.")
   end
   return true
end

I wana ask u why open and close u can use if player use door and have x items teleport to x pos

cuz i wanna try new ways
 
use this
Code:
local open_door = 6258
local closed_door = 6257
local scroll_id = 1949
local function changeBack(Pos)
doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)
end
local function GoBack(cid, pos)
if not(isPlayer(cid)) then return true end
doTeleportThing(cid, {x = xxxx, y = xxxx, z = x}) -- here any postion u want player tp to
end

function onUse(cid, item, frompos, item2, toPosition)
if (item.actionid == 6227) then
if getPlayerItemCount(cid, scroll_id, 1) then
doTransformItem(item.uid, open_door)
addEvent(changeBack,5000,toPosition)
addEvent(GoBack,5000, cid, pos)
else
doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"You don't have the scroll password.")
end
end
return true
end
 
You can check for a player on a position with " getThingFromPos(position).uid ".
So probably like:

local pp = getThingFromPos(position).uid

if isPlayer(pp) then
doTeleportThing(pp, destination)
end

Bad, very bad code.

Better use something more like....

Code:
pos1 = {x = 1000, y = 1000, z = 7} //1 side of door
pos2 = {x = 1000, y = 1000, z = 7} //other side of door

if getPlayerPosition(cid) == pos1 then
doTeleportThing(cid, pos2)
elseif getPlayerPosition(cid) == pos2 then
doTeleportThing(cid, pos1)
end
 
Bad, very bad code.

Better use something more like....

Code:
pos1 = {x = 1000, y = 1000, z = 7} //1 side of door
pos2 = {x = 1000, y = 1000, z = 7} //other side of door

if getPlayerPosition(cid) == pos1 then
doTeleportThing(cid, pos2)
elseif getPlayerPosition(cid) == pos2 then
doTeleportThing(cid, pos1)
end
Code:
doTeleportThing(cid, 1 == 1 and x or y)
 
doTeleportThing(cid, 1 == 1 and x or y)
Yeah but my code isn't just teleporting what ever player is standing in the spot. Meaning a player could force another player to teleport outside if he is standing in front of the door. I don't think that's what he wants.

Did I say that was the most accurate way to code it? No, but I said mine works the correct way. Don't comment on my comments unless you are going to be smart about it. Just make a comment telling him your way of doing it.
 
Its not work




Code:
[15:47:27.684] [Error - Action Interface]
[15:47:27.684] In a timer event called from:
[15:47:27.684] data/actions/scripts/porta_labmino.lua:onUse
[15:47:27.684] Description:
[15:47:27.684] attempt to index a nil value
[15:47:27.684] stack traceback:
[15:47:27.684]    [C]: in function 'getThingFromPos'
[15:47:27.684]    data/actions/scripts/porta_labmino.lua:6: in function <data/actions/scripts/porta_labmino.lua:5>

Code:
local open_door = 6258
local closed_door = 6257
local scroll_id = 1949

local function changeBack(Pos)
   local pp = getThingFromPos(position).uid
   if isPlayer(pp) then
     local destination = getCreaturePosition(pp)
     doTeleportThing(pp,{x=destination.x,y=destination.y-1,z=destination.z})
   end

   doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)
end

function onUse(cid, item, frompos, item2, toPosition)
   if item.actionid == 7420 and getPlayerItemCount(cid,scroll_id) >= 1 then
     doTransformItem(item.uid, open_door)
     addEvent(changeBack,5000,toPosition)
   else
     doPlayerSendTextMessage(cid, MESSAGE_EVENT_ADVANCE,"You don't have the scroll password.")
   end
   return true
end



cuz i wanna try new ways

You can't expect it to work that way when in the changeBack(Pos) function, you only give "Pos" as argument, and then you attempt to use an argument "position" which is not defined anywhere.

local function changeBack(Pos)
local pp = getThingFromPos(ENTERDOORPOSITIONHERE).uid
if isPlayer(pp) then
doTeleportThing(pp,ENTERPOSITIONWHERETOTELEPORTPLAYERHERE)
end

doTransformItem(getTileItemById(Pos, open_door).uid, closed_door)
end
 
Back
Top