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

Solved Pulling Levers > Spawning Ladder problem.

SunMage

New Member
Joined
Jun 1, 2013
Messages
58
Reaction score
4
Hello fellow OTLanders.

I'm in search for help for an idea I had for a quest but i'm unable to script it.
I'm not a professional or anything but I do have some basic history not too long ago programming in LUA.

The idea is that i've placed 4 different levers in my map, it doesn't matter the order they are pulled (but you can tell me if you want, how that would be done).
When all of them are pulled a ladder should appear at given X,Y,Z position. Sounds simple? It probably is.

Sidenote: After you climb up the ladder, there will be tiles with onStepIn function that will pull back all the levers and ultimately making the ladder dissappear, can use help with that too.

Would much appreciate any help I can get from this.
 
Well, it seems that you do have the basics so this could be a good chance to learn how to do it by yourself!!
I will give you some guidance though and you can come back and ask me about anything or errors related.

Since you have 4 different levers with no order, you are looking at levers that do the same thing:
- Update a counter
When that counter reaches 4 (or the ammount of levers you wish), you want to:
- Create a ladder
When the player uses the ladder
- Make ladder dissappear
- Update counter to 0

Well you're gonna have 2 scripts!
1- Lever script:
  • Update counter (Both ways, meaning if it's in one side it removes a point and if it is used to the other side it increments)
  • Create ladder when counter is equal to -in this case- 4.
2- Ladder script:
  • Make lader dissapear and make counter zero
Since you have 4 levers that do the same thing, then you are looking at an action id, a way to represent which levers in the gameworld will be used for this particular script.
For the ladder since it is individual, you are using an unique id (it could be aid though).

The two scripts are use scripts, this means they are actions, and you will require the onUse function.
For counters you are better off using global storages, this is using a particular key with a value that represents the counter. The storages are handled by the database.
Good luck!! Try to make the logic work before trying it out! And of course ask if you don't know what to do next.
 
Hello fellow OTLanders.

I'm in search for help for an idea I had for a quest but i'm unable to script it.
I'm not a professional or anything but I do have some basic history not too long ago programming in LUA.

The idea is that i've placed 4 different levers in my map, it doesn't matter the order they are pulled (but you can tell me if you want, how that would be done).
When all of them are pulled a ladder should appear at given X,Y,Z position. Sounds simple? It probably is.

Sidenote: After you climb up the ladder, there will be tiles with onStepIn function that will pull back all the levers and ultimately making the ladder dissappear, can use help with that too.

Would much appreciate any help I can get from this.
It would help if you post your server version, else people have this guess this and might have to rewrite things later.
 
@Limos

I'm using TFS 1.1, sorry. Forgot about that.

Well, it seems that you do have the basics so this could be a good chance to learn how to do it by yourself!!
I will give you some guidance though and you can come back and ask me about anything or errors related.

Since you have 4 different levers with no order, you are looking at levers that do the same thing:
- Update a counter
When that counter reaches 4 (or the ammount of levers you wish), you want to:
- Create a ladder
When the player uses the ladder
- Make ladder dissappear
- Update counter to 0

Well you're gonna have 2 scripts!
1- Lever script:
  • Update counter (Both ways, meaning if it's in one side it removes a point and if it is used to the other side it increments)
  • Create ladder when counter is equal to -in this case- 4.
2- Ladder script:
  • Make lader dissapear and make counter zero
Since you have 4 levers that do the same thing, then you are looking at an action id, a way to represent which levers in the gameworld will be used for this particular script.
For the ladder since it is individual, you are using an unique id (it could be aid though).

The two scripts are use scripts, this means they are actions, and you will require the onUse function.
For counters you are better off using global storages, this is using a particular key with a value that represents the counter. The storages are handled by the database.
Good luck!! Try to make the logic work before trying it out! And of course ask if you don't know what to do next.

I do appreciate your help a lot but I can honestly say something like this is what I expected it to be.

In data/actions/scripts, will it work to make a global statement and that should make it work for all other scripts in there? (Yes I can try, and I will).

I have no idea what to put in the parameters in onUse(cid, item, fromPosition, itemEx, toPosition), like, what does all the parameters mean? Yes it's obvious but where are they coming from and is it replaceable, with what?
Same thing with doTileAddItemEx(pos, uid), since I think those two are the main functions i'm going to use.

I tried using doTileAddItem({x = 100, y = 100, z = 7}, 1386) while pulling a lever but seems to be the incorrect way to put it.
That is why i'm asking for help by anyone that can give me any help or make the whole thing for me.

Thank you.
 
Last edited by a moderator:
the onUse function is executed when anything is used.
The parameters mean:
cid - The player
item - The item used
fromPosition - The position of the player
itemEx - Item used onto something
toPosition - The position of the item

What you do is make a script in data/actions/scripts and then you register it in actions.xml with the proper actionid or uniqueid for that item.
Say I want a lever to make a rock in a position, if i just make the onUse function and register it in actions.xml with the itemid of a lever then this will happen to every lever, that's why you use unique id, or action id, this IDs represent which specific items do the job for that specific script.
After registering it, let's say with actionid=8000 in actions.xml and linking it to the script:
Code:
  <action actionid="8000" event="script" value="myscript.lua"/>
in myscript.lua you're gonna call the onUse function:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
Now everytime the item with actionid == 8000 is executed, this script will be executed.
So now think what you want to do in it.
You should use a global storage because variables are destroyed after the script is executed, thus when you press another lever then how will that execution know what the counter previously was?? That's the main idea behind it.
You are gonna be using:
Game.getStorageValue and Game.setStorageValue for the global storages as per 1.1 (I guess..)

The script is executed everytime the lever is used so you want to know the position of the lever, this way you know when to increment the counter and when to decrement it.
For this use item.itemid where 1945 is non-used and 1946 is used.
Try something out and post your doubts here, try to look-up some other lever scripts to understand better. I know you may want to just have the script done, but if you truly get this then things will get easier, specially because you have global storages here that are used for a lot of stuff.
 
the onUse function is executed when anything is used.
The parameters mean:
cid - The player
item - The item used
fromPosition - The position of the player
itemEx - Item used onto something
toPosition - The position of the item

What you do is make a script in data/actions/scripts and then you register it in actions.xml with the proper actionid or uniqueid for that item.
Say I want a lever to make a rock in a position, if i just make the onUse function and register it in actions.xml with the itemid of a lever then this will happen to every lever, that's why you use unique id, or action id, this IDs represent which specific items do the job for that specific script.
After registering it, let's say with actionid=8000 in actions.xml and linking it to the script:
Code:
  <action actionid="8000" event="script" value="myscript.lua"/>
in myscript.lua you're gonna call the onUse function:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
Now everytime the item with actionid == 8000 is executed, this script will be executed.
So now think what you want to do in it.
You should use a global storage because variables are destroyed after the script is executed, thus when you press another lever then how will that execution know what the counter previously was?? That's the main idea behind it.
You are gonna be using:
Game.getStorageValue and Game.setStorageValue for the global storages as per 1.1 (I guess..)

The script is executed everytime the lever is used so you want to know the position of the lever, this way you know when to increment the counter and when to decrement it.
For this use item.itemid where 1945 is non-used and 1946 is used.
Try something out and post your doubts here, try to look-up some other lever scripts to understand better. I know you may want to just have the script done, but if you truly get this then things will get easier, specially because you have global storages here that are used for a lot of stuff.

Okay thank you for the information you put out, but i've got a few things to clear out;
  • onUse parameters; are they changeable and when would you change any of the params? Skip-able?
  • item parameter; it's the item you put the unique id/action id on.. right?
  • fromPosition ...; does this matter when you are pulling a lever?
  • itemEx ...; This would only be like, using a small ruby on the altar to "charge" it, kinda thing.
  • toPosition ...; Still don't understand why you would have this parameter when pulling a lever.
I've gotten so far, i've made 4 levers, and made a script and registered it in actions.xml aswell as putting that action ID on all the levers.
In game it works perfectly to pull each one of the levers and it will increment my value for each push, and decrement for every pull.
The problem is that when the variable hits 4, it should spawn a Ladder.. With what command would I use? Another Script?

Also i've tried to make a global variable in a separate script in the same folder, doesn't seem to be working that way. Can you tell me how to make a global variable accesible from any Action script i'd make (otherwise I cant finish the script)?

  • Game.getStorageValue and Game.setStorageValue; when to use them and where? For what?

This is what i've come up with so far (since I don't know how to make a global variable accesible from another script in the same folder then i've tried to make a local variable).
Code:
local testcount = 0

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1945 then
        testcount = testcount + 1
        doCreatureSay(cid, testcount, TALKTYPE_ORANGE_1)
        doTransformItem(item.uid, item.itemid + 1)
    elseif item.itemid == 1946 then
        testcount = testcount - 1
        doCreatureSay(cid, testcount, TALKTYPE_ORANGE_1)
        doTransformItem(item.uid, item.itemid - 1)
    end
    return TRUE
end

if testcount == 4 then
    doTileAddItem({x = 279, y = 579, z = 4}, 1386)
end

And by the way, how do I make it so that when the lever is pulled, the number/letters will show up over the lever and not on myself (cid)?
 
Okay thank you for the information you put out, but i've got a few things to clear out;
  • onUse parameters; are they changeable and when would you change any of the params? Skip-able?
  • item parameter; it's the item you put the unique id/action id on.. right?
  • fromPosition ...; does this matter when you are pulling a lever?
  • itemEx ...; This would only be like, using a small ruby on the altar to "charge" it, kinda thing.
  • toPosition ...; Still don't understand why you would have this parameter when pulling a lever.

To keep it short, let's say they are not unchangeable (meaning the names can change but the position of each parameter means something).
Let's clear this out, a function recieves information from the outside, this information is given by the parameters, this is handled by TFS, you don't need to pay attention to this, what you have is the info that's neccessary to make your scripts.
The onUse function applies to WHATEVER thing you want to, toPosition is the position of the thing you use, it may not be neccessary for pulling a lever (or maybe if you want to add an effect on the lever position then it is!!).
Take the parameters as information given to you:
item -> This is the item given to you
item.itemid is the itemid ; item.actionid is the actionid ; item.uid is the uniqueid

fromPosition -> This is the position of the player!!
fromPosition.x is the x coord ; fromPosition.y is the y coord ; fromPosition.z is the z coord
If you were to "see" fromPosition it would look like: fromPosition = {x = getplayerpos.x, y = getplayerpos.y, z = getplayerpos.z}

itemEx -> Exactly what you said, this is the use with.. e.g using a potion onto someone/something
itemEx.itemid is the itemid ; itemEx.actionid is the actionid ; itemEx.uid is the uniqueid

toPosition -> Same as fromPosition but now the position is the position of the thing you used

Just rememer, everytime you use something that is registered in your actions.xml, it will come to the specific script and RUN the onUse function you defined, when it runs it, it will give YOU the information stored (cid, item, frompos, ...) in the parameters. Then you define a script for the hypothetical information that is to come!
For example, if you make an item that teleports you but you can only use it in a specific position, you are gonna be using fromPosition to check if you are at the correct position when using the item.
(This is not exactly the case, it is much more technical BUT let's keep it like this)

I've gotten so far, i've made 4 levers, and made a script and registered it in actions.xml aswell as putting that action ID on all the levers.
In game it works perfectly to pull each one of the levers and it will increment my value for each push, and decrement for every pull.
The problem is that when the variable hits 4, it should spawn a Ladder.. With what command would I use? Another Script?

No, when the variable hits four the same script will add the ladder. But remember that after adding the ladder what happens to the levers?? Do they become unmoveable? After the ladder is created when pulling a lever does it remove the ladder? This has to be handled in the lever script aswell.

Also i've tried to make a global variable in a separate script in the same folder, doesn't seem to be working that way. Can you tell me how to make a global variable accesible from any Action script i'd make (otherwise I cant finish the script)?

  • Game.getStorageValue and Game.setStorageValue; when to use them and where? For what?

Global storages are what you need to make a global variable.
I'm sure (or I hope that) you know what storages are, they are just keys with specific values stored. In TFS 1.1 I think they are not handled by the database anymore, but it doesn't matter, you must think them as global variables, that is variables that are there for any script that wants to access them.
with Game.getStorageValue you get the current state of that global variable (that is your counter!!) and with Game.setStorageValue you set the value of that storage to whatever you want (increment or decrement the value). You NEED global variables because you MUST reset the counter when using the ladder script (the second script, ladder use).
This is how they look like:
Code:
Game.getStorageValue(storage)
Game.setStorageValue(storage, value)
So let's say I want to increment the value of this storage: (remember empty storages are set to -1)
Code:
-- Set a variable to my storage
local storage = 1231
-- First I check if my storage is empty, if it is (first use) then set it to zero (because I want the counter to start at zero)
if(Game.getStorageValue(storage) < 0) then Game.setStorageValue(storage, 0) end
-- Now I'm sure the storage starts at zero
-- If the player pushes then I increment:
Game.setStorageValue(storage, Game.getStorageValue(storage)+1)
-- If the player pulls then I decrement:
Game.setStorageValue(storage, Game.getStorageValue(storage)-1)
-- What's the state of my current counter??
print(Game.getStorageValue(storage))
Now this is the same as a local variable BUT the main difference is that you can actually access this stored value from another script, as long as you know the storage key (and you do because you set it up!!)
So at your second script you are gonna be updating the counter back to zero:
Code:
-- Since I know the storage key then I can access it from any script
local storage = 1231
-- Set the storage to zero
Game.setStorageValue(storage, 0)

Just think of global storages as a global variable, except this has a storage key and for that specific key it has a value in it. This value stored in that specific key is gonna be your counter and it is accessible from any script.

This is what i've come up with so far (since I don't know how to make a global variable accesible from another script in the same folder then i've tried to make a local variable).
Code:
local testcount = 0

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if item.itemid == 1945 then
        testcount = testcount + 1
        doCreatureSay(cid, testcount, TALKTYPE_ORANGE_1)
        doTransformItem(item.uid, item.itemid + 1)
    elseif item.itemid == 1946 then
        testcount = testcount - 1
        doCreatureSay(cid, testcount, TALKTYPE_ORANGE_1)
        doTransformItem(item.uid, item.itemid - 1)
    end
    return TRUE
end

if testcount == 4 then
    doTileAddItem({x = 279, y = 579, z = 4}, 1386)
end

That's pretty good tbh! It is exactly what you have to do.
Instead of testcount you are gonna be using global storages, so that you can later in the ladder script set the storage back to 0.
Doing testcount = testcount+1 is equivalent to Game.setStorageValue(storage, Game.getStorageValue(storage)+1)
The last is NEVER executed because it is outside the onUse scope!! The function will execute and will leave at the end of it's scope, that is the end after the return TRUE. That should be inside the onUse function (actually everything that will happen must be inside the function, except for variable/tables/etc.)

And by the way, how do I make it so that when the lever is pulled, the number/letters will show up over the lever and not on myself (cid)?

You are gonna have to use toPosition (the position of the lever). I'm not sure if doCreatureSay would work in this case, I don't think so..
Not sure what would.
 
To keep it short, let's say they are not unchangeable (meaning the names can change but the position of each parameter means something).
Let's clear this out, a function recieves information from the outside, this information is given by the parameters, this is handled by TFS, you don't need to pay attention to this, what you have is the info that's neccessary to make your scripts.
The onUse function applies to WHATEVER thing you want to, toPosition is the position of the thing you use, it may not be neccessary for pulling a lever (or maybe if you want to add an effect on the lever position then it is!!).
Take the parameters as information given to you:
item -> This is the item given to you
item.itemid is the itemid ; item.actionid is the actionid ; item.uid is the uniqueid

fromPosition -> This is the position of the player!!
fromPosition.x is the x coord ; fromPosition.y is the y coord ; fromPosition.z is the z coord
If you were to "see" fromPosition it would look like: fromPosition = {x = getplayerpos.x, y = getplayerpos.y, z = getplayerpos.z}

itemEx -> Exactly what you said, this is the use with.. e.g using a potion onto someone/something
itemEx.itemid is the itemid ; itemEx.actionid is the actionid ; itemEx.uid is the uniqueid

toPosition -> Same as fromPosition but now the position is the position of the thing you used

Just rememer, everytime you use something that is registered in your actions.xml, it will come to the specific script and RUN the onUse function you defined, when it runs it, it will give YOU the information stored (cid, item, frompos, ...) in the parameters. Then you define a script for the hypothetical information that is to come!
For example, if you make an item that teleports you but you can only use it in a specific position, you are gonna be using fromPosition to check if you are at the correct position when using the item.
(This is not exactly the case, it is much more technical BUT let's keep it like this)



No, when the variable hits four the same script will add the ladder. But remember that after adding the ladder what happens to the levers?? Do they become unmoveable? After the ladder is created when pulling a lever does it remove the ladder? This has to be handled in the lever script aswell.



Global storages are what you need to make a global variable.
I'm sure (or I hope that) you know what storages are, they are just keys with specific values stored. In TFS 1.1 I think they are not handled by the database anymore, but it doesn't matter, you must think them as global variables, that is variables that are there for any script that wants to access them.
with Game.getStorageValue you get the current state of that global variable (that is your counter!!) and with Game.setStorageValue you set the value of that storage to whatever you want (increment or decrement the value). You NEED global variables because you MUST reset the counter when using the ladder script (the second script, ladder use).
This is how they look like:
Code:
Game.getStorageValue(storage)
Game.setStorageValue(storage, value)
So let's say I want to increment the value of this storage: (remember empty storages are set to -1)
Code:
-- Set a variable to my storage
local storage = 1231
-- First I check if my storage is empty, if it is (first use) then set it to zero (because I want the counter to start at zero)
if(Game.getStorageValue(storage) < 0) then Game.setStorageValue(storage, 0) end
-- Now I'm sure the storage starts at zero
-- If the player pushes then I increment:
Game.setStorageValue(storage, Game.getStorageValue(storage)+1)
-- If the player pulls then I decrement:
Game.setStorageValue(storage, Game.getStorageValue(storage)-1)
-- What's the state of my current counter??
print(Game.getStorageValue(storage))
Now this is the same as a local variable BUT the main difference is that you can actually access this stored value from another script, as long as you know the storage key (and you do because you set it up!!)
So at your second script you are gonna be updating the counter back to zero:
Code:
-- Since I know the storage key then I can access it from any script
local storage = 1231
-- Set the storage to zero
Game.setStorageValue(storage, 0)

Just think of global storages as a global variable, except this has a storage key and for that specific key it has a value in it. This value stored in that specific key is gonna be your counter and it is accessible from any script.



That's pretty good tbh! It is exactly what you have to do.
Instead of testcount you are gonna be using global storages, so that you can later in the ladder script set the storage back to 0.
Doing testcount = testcount+1 is equivalent to Game.setStorageValue(storage, Game.getStorageValue(storage)+1)
The last is NEVER executed because it is outside the onUse scope!! The function will execute and will leave at the end of it's scope, that is the end after the return TRUE. That should be inside the onUse function (actually everything that will happen must be inside the function, except for variable/tables/etc.)



You are gonna have to use toPosition (the position of the lever). I'm not sure if doCreatureSay would work in this case, I don't think so..
Not sure what would.

You are seriously the most sincere person i've ever spoken with through a forum. Thank you very much and i've got it to work perfectly right now all thanks to you aswell as some trial and error!

Here is the final outcome:

Code:
local storage = 10000
local talktype = TALKTYPE_ORANGE_1

function onUse(cid, item, fromPosition, itemEx, toPosition)
    if Game.getStorageValue(storage) == nil or Game.getStorageValue(storage) < 0 or Game.getStorageValue(storage) >= 5 then
        Game.setStorageValue(storage, 0)
    end
   
    if item.itemid == 1945 then
        Game.setStorageValue(storage, Game.getStorageValue(storage)+1)
        doTransformItem(item.uid, item.itemid + 1)
    elseif item.itemid == 1946 then
        Game.setStorageValue(storage, Game.getStorageValue(storage)-1)
        doTransformItem(item.uid, item.itemid - 1)
    end
   
    if Game.getStorageValue(storage) <= 0 then
        doCreatureSay(cid, "Something seems wrong.. Maybe you should start over.", talktype)
    elseif Game.getStorageValue(storage) == 1 then
        doCreatureSay(cid, "You pulled the first lever! 3 more to go.", talktype)
    elseif Game.getStorageValue(storage) == 2 then
        doCreatureSay(cid, "You pulled the second lever! 2 more to go.", talktype)
    elseif Game.getStorageValue(storage) == 3 then
        doCreatureSay(cid, "You pulled the third lever! 1 more to go.", talktype)
    elseif Game.getStorageValue(storage) == 4 then
        doCreatureSay(cid, "You hear a ladder falling down from upstairs...", talktype)
    end
   
    local ladder = Tile(Position(279, 759, 4)):getItemById(1386)
    if Game.getStorageValue(storage) == 4 then
        Game.createItem(1386, 1, Position(279, 759, 4))
    else
        ladder:remove()
    end
    return TRUE
end

Very sorry that I can not reply with as big of a wall as you did, even if I want to, because when things are solved it's hard to find things to say other than thank you.
 
No problem!! I thought this was a good opportunity to learn by yourself and you proved it exceptionally.
Just a handful of things:
At line 5 you are just looking at the possibility of storage < 0. It's never nil and it can never be >= 5 (Think about it)
Line 17 doesn't make much sense to me, if I push and then pull the same lever why would something be wrong? Maybe you meant < 0 (Which is an impossible situation!!)
At line 33 you may want to check if the ladder is actually there before trying to remove it, this may cause some errors when you press the lever because it will try to remove something that isn't there (Maybe it is already handled in TFS 1.1, so if it gives no errors then ignore this)

Other than that, perfect.
 
At line 5 you are just looking at the possibility of storage < 0. It's never nil

That's not true for global storages in TFS 1.x

Player storages are never nil, they're -1 by default.
Global storages are nil by default, and when unregistering them they should be set back to nil.

Other than that, this thread is exemplary of the direction that this community should be heading.
Red
 
That's not true for global storages in TFS 1.x

Player storages are never nil, they're -1 by default.
Global storages are nil by default, and when unregistering them they should be set back to nil.

Other than that, this thread is exemplary of the direction that this community should be heading.
Red

Oh well good to know!
 
No problem!! I thought this was a good opportunity to learn by yourself and you proved it exceptionally.
Just a handful of things:
At line 5 you are just looking at the possibility of storage < 0. It's never nil and it can never be >= 5 (Think about it)
Line 17 doesn't make much sense to me, if I push and then pull the same lever why would something be wrong? Maybe you meant < 0 (Which is an impossible situation!!)
At line 33 you may want to check if the ladder is actually there before trying to remove it, this may cause some errors when you press the lever because it will try to remove something that isn't there (Maybe it is already handled in TFS 1.1, so if it gives no errors then ignore this)

Other than that, perfect.

Thank you very much, and yes indeed as Red said, things were nil and that's why I put it there and even if things are impossible i'm the one who likes to have an "anti-fail" system in to my scripts as much as possible IF something should go wrong even if it can't, might be an overdo but hey, that's me.

Did anyone ever make the moveevent script?

I'm having serious troubles using onStepIn function, I can not seem to get anything to work with it. I'm using TFS 1.1.
Perhaps @Limos or @Red can give me just anything basic with this function and i'll work on from there, with trial and error.
 
In movement.cpp you can see which parameters are used.
https://github.com/otland/forgottenserver/blob/1.1/src/movement.cpp#L831
So it will look like this.
Code:
function onStepIn(creature, item, pos, fromPosition)
The creature is the userdata of the creature that steps on the item, item is the item the creature steps on, pos is the position it steps on and fromPosition is the last position before stepping on the item.
Since the creature that steps on the item can also be a monster or an NPC, it's good to check if it's a player so it only works for players.
Code:
if not creature:isPlayer() then
     return true
end
What you can do next is check if the ladder is there, then use addEvent (assuming you want the ladder to be removed after some time) and call an own Lua made function.
Code:
if Tile(Position(94, 114, 7)):getItemById(1386) then
Code:
addEvent(doRemoveLadder, 5 * 1000)
In the local function doRemoveLadder you check again if the ladder is still there (incase people step on it multiple times) and then transform the levers and remove the ladder.
You can create a table for the 4 positions of the levers, then get the item userdata and transform it.
Code:
local positions = {
     Position(94, 116, 7),
     Position(96, 120, 7),
     Position(98, 125, 7),
     Position(101, 130, 7)
}
Since you have to execute the same functions 4x, only with different positions, best is to do this with a loop.
Code:
for x = 1, #positions do
     local lever = Tile(positions[x]):getItemById(1946)
     if lever then
         lever:transform(1945)
     end
end
For the ladder you can also create a variable like with the levers, since you are going to use it twice, 1x to check if it's there and 1x to remove it.
 
@Limos

I've tested exactly what you said and I can not possibly notice any error in the script. It gives me no errors and doesn't do anything at all when i'm stepping on the tiles, yes i've registered the Action ID and i've also put them in my Map Editor (RME), it just doesn't do anything. I can't get the function onStepIn to work at all on TFS 1.1.

Here is what I made;

actions.xml

Code:
    <action actionid="15003" script="quests/tombs of shadow/removeladder.lua"/>

removeladder.lua

Code:
function onStepIn(creature, item, pos, fromPosition)
  
    if not creature:isPlayer() then
        return true
    end
  
    local ladder = Tile(Position(279, 759, 4)):getItemById(1386)
    if ladder then
        ladder:remove()
    end
  
    local positions = {
     Position(272, 749, 6),
     Position(286, 749, 6),
     Position(286, 749, 6),
     Position(272, 749, 6)
}
  
    for x = 1, #positions do
        local lever = Tile(positions[x]):getItemById(1946)
        if lever then
            lever:transform(1945)
        end
    end
    return true
end


EDIT: Yes, it does give me an error when I /reload actions

[Warning - Event::checkScript] Event onUse not found. scripts/quests/tombs of shadow/removeladder.lua
 
You must put this in your moveevents folder, and register it in moveevents.xml!!
The warning is specific, it didnt found the onUse (because it was an onStepIn!!), in the actions scope it should be onUse, you should be in the moveevents folder
 
You must put this in your moveevents folder, and register it in moveevents.xml!!
The warning is specific, it didnt found the onUse (because it was an onStepIn!!), in the actions scope it should be onUse, you should be in the moveevents folder

Christ, I feel like a total moron right now.
 
Christ, I feel like a total moron right now.

Hehe, it happens to the best of us!

Code:
local positions = {
    Position(272, 749, 6),
    Position(286, 749, 6),
    Position(286, 749, 6),
    Position(272, 749, 6)
}

I also recommend moving this snippet outside the onStepIn function (that way you don't it doesn't get declared every time the script runs.)
Red
 
Back
Top