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

Rookgaard drawbridge issue

lunara

Member
Joined
Dec 20, 2014
Messages
140
Reaction score
8
When i press the lever it wont happing anything...
here is a pic when i click
EzgubWf.png

I use tfs 0.4 SVN

Here my rats.lua
Code:
function onUse(cid, item, frompos, item2, topos)
gatepos = {{x=1099, y=1205, z=8}, {x=1100, y=1205, z=8}, {x=1101, y=1205, z=8}}
getgate = getThingfromPos(gatepos)

if item.uid == 4508 and item.itemid == 1945 and getgate.itemid == 5770 then
doRemoveItem(getgate.uid,1)
doTransformItem(item.uid,item.itemid+1)
elseif item.uid == 4508 and item.itemid == 1946 and getgate.itemid == 0 then
doCreateItem(5770,1,gatepos)
doTransformItem(item.uid,item.itemid-1)
else
doPlayerSendCancel(cid,"Sorry not possible.")
end
  return 1
  end
REPP++ Help!
 
You can think of the way onUse works as a controller in this case it is an action which controls a switch.
The rest of the script executes the actions of the switch.

These parameters have nothing to do with the gate or its position, they only effect the switch.
Code:
onUse(cid, item, frompos, item2, topos)

Since you have defined gatepos as a table of positions you must reference each position by its index.
Code:
gatepos = {{x=1099, y=1205, z=8}, {x=1100, y=1205, z=8}, {x=1101, y=1205, z=8}}

There are 3 positions in gatepos
Code:
    gatepos = {
        {x=1099, y=1205, z=8}, -- index 1
        {x=1100, y=1205, z=8}, -- index 2
        {x=1101, y=1205, z=8}  -- index 3
    }

This code will not work as expect because we are passing the entire table to getThingfromPos.
Code:
getgate = getThingfromPos(gatepos)

We need to find a way to cycle through all those positions as needed, we can accomplish this using a for loop.
So we will redefine the original code as such.
Code:
--[[
    We can define the positions outside of onUse because this data never changes.
    Let's also structure it so it is readable :)
]]
local gatePosition = {
    {x = 1099, y = 1205, z = 8}, -- index 1
    {x = 1100, y = 1205, z = 8}, -- index 2
    {x = 1101, y = 1205, z = 8}  -- index 3
}
-- this table will hold all of the gate item id's
local getGate = {}

-- the item id of the gate
local gateItemId = 5770

function onUse(cid, item, frompos, item2, topos)
    -- lets 1st check the switch to see what state it is in
    if item.itemid == 1945 then
        -- now we will cycle through all the positions of the gate
        for indexOf = 1, #gatePosition do
            -- store the items if any at each index of gatePosition into getGate
            getGate[indexOf] = getThingfromPos(gatePosition[indexOf])
            -- now lets check if getGate equals gateItemId
            if getGate[indexOf].itemid == gateItemId then
                -- if those items do exist, lets remove them
                doRemoveItem(getGate[indexOf].uid, 1)
            end
        end
        -- transform the switch to 1946
        doTransformItem(item.uid, item.itemid + 1)
    -- incase the switch has already been pulled
    elseif item.itemid == 1946 then
        -- now we will cycle through all the positions of the gate
        for indexOf = 1, #gatePosition do
            -- store the items if any at each index of gatePosition into getGate
            getGate[indexOf] = getThingfromPos(gatePosition[indexOf])
            -- now lets check if getGate does not equal gateItemId
            if getGate[indexOf].itemid ~= gateItemId then
                -- if gateItemId does not exist, lets create it at the index of gatePosition
                doCreateItem(gateItemId, 1, gatePosition[indexOf])
            end
        end
        -- transform the switch to 1945
        doTransformItem(item.uid, item.itemid - 1)
    end
    return true
end
Hope it works out :)
 
You can think of the way onUse works as a controller in this case it is an action which controls a switch.
The rest of the script executes the actions of the switch.

These parameters have nothing to do with the gate or its position, they only effect the switch.
Code:
onUse(cid, item, frompos, item2, topos)

Since you have defined gatepos as a table of positions you must reference each position by its index.
Code:
gatepos = {{x=1099, y=1205, z=8}, {x=1100, y=1205, z=8}, {x=1101, y=1205, z=8}}

There are 3 positions in gatepos
Code:
    gatepos = {
        {x=1099, y=1205, z=8}, -- index 1
        {x=1100, y=1205, z=8}, -- index 2
        {x=1101, y=1205, z=8}  -- index 3
    }

