03.07.2014, 15:00
This include doesnt really provide a special feature, it is mainly an include to optimize NPC usage, reduce wasted player slots, and allow a better game experience when working with NPCs.
What is it?
The include actually provides a pool of ready RNPCs that can be used anytime for anything. It will fill the pool on server start, and once the NPCs connected they can be claimed for any task, and later returned to the pool to be available again for the next task. This might sound pretty useless, but this system has great advantages when working with many NPCs with minor roles - like NPCs standing in a shop - or in general NPC streaming.
You could either connect 50 NPCs and put them all in the shops, where they are standing all day, taking up 50 player slots, even if theres noone in their shop.
Or you connect a pool of 10 NPCs, and whenever a player enters a shop, a NPC from the pool is picked and teleported into the shop. And once the shop is empty again, the NPC is returned to the pool to be used again later.
It is very unlikely that there is some player in every shop at the same time, so by using the pool you can reduce the wasted slots without affecting the game experience. This can safe you real money if youre paying your server hoster per slots.
Sure, you could just connect a new NPC when a player enters a shop, and kick him once the player leaves, but the major problem about this is, that NPCs - just like players - need some seconds to connect and spawn. And it would totally ruin the game experience when the shop owner suddenly pops up seconds after you entered the shop.
--> Streaming NPCs nicely without a pool is impossible.
This include doesnt provide any streaming or NPC actions, it just offers the pool. I might however release an example script later that explains how to use the pool for streaming, but it really isnt difficult. The pool got a constant maximum size, and a current size that can be changed during the runtime. So if you notice youre running low on available NPCs you can simply increase the pool without restarting the server. Or if youre low on player slots, you can reduce the pool size to get additional free slots.
Usage:
This include is based on RNPC, so it requires the RNPC plugin.
Theres just some small reference to it, so it may also be changed to work with FCNPC or the stock NPCs.
Consider that connecting too many NPCs at once may cause flood warnings. So do not increase the pool size in too big steps, or the pool might get buggy.
before including this include in your script, you may define one of these settings:
Anywhere in your script you might use one of these functions then:
The source code also is widely documented, so this include may be used to learn more about how a pool could work.
Im very aware that this isnt interesting for everyone, but Im pretty sure that most people working with NPCs can benefit from it.
Any questions or suggestions? Just post them here.
Download/Links
Version 1.0 (3.7.2014)
RNPC plugin
What is it?
The include actually provides a pool of ready RNPCs that can be used anytime for anything. It will fill the pool on server start, and once the NPCs connected they can be claimed for any task, and later returned to the pool to be available again for the next task. This might sound pretty useless, but this system has great advantages when working with many NPCs with minor roles - like NPCs standing in a shop - or in general NPC streaming.
You could either connect 50 NPCs and put them all in the shops, where they are standing all day, taking up 50 player slots, even if theres noone in their shop.
Or you connect a pool of 10 NPCs, and whenever a player enters a shop, a NPC from the pool is picked and teleported into the shop. And once the shop is empty again, the NPC is returned to the pool to be used again later.
It is very unlikely that there is some player in every shop at the same time, so by using the pool you can reduce the wasted slots without affecting the game experience. This can safe you real money if youre paying your server hoster per slots.
Sure, you could just connect a new NPC when a player enters a shop, and kick him once the player leaves, but the major problem about this is, that NPCs - just like players - need some seconds to connect and spawn. And it would totally ruin the game experience when the shop owner suddenly pops up seconds after you entered the shop.
--> Streaming NPCs nicely without a pool is impossible.
This include doesnt provide any streaming or NPC actions, it just offers the pool. I might however release an example script later that explains how to use the pool for streaming, but it really isnt difficult. The pool got a constant maximum size, and a current size that can be changed during the runtime. So if you notice youre running low on available NPCs you can simply increase the pool without restarting the server. Or if youre low on player slots, you can reduce the pool size to get additional free slots.
Usage:
This include is based on RNPC, so it requires the RNPC plugin.
Theres just some small reference to it, so it may also be changed to work with FCNPC or the stock NPCs.
Consider that connecting too many NPCs at once may cause flood warnings. So do not increase the pool size in too big steps, or the pool might get buggy.
before including this include in your script, you may define one of these settings:
pawn Код:
#define RNPC_POOL_MAXSIZE // The absolute maximum pool size (default: 50)
#define RNPC_POOL_STARTSIZE // The initial size of the pool, will be filled on server start
pawn Код:
// Returns the playerid of a idle NPC from the pool, or INVALID_PLAYER_ID if the pool is empty
// The NPC counts as "in use" then, and must be returned later to be available again.
// fortask sets an ID for the current task of the NPC, this might be helpful for some stuff
PickRNPCFromPool(fortask)
// Returns the ID of the current task of the pool NPC,
// or -1 if the NPC either isnt in the pool, or currently got no task
GetPoolRNPCRole(npcid)
// Puts a NPC back into the pool, making him available for
// later use again
ReturnRNPCToPool(npcid)
// Sets the desired new size of the pool, either kicking
// NPCs, or connecting new ones
// The noactivekick parameter sets whether when reducing the
// size, only inactive NPCs should be kicked, even if the new pool
// size cant be reached then
// Returns the new pool size
SetRNPCPoolSize(newsize, noactivekick=1)
// Callback: Is called when the pool is used up, and
// a NPC was requested, but couldnt be provided
// might be helpful to increase the pool size automatically
OnRNPCPoolFull(curSize, maxSize)
Im very aware that this isnt interesting for everyone, but Im pretty sure that most people working with NPCs can benefit from it.
Any questions or suggestions? Just post them here.
Download/Links
Version 1.0 (3.7.2014)
RNPC plugin