Author Topic: Making a container spawn x bag each 30 real time minutes  (Read 2621 times)

Making a container spawn x bag each 30 real time minutes
« on: March 07, 2017, 02:31:04 pm »
The concept idea is to make a certain container in a certain map, spawn a bag (or some items randomly) and make it "refresh" each 30 real minutes.

This is what I got so far.

Code: [Select]
//////randomizer spawner clutter A

void _ItemConA( Item& item, bool firstTime )
{
CreateTimeEvent( __FullSecond + REAL_MINUTE( 1 ), "e_AddItemSelfA", item.Id, true );
}

uint e_AddItemSelfA(uint[] @ values)
{
Item@ item = GetItem( values[ 0 ] );
item.AddItem( PID_BOTTLE_CAPS, Random( 0, 100 ), 0 );
item.AddItem( PID_ANTIDOTE, Random( 0, 1 ), 0 );
item.AddItem( PID_BLUE_CONDOM, Random( 0, 1 ), 0 );

CreateTimeEvent( __FullSecond + 20, "e_AddItemSelfA", item.Id, true );
return 0;
}

I have it working but what I want is to add the items through bags from _bags.fos
« Last Edit: March 07, 2017, 05:06:31 pm by Grey »

Re: Making a container spawn x bag each 30 real time minutes
« Reply #1 on: March 07, 2017, 08:03:22 pm »
Take a look at spawner_containers.fos. Don't mind the terrible formating on some of the entries.

It basically is a whole system for doing this. You can set a timer, a locking value and so on.

On the other hand _bags works great for non-respawning loot but I don't think it respawns.

Either way you shouldn't need much need code at all for random treasure generation. The game has like 2-5 systems already in place for that.

Re: Making a container spawn x bag each 30 real time minutes
« Reply #2 on: March 08, 2017, 12:20:27 am »
You're right. It's not possible to make it respawn if it's a Bag. Also, trying to port the script you said from 2238 SDK to my engine can be a pain in the ass.

This is the code I used BTW. If anyone is interested. I took it from here (all the credits goes for them not me) : http://fonline.ru/forum/threads/4986/

Code: [Select]
#include "_macros.fos"
#include "_itempid.fos"
#include "_bags.fos"
#include "_defines.fos"

void _ItemConA( Item& item, bool firstTime )
{
CreateTimeEvent( __FullSecond + REAL_MINUTE( 30 ), "e_AddItemSelfA", item.Id, true );
}
 
uint e_AddItemSelfA(uint[] @ values)
{
Item@ item = GetItem( values[ 0 ] );

if( CountContainerItems( item ) > 0 )
{
CreateTimeEvent( __FullSecond + REAL_MINUTE( 30 ), "e_AddItemSelfA", item.Id, true );
return 0;
}
else
{
item.AddItem( PID_BOTTLE_CAPS, Random( 0, 1 ), 0 );
CreateTimeEvent( __FullSecond + REAL_MINUTE( 30 ), "e_AddItemSelfA", item.Id, true );
}
return 0;
}

uint CountContainerItems( Item& container )
 
{
 
Item@ item;
 
Item@[] items;
 
uint  count = 0;
 
container.GetItems( 0, items );
 
for( uint i = 0, l = items.length(); i < l; i++ )
 
{
 
@item = items[ i ];
 
if( valid( item ) )
 
{
 
if( item.GetType() == ITEM_TYPE_WEAPON ||
 
item.GetType() == ITEM_TYPE_ARMOR ||
 
item.GetType() == ITEM_TYPE_DRUG )
 
count += item.GetCount();
 
else
 
count += 1;
 
}
 
}
 
return count;
 
}

Basically, it creates a randomizer in a container. If the container is empty, it generates 0 or 1 bottlecaps each 30 minutes. If not, stays like that.

Re: Making a container spawn x bag each 30 real time minutes
« Reply #3 on: March 08, 2017, 04:44:45 pm »
You can use bags in spawners.
Here is some code from 2238 used to spawn items into new character's inventory, you can easily change that to spawning into container:
https://github.com/rotators/fo2238/blob/master/Server/scripts/main.fos#L1734-L1750

Re: Making a container spawn x bag each 30 real time minutes
« Reply #4 on: March 10, 2017, 12:22:50 am »
Yes, but the thing is how to make them  "refresh"? I take that for other purposes anyway, it could be userful.