View Single Post
  #10  
Old 03-08-2016, 11:19 AM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 88,317
Kyttias is on a distinguished road
Default

We're going to set it up like this: 1% of the time the pet may get a status effect. Of the 99% of the time that the pet does not come away with a status effect, 75% of the remaining time - nothing will happen at all. Of the other 25% of the time, 5% of the time it will either be because it found some money or an item (about 50% toward either). The remaining 20% of the time it will say a random phrase based on its species. Below is commented but empty code just to get the odds of each event happening right:
PHP Code:
$status_chance mt_rand(1100);  
if (
$status_chance <= 1){ # One percent chance the pet will obtain a status effect.
    /* We would apply a status effect here...*/
} else { # Ninety-nine percent chance the pet will not get a status effect. Will something else happen?
    
$something_chance mt_rand(1100); 
    if (
$something_chance <= 25){ # Twenty-five percent chance something will happen.
        
$gift_chance mt_rand(1100); 
        if (
$gift_chance <= 5){ # Five percent chance the user will receive a gift from their pet.
            
$item_chance mt_rand(1100);
            if (
$item_chance <= 50){ # Fifty percent chance the gift from their pet will be an item.
                /* The pet has found an item for you! */ 
            
} else { # Fifty percent chance the gift from their pet will be money.
                /* The pet has found some money for you! */
            
}
        } else { 
# Twenty percent chance the pet will talk but have no gift.
            /* No gift will be given but a neat species-specific phrase can still be said! */
        
}
    } else { 
# Seventy-five percent chance nothing will happen whatsoever.
        /* Nothing will happen with the pet at all. */
    
}

Basically, just a tower of if-else statements so far, using PHP's built in mt_rand() function - we're feeding it the numbers 1 and 100 so it'll choose a random number between the two, just like rolling (if possible) a 100-sided dice. It's the easiest way to fudge in percents.

More soon! I've got to go look up some of the code I've used to give items and such again.

1) Is it alright if items and money are automatically collected, even without the user clicking or doing anything? It becomes much more complicated otherwise.

2) Inevitably if you wanted to, say, make it so your active pet can find an abandoned egg 1/500th of the time (about 0.2% chance of happening) but require that the user also be paying attention and clicking that message, remind me - I should be able to think this one through, given enough time. Let me know if this is something you want.

3) These percents should all be easy to modify. Let me know if you have questions and I can help tweak the code. If you change an mt_rand(1,100) to mt_rand(1,200) you will literally make something twice as hard to get and this will be relevant as soon as you want things to happen less than 1% of the time. One percent of that (1,200) would be 0.5% instead of (1,100)'s obvious 1%.

4) The fake status... placeholders for potentially real ones later? Is there a list of random events (nice ones are better than mean ones) you'd be interested in? Such as the pet suddenly gaining experience (as if clicked) or an entire level (if it's not frozen)? More complicated things (that existing item functions can't do) I might be interested in helping out with later, once everything else is done. For now, status effects will be the last on the list of things I'll do, and we'll fill it in with a message of "a status effect would have happened here" so long as we're testing. There are also some ideas I have that would be optional status effects that would require the user to click to accept and have it explained that the changes are somewhat permanent but entirely optional - such as the pet's gender or species changing, or the species' alternate appearance activated. Most of the time the user would be enthusiastically agreeing to this change but what if they really like their pet exactly how it is? We wouldn't want to force something, no matter how cool we think it is.
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.

Last edited by Kyttias; 03-08-2016 at 12:32 PM.
Reply With Quote