DragonPrime - LoGD Resource Community
Welcome Guest
  • Good morning, Guest.
    Please log in, or register.
  • July 25, 2016, 10:47:53 AM
Home Forums News Links Downloads Login Register Advanced Search
* * *
DragonPrime Menu
Login
 
 
Resource Pages
IRC Channels
Search

Pages: [1]   Go Down
  Print  
Author Topic: Death in Mines  (Read 1960 times)
0 Members and 1 Guest are viewing this topic.
Interloper
Guest
« on: August 02, 2004, 08:40:14 PM »


Argh! I've been sitting here for a while reading threads on these boards and staring at the php source in the home that an answer to the question I'm about to ask will pop into my head because it seems simple in theory and I know that more than likely it really is simple and I just lack the knowledge to know how to pull it off... And I've lost my train of thought.

Anyway, the question I'm asking is hopefully an easy one that hopefully someone will be kind enough to help me out with.

Basically when people die in the mines I don't want it to be certain that they lose ALL of their gems, but that there's a slight chance they might recover a few of them. I figured that the best way to do this would be to make it that the players lose gems by percentage --  they have the largest chance to lose all of their gems, and slightly smaller chances of losing say 50% of their gems, then an even smaller chance they only lose 25% etc. etc.

This poses problems from the point of view that... How will that work if the amount of gems they're going to lose isn't a whole number (for example -- how do you lose 25% of your gems if you only have 2 gems?).

So if anyone could spare the time to help me out  so that my players won't make the mines completely redundant when they're saving for high-priced mounts I'd be truly appreciative.

 Smiley
Logged
Eth
Member
Codemeister
****
Offline Offline

Posts: 302


Shameless Drunk


View Profile
« Reply #1 on: August 02, 2004, 09:18:45 PM »

Well one approach is to use the round function:

Code:
$gemloss=round($session[user][gems]*.25);
$session[user][gems]-=$gemloss;

It'll simply round up (or down) the value returned by the above variable and return a whole number. That number can than be subtracted from the user's gems. Easy as that.

Or you could make it so users with less than 4 (for example) gems are immune from losing any gems. In that case this would work:

Code:
if ($session[user][gems]>3){
$gemloss=round($session[user][gems]*.25);
output("You've lost a quarter ($gemloss) of your gems in the mine collapse!`n");
$session[user][gems]-=$gemloss;
}

That's one approach to it anyways. Hope that was of some help to you. Smiley
Logged

Purveyor of fine cloaks, gloves, boots, gerbils, and Siamese cats.
dvd871
Guest
« Reply #2 on: August 02, 2004, 10:21:00 PM »

I think this is what you're after:
Code:
switch(e_rand(1,10)) {
    case 1: case 2: case 3: case 4: case 5:
    $session[user][gems]=0;
    output(`nYou lost all of your gems!");
    break;
    case 6: case 7: case 8:
    $session[user][gems]=round($session[user][gems]*.50);
    output(`nYou lost 50% of your gems!");
    break;
    case 9: case 10:
    $session[user][gems]=round($session[user][gems]*.25);
    output(`nYou lost 25% of your gems!");
    break;
}
Logged
Interloper
Guest
« Reply #3 on: August 03, 2004, 06:45:18 AM »

Awesome. Grin

Thanks for the help (and for bothering to decipher my post), it seems to be just what I was looking for. I'll have a play around with it when I'm feeling more awake.

You guys rock!

Edit:

Okay I couldn't help myself taking a look at it now even though I'm probably too asleep to comprehend much at the moment, and I'm confused as to where exactly I would put  the code dvd871 posted.

I've found the cases and the different outcomes in goldmine.php, as well as what occurs after death (around where it checks whether the mount is killed as well and that sort of thing) but I'm not sure where my new code should go...  Embarrassed
« Last Edit: August 03, 2004, 07:03:12 AM by Interloper » Logged
Eth
Member
Codemeister
****
Offline Offline

Posts: 302


Shameless Drunk


View Profile
« Reply #4 on: August 03, 2004, 10:32:48 AM »

Jump down to around line 136 and find the block of code that reads as such:

Code:
$exp=$session[user][experience]*0.6;
output("At least you learned something about mining from this experience and have gained $exp experience.`n`n");
output("`3You may continue to play tommorrow`n");
$session[user][experience]+=$exp;
$session[user][alive]=false;
$session[user][hitpoints]=0;
debuglog("lost {$session['user']['gold']} gold and {$session['user']['gems']} gems by dying in the goldmine");
$session[user][gold]=0;
$session[user][gems]=0;
addnav("Daily News","news.php");
addnews($session[user][name]." was completely buried when ".($session[user][sex]?"she":"he")." became greedy digging in the mines");
That's the block of code you're looking for.
 
This is the line you're looking for in that block:
Code:
$session[user][gems]=0;

But if I'm not mistaken, you can't place case statements within case statements, at least not from my experiments. So, that leads me to this alternative. This is just one of many ways to accomplish what you're after.

Try this for example, just replace this with the line I posted above:

Code:
$gc=e_rand(1,10);
if ($gc>=6){
output("You've lost ALL of your gems!");
$session[user][gems]=0;
}else if ($gc>=3 && $gc<=5){
output("You've lost HALF of your gems!");
$session[user][gems]=round($session[user][gems]*.50);
}else{
output("You've lost a quarter of your gems!");
$gemloss=round($session[user][gems]*.25);
$session[user][gems]-=$gemloss;
}

Best of luck. Smiley
Logged

Purveyor of fine cloaks, gloves, boots, gerbils, and Siamese cats.
dvd871
Guest
« Reply #5 on: August 03, 2004, 02:14:55 PM »

Yea case within case will not work properly.   Tongue
Logged
Interloper
Guest
« Reply #6 on: August 03, 2004, 06:50:24 PM »

Woo it worked! I edited it slightly to include losing half of your gems, stuck it in goldmine.php and tested with admin player and it seemed to work perfectly.

One minor question about e_rand though -- I tried to set it up so that you would have basically a 40% chance of losing ALL your gems, 30% chance to lose most, 20% chance to lose half of them and a 10% chance that you only lose some. I think I got it right but I wasn't sure if "e_rand(1,10)" actually includes 10 as a possible result (which my percentages rely on) or if it only counts to 9 or something.

 Here is the code I used:

Code:
$gc=e_rand(1,10);
if ($gc>=7){
output("You've lost ALL of your gems!");
$session[user][gems]=0;
}else if ($gc>=4 && $gc<=6){
output("You've lost most of your gems!");
$session[user][gems]=round($session[user][gems]*.25);
}else if ($gc>=2 && $gc<=3){
output("You've lost half of your gems!");
$session[user][gems]=round($session[user][gems]*.50);
}else{
output("You've lost some of your gems!");
$gemloss=round($session[user][gems]*.75);
$session[user][gems]-=$gemloss;
}

Thanks again for your help everyone, I finally feel like I'm learning something.

 Smiley
« Last Edit: August 03, 2004, 06:51:46 PM by Interloper » Logged
Kendaer
Guest
« Reply #7 on: August 03, 2004, 11:04:45 PM »

e_rand is inclusive.

so e_rand(1,10) will generate numbers from the set [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  


*
DragonPrime Notices
Welcome to DragonPrime - The LoGD Resource Community!

Support Us
No funds raised yet this year
Your help is greatly appreciated!
Who's Online
42 Guests, 0 Users
DragonPrime LoGD
Recent Topics
Home Forums News Links Downloads Login Register Advanced Search