Scripting related questions..
#1

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?
Reply
#2

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.
Reply
#3

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);
Reply
#4

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}
Reply
#5

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]);
      }
}
Reply
#6

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).
Reply
#7

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.
Reply
#8

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

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?
Reply
#10

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.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)