mIRC Homepage

mIRC RPG vs. Random Number Generator *SOLVED*

Posted By: KubosKube

mIRC RPG vs. Random Number Generator *SOLVED* - 03/02/17 02:50 PM

Literally, the code just started working right. I don't know if I accidentally fixed it while fixing something else or what, but you can safely ignore this post, or go ahead and read it for ideas on your own chat bot. I will happily read any suggestions on how to streamline this to run smoother, though.

I'm trying to make an RPG game for my chat channel to help keep people entertained, but it seems to be having one small issue.

First, I'll share my code. If you want, you can read the summary under the script instead.

Quote:

;#### EXAMPLE MERCHANT ####
; /rpgGenerateStock ItemName PercentRarity MinStock MaxStock

;#### MERCHANT ####
alias rpgMerchant {
/rpgGenerateStock Bandage 90 40 50
/rpgGenerateStock Salve 90 40 50
/rpgGenerateStock SmellingSalts 50 10 20
/rpgGenerateStock HickoryWood 40 1 3
/rpgMerchantMsg
}

;#### This is just the output. It shows ( %rpgItemName.stock , $ ItemPrice ) ####
alias rpgMerchantMsg {
msg $chan /me Debug: Chances - Bandage %rpgBandage.chance , Salve %rpgSalve.chance , Smelling Salts %rpgSmellingSalts.chance , Hickory Wood %rpgHickoryWood.chance
msg $chan /me We've found a merchant! You can !buy : Bandage ( %rpgBandage.stock - $ 5 ), Salve ( %rpgSalve.stock - $ 5 ), Smelling Salts ( %rpgSmellingSalts.stock - $ 35 ), Hickory Wood ( %rpgHickoryWood.stock - $ 50 ), Strange Token ( ∞ - $ 20 )
}

;#### STOCK MANAGER ####
alias rpgGenerateStock {
set %rpg [ $+ [ $1 [ $+ [ .chance ] ] ] ] $rand(1,100)
if (%rpg [ $+ [ $1 [ $+ [ .chance ] ] ] ] <= $2) {
set %rpg [ $+ [ $1 [ $+ [ .stock ] ] ] ] $rand($3,$4)
}
else {
set %rpg [ $+ [ $1 [ $+ [ .stock ] ] ] ] 0
}
}


Now to explain.
1. Call "rpgMerchant". I have this on a timer.
2. rpgMerchant will call "rpgGenerateStock ItemName PercentRarity MinStock MaxStock"
3. rpgGenerateStock will generate some $rand numbers to determine the value of %rpgItemName.chance and, if value is low enough for the rarity of the item, will generate a value for %rpgItemName.stock too.
4. My bot will announce the Merchant's arrival and show his stock.

Now HERE is my dilemma.
The Hickory Wood is not working right. Everything else is.
My output looks like:
"Debug: Chances - ... Hickory Wood 50" (This is above the %40 chance, so %rpgHickoryWood.stock should be set to 0)
"We've found the Merchant! Blah blah........ Hickory Wood ( 3 - $ 50 )"

And also, it does this:
"Debug: Chances - ... Hickory Wood 26" (This is within the %40 limit)
"We've found... Hickory Wood ( 0 - $ 50 )"

So basically, my Hickory Wood is doing the exact opposite of what I told it to do. Any suggestions?

If anyone of you are hooked up to Twitch Messaging Interface, you can join #kuboskube and I can show you first-hand what the output looks like.
Posted By: splinny

Re: mIRC RPG vs. Random Number Generator *SOLVED* - 06/02/17 07:33 PM

May be something was wrong with Debug output. Or some small delay required after last /rpgGenerate.
© 2022 mIRC Discussion Forums