random create

Non-platform specific questions.

random create

Postby Zehper48 » Tue Jul 18, 2006 9:18 pm

how do i make if player collides with the enemy there is a 10% chance that coin will be created
I like score
User avatar
Zehper48
 
Posts: 241
Joined: Sun Jun 11, 2006 1:34 am
Location: Advanced Noob
Score: 4 Give a positive score

Postby Game A Gogo » Tue Jul 18, 2006 9:43 pm

use on destroy of the actor
Code: Select all
int coinC;
coinC=rand(10);
if(coinC ==1)
{
createactor("Coin", 0, 0, "non
_relative");

note: the create actor function may not be the good things in it, just replace it whit the real create action.
Programming games is an art,
    Respect it.
User avatar
Game A Gogo
 
Posts: 3466
Joined: Wed Jun 29, 2005 10:49 pm
Location: French Canada *laughs*
Score: 181 Give a positive score

Postby DilloDude » Wed Jul 19, 2006 12:15 am

a good idea to use round(rand(10)) rather than just rand(10) or else the chance will be very slim
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score

Postby DilloDude » Wed Jul 19, 2006 7:45 am

I'm currently working on a function for creating random items. It has a lot of parameters where you put the chance of each item you want to be able to create. It then chooses a number and finds which item to create. I have tested one sample by doing the arithmetic with a calculator, and it got the desird results, but I haven't tested in an actual game. You can modify it for any number of items.
Code: Select all
void LeaveItem(int th, int fl, int ar, int br, int sl, int gl, int rb, int hp, int na)
{
    int total = th + fl + ar + br + sl + gl + rb + hp + na;
    double THC;
    double FLC;
    double ARC;
    double BRC;
    double SLC;
    double GLC;
    double RBC;
    double HPC;
    if (total != 0)
    {
        double itm = rand(100);

        THC = (round(th) / total) * 100;
        FLC = ((round(fl) / total) * 100) + THC;
        ARC = ((round(ar) / total) * 100) + FLC;
        BRC = ((round(br) / total) * 100) + ARC;
        SLC = ((round(sl) / total) * 100) + BRC;
        GLC = ((round(gl) / total) * 100) + SLC;
        RBC = ((round(rb) / total) * 100) + GLC;
        HPC = ((round(hp) / total) * 100) + RBC; 
   
        if (itm <= THC){CreateActor("TH");}
        else if (itm <= FLC){CreateActor("FL");}
        else if (itm <= ARC){CreateActor("AR");}
        else if (itm <= BRC){CreateActor("BR");}
        else if (itm <= SLC){CreateActor("SL");}
        else if (itm <= GLC){CreateActor("GL");}
        else if (itm <= RBC){CreateActor("RB");}
        else if (itm <= HPC){CreateActor("HP");}
    }
}

the last parameter (na) is the chance that nothing will be created. Note that the Create Actor parts are not complete; you will need to complete these (possibly adding script for random location). For your example, if you wanted to create an item GL (short for GoLd coin), with a 90% chance that nothing will be created and a 10% chance that it will be a GL, put:
Code: Select all
LeaveItem(0, 0, 0, 0, 0, 1, 0, 0, 9);

But you can remove the parameters you don't need so you can only create the items you want. If na is not the last parameter, you will need an else.
If modifying it seems a bit complicated, just post the types of items you want and I can do the modification for you.
Image
User avatar
DilloDude
 
Posts: 866
Joined: Tue Jan 24, 2006 9:51 am
Location: Nyerellion
Score: 58 Give a positive score


Return to General

Who is online

Users browsing this forum: No registered users and 1 guest