SA-MP Forums Archive
Randomized Pickups that give weapons. - 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: Randomized Pickups that give weapons. (/showthread.php?tid=497920)



Randomized Pickups that give weapons. - rangerxxll - 01.03.2014

Hello. So I'm trying to create pickups that randomly spawn on a custom island. Once they spawn, a player will receive a random weapon (must be specified. So they don't get miniguns, etc.) I'd like to learn how to properly place random pickups in a array and randomly generate them each round of the match, and they will give the player a random weapon.

I can easily get the coordinates, but the issue is to randomize them every match. I also need to know how to make the pickups give weapons.

pawn Код:
new Float:rSpawns[][] =
{
    {3878.7217,466.0317,7.4426},
    {3726.5127,263.8537,7.4798},
    {3695.7917,421.2384,7.4630},
    {3640.9050,344.2969,7.4534},
    {3967.2261,423.8549,28.4928},
    {3928.4590,301.3971,38.8480}
};
What would this code be? Instead of coordinates, would it be "CreatePickup"?

If you need more information, let me know. Thanks for any assistance.


Re: Randomized Pickups that give weapons. - Crayder - 01.03.2014

Hold on let me get this straight... You want only one of them to be used each round, or do you want to create random one and a timer to randomly destroy it and create a new one in another random spot... Because only one spot to be used in each round wouldn't be very smart, I THINK what i said would be better because players could find that ONE spot and camp there if you don't choose my way (learned this from experience in my server :P)...


Re: Randomized Pickups that give weapons. - rangerxxll - 01.03.2014

I'd probably like your way, if possible lol. That's the point of randomizing them. And I'd like at least 6 pickups to be in a game.


Re: Randomized Pickups that give weapons. - Crayder - 01.03.2014

Ok, ill make the code unless someone else does, just gotta get my room straight and hook up my computer (Im on my phone:P)... I just moved to my new house


Re: Randomized Pickups that give weapons. - rangerxxll - 01.03.2014

Quote:
Originally Posted by Crayder
Посмотреть сообщение
Ok, ill make the code unless someone else does, just gotta get my room straight and hook up my computer (Im on my phone:P)... I just moved to my new house
Much appreciated. I'll be awaiting a response and hopefully we can get this system implemented.


Re: Randomized Pickups that give weapons. - rangerxxll - 02.03.2014

Still awaiting assistance. If you have a alternative to this, then please let me know. Just to clarify - I am looking to create randomized pickups that give weapons during a round.


Re: Randomized Pickups that give weapons. - Scenario - 02.03.2014

pawn Код:
new Float:rSpawns[][] =
{
    {3878.7217,466.0317,7.4426}, // array ID 0
    {3726.5127,263.8537,7.4798}, // array ID 1
    {3695.7917,421.2384,7.4630}, // array ID 2
    {3640.9050,344.2969,7.4534}, // array ID 3
    {3967.2261,423.8549,28.4928}, // array ID 4
    {3928.4590,301.3971,38.8480} // array ID 5
};

public OnGameModeInit()
{
    for(new i = 0, iRandom; i < 6; i++) make a loop that auto-adds +1 to i each time a new pickup is made; limit the amount of pickups to 6 via i < 6; change 6 to increase the amount of pickups
    {
        iRandom = random(sizeof(rSpawns)); // pick a random data set ID from rSpawns
        CreatePickup(-1, -1, rSpawns[iRandom][0], rSpawns[iRandom][1], rSpawns[iRandom][2], -1);
    }
    return 1;
}
rSpawns is the name of the array. The [iRandom] is a random ID of the set of data in the array. Each {} encloses a new set of data. Each , inside of a set of data is like a different ID.
So, doing rSpawns[0] will give you this set of data: 3878.7217,466.0317,7.4426
Then, doing rSpawns[0][0] will give you this piece of the set: 3878.7217
Just like doing rSpawns[0][2] will give you this piece: 7.4426


Re: Randomized Pickups that give weapons. - Crayder - 04.03.2014

Quote:
Originally Posted by RealCop228
Посмотреть сообщение
pawn Код:
new Float:rSpawns[][] =
{
    {3878.7217,466.0317,7.4426}, // array ID 0
    {3726.5127,263.8537,7.4798}, // array ID 1
    {3695.7917,421.2384,7.4630}, // array ID 2
    {3640.9050,344.2969,7.4534}, // array ID 3
    {3967.2261,423.8549,28.4928}, // array ID 4
    {3928.4590,301.3971,38.8480} // array ID 5
};

public OnGameModeInit()
{
    for(new i = 0, iRandom; i < 6; i++) make a loop that auto-adds +1 to i each time a new pickup is made; limit the amount of pickups to 6 via i < 6; change 6 to increase the amount of pickups
    {
        iRandom = random(sizeof(rSpawns)); // pick a random data set ID from rSpawns
        CreatePickup(-1, -1, rSpawns[iRandom][0], rSpawns[iRandom][1], rSpawns[iRandom][2], -1);
    }
    return 1;
}
rSpawns is the name of the array. The [iRandom] is a random ID of the set of data in the array. Each {} encloses a new set of data. Each , inside of a set of data is like a different ID.
So, doing rSpawns[0] will give you this set of data: 3878.7217,466.0317,7.4426
Then, doing rSpawns[0][0] will give you this piece of the set: 3878.7217
Just like doing rSpawns[0][2] will give you this piece: 7.4426
He doesnt want all of them created at the same time... and they need destroyed after being picked up... and as its destroyed a new random one needs to be created... Its the same system used in my old GM Hunger Games... Just dont have access to it yet, or i would've given it to him already


Re: Randomized Pickups that give weapons. - rangerxxll - 04.03.2014

I'm just using the good old (if pickupid == whatever.) It seems to be working. May not be the most space efficient, or just efficient in general but it works. I couldn't get it to work with an array.