SA-MP Forums Archive
Need help with jobs. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Need help with jobs. (/showthread.php?tid=452437)



Need help with jobs. - ThaCrypte - 21.07.2013

Well, i want to create some jobs in my server, but i want it to be like a random job everytime you do /startjob , but i never really understood how to make stuff go random, like gambling etc. So could anyone explain me how to do it?


Re: Need help with jobs. - Threshold - 21.07.2013

Use the 'random' function...

pawn Код:
cmd:startjob(playerid, params[])
{
    if(isplayerthis || isplayerthat) //Examples
    {
        new number = random(6); //We have 6 jobs to choose from, so that's what we use. (It is possible to get 0)
        switch(number) //Remember, you must have yournumber + 1 in the random slot. Example: We want 5 options, so we do random(6). We want 3 options, we enter random(4). etc.
        {
            case 0:
            {
                //Truck Driver
            }
            case 1:
            {
                //Taxi Driver
            }
            case 2:
            {
                //Medic
            }
            //etc. case 3, 4, 5...
        }
    }
    return 1;
}
This is merely an example, and most likely will not perform as expected or intended. I suggest you use the following functions to help you create what you are looking for:
https://sampwiki.blast.hk/wiki/Random
https://sampwiki.blast.hk/wiki/Control_Structures


Re: Need help with jobs. - ThaCrypte - 21.07.2013

Well, this already helped me alot.
But the what i actually ment like:
player is a trucker, enters a truck, type's /startjob.
Now a random number will be taken, and a random destination.

But with this i think i can do alot. just add case's and then add within like
pawn Код:
case 0:
{
    If (playerdata(playerid) jobid == 1); //trucker in this case
    {
      Etc etc
    }
}
case 1:
{
 ETC
}



Re: Need help with jobs. - arakuta - 21.07.2013

pawn Код:
CMD:startjob(playerid)
{
    new job = random(10); // This will get something between 0 and 9
    switch(job) // Make a switch for job, it works like else if
    {
        case 0:
        {
            // Things that will happen if the job is 0...
        }
        case 1:
        {
            // Things of job 2...
        }
        // And there you'll go...
    }
    return 1;
}