*Edit* I remembered a question I forgot in the original post
Hi all,
I've been wanting to do this script for a while, but I guess my mind didn't properly grasp the idea until recently.
This is, in a nutshell, what I'm trying to accomplish, and the accompanying code.
The script is based on a sailing feature that this mud has, where a player sinks pirate ships, salvages gold-ingots, and sells them for in-game gold.
Original idea:
Quote: -Get # of ingots (@ingots)
-multiply # of ingots by respective ingot values (495 519 544 569 594 618) (@prices)
-include the corresponding ingot threshold values
-output corresponding values into the output of the screen (using the Note( ) command?)
This is the code I have so far:
price495 = tonumber(GetVariable("ingot")) * 495
price519 = tonumber(GetVariable("ingot")) * 519
price544 = tonumber(GetVariable("ingot")) * 544
price569 = tonumber(GetVariable("ingot")) * 569
price594 = tonumber(GetVariable("ingot")) * 594
price618 = tonumber(GetVariable("ingot")) * 618
Note("Ingots at 495" .. " " .. math.floor(price495))
Note("Ingots at 519" .. " " .. math.floor(price519))
Note("Ingots at 544" .. " " .. math.floor(price544))
Note("Ingots at 569" .. " " .. math.floor(price569))
Note("Ingots at 594" .. " " .. math.floor(price594))
Note("Ingots at 618" .. " " .. math.floor(price618))
The variables price495.....price618, and ingot have all been created, and as it currently stands this works perfectly. If, say, I had 100 ingots it displays to my output window:
Ingots at 495: 49500
Ingots at 519: 51900
Ingots at 544: 54400
Ingots at 569: 56900
Ingots at 594: 59400
Ingots at 618: 61800
I only need to expand/edit a few functionalities, which I need help doing.
1) I want to take the value that price495 = tonumber(GetVariable("ingot")) * 495 calculates and have that actually set to the correct variable (in this case, 495). I was trying to use the SetVariable command, which I've used just fine in another sailing script, but I was not sure how to post math functions inside that command. I also tried
local tmp = GetVariable("ingot")
tmp = tmp * 495
SetVariable("price495",tmp)
which works fine but the code becomes a bit convoluted at the end.
2) The # of ingots you can sell at each selling spot varies based on thresholds (which I have painstakingly gathered over my years spent sailing). For instance, at the port for the main towne of Rune, the trader will buy perhaps only 2000 ingots at 618 per, and then another 2000 at 594 per, another 2000 at 569 per, but then another 4000 at 544 per, etc. These values vary for each port, and increase as you go down (You could sell maybe 20,000 ingots at 318 gold per, for instance).
My issue becomes how do I post the various thresholds, for the various ports, in an easy to read fashion, and what code can I use to accomplish this? My scripting knowledge is limited, and the code I used above is from a script I made quite some time ago and as you can see the code I used is rather primitive, and I'm sure it could be cleaned up using lua math functions and a host of other things.
3) I would eventually like to make this into a plugin, but I've never made a plugin before. I know there is a plugin wizard but I'm somewhat confused as to what codebits I put where. Could someone guide me on this?
4) I also want to show the difference between prices. So, if I can sell 100 ingots at 594 per ingot for 59,400 gold, and 100 at 569 for 56,900 gold, have it show that price difference of 2,500 gold in a new line in the output.
I apologize for the length of my post, but it seemed prudent to list all the steps I've already tried as well as what exactly it is I'm trying to accomplish so you guys can best help me.
Thanks in advance,
Forral
*EDIT* Just want to note, I'm using an alias for all this code...that is, I have an alias named "price" and that is what all this code is going into. I have it sent to "script", and it outputs to my window.
*EDIT again!!* I got the functionality for the change between prices working...the code I added (for 495 to 519) is:
change = tonumber(GetVariable("price519")) - tonumber(GetVariable("price495"))
Note("Change 495 to 519:" .. " " .. change)
I'm sure this can be cleaned up and made alot prettier, but this works so far! |