Command give random if
#1

PHP код:
CMD:startm(playeridparams[])
{
    if(
IsPlayerInRangeOfPoint(playerid,2.0, -216.7863985.105219.3948))
    {
    if(
Militar[playerid] == 1)
    {
    
MilitarJob[playerid] = 1;
    }
    else return 
SendClientMessage(playerid, -1"{FFCC33}Text!");
    }
    else return 
SendClientMessage(playerid,-1,"*"COL_RED" Text !");
    return 
1;

I want to type /startm and set random militarjob[playerid] = Random (1, 7, 14 or 20) one of these 4.
How can I achieve this?


Can I set MilitarJob[playerid] = X.

X = 1, 7, 14 ,20 ?
Reply
#2

You can make an array with these 4 values and then use ‘random’ function.
Reply
#3

Try this

Код:
forward Militar(playerid);
public Militar(playerid);
{
	new rr = random(3);
	switch(rr)
	{
		case 0: militarjob[playerid] = 1;
		case 1: militarjob[playerid] = 7;
		case 2: militarjob[playerid] = 14;
		case 3: militarjob[playerid] = 20;
	}
	return 1;
}
and use SetTimerEx in your command to set the timer
Reply
#4

Quote:
Originally Posted by Ritzy
Посмотреть сообщение
You can make an array with these 4 values and then use ‘random’ function.
PHP код:
new Float:Numbers[][5] =
{
    {
1},
    {
2},
    {
3}.
    {
4}
}; 

PHP код:
CMD:startm(playeridparams[]) 

    if(
IsPlayerInRangeOfPoint(playerid,2.0, -216.7863985.105219.3948)) 
    { 
    if(
Militar[playerid] == 1
    { 
    
MilitarJob[playerid] = Numbers
    } 
    else return 
SendClientMessage(playerid, -1"{FFCC33}Text!"); 
    } 
    else return 
SendClientMessage(playerid,-1,"*"COL_RED" Text !"); 
    return 
1

?
Reply
#5

Quote:
Originally Posted by Zeus666
Посмотреть сообщение
PHP код:
new Float:Numbers[][5] =
{
    {
1},
    {
2},
    {
3}.
    {
4}
}; 

PHP код:
CMD:startm(playeridparams[]) 

    if(
IsPlayerInRangeOfPoint(playerid,2.0, -216.7863985.105219.3948)) 
    { 
    if(
Militar[playerid] == 1
    { 
    
MilitarJob[playerid] = Numbers
    } 
    else return 
SendClientMessage(playerid, -1"{FFCC33}Text!"); 
    } 
    else return 
SendClientMessage(playerid,-1,"*"COL_RED" Text !"); 
    return 
1

?
Ah mate you don’t use random function at all. Sorry it’s hard to write code on iPad but refer to this it will help -
https://sampwiki.blast.hk/wiki/Random
Reply
#6

Quote:
Originally Posted by scripter112
Посмотреть сообщение
Try this

Код:
forward Militar(playerid);
public Militar(playerid);
{
	new rr = random(3);
	switch(rr)
	{
		case 0: militarjob[playerid] = 1;
		case 1: militarjob[playerid] = 7;
		case 2: militarjob[playerid] = 14;
		case 3: militarjob[playerid] = 20;
	}
	return 1;
}
and use SetTimerEx in your command to set the timer
Did these, now I should MilitarJob[playerid] = rr;


?
Reply
#7

Quote:
Originally Posted by Zeus666
Посмотреть сообщение
Did these, now I should MilitarJob[playerid] = rr;


?
put this in your script and on your command use
Код:
SetTimerEx("Militar", 1000, false, "i", playerid);
if you want to repeat timer change false to true
You can read this
Reply
#8

PHP код:
new Float:Numbers[4] = 

    
1,  
    
7
    
14,
    
20
}; 
Later...
PHP код:
   MilitarJob[playerid] = Numbers[random(sizeof Numbers)]; 
Reply
#9

You post easy stuff almost every day, you should take a good look at the samp functions before consulting here
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)