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

Lua TFS 1.1 - Actionid with target item not item

sircurse

Curseria RTG - TFS 1.1
Joined
Nov 12, 2007
Messages
107
Reaction score
2
Location
Brazil
Twitch
curseofcourse
Hi,

Is it possible to configure the actions.xml to recognize a target.actionid instead the item itself?

For instance:
<action actionid="50236" script="quests/XXXXXX.lua"/>

Usually the action 50236 must me set in a regular item, but if this item is in a rock and I have to use a pick, I will need use something like:
<action itemid="2553" script="tools/pick.lua"/>

And inside of the pick.lua I will use the conditions to find the actionid of the target item. But in my case I want each file .lua for the quest itself, and dont have it mixed with other .lua fliles.

On regular way I will have my quest.lua and pick.lua which contains a part of the quest, but I want to keep the quests more organized making it easy to manage.

So there is any way to do it?
 
It's been a long time since I scripted stuffs like this.. but I guess this could work:
Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
   if item.actionid == 50236 then
       if item.itemid == 2553 then
         <do shit>
       end
   end
   return true
end

As I said, I'm not sure, though.
 
It's good to hear you want to keep things organized, they usually get out of hand quickly when stretching the functionality.

As EvoSoft posted, there are parameters in the onUse function. One of them is item, another is itemEx. One of these is the item that is used and the other is, the target item.

Ignazio
 
I think I didnt express myself good enough, but to call an action on actions.xml, the actionid MUST be on the item you are using, right?
But if the actionid is on the target?

Ok I know that you can use target.item or itemEx, whatever... BUT to do it, in this example I will need to open the pick.lua and add the script in there, so I will have two piece of code in two different files, now image... if I have a huge quest with lots of actions like this, using pick, shovel, rope, etc, etc, etc... Now can you see how confuse will be that quest to manage?

If I do a upgrade on server and have to change some function that are commum in all these files? Would be a disaster....

I was thinking in actions.xml to be something like this:
<action target.actionid="50236" script="quests/XXXXXX.lua"/>

See how can it be very useful and easy to manage? I dont care if the item that will be used on my target on the actions.xml level... I just need to make a check in my main quest.lua file.

Curse.
 
Interesting thought. To begin with, you can assign all your tools to connect to a certain script, the problem then is if your pick for instance have multiple purposes, like opening a chest, opening a hole, four other quests, etc.

Code:
<action itemid="<pickid>" script="quest.lua"/>

Or you could make a collection script for all tools, and call other functions, scripts from that script.

Code:
<action itemid="<pickid>;<shovelid>;<ropeid>;<etc>" script="tools.lua"/>

And in `tools.lua` you can find what tools are valid for your quest, and what action id the target item has.

Althought you can't register multiple files for the same item, I think. Maybe you could use an action id for the tools, concerning this quest, the question is if the scripts would interfere with each other.
You could have all the logic in global files, or included files, and simply have these action scripts as controllers, finding the right function to execute, this build would be some what more complex though.

Are any of these ideas a probable solution?

Ignazio
 
Thank you Ignazio for the suggestion, I think I understand what you said but it will have different scripts yet, I think if there is a solution probably would be made in sources, something to capture the actionid from target.

I think it is possible since you can have in .lua file the target.actionid, but there is no way yet to register a target.actionid on actions.xml.


For instance, in movements I dont have this kind of problem, cuz I can use an event:
<movevent event="AddItem" tileitem="1" actionid="13101" script="quests/ancient_tombs_quest.lua"/> -- The Ancient Tombs
This event check if the item that I m adding to is a Scarab Coin.

Imagine how would be nice on actions events like that? A event called "UseTo", and on target I have my action ID, it will check if the item that I m using "UseTo" is an item ID that I have set (a pick for instance), if dont it will do the regular action that is set in tools.lua (open roles, etc etc etc..)


Curse.
 
Last edited:
What I would suggest if you want it to be organized, is to create your own global functions for each quest in individual files, make global.lua load them, call the functions in the onUse for a shovel/pick/whatever. That way everything is in its own file, organized, and the shovel/pick script isn't a total mess, and instead would only contain maybe a few if statements and then a function call for each. Best thing I can recommend without source edits.
 
Back
Top