Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Ralph1971
Wanderer


Joined: 01 Mar 2008
Posts: 64

PostPosted: Sat Jan 10, 2009 6:46 pm   

#math and decimals
 
I"m trying to midas items, and give the coins back to whomever gave me the item, keeping a percentage for myself.
I have the majority of things done, but when I try (for example) to midas something that's worth 83333 coins, I have the process like this..
#math mygold (@itemgold*.02)... problem is, in this case, the mygold portion ends up being 1666.66.. and it throws my triggers into a spin with the next line..
#math chargold @itemgold-@mygold
give @chargold coins @char

it won't let me give partials.. 1666.66.. "I'm sorry, you can't do that"
how can I set it up so that it rounds to the nearest coin on the @mygold math process?
if it helps, here is the goldend step of the process
Code:

#math itemgold @endgold-@startgold
#math mygold (@itemgold*.02)
#math chargold @itemgold-@mygold
#say Item gold is @itemgold
#say My gold is @mygold
#add tgold @tgold+@mygold
#add tmidasgold @tmidasgold+@tgold
#say I midas'd @Item.name for @itemgold gold pieces. Your share is @chargold gold pieces.
give @chargold coin @midchar


Last edited by Ralph1971 on Sat Jan 10, 2009 6:51 pm; edited 1 time in total
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4715
Location: Pensacola, FL, USA

PostPosted: Sat Jan 10, 2009 6:49 pm   
 
you could force it into an integer, and use %mod to add the remainder back on.

#MATH mygold (%int(@itemgold*.02)+%mod(@itemgold/50))
_________________
Discord: Shalimarwildcat
Reply with quote
Scirkhan
Apprentice


Joined: 14 Sep 2007
Posts: 167
Location: aztx

PostPosted: Mon Jan 12, 2009 11:43 am   
 
This line of code looks like what you are wanting:
Code:
#math mygold (%round(@itemgold*0.02))



#eval
%eval
%int
%mod
%round
<---

Are all very useful.

#MATH mygold @itemgold/50
#MATH mygold (@itemgold/50+%mod(@itemgold/50))

#MATH mygold (%int(@itemgold*0.02))
#MATH mygold (%int(@itemgold/50))
#MATH mygold (%int(@itemgold/50)+%mod(@itemgold/50))

give @itemgold%round(@itemgold-@itemgold*0.02) coin @midchar
give %eval(@itemgold-@itemgold/50) coin @midchar
-------------------------------------------------------------------------
For some reason *.02 doesn't work for me. So:
#math mygold (@itemgold*.02) didn't work for me. I don't know why but what I've found is
#math mygold @itemgold/50 doesn't give floating numbers.

NOTE: "/" truncates, does not give floating numbers.
*0.02 worked for me. *.02 doesn't.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4715
Location: Pensacola, FL, USA

PostPosted: Mon Jan 12, 2009 8:35 pm   
 
if you change it to /50.0 it should give a float
_________________
Discord: Shalimarwildcat
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot 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

© 2009 Zugg Software. Hosted by Wolfpaw.net