This code will not work as expect because we are passing the entire table to getThingfromPos.
Code:
getgate = getThingfromPos(gatepos)

We need to find a way to cycle through all those positions as needed, we can accomplish this using a for loop.
So we will redefine the original code as such.
Code:
--[[
    We can define the positions outside of onUse because this data never changes.
    Let's also structure it so it is readable :)
]]
local gatePosition = {
    {x = 1099, y = 1205, z = 8}, -- index 1
    {x = 1100, y = 1205, z = 8}, -- index 2
    {x = 1101, y = 1205, z = 8}  -- index 3
}
-- this table will hold all of the gate item id's
local getGate = {}

-- the item id of the gate
local gateItemId = 5770

function onUse(cid, item, frompos, item2, topos)
    -- lets 1st check the switch to see what state it is in
    if item.itemid == 1945 then
        -- now we will cycle through all the positions of the gate
        for indexOf = 1, #gatePosition do
            -- store the items if any at each index of gatePosition into getGate
            getGate[indexOf] = getThingfromPos(gatePosition[indexOf])
            -- now lets check if getGate equals gateItemId
            if getGate[indexOf].itemid == gateItemId then
                -- if those items do exist, lets remove them
                doRemoveItem(getGate[indexOf].uid, 1)
            end
        end
        -- transform the switch to 1946
        doTransformItem(item.uid, item.itemid + 1)
    -- incase the switch has already been pulled
    elseif item.itemid == 1946 then
        -- now we will cycle through all the positions of the gate
        for indexOf = 1, #gatePosition do
            -- store the items if any at each index of gatePosition into getGate
            getGate[indexOf] = getThingfromPos(gatePosition[indexOf])
            -- now lets check if getGate does not equal gateItemId
            if getGate[indexOf].itemid ~= gateItemId then
                -- if gateItemId does not exist, lets create it at the index of gatePosition
                doCreateItem(gateItemId, 1, gatePosition[indexOf])
            end
        end
        -- transform the switch to 1945
        doTransformItem(item.uid, item.itemid - 1)
    end
    return true
end
Hope it works out :)
I'm tired and still not work but thank you anyway /:
 
I'm tired and still not work but thank you anyway /:
What seems to be the issue, what errors did you get?

I know what it might be, add stackpos = 1 to the each of the positions, like this.
Code:
local gatePosition = {
    {x = 1099, y = 1205, z = 8, stackpos= 1}, -- index 1
    {x = 1100, y = 1205, z = 8, stackpos= 1}, -- index 2
    {x = 1101, y = 1205, z = 8, stackpos= 1}  -- index 3
}
If that doesn't work change stackpos to 0.
 
What seems to be the issue, what errors did you get?
My actions.xml
http://pastebin.com/5re0k0eW<<<<Look



My rats.lua in actions/scrips
Code:
function onUse(cid, item, frompos, item2, topos)
gatepos = {{x=32099, y=32205, z=8}, {x=32100, y=32205, z=8}, {x=32101, y=32205, z=8}}
getgate = getThingfromPos(gatepos)

if item.uid == 4508 and item.itemid == 1945 and getgate.itemid == 5770 then
doRemoveItem(getgate.uid,1)
doTransformItem(item.uid,item.itemid+1)
elseif item.uid == 4508 and item.itemid == 1946 and getgate.itemid == 0 then
doCreateItem(5770,1,gatepos)
doTransformItem(item.uid,item.itemid-1)
else
doPlayerSendCancel(cid,"Sorry not possible.")
end
  return 1
  end
My second rats.lua in actions/scrips/other/rats.lua
Code:
  -- rook lever by Sasir~
local posi3 = {x=32102, y=32205, z=8} --
poss = {
[1] = {x=32099, y=32205, z=8},
[2] = {x=32100, y=32205, z=8},
[3] = {x=32101, y=32205, z=8}
}

