Quick [Random] Question
#1

So I am making an Arms Dealer command where you do /getmats and it gives you a random place to deliver the materials.

I have a float for the co-ordinates:

Код:
new Float:DROPMATS[][3] =
{
        {-1322.2762,2498.0610,87.0469}, //dropmats one
        {-2433.6064,2293.0537,4.9844}, //dropmats two
        {1405.9614,969.5345,10.8130}, //dropmats three
        {2867.3218,2569.6433,10.8203}, //dropmats four
	{2367.7493,2759.4209,10.8203}, //dropmats five
	{1882.1393,721.3551,10.8203}, //dropmats six
	{870.1201,-25.4718,63.9474} //dropmats seven
};
And then this is in my /getmats command:

Код:
new rand = random(sizeof(DROPMATS));
SetPlayerCheckpoint(playerid, DROPMATS[rand][0], DROPMATS[rand][1], DROPMATS[rand][2], 3);
And when it gives me a random checkpoint, I also want it to send the player a message corresponding to the co-ordinates it picked.

So for example:

If the co-ordiantes randomly selected where [-1322.2762,2498.0610,87.0469], that is Aldea Malvade, so when it is randomly selected, it would set their checkpoint and then:

Код:
SendCleintMessage(playerid, 1, "The package reads Aldea Malvade. Deliver it to the red marker.");
How would I do that?
Reply
#2

When he delivers the mats use this:
Код:
    if(IsPlayerInRangeOfPoint(playerid, 10.0, -1322.2762,2498.0610,87.0469))
    {
        SendClientMessage(playerid, -1, "The package reads Aldea Malvade. Deliver it to the red marker.");
    }
the 10.0 is the range to check what range is he or isn't he.
Reply
#3

Quote:
Originally Posted by Kruno88
Посмотреть сообщение
When he delivers the mats use this:
Код:
    if(IsPlayerInRangeOfPoint(playerid, 10.0, -1322.2762,2498.0610,87.0469))
    {
        SendClientMessage(playerid, -1, "The package reads Aldea Malvade. Deliver it to the red marker.");
    }
the 10.0 is the range to check what range is he or isn't he.
I don't want it to send the message when he delivers the mats, I want it to send the message when he gets the mats.
Reply
#4

pawn Код:
new rand = random(sizeof(DROPMATS));
SetPlayerCheckpoint(playerid, DROPMATS[rand][0], DROPMATS[rand][1], DROPMATS[rand][2], 3);


// Add THIS
new string[128],location[32];

// Find out what location was randomly chosen, and format the location string accordingly
if(rand  == 0)) format(location,32,"Location 1");
if(rand  == 1)) format(location,32,"Location 2");
if(rand  == 2)) format(location,32,"Location 3");
if(rand  == 3)) format(location,32,"Location 4");
if(rand  == 4)) format(location,32,"Location 5");
if(rand  == 5)) format(location,32,"Location 6");
if(rand  == 6)) format(location,32,"Location 7");

// Create a string including the name of the location, e.g "Location 1"
format(string,sizeof(string),"The package reads %s. Deliver it to the red marker.",location);
SendClientMessage(playerid,-1, string);
I would've done it differently but this should work with your existing code, if
it actually works, i have not tested or looked for any errors in your code.

I haven't scripted for years so I could've made a mistake.
Reply
#5

Quote:
Originally Posted by liquor
Посмотреть сообщение
pawn Код:
new rand = random(sizeof(DROPMATS));
SetPlayerCheckpoint(playerid, DROPMATS[rand][0], DROPMATS[rand][1], DROPMATS[rand][2], 3);


// Add THIS
new string[128],location[32];

// Find out what location was randomly chosen, and format the location string accordingly
if(rand  == 0)) format(location,32,"Location 1");
if(rand  == 1)) format(location,32,"Location 2");
if(rand  == 2)) format(location,32,"Location 3");
if(rand  == 3)) format(location,32,"Location 4");
if(rand  == 4)) format(location,32,"Location 5");
if(rand  == 5)) format(location,32,"Location 6");
if(rand  == 6)) format(location,32,"Location 7");

// Create a string including the name of the location, e.g "Location 1"
format(string,sizeof(string),"The package reads %s. Deliver it to the red marker.",location);
SendClientMessage(playerid,-1, string);
I would've done it differently but this should work with your existing code, if
it actually works, i have not tested or looked for any errors in your code.

I haven't scripted for years so I could've made a mistake.
You added an extra bracket on the "if(rand == 1)) format(location, bla bla bla)".

lol, but thanks very much man, it worked and I REP'ed you. Again, thanks.
Reply
#6

No problem, though the extra bracket would work, i often used it few years ago :P
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)