FOnline Development > Questions and Answers
Making a container spawn x bag each 30 real time minutes
(1/1)
Grey:
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: ---//////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;
}
--- End code ---
I have it working but what I want is to add the items through bags from _bags.fos
AnarchCassius:
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.
Grey:
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: ---#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;
}
--- End code ---
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.
mojuk:
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
Grey:
Yes, but the thing is how to make them "refresh"? I take that for other purposes anyway, it could be userful.
Navigation
[0] Message Index
Go to full version