Gold Checking Question!

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.
Post Reply
Damien
Adept Poster
Posts: 82
Joined: Sat Apr 15, 2006 11:50 am

Gold Checking Question!

Post by Damien »

Hello!

I got a question and its hard to explain so i made this:

http://img215.imageshack.us/my.php?image=awdasdw4fo.png

Ok, i want to do so when you click the button, the scripts checks if you have 10k in your Backpack.

If you do have the 10k, you will receive a spellbook in your backpack,
if you dont have it will give you a message saying something like:
You dont have enough money... :/

I've checked some scripts like Bounty etc to see how this Gold Checking thing works but i cant understand it :(

Someone please help me :(

Here is the gumps script btw:

Code: Select all

use uo; 
use os; 

include "include/attributes"; 

program goldquestion( who ) 

var gflayout := { 
      "nodispose", 
      "nomove",    
      "page 0",    
      "resizepic 55 55 9250 290 200", 
      "TilePic 140 170 3834",
      "text 107 65 0 0", 
      "page 1",        
      "text 65 145 0 1", 
      "button 190 170 210 211 1 0 1"
      }; 
var gfdata := { 
      "Want to buy a spellbook?",    
      "Click here to buy a spellbook for 10k!"    
      }; 

var choice := SendDialogGump( who, gflayout, gfdata ); 
if(choice[0] == 1) 

CreateItemInBackpack(who, 0x3834, 1);

endif

endprogram 
I Thank for every reply :)
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

Code: Select all

var gold_obj := GetObjTypeByName("GoldCoin");
if ( !ConsumeSubstance(mobile.backpack, gold_obj, 10000) )
   SendSysMessage(mobile, "You do not have enough gold.");
   return 0;
endif
ConsumeSubstance() will only work if there is enough in the container (and its sub containers), or it wont do anything at all.
Damien
Adept Poster
Posts: 82
Joined: Sat Apr 15, 2006 11:50 am

Post by Damien »

Thanks alot i highly appreciate it :)
Harley
Forum Regular
Posts: 360
Joined: Sat Mar 18, 2006 1:41 am

Post by Harley »

Okay, thank u Austin, but, I have one problem. I don't know how to destroy gold coin at bank.
Example: mobile.backpack - destroy at backpack. But, at properties of Pol documentation doesn't wrote "bank". My question, how can gold coin's(or something items), destroing at bankbox?

Thanks!
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

Bankbox is a container as well - you would just retrieve it however you do and use consume substance on that.

Pseudo Code: (do not use literally)

Code: Select all

var storage_area := FindStorageArea("GlobalBanks");
var bank_box := FindRootItemInStorageArea(storage_area, "Bankbox of "+mobile.serial);

if ( !ConsumeSubstance(bankbox, goldcoin, 10000) )
    return 0;
endif

Harley
Forum Regular
Posts: 360
Joined: Sat Mar 18, 2006 1:41 am

Post by Harley »

Dear Austin, look please here. I have one idea about this function of destroy gold at bank. Pol Server have one function at POL Object Class Reference/Character/spendgold. This function destroy gold at character backpack. My idea Ñ
Gnafu
Grandmaster Poster
Posts: 136
Joined: Thu Feb 02, 2006 7:29 am

Post by Gnafu »

Do you want to create a bankomat? or a credit card system? :P
Harley
Forum Regular
Posts: 360
Joined: Sat Mar 18, 2006 1:41 am

Post by Harley »

Em, at realy I have wrote this idea with no idea for my self and etc.
I would like that have added similarity of a command spendgold. We shall admit to make it as function which would be responsible character and bank.

Example:

Spendgold(who, backpack, 1500) or
Spendgold(who, bank, 1500) // 1500 - this is money(gold or etc coins).

and all. :) Thanks for attention.
User avatar
Austin
Former Developer
Posts: 621
Joined: Wed Jan 25, 2006 2:30 am

Post by Austin »

You could just as easily script that AND make it more dyanamic too...

I havn't tested this, just writing as I make this post.

Code: Select all

function ConsumeSubstanceEX(container_array, objtype, amount)
    var amt_found := 0;
    var matches := array;
    
    foreach container in ( container_array )
         foreach item in ( EnumerateItemsInContainer(container) )
              if ( item.objtype == objtype )
                   amt_found := amt_found+item.amount;
                   matches.Append(item);
              endif
         endforeach
     endforeach

     if ( amt_found < amount )
          return error{"errortext":="Not enough containers."};
     endif
     
     foreach item in ( matches )
         var i_amount := item.amount;
         ConsumeSubstance(item, amount);
         amount := amount - i_amount;
         if ( amount <= 0 )
                 return 1;
         endif
     endforeach
endfunction
Post Reply