[HELP] Specialized Item Replacement Script
Posted: Sun Oct 14, 2012 6:08 pm
Before I break down and ask someone to write a script for me, as I would undoubtedly learn fastest by examining a properly constructed piece of code, I am going to try and piece my intent together by asking specific questions to help me overcome my obstacles. If, in the end, I cannot get it to work, I'll try to explain the whole concept and see if someone is willing to help out. But first, stubborn and willful me is going to try to do it with what little help is required.
My first few questions are probably quick and easy to answer, and have to do with the thread's topic (obviously)
1: How does one look up an instance of an item inside a list?
Example: if I want to list all melee weapons and see if a character is holding one of the items in that list in either hand, how do I go about it? My script returns no errors, but does nothing at the same time.
2: Is LUA like Java, in that I can use a variable and increment the position inside that list for the returned item?
Example: Say my list has "longsword_rusted", "longsword_pitted", "longsword_sharpened" in it (in the 5th - 7th spots). Can I use the above code (Q1) to find the "longsword_rusted" in my hand and through an action return its item placement in the list, +n, resulting in replacing it with the sharpened version?
Last year I could have done it in Java, but it's been so long that I don't really remember everything and I'm not using the same language.
3: This is the important part, because it's one of the last things I figured out before and I'm stuck on it again. . . How do you tie it all together?
All the wonderful scripting references and libraries and stuff only show me each separate piece of code, and no mention of how they tie together. I've learned enough to pretty much edit most existing scripts, but adding to them is where I get stuck. This time I'll give an example of the short item swap process.
Example: Champion 1 is a Swords specialist with 22 in his swords skill. He finds a rusty longsword and a whetstone. By equipping the rusty longsword and right-clicking the whetstone the game takes a floor() of his swords skill * 0.2 and finds that he has a modifier of 2. It then finds the list location of the rusty longsword and removes/destroys it (not sure which is more proper), then equips the champion with the item 2 slots higher in the list. "longsword_rusty", "longsword_pitted", "longsword_sharpened" (or somesuch naming convention). Equip weapon, trigger effect, get better weapon based on relative skill.
The example is inspired by my original concept (and I may expand upon it later since I like it), but it'll still take some considerable editing on my part to turn an explanation of this into my intended result.
My first few questions are probably quick and easy to answer, and have to do with the thread's topic (obviously)
1: How does one look up an instance of an item inside a list?
Example: if I want to list all melee weapons and see if a character is holding one of the items in that list in either hand, how do I go about it? My script returns no errors, but does nothing at the same time.
2: Is LUA like Java, in that I can use a variable and increment the position inside that list for the returned item?
Example: Say my list has "longsword_rusted", "longsword_pitted", "longsword_sharpened" in it (in the 5th - 7th spots). Can I use the above code (Q1) to find the "longsword_rusted" in my hand and through an action return its item placement in the list, +n, resulting in replacing it with the sharpened version?
Last year I could have done it in Java, but it's been so long that I don't really remember everything and I'm not using the same language.
3: This is the important part, because it's one of the last things I figured out before and I'm stuck on it again. . . How do you tie it all together?
Example: Champion 1 is a Swords specialist with 22 in his swords skill. He finds a rusty longsword and a whetstone. By equipping the rusty longsword and right-clicking the whetstone the game takes a floor() of his swords skill * 0.2 and finds that he has a modifier of 2. It then finds the list location of the rusty longsword and removes/destroys it (not sure which is more proper), then equips the champion with the item 2 slots higher in the list. "longsword_rusty", "longsword_pitted", "longsword_sharpened" (or somesuch naming convention). Equip weapon, trigger effect, get better weapon based on relative skill.
The example is inspired by my original concept (and I may expand upon it later since I like it), but it'll still take some considerable editing on my part to turn an explanation of this into my intended result.