SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 21/03/2018, 09:33 PM   #1
Zeus666
Gangsta
 
Join Date: Mar 2015
Posts: 674
Reputation: 50
Default Command give random if

PHP Code:
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 ?
Zeus666 is offline   Reply With Quote
Old 21/03/2018, 09:39 PM   #2
Ritzy2K
High-roller
 
Ritzy2K's Avatar
 
Join Date: Jun 2014
Location: India
Posts: 1,548
Reputation: 170
Default Re: Command give random if

You can make an array with these 4 values and then use ‘random’ function.
__________________
Ritzy2K is offline   Reply With Quote
Old 21/03/2018, 09:40 PM   #3
scripter112
Little Clucker
 
Join Date: Feb 2018
Posts: 35
Reputation: 0
Default Re: Command give random if

Try this

Code:
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
scripter112 is offline   Reply With Quote
Old 21/03/2018, 09:40 PM   #4
Zeus666
Gangsta
 
Join Date: Mar 2015
Posts: 674
Reputation: 50
Default Re: Command give random if

Quote:
Originally Posted by Ritzy View Post
You can make an array with these 4 values and then use ‘random’ function.

PHP Code:
new Float:Numbers[][5] =
{
    {
1},
    {
2},
    {
3}.
    {
4}
}; 


PHP Code:
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


?
Zeus666 is offline   Reply With Quote
Old 21/03/2018, 09:43 PM   #5
Ritzy2K
High-roller
 
Ritzy2K's Avatar
 
Join Date: Jun 2014
Location: India
Posts: 1,548
Reputation: 170
Default Re: Command give random if

Quote:
Originally Posted by Zeus666 View Post
PHP Code:
new Float:Numbers[][5] =
{
    {
1},
    {
2},
    {
3}.
    {
4}
}; 


PHP Code:
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 -
http://wiki.sa-mp.com/wiki/Random
__________________
Ritzy2K is offline   Reply With Quote
Old 21/03/2018, 09:44 PM   #6
Zeus666
Gangsta
 
Join Date: Mar 2015
Posts: 674
Reputation: 50
Default Re: Command give random if

Quote:
Originally Posted by scripter112 View Post
Try this

Code:
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;


?
Zeus666 is offline   Reply With Quote
Old 21/03/2018, 09:57 PM   #7
scripter112
Little Clucker
 
Join Date: Feb 2018
Posts: 35
Reputation: 0
Default Re: Command give random if

Quote:
Originally Posted by Zeus666 View Post
Did these, now I should MilitarJob[playerid] = rr;


?
put this in your script and on your command use
Code:
SetTimerEx("Militar", 1000, false, "i", playerid);
if you want to repeat timer change false to true
You can read this
scripter112 is offline   Reply With Quote
Old 21/03/2018, 09:58 PM   #8
jlalt
Banned
 
Join Date: Oct 2014
Location: Iran
Posts: 1,273
Reputation: 366
Default Re: Command give random if

PHP Code:
new Float:Numbers[4] = 

    
1,  
    
7
    
14,
    
20
}; 
Later...
PHP Code:
   MilitarJob[playerid] = Numbers[random(sizeof Numbers)]; 
jlalt is offline   Reply With Quote
Old 22/03/2018, 08:07 AM   #9
m1kas
Little Clucker
 
Join Date: Sep 2017
Posts: 41
Reputation: 6
Default Re: Command give random if

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

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Random give me 80 same pos ! DiamantEspace18 Scripting Help 0 14/01/2015 11:43 AM
how give random player weapon? EitayEliyahu Scripting Help 7 05/08/2013 05:43 PM
[HELP]Give random weapon HELP ME = REP+ xD InTeL_cOrE_i7 Scripting Help 3 10/06/2013 01:17 PM
give random money and msg print if its low or high omidi Scripting Help 2 18/03/2013 10:57 PM
Random give knackworst Help Archive 18 05/11/2010 06:29 PM


All times are GMT. The time now is 01:37 PM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.