SA-MP Forums Archive
Scripting related questions.. - 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: Scripting related questions.. (/showthread.php?tid=501252)



Scripting related questions.. - Dokins - 17.03.2014

Hi there, I was wondering. How do I do something like this:

Grant Alexander pulls the steering column out
(Few seconds later)
"" grabs two wires
(Few seconds later)
"" twists the wires together
(Few seconds later)
Vehicle has a random chance of starting. Say 1/3.


How do I do that?
How do I also do this:

Make something have a 1/10 chance of being successful?

It's how it's done that confuses me, could someone let me know?


Re: Scripting related questions.. - Calabresi - 17.03.2014

By a timer. You just simply set a variable's value to 1, 2, 3 and set what's going to happen after what by setting them after an action gets done in that timer. And about the chance;

pawn Код:
new chance = random(100);
if(chance < 11)
{
       blablabla
}
That's logically it.


Re: Scripting related questions.. - Dokins - 17.03.2014

That's still pretty confusing tbh. Can you be a little more clear? Also why is the random(100)? And not 10 like why is it not if num = 1
Random(10);


Re: Scripting related questions.. - Raisingz - 17.03.2014

Random(x) generates numbers between 0 and X-1, including them both. So your possible cases are X, statistically speaking, if you want an 1/10 chance, all you need to do is
Код:
new chance = random(10);
if(chance == 0) //it could be any number, but meh
{
       blablabla
}
EDIT: Generated numbers by this algorithm are {0,1,2,3,4,5,6,7,8,9}


Re: Scripting related questions.. - Calabresi - 17.03.2014

Quote:
Originally Posted by Dokins
Посмотреть сообщение
That's still pretty confusing tbh. Can you be a little more clear? Also why is the random(100)? And not 10 like why is it not if num = 1
Random(10);
I just gave an example, it also could be random(10) aswell, chance is still 10%. What I told was something like that;

pawn Код:
new player_Status[MAX_PLAYERS], player_Timer[MAX_PLAYERS];

CMD:hotwire(playerid, params[])
{
      player_Status[playerid] = 1;
      player_Timer[playerid] = SetTimerEx("aFewSecondsTimer", 5000, true, "i", playerid);
}

forward aFewSecondsTimer(playerid);
public aFewSecondsTimer(playerid)
{
      if(player_Status[playerid] == 1)
      {
          blablablabla
          player_Status[playerid] = 2;
      }
      else if(player_Status[playerid] == 2)
      {
          blablablabla
          player_Status[playerid] = 3
      }
      else if(player_Status[playerid] == 3)
      {
          blablablabla
          KillTimer(player_Timer[playerid]);
      }
}



Re: Scripting related questions.. - Dokins - 17.03.2014

I don't understand the first part (messages every few seconds) also wait... Shouldn't random be 9 if it starts at 0? I'm confused.

EDIT: ahh I see the first part now but what about the second? (thank you will rep up).


Re: Scripting related questions.. - Calabresi - 17.03.2014

Quote:
Originally Posted by Dokins
Посмотреть сообщение
I don't understand the first part (messages every few seconds) also wait... Shouldn't random be 9 if it starts at 0? I'm confused.
No. If you make random(9), it will have chance to pick one of those numbers;

0, 1, 2, 3, 4, 5, 6, 7, 8

Which makes it's chance 1/9.


Re: Scripting related questions.. - Dokins - 17.03.2014

NOW I UNDERSTAND 0 after all of this time haha! I appreciate that. I will rep up, have a good one. Thank you.


Re: Scripting related questions.. - Dokins - 17.03.2014

Sorry for double post...I just realised... What happens like if this happened.

You said it goes like 0, 1 , 2 etc.

So if it was random(10) and I was looking to get the number 10 I.e chance = 10 how is that possible if it only goes up to 9 including the 0?


Re: Scripting related questions.. - Calabresi - 17.03.2014

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Sorry for double post...I just realised... What happens like if this happened.

You said it goes like 0, 1 , 2 etc.

So if it was random(10) and I was looking to get the number 10 I.e chance = 10 how is that possible if it only goes up to 9 including the 0?
Why would you want to get number 10? Getting any of those numbers will bring you the chance of 1/10, you don't need to pick 10 up for 1/10 chance.