 |
Castle Paradox
|
View previous topic :: View next topic |
Author |
Message |
The Drizzle Who is the Drizzle?

Joined: 12 Nov 2003 Posts: 432
|
Posted: Mon Jan 19, 2009 9:04 am Post subject: Making a bank |
|
|
I want to make a bank for my game in which users can store their money and items (because they lose it all if they die). Each character would have their own "account" which would be accessible if that character were the leader of the group. Players should be able to deposit and withdraw specific amounts. There would be separate bankers for both money and items. Can anyone give me an idea of how to implement this, generally? If you have really specific details, that'd be welcome too, I just want to know if anyone has ideas for how to make this user-friendly. _________________ My name is...
The shake-zula, the mic rulah, the old schoola, you wanna trip? I'll bring it to yah... |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Mon Jan 19, 2009 10:12 am Post subject: |
|
|
Seems like making it one joint bank account would make it easier to script and simultaneously more user-friendly.
Anyway, no matter what your method, the tricky part is going to be the item transfer. There's no good interface for allowing the user to select an item from the menu without causing it to be used. It'd be nice if there were an analog for "items menu" that returned the selected item instead of using it.
What you'll have to do instead (unless James catches wind of this and grants mercy on you) is create a custom menu populated with a list of the player's inventory (or the bank's). The menu commands are not in the wiki, for no good reason, but the relevant commands are here, specifically:
- create menu - returns a menu handle
- add menu item - returns a menu item handle
- set menu item caption - lets you change a menu item's text
- get item name - to be used in conjunction with that last one
If this sounds like a lot of trouble, that's because it is. I'd bug James to create an items menu command like the one I mentioned above, though there are still problems with that interface, mostly the question of how you'll show the bank's inventory. (Hint: You'd do it by dumping the entire hero inventory into variables and swapping in the bank inventory.) If you're familiar with custom menus, then it's debatable which method is easier, but this way preserves the current item interface, which is better for the user.
Any way you decide to go about this will not be an easy scripting experience. _________________
|
|
Back to top |
|
 |
The Drizzle Who is the Drizzle?

Joined: 12 Nov 2003 Posts: 432
|
Posted: Mon Jan 19, 2009 11:03 am Post subject: |
|
|
Hmmm... I could probably swing it so their don't have to be individual accounts, even though it presents kind of a problem, plot-wise. And the more I think about it, I suppose the item bank isn't impossibly difficult to implement with menus, but it does seem extremely time consuming, so I'm questioning the importance of it. I'll probably just throw the idea away. Any tips for how to implement just the money bank? _________________ My name is...
The shake-zula, the mic rulah, the old schoola, you wanna trip? I'll bring it to yah... |
|
Back to top |
|
 |
Moogle1 Scourge of the Seas Halloween 2006 Creativity Winner


Joined: 15 Jul 2004 Posts: 3377 Location: Seattle, WA
|
Posted: Mon Jan 19, 2009 11:27 am Post subject: |
|
|
That's a lot easier.
You want to use input string to ask the player how much money to deposit/withdraw. Use this function:
Code: | # number from string:: Convert a string to a number by stripping all non-numeric components
# @param string: Which string to use
# @return Numeric value
script, number from string, string = 0, begin
variable(val, i, char)
for(i, 1, string length(string)) do (
char := ascii from string(string, i)
if (char >= 48 && char <= 57) then (
val := val * 10
val += char -- 48
)
)
return(val)
end |
And you get a number. (James is making this a built-in function in the next release. This script doesn't support negative numbers, but that's fine for your purposes.)
Check if the player/bank has enough money and transfer it to/from a global variable. _________________
|
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Mon Jan 19, 2009 9:04 pm Post subject: |
|
|
Sorry I missed this earlier (I get php errors a lot lately when trying to get on Castle Paradox). Moogle is right - an item bank will not be particularly fun. But first of all, how are you arranging for each character to have their own item account right now? That alone seems impossible without a ton of scripting to begin with. All in all, if you've already managed that, I don't think the band will be much of a problem, and I can probably help you with it. Plus, I'll be real jealous if you've actually come up with a way to give each hero their own item menu that still makes use of the standard item menu.
If you ditch the individual accounts, the item bank is not much of a problem at all. The only tiring part will be declaring x global variables (where x is the number of items you have); beyond that it's all storing with super-for-loops, which might be tiring for the computer, but will only be a handful of code relatively speaking (not more than 50-100 lines, I should say before diving in). You'll probably also want to know about 'menu extra data', accessible with:
get menu item extra(menu item handle, extra)
set menu item extra(menu item handle, extra)
where you'll be able to store either the item ID or the ID of the global variable involved (not sure yet which will make the coding easier; possibly you'll want to do both).
If you do decide you want to do this, I'm pretty sure I can help. You can also look at the item script file in the zip of Tales 2 to get an idea script-wise of what all goes into 'populating' an item menu:
http://www.slimesalad.com/forum/viewgame.php?t=196 _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
The Drizzle Who is the Drizzle?

Joined: 12 Nov 2003 Posts: 432
|
Posted: Mon Jan 19, 2009 10:58 pm Post subject: |
|
|
Thanks for the tip msw. I'll check out your tales script and see if I can understand it. I'm not very well-versed in scripting and it'd be nice to check out some examples. Do you put in a lot of notes? _________________ My name is...
The shake-zula, the mic rulah, the old schoola, you wanna trip? I'll bring it to yah... |
|
Back to top |
|
 |
NeoSpade Of course!

Joined: 23 Sep 2008 Posts: 249 Location: Wales GB
|
|
Back to top |
|
 |
msw188
Joined: 02 Jul 2003 Posts: 1041
|
Posted: Tue Jan 20, 2009 10:33 am Post subject: |
|
|
Actually, I just looked at my item scripts, and they are not commented very well at all. I went through and found the most relevant snippet:
Code: | for(n,0,7),do
begin
itm:=readglobal(who*8+81+n)
if(itm<>0),then
begin
getitemname(1,absvalue(itm))
eqpslot:=equipwhere(findhero(eqpHero),absvalue(itm))
if(eqpslot<>false),then
begin
if( checkequipment(findhero(eqpHero),eqpslot)==absvalue(itm) ),then
begin
$3:=" - Eq"
concatenate strings (1,3)
end
end
set menuitem caption( menuitem by slot(topmenu,n+1), 1)
set menuitem extra( menuitem by slot(topmenu,n+1), 2, who*8+81+n)
end
else ###there was no item in the nth slot
begin
while(nextmenuitem( menuitem by slot(topmenu,n+1) ) ),do
begin
deletemenuitem( menuitem by slot(topmenu,n+1) )
end
deletemenuitem( menuitem by slot(topmenu,n+1) )
n:=7
end
end |
The letter "n" and the codes "itm" and "who" are local variables. n goes from 0 to 7 because each hero can only hold eight items (this was to allow item use in battle to take advantage of the eight rows that are designated levelMP properties). The read global line with (who*8+81+n) is just showing where in the globals to start looking - hero 0's first (zeroth) item is stored in global 81.
Note that I do not create a menu anywhere. I have already made the menu in custom, and it was opened earlier in the script. The menu in custom is already a dummy menu with nine slots - the first one is for the caption "Hero's Items" and the other eight are waiting for their captions to be defined from this plotscript. So I never need to create menu items either; instead, I have to delete them if the hero has less than eight items. That is what the second half of the script is doing.
Maybe this isn't as great an example as I had hoped. If you aren't worrying about individualized item ownership, your script is likely going to be backwards from mine. You won't need globals to keep track of what the hero's have at all. Something like:
[pseudocode]
Code: |
variable(M, n, MI)
M:=createmenu
$1:="Items"
set menuitem caption(menuitem by slot(M,0), 1)
for(n, 0, last item ID),do
begin
if(inventory(n)<>0),then
begin
MI:=add menuitem
set menuitem caption(MI, get item name(n))
set menuitem extra(MI, 0, n) #store the item ID of this item in this menuitem
set menuitem extra(MI, 1, inventory(n)) #store the amount of this item in this menuitem
#set up the menuitem to call a script that makes the exchange
end
end
|
[/pseudocode]
I called it pseudocode because it is totally off the top of my head, and I have to go to work soon so I can't work out the "set up the menuitem to call a script that makes the exchange" part at the moment. But this is already a decent start, and we're at what, 15 lines of code or so? All we need now is to clean this up, call it properly (both easy) and work out the exchange (a little harder, but not by much I hope).
Let me know if you want to continue down this path, or if you want to be extra brave and put together the individualized hero item lists, or if you'd rather just scrap the idea altogether. _________________ My first completed OHR game, Tales of the New World:
http://castleparadox.com/gamelist-display.php?game=161
This website link is for my funk/rock band, Euphonic Brew:
www.euphonicbrew.com |
|
Back to top |
|
 |
The Drizzle Who is the Drizzle?

Joined: 12 Nov 2003 Posts: 432
|
Posted: Thu Jan 22, 2009 2:40 pm Post subject: |
|
|
I'll let you know soon enough msw, but I can't work right now since my computer at home is, well, broken. I should have it fixed by this weekend. _________________ My name is...
The shake-zula, the mic rulah, the old schoola, you wanna trip? I'll bring it to yah... |
|
Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|