Page 1 of 1
A bank check script
Posted: Tue Jul 08, 2008 10:24 pm
by Poi
I am working on a bank heck script and need some help...
So far, I have a script that takes the amount the user told it, checks their bank to make sure they have that much gold and checks to see if they even put in an amount...
Anyways, now I need a subscript/function that removes that amount of gold from their bank, and a subscript that adds that amount to their bank
If anyone wants to explain to me how I could do this, or even write something up(as I plan to put this in custom scripts) that would be great
Edit:
Also, would this work to find out if the check is in their bank?
Code: Select all
var bankbox := FindBankBox( who );
if ( bankbox != deed.Container )
SendSysMessage(mobile, "The deed must be in your bank.");
return 0;
endif
Posted: Sat Jul 12, 2008 7:48 pm
by Poi
Still need help on this, btw
I don't thin doing createstack would work because you can only make a stack up to 60k right?
Posted: Sun Jul 13, 2008 12:33 pm
by Luth
For checks worth more than 60k, you'll need to create multiple stacks when cashing them. Something like (psuedo code):
while(worth > 0)
CreateStack(gold, Min(60000, worth))
worth -= Min(60000, worth);
endwhile
Posted: Sun Jul 13, 2008 1:28 pm
by Poi
Luth wrote:For checks worth more than 60k, you'll need to create multiple stacks when cashing them. Something like (psuedo code):
while(worth > 0)
CreateStack(gold, Min(60000, worth))
worth -= Min(60000, worth);
endwhile
Shouldn't it be Max not Min?
I don't think I understand what a lot of that is...
for example should it be more like
Code: Select all
var amount;
var stack;
while(worth > 0)
if (worth >= 60000)
amount = 60000;
endif
if (worth < 60000)
amount = worth;
endif
stack = CreateStack(goldcoin, amount);
worth = worth - amount
if (worth <= 0)
destroyitem(Check);
endif
endwhile
man, I can't believe I just coded that.. that like cam out of nowhere and looks like it might work... does anyone see any issues with this?
Posted: Sun Jul 13, 2008 1:51 pm
by Poi
I got it working(ish)
Still need to do this:
1. Make the gold in your bank disappear when making the check...(Need help with this)
2. and the check doesn't seem to want to use the Script assigned to it... so not sure if this actually creates the gold yet...
EDIT:::
Error in console:
Exception caught while loading script pkg/checksystem/bankcheck.elc: Undefined execution of token 61
Unable to read script 'pkg/checksystem/bankcheck.elc'
Here's the script:
Code: Select all
use os;
use uo;
include "util/bank";
program bankcheck(who, deed)
var worth := GetObjProperty(deed, "amt");
if (!worth)
SendSysMessage(who, "That check is blank, there isn't to much you can do with it");
return;
endif
if (worth <= 0)
SendSysMessage(who, "That check is blank, there isn't to much you can do with it");
return;
endif
var bankbox := FindBankBox( who );
if ( bankbox != deed.Container )
SendSysMessage(who, "The deed must be in your bank.");
return;
endif
var amount := 0;
while(worth > 0)
if (worth >= 60000)
amount := 60000;
endif
if (worth < 60000 && worth > 0)
amount := worth;
endif
stack := CreateItemInContainer( bankbox, 0xEED, amount );
if (stack)
deed.amt := worth - amount;
worth := deed.amt;
endif
if (worth <= 0)
destroyitem(deed);
endif
endwhile
endprogram
Posted: Sun Jul 13, 2008 8:31 pm
by CWO
are you sure you're using the same ecompile.exe that came with the pol.exe you're running? and you're using deed.amt? Deed.amt should always be 1 if the deed exists. If you want to keep track of the amount of gold on a deed, you'd have to have a custom prop on it with Get/SetObjProperty(deed, "amt", 60000); (replacing 60000 with your variable for how much gold when setting it)
Posted: Mon Jul 14, 2008 8:00 am
by Poi
Yes, I'm sure im using the same one...
Heres an updated er and this gives me the same console error(and when I say console, I mean the actual pol.exe not ecompile)
Code: Select all
use os;
use uo;
include "util/bank";
program bankcheck(who, deed)
var maxamt := 60000; //Don't touch this line!(unless lowering it below 60k, as 60k is the stackable limit.)
var namt := 0;
var worth := GetObjProperty(deed, "amt");
if (!worth)
SendSysMessage(who, "That check is blank, there isn't to much you can do with it");
return;
endif
if (worth <= 0)
SendSysMessage(who, "That check is blank, there isn't to much you can do with it");
return;
endif
var bankbox := FindBankBox( who );
if ( bankbox != deed.Container )
SendSysMessage(who, "The deed must be in your bank.");
return;
endif
var amount := 0;
while(worth > 0)
if (worth >= maxamt)
amount := maxamt;
endif
if (worth < maxamt && worth > 0)
amount := worth;
endif
stack := CreateItemInContainer( bankbox, 0xEED, amount );
if (stack)
namt := worth - amount;
SetObjProperty(deed, "amt", namt);
worth := GetObjProperty(deed, "amt");
endif
if (worth <= 0)
destroyitem(deed);
endif
endwhile
endprogram
Posted: Mon Jul 14, 2008 9:02 am
by Turley
Poi wrote:
Code: Select all
stack := CreateItemInContainer( bankbox, 0xEED, amount );
"stack" is a reserved operand. You have to use a different variablename.
Posted: Mon Jul 14, 2008 10:16 am
by Poi
Turley wrote:Poi wrote:
Code: Select all
stack := CreateItemInContainer( bankbox, 0xEED, amount );
"stack" is a reserved operand. You have to use a different variablename.
Thank you...
New issues now
First let me post my scripts:
Create check script(I haven't added it to the bank vendor yet, just a simple text command)
Code: Select all
use os;
use uo;
include "util/bank";
program textcmd_createcheck( who, text )
var bankbox := FindBankBox( who );
if (!text)
SendSysMessage(who, "You can't write a blank check, silly.");
return 0;
endif
var amt1 := 0;
foreach item in EnumerateItemsInContainer( bankbox )
if(item.objtype == 0xeed)
amt1 := (amt1 + item.amount);
endif
endforeach
if (text > amt1)
SendSysMessage(who, "Silly, you don't have that many gold coins!");
return 0;
endif
var check := CreateItemInBackpack( who, 0x5abd );
var madecheck := SetObjProperty(check, "amt", text);
if (madecheck)
SetName(check, "a bank check for " + text + " gold coins");
else
destroyitem(check);
SendSysMessage(who, "Your hand is shaking to much to right the check.");
endif
endprogram
I haven't gotten to do the destroy gold in bank part yet, but this is just for reference with my new problem, read on
This is the script that runs when the check is double clicked..
Well, now when I double click the check it tells me
"That check is blank, there isn't to much you can do with it"
Which tells me that the worth variable is either less then or equal to 0...
And the worth variable is the get prop for "amt"(the amount on the check)
And just to clear something up, when it tells me "That check is blank, there isn't to much you can do with it" that is the second if, meaning worth <= 0, rather then (!worth)
(read the script a bit, you will understand)
Code: Select all
use os;
use uo;
include "util/bank";
program bankcheck(who, deed)
var maxamt := 60000; //Don't touch this line!(unless lowering it below 60k, as 60k is the stackable limit.)
var namt := 0;
var worth := GetObjProperty(deed, "amt");
if (!worth)
SendSysMessage(who, "That check is blank, there isn't much you can do with it");
return;
endif
if (worth <= 0)
SendSysMessage(who, "That check is blank, there isn't to much you can do with it");
return;
endif
var bankbox := FindBankBox( who );
if ( bankbox != deed.Container )
SendSysMessage(who, "The deed must be in your bank.");
return;
endif
var amount := 0;
var stackg := 0;
while(worth > 0)
if (worth >= maxamt)
amount := maxamt;
endif
if (worth < maxamt && worth > 0)
amount := worth;
endif
stackg := CreateItemInContainer( bankbox, 0xEED, amount );
if (stackg)
namt := worth - amount;
SetObjProperty(deed, "amt", namt);
worth := GetObjProperty(deed, "amt");
endif
if (worth <= 0)
destroyitem(deed);
endif
endwhile
endprogram
Just want to say thanks to all of you, and your help

Posted: Mon Jul 14, 2008 12:43 pm
by Luth
In the interest of spreading my coding practices (I'm so selfish), here's a cleaner version of your cash-check script. The only changes were to remove redundant or unneeded lines; all functionality remains the same. Oh, and moving a couple variables inside the while loop (since the values aren't needed from one iteration to the next, and they're not used afterward either).
Code: Select all
use os;
use uo;
include "util/bank";
program bankcheck(who, deed)
var maxamt := 60000; //Don't touch this line!(unless lowering it below 60k, as 60k is the stackable limit.)
var worth := CInt(GetObjProperty(deed, "amt"));
if (worth <= 0) //this will also be true if worth is an error (ie: amt doesn't exist as a cprop)
SendSysMessage(who, "That check is blank, there isn't to much you can do with it");
return;
endif
var bankbox := FindBankBox( who );
if ( bankbox != deed.Container )
SendSysMessage(who, "The deed must be in your bank.");
return;
endif
while(worth > 0)
//Compare this line with your two IF statements and figure out why it does the same thing. :)
var amount := Min(maxamt, worth);
var stackg := CreateItemInContainer( bankbox, 0xEED, amount );
if (!stackg)
SendSysMessage(who, "Unable to finish this check cashing request.");
return;
endif
worth -= amount;
SetObjProperty(deed, "amt", worth); // Safety for if something happens and only part of the check is cashed
endwhile
// Success! worth must be == 0 if you got here
DestroyItem(deed);
endprogram
Posted: Mon Jul 14, 2008 1:57 pm
by Poi
I don't see Min(maxamt, worth); in the docs anywhere, and it doesn't make any since to me, its not a minimum amount(min) I'm trying to get its a maximum so I don't see what that does, before I accept your script mind explaining that part to me so I can understand it?
Posted: Tue Jul 15, 2008 1:10 am
by Turley
Min()/Max() is a 97 core function. Added 10-20
maxamt is 60000 the maximum stackamount you can create. So if worth is higher then 60000 Min() returns maxamt. In this case the function Min() returns the maximum amount you can create at once.
But Min/Max always returns double (you can call it a core bug) so the correct line would be:
Code: Select all
var amount := CInt(Min(maxamt,worth));
Posted: Tue Jul 15, 2008 6:05 pm
by Poi
I'm on 096
Posted: Tue Jul 15, 2008 6:14 pm
by ncrsn
Bugfree and 096-compatible Min and Max functions:
Code: Select all
function Min( byref value1, byref value2 )
if (value1 < value2)
return value1;
else
// If equal, does not matter which one we return.
return value2;
endif
endfunction
function Max( byref value1, byref value2 )
if (value1 > value2)
return value1;
else
// If equal, does not matter which one we return.
return value2;
endif
endfunction
Posted: Tue Jul 15, 2008 7:14 pm
by Poi
Well, uhm thanks.
But we seem to have gotten lost...
The min/mac functions are just fine, the problem is(or should be) explained at
http://forums.polserver.com/sutra11205.php#11205
Posted: Wed Jul 16, 2008 12:15 am
by MontuZ
Please do not just copy and paste. Go over it, see how it works and learn from it, like all of us are continuously doing =)
The Gumps package can be found in the 097 distro. I haven't found any bugs, so if you find any please do tell.
Bank check's;
Code: Select all
use uo;
include ":Gumps:Include/yesno";
program Check(mobile, check)
if ( !ReserveItem(check) )
SendSysMessage(mobile, "That item is already being used.");
return 0;
endif
if ( check.Container != mobile.Backpack )
SendSysMessage(mobile, "That item must be in your backpack.");
return 0;
endif
var check_amount := CInt(GetObjProperty(check, "CheckAmount"));
if ( !check_amount )
SendSysMessage(mobile, "This is a blank check.");
SetName(check, "Blank Check");
return 0;
else
if ( YesNo(mobile, "Are you sure you want to cash this "+(check_amount)+"gp check now?") )
var result := CreateGoldInContainer(mobile.Backpack, check_amount);
if ( result )
SendSysMessage(mobile, "Your backpack is too full!");
SendSysMessage(mobile, "Any remaining gold will be left on the check.");
SetObjProperty(check, "CheckAmount", result);
SetName(check, "Check for "+(result)+" Gold");
return 0;
elseif ( result == 0 )
SendSysMessage(mobile, "Your check has been cashed.");
SubtractAmount(check, 1);
return 1;
else
SendSysMessage(mobile, "Seriously...");
return 0;
endif
else
SendSysMessage(mobile, "Aborted.");
return 0;
endif
endif
return 0;
endprogram
function CreateGoldInContainer(container, amount)
if ( container )
var current_amount := amount;
var stacks := (amount / 60000);
var recieved;
for ( recieved := 1; recieved <= stacks; recieved += 1 )
if ( CreateItemInContainer(container, 0x0EED, 60000) )
current_amount -= 60000;
else
return (current_amount);
endif
SleepMS(2);
endfor
var left_over_amount := (amount - (stacks * 60000));
if ( !CreateItemInContainer(container, 0x0EED, left_over_amount) )
return (left_over_amount);
else
return 0;
endif
else
return (-1);
endif
endfunction
Withdraw function for bankers;
Code: Select all
function WithdrawGoldFromBank(bank_box, backpack, amount)
var current_amount := amount;
var stacks := (amount / 60000);
var recieved;
for (recieved := 1; recieved <= stacks; recieved := recieved + 1 )
if ( ConsumeSubstance(bank_box, 0x0EED, 60000) )
if ( CreateItemInContainer(backpack, 0x0EED, 60000) )
current_amount -= 60000;
else
return (current_amount);
endif
endif
SleepMS(2);
endfor
var left_over_amount := (amount - (stacks * 60000));
if ( ConsumeSubstance(bank_box, 0x0EED, left_over_amount) )
if ( !CreateItemInContainer(backpack, 0x0EED, left_over_amount) )
return (left_over_amount);
endif
endif
return 0; // Successfully withdrew the gold.
endfunction
Posted: Wed Jul 16, 2008 7:14 am
by Poi
Well, I looked over those and after the numerous errors fixed in ecompile, it doesn't work.
So, for future reference again(yes, I said this before) I'm on 96, not 97. Thanks.
If someone could simply show me how to write a PROPER property, with both GET and SET, that would be nice because I have a feeling that is where my problem lies.
MontuZ, thanks for trying to help but I would rather write a crappy script that is my own then use a good one that someone wrote for me
Any I probably sound rude right now, I'm not trying to be.
And again, 096.
Posted: Wed Jul 16, 2008 1:40 pm
by MontuZ