local lever = {
[1] = {x=32098, y=32204, z=8},
[2] = {x=32104, y=32204, z=8}
}
local itemids = 5770
function onUse(cid, item, fromPosition, itemEx, toPosition)
        if item.itemid == 1945 then
                doCreateItem(itemids,poss[1])
                if getTileItemById(poss[2],4645).itemid ~= nil then
                        doTransformItem(getTileItemById(poss[2],4645).uid,itemids)
                end
                if getTileItemById(poss[3],4647).itemid > 0 then
                        doTransformItem(getTileItemById(poss[3],4647).uid,itemids)
                end
                for i=1,#lever do
                        if lever[i].x == fromPosition.x then
                                o = i
                        end
                end
                if o == 1 then
                        b = 2
                else
                        b = 1
                end
                doTransformItem(item.uid,item.itemid+1)
                doTransformItem(getTileItemById(lever[b],1945).uid,1946)
        elseif item.itemid == 1946 then
                for p = 1,#poss do
                doRelocate(poss[p], posi3)
                end
                for z =1,#poss do
                                poss[z].stackpos = 254
                                if getThingFromPos(poss[z]).itemid > 1000 then
                                        doRemoveItem(getThingFromPos(poss[z]).uid)
                                end
                                poss[z].stackpos = 1
                                if getThingFromPos(poss[z]).itemid > 1000 then
                                        doRemoveItem(getThingFromPos(poss[z]).uid)
                                end

                end
                for i=1,#lever do
                        if lever[i].x == toPosition.x then
                                o = i
                        end
                end
                if o == 1 then
                        b = 2
                else
                        b = 1
                end
                doCreateItem(4616,poss[1])
                doCreateItem(351,poss[2])
                doCreateItem(351,poss[3])
                doCreateItem(4645,poss[2])
                doCreateItem(4647,poss[3])
                doTransformItem(item.uid,item.itemid-1)
                doTransformItem(getTileItemById(lever[b],1946).uid,1945)
        end
        return TRUE
end
 
Code:
local positions = {
[1] = {x = 1099, y = 1205, z = 8}, --dont touch--
[2] = {x = 1100, y = 1205, z = 8}, --dont touch--
[3] = {x = 1101, y = 1205, z = 8} --dont touch--
}

local left_side = {x = 1098, y = 1205, z = 8} --dont touch--
local right_side = {x = 1102, y = 1205, z = 8} --dont touch--

local lever = 1945 --dont touch--
local lever2 = 1946 --dont touch--
local lever_pos = {x = 1098, y = 1204, z = 8} --dont touch--
local lever2_pos =  {x = 1104, y = 1201, z = 8} --dont touch--
local uid = 4508 --dont touch--
local bridge_tile = 5770 --dont touch--

-------------EDIT HERE-------------------------
local water_id = 1111 --Set to any water id
local left_bank = 1111 -- set to item id of the left side water border (where water connects to land)
local right_bank = 1111 --Set to itemid of the right side water border (where water connects to land)
------------------------------------------------
function onUse(cid, item, frompos, item2, topos)
   
    if item.itemid == lever and item.uid == uid then
    ------------Create Bridge-------------------
        for i = 1, #positions do
            doCreateItem(bridge_tile, 1, positions[i])
        end
        doTransformItem(getThingFromPos(lever_pos).uid, lever2)
        doTransformItem(getThingFromPos(lever2_pos).uid, lever2)
        doItemSetAttribute(getThingFromPos(lever_pos).uid, 'uid', uid)
        doItemSetAttribute(getThingFromPos(lever2_pos).uid, 'uid', uid)
    -------------------------------------------------
    elseif item.itemid == lever2 and item.uid == uid then
    ----------TELEPORT ANY PLAYERS STANDING ON BRIDGE--------------------
        for i = 1, #positions do
            if isPlayer(getThingFromPos(positions[i]).uid) then
                if positions[i] == positions[1] then
                    doTeleportThing(getThingFromPos(positions[i]).uid, left_side)
                elseif positions[i] == positions[2] then
                    doTeleportThing(getThingFromPos(positions[i]).uid, left_side)
                elseif positions[i] == positions[3] then
                    doTeleportThing(getThingFromPos(positions[i]).uid, right_side)
                end
            end
        end
    -----------------------------------------------------------------------
    ----------------------REMOVE BRIDGE-----------------------------------
        for i = 1, #positions do
            if positions[i] == positions[1] then
                doTransformItem(getThingFromPos(positions[i]).uid, left_bank)
            elseif positions[i] == positions[2] then
                doTransformItem(getThingFromPos(positions[i]).uid, water_id)
            elseif positions[i] == positions[3] then
                doTransformItem(getThingFromPos(positions[i]).uid, right_bank)
            end
        end
        doTransformItem(getThingFromPos(lever_pos).uid, lever1)
        doTransformItem(getThingFromPos(lever2_pos).uid, lever1)
        doItemSetAttribute(getThingFromPos(lever_pos).uid, 'uid', uid)
        doItemSetAttribute(getThingFromPos(lever2_pos).uid, 'uid', uid)
    end-----------------------------------------------------------------
return true
end
 
Last edited:
Back
Top