Items spawn on same coords
#1

I'm trying to set up a system where when items respawn, they get spawned at random locations. However, when they spawn, they all spawn on the same spot.

pawn Код:
forward LootRespawn();
public LootRespawn()
{
    new res = randomEx(1, 2);
    new amount = randomEx(1, 10);
    new Locs = random(sizeof(TestSpawns));
    if(res == 1)
    {
        CreateItem(1580, amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
        CreateItem(1577, amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
        CreateItem(373, amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
        CreateItem(348, 1, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
    }
    if(res == 2)
    {
        CreateItem(2806, amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
        CreateItem(2663, amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
        CreateItem(335, 1, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
        CreateItem(2358, amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
    }
pawn Код:
new Float: TestSpawns[][] =
{
    {377.64130, 2542.36963, 15.53980},
    {381.50552, 2542.74146, 15.53976},
    {381.19205, 2539.23486, 15.54050},
    {378.27368, 2539.07715, 15.54048}
};
Reply
#2

You need to do the random after everytime you created the item, or else it will spawn in same positions with same amount.

Код:
forward LootRespawn();
public LootRespawn()
{
	new res = randomEx(1, 2);
	new ItemRes[][4] =
	{
		{1580, 1577, 373, 348}, // items for res == 1
		{2806, 2663, 335, 2358} // items for res == 2
	};
	for(new i = 0; i < sizeof(ItemRes); i++) // This will do loop 4 times
	{
		if((res == 1 && i == 3) || (res == 2 && i == 2)) amount = 1;
		// The 4th (i+1) item (res == 1) which is model 348 should only have 1 amount.
		// OR the 3rd (i+1) item (res == 2) which is model 335 should only have 1 amount too.
		
		else amount = randomEx(1, 10); // Otherwise, randomize the amount.
		Locs = random(sizeof(TestSpawns));
		CreateItem(ItemRes[res][i], amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
		/* res is already randomized so no need to check if it's equal to one or two since
			the function is mostly doing the same for both res, which is just differences with the items
			that we have to separate it in ItemRes array now. */
	}
If you don't really mean the amount get randomized or you want the amount for each "res" is same, then just put the if-else check for amount to outside the loop.
Код:
forward LootRespawn();
public LootRespawn()
{
	new res = randomEx(1, 2);
	new ItemRes[][4] =
	{
		{1580, 1577, 373, 348}, // items for res == 1
		{2806, 2663, 335, 2358} // items for res == 2
	};
	// THIS WILL ONLY DO ONCE
	if((res == 1 && i == 3) || (res == 2 && i == 2)) amount = 1;
	// The 4th (i+1) item (res == 1) which is model 348 should only have 1 amount.
	// OR the 3rd (i+1) item (res == 2) which is model 335 should only have 1 amount too.
	
	else amount = randomEx(1, 10); // Otherwise, randomize the amount.
	for(new i = 0; i < sizeof(ItemRes); i++) // This will do loop 4 times
	{
		Locs = random(sizeof(TestSpawns));
		CreateItem(ItemRes[res][i], amount, 1, TestSpawns[Locs][0], TestSpawns[Locs][1], TestSpawns[Locs][2], 0, 0);
		/* res is already randomized so no need to check if it's equal to one or two since
			the function is mostly doing the same for both res, which is just differences with
			the items that we have to separated it in ItemRes array now. */
	}
If it's not working like what you want, then you need to explain more how the items should be spawned with that callback by pointing out what is "res" for.
Reply
#3

Sorry I didn't explain it more clearly.

What happens with the current code I have is when the items respawn, they all spawn on the same x, y, z coords. I want to fix that when one 'x, y, z' set of coords is taken, it doesn't spawn anymore items there and moves on to another set of 'x, y, z' coords.

EDIT:



Here's what the issue is, you can see all the items are spawning on top of each other when they shouldn't.
Reply
#4

Quote:
Originally Posted by DTV
Посмотреть сообщение
Here's what the issue is, you can see all the items are spawning on top of each other when they shouldn't.
I do understand that issue now, to fix that, you shouldn't use random, but use the loop or mark the position that is already used.

But you haven't explained the use of "res" and the amount, should it be same OR random??
Reply
#5

Quote:

I do understand that issue now, to fix that, you shouldn't use random, but use the loop or mark the position that is already used.

Mind showing me an example so I can understand easier?

Quote:

But you haven't explained the use of "res" and the amount, should it be same OR random??

The 'amount' variable is simply the amount of said item that will spawn (ex. You have picked up 10 meat.)

'Res' is merely a random variable that determine which selection of items will spawn. I can't use anything that randomizes the items themselves as each item has a unique item type assigned to them since some of the items share the same object id. If an item doesn't use their unique item type id, they simply don't work.
Reply
#6

I looked at your code and decided to try to take away from it what I could and ended up with this:

pawn Код:
//all the current items you can get

new ItemSpawns[][2] =
{
    {2806, 1}, //meat
    {2806, 2}, //steak
    {2663, 1}, //cram
    {2663, 2}, //mac cheese
    {2769, 1}, //iguana
    {2769, 2}, //squirrel
    {1580, 1}, //stimpak
    {1580, 2}, //doc bag
    {1575, 1}, //jet
    {1575, 2}, //psycho
    {1575, 3}, //mentats
    {1575, 4}, //buffout
    {2647, 1}, //dirty water
    {2647, 2}, //pure water
    {1484, 1}, //nuka
    {1577, 1}, //radaway
    {373, 1}, //armor
    {333, 1}, //golf club
    {334, 1}, //baton
    {335, 1}, //combat knife
    {336, 1}, //bat
    {337, 1}, //shovel
    {338, 1}, //pool cue
    {339, 1}, //katana
    {346, 1}, //colt 45
    {348, 1}, //deagle
    {349, 1}, //shotgun
    {351, 1}, //spaz
    {353, 1}, //smg
    {356, 1}, //m4
    {357, 1}, //rifle
    {358, 1}, //sniper
    {2358, 1}, //pistol ammo
    {2358, 2}, //shotgun ammo
    {2358, 3}, //smg ammo
    {2358, 4}, //assault rifle ammo
    {2358, 5} //rifle ammo
};
pawn Код:
forward LootRespawn();
public LootRespawn()
{
    new Items = random(sizeof(ItemSpawns));
    new amount = randomEx(1, 10);
    for(new i=0; i<MAX_ITEMS; i++)
    {
        DeleteAllItems(i);
        if(ItemSpawns[Items][0] == 333 || ItemSpawns[Items][0] == 334 || ItemSpawns[Items][0] == 335 || ItemSpawns[Items][0] == 336 || ItemSpawns[Items][0] == 337 || ItemSpawns[Items][0] == 338 || ItemSpawns[Items][0] == 339 ||
        ItemSpawns[Items][0] == 346 || ItemSpawns[Items][0] == 348 || ItemSpawns[Items][0] == 349 || ItemSpawns[Items][0] == 351 || ItemSpawns[Items][0] == 353 || ItemSpawns[Items][0] == 356 || ItemSpawns[Items][0] == 357 ||
        ItemSpawns[Items][0] == 338) amount = 1;
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 377.64130, 2542.36963, 15.53980, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 381.50552, 2542.74146, 15.53976, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 381.19205, 2539.23486, 15.54050, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 378.27368, 2539.07715, 15.54048, 0, 0);
        LoadItemVisual(i);
    }
    return 1;
}
However the issue hasn't changed much. The items now spawn in each of their own locations, but they are all the same item and not randomized.
Reply
#7

Anyone?
Reply
#8

That's because you only randomize the item once. You should add it to the for loop.
Reply
#9

pawn Код:
forward LootRespawn();
public LootRespawn()
{
        new Items, amount;
    for(new i=0; i<MAX_ITEMS; i++)
    {
        DeleteAllItems(i);
     Items = random(sizeof(ItemSpawns));
    amount = randomEx(1, 10);
        if(ItemSpawns[Items][0] == 333 || ItemSpawns[Items][0] == 334 || ItemSpawns[Items][0] == 335 || ItemSpawns[Items][0] == 336 || ItemSpawns[Items][0] == 337 || ItemSpawns[Items][0] == 338 || ItemSpawns[Items][0] == 339 ||
        ItemSpawns[Items][0] == 346 || ItemSpawns[Items][0] == 348 || ItemSpawns[Items][0] == 349 || ItemSpawns[Items][0] == 351 || ItemSpawns[Items][0] == 353 || ItemSpawns[Items][0] == 356 || ItemSpawns[Items][0] == 357 ||
        ItemSpawns[Items][0] == 338) amount = 1;
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 377.64130, 2542.36963, 15.53980, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 381.50552, 2542.74146, 15.53976, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 381.19205, 2539.23486, 15.54050, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 378.27368, 2539.07715, 15.54048, 0, 0);
        LoadItemVisual(i);
    }
    return 1;
}
Reply
#10

Quote:
Originally Posted by Joe Staff
Посмотреть сообщение
pawn Код:
forward LootRespawn();
public LootRespawn()
{
        new Items, amount;
    for(new i=0; i<MAX_ITEMS; i++)
    {
        DeleteAllItems(i);
     Items = random(sizeof(ItemSpawns));
    amount = randomEx(1, 10);
        if(ItemSpawns[Items][0] == 333 || ItemSpawns[Items][0] == 334 || ItemSpawns[Items][0] == 335 || ItemSpawns[Items][0] == 336 || ItemSpawns[Items][0] == 337 || ItemSpawns[Items][0] == 338 || ItemSpawns[Items][0] == 339 ||
        ItemSpawns[Items][0] == 346 || ItemSpawns[Items][0] == 348 || ItemSpawns[Items][0] == 349 || ItemSpawns[Items][0] == 351 || ItemSpawns[Items][0] == 353 || ItemSpawns[Items][0] == 356 || ItemSpawns[Items][0] == 357 ||
        ItemSpawns[Items][0] == 338) amount = 1;
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 377.64130, 2542.36963, 15.53980, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 381.50552, 2542.74146, 15.53976, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 381.19205, 2539.23486, 15.54050, 0, 0);
        CreateItem(ItemSpawns[Items][0], amount, ItemSpawns[Items][1], 378.27368, 2539.07715, 15.54048, 0, 0);
        LoadItemVisual(i);
    }
    return 1;
}
I did this before you posted this and I had no luck (I think anyways, I've lost track of how many things I've been doing to make this work :/)

pawn Код:
forward LootRespawn();
public LootRespawn()
{
    new amount = randomEx(1, 5);
    for(new i=0; i<MAX_ITEMS; i++)
    {
        DeleteAllItems(i);
    }
    for(new i=0; i<sizeof(ItemSpawns); i++)
    {
        for(new j=0; j<sizeof(RandomItems); j++)
        {
            CreateItem(RandomItems[j][0], amount, RandomItems[j][1], ItemSpawns[i][0], ItemSpawns[i][1], ItemSpawns[i][2], 0, 1);
        }
    }
    for(new i=0; i<MAX_ITEMS; i++)
    {
        LoadItemVisual(i);
    }
    return 1;
}
I've been trying to try this one, but when I try to connect to localhost, I get this.
Код:
[connection] 127.0.0.1:63958 request connection cookie.
Kicking 127.0.0.1 because they didn't logon to the game.
Before you ask, I am 100% sure this piece of code is what's causing this issue as I can connect to the server fine when I comment this code out of the script, but I have no clue what's wrong with this as I have something that's does the same type of thing but doesn't pose an issue.
pawn Код:
//The code for reference

forward UpdateHouseData();
public UpdateHouseData()
{
    foreach(Player, i)
    {
        for(new j = 0; j<MAX_HOUSES; j++)
        {
            if(fexist(HousePath(i)))
            {
                if(IsPlayerInRangeOfPoint(i, 1, House[j][ExtPosX], House[j][ExtPosY], House[j][ExtPosZ]))
                {
                    ShowHouseInfo(i, j, 2000);
                }
            }
        }
    }
    return 1;
}

EDIT: nvm, this doesn't work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)