SA-MP Forums Archive
Command give random if - 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: Command give random if (/showthread.php?tid=651529)



Command give random if - Zeus666 - 21.03.2018

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 ?


Re: Command give random if - Ritzy2K - 21.03.2018

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


Re: Command give random if - scripter112 - 21.03.2018

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


Re: Command give random if - Zeus666 - 21.03.2018

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

?


Re: Command give random if - Ritzy2K - 21.03.2018

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


Re: Command give random if - Zeus666 - 21.03.2018

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;


?


Re: Command give random if - scripter112 - 21.03.2018

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


Re: Command give random if - jlalt - 21.03.2018

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

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



Re: Command give random if - m1kas - 22.03.2018

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