x1 = ch->silver / 100;
sprintf(buf, "You've exchanged %ld silver for %d gold.\n\r", x1*100, x1); // properly display how much silver traded in
send_to_char(buf, ch);
@@ ch->silver = ch->silver % 100; // modulus finds remainder.
ch->gold += x1;
x1 = 0;
sprintf(buf, "You've exchanged %ld silver for %ld gold.\r\n", ch->silver, ch->silver/100);
send_to_char (buf, ch);
int coins = ch->silver; // So we can read the code more easily, we'll use 'coins'
ch->gold += coins/100; // 100th conversion
ch->silver -= (coins/100) * 100; // 100 silver per gold then removed.
if (ch->silver > 0) // Only say we're giving change if we have silver left over.
{
sprintf(buf, "You get %d silver in change.\r\n", ch->silver);
send_to_char(buf, ch);
}
// col is an int.
if (++col % 4 == 0)
strcat (buf1, "\r\n");
printf("Modulo stuff: ");
for(i = 0; i < 9; i++) {
printf("i = %d ", i);
if( ! i % 4 ) printf("\n");
}
Modulo stuff: i = 0
i = 1 i = 2 i = 3 i = 4
i = 5 i = 6 i = 7 i = 8
because 0 mod anything is 0. :)
Also, I think using negative numbers is either an error, or usually implemented as (-3 % 4) == (int)((unsigned int)(-3) % 4)
But YMMV.
I had a long and very drawn out, if(ch->mkill == # || ch->mkill == #2 || etc || etc) { Give bonus'}.
I was then telling a friend about this a while back and he gave me a more simplistic version on how to run such a thing,
if (ch->mkill % # == 0) //my players know I post here often.
{
ch->hit = ch->max_hit;
ch->max_hit += 100;
ch->max_mana += 100;
ch->max_move += 100;
ch->pcdata->perm_hit += 100;
ch->pcdata->perm_mana +=100;
ch->pcdata->perm_move += 100;
ch->hit = ch->max_hit;
ch->mana = ch->max_mana;
ch->move = ch->max_move;
stc("{CYou{W'{Cve been awarded {D100 {Chitpoints{W, {Cmana{W, {Cmove and restored for your kills{W!{x\n\r", ch);
}
Now, I guess the question is how does this work? Im trying to use this in my convert command, so that
when players go to exchange their silver into gold, they are left that remainder (100silver = 1gold).
It didn't seem like their was a lot of loss, so I have it coded as:
x1 = ch->silver / 100;
sprintf(buf, "You've exchanged %ld silver for %d gold.\n\r", ch->silver, x1);
send_to_char(buf, ch);
ch->silver = 0;
ch->gold += x1;
x1 = 0;
:right now, and I had a player suggest that I break it up so that they can save that silver that they lose.
I tried to code it out, but since I don't really understand how that % value works, it didn't convert
any silver to gold, or deduct anything.
All I know is when the value is reached in fight.c that I had chosen, it does what I want it to.