Jump to content

[SCRIPTING] Random Amount of Gold


Recommended Posts

Okay, so I want the player to purchase something, but for the system to choose a random amount of gold, and the player to get that gold removed.I'd like to have a limit on the gold from anywhere between 500 and 1000 gold.

 

I spotted this:

 

http://www.creationkit.com/index.php?title=RandomFloat_-_Utility

 

But I don't know if that is what I need. I have this simple bit of script at the moment:

;Script example, not entire script! Everything is working.  

MiscObject Property Gold001 Auto      

If (Game.GetPlayer().GetItemCount(Gold001) >= 500)
             ;Purchase things
Elseif (Game.GetPlayer().GetItemCount(Gold001) < 500)
             ;Message to show you don't have enough gold.

How can I do this everyone? What would be even better is the activating the activator and pressing purchase, then after that it would store that randomly generated value for later. I'd also love it to say you need X random gold (from the random values generated) if you don't have enough, but I'm not sure how to do that either.

 

Thanks everyone.

Edited by Guest
Link to comment
Share on other sites

You wouldn't be able to do this with the built in store/merchant feature as those prices are calculated based on set values. However, if for instance you were to set up a store with visual items that the player can click on. Then the script attached to the object/activator could do all the calculations and purchase handling.

 

Easiest would be to set it up so that the first time activated/clicked-on the price is generated and displayed then remains fixed until purchased. Once purchased the price could be flushed so that a new activation/click would create a new generated price.

 

Something like (in incomplete/psuedo code)

Weapon Property MyItem Auto ; point to the item being sold - change property type as needed
MiscObject Property Au Auto ; gold item
Value = 0 ;default value of item
Actor PlayerRef 
Bool Purchased = false

Event OnInit()
  PlayerRef = Game.GetPlayer()
EndEvent

Event OnActivate(blah blah blah)
  If Value == 0
    Value = Utility.RandomInt(500,1000)
  EndIf
  If PlayerRef.GetItemCount(Au) >= Value
    If ;player decides to buy
      PlayerRef.AddItem(MyItem,1)
      PlayerRef.RemoveItem(Au,Value)
      Purchased = true
    Else ;player did not buy
    EndIf
    If Purchased == true
      Value = 0
      Purchased == false
    EndIf
  Else
    ;not allow purchase
  EndIf
EndEvent

The bool is there if you are going to be presenting the user with the ability to opt out of purchasing, otherwise you probably don't need it.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...