VIP

New GameMaps in development!

x

We are working hard to bring you the best experience possible with our upcoming relaunch!

You can help fund the relaunch by
Upgrading to VIP or Donating.

  • VIP Goal Progress: 100% Goal Reached!
  • Top Donator: Anonymous ($100)
Left 4 Dead 2
Left 4 Dead 2 is a single-player and multiplayer co-operative survival horror FPS game.
VSLib Developer Guide - Random Item Spawning
7,096
This guide describes how to use the Random Item Spawning feature in VSLib. 

The feature gives you the ability to randomly spawn items at set spawnpoints at any time in your mutation or mod.

Class reference: https://l4d2scripters.github.io/vslib/docs/db/d2b/class_v_s_lib_1_1_random_item_spawner.html
Usage
To initialize a spawner create a spawner object:
VSLib.RandomItemSpawner(spawnArray, itemArray = null, flags = 0)

Arguments:

spawnArray: An array of vectors or VSLib entity objects for the location spawn points.

itemArray: An array of spawnable items (see Spawn Lists for more information).

itemList: Use a custom item list of the same format as the one below.

flags:
RANDOM_USEPARTICLES: Spawns a fireworks particle effect where an item spawns.
RANDOM_ALLOWMULTIPLEITEMS: Can spawn multiple items on the same spawnpoint during a single call of SpawnRandomItems().


Example:
mySpawner <- VSLib.RandomItemSpawner(mySpawnArray, myItemArray, (RANDOM_USEPARTICLES | RANDOM_ALLOWMULTIPLEITEMS));


Items are spawned with: SpawnRandomItems(amount)
Where amount is the number of items spawned. The function returns an array with the entity objects of the items spawned.

Example:
spawnedItemArray = mySpawner.SpawnRandomItems(5);
Spawn Lists
This list determines what items can spawn, and the probability of each weapon spawning. If no list is specified, the default one below is used.

The item probability is relative to the other items, the actual spawning probability is the items probability divided by the probabilities of all items added together.

Melee weapons and upgrades get converted to other entities when they spawn. They are untrackable, and will not be returned by the spawning function.

ent: Classname of the item. The spawn list currently supports the entities specified below.
prob: This is the probability for the item to spawn.
ammo: The ammo reserves primary weapons spawn with. Weapons spawn with double the value set. Set to null on other items.
melee_type: Works the same way as on a weapon_melee_spawn. Set to null if not a melee weapon.
myItemArray <-
[
	//Entity:				Probability:	Ammo:		Melee type:
	{ent = "weapon_rifle"			prob = 10,	ammo = 50,	melee_type = null	},
	{ent = "weapon_shotgun_spas"		prob = 10,	ammo = 10,	melee_type = null	},
	{ent = "weapon_sniper_military"		prob = 10,	ammo = 15,	melee_type = null	},
	{ent = "weapon_rifle_ak47"		prob = 10,	ammo = 40,	melee_type = null	},
	{ent = "weapon_autoshotgun"		prob = 10,	ammo = 10,	melee_type = null	},
	{ent = "weapon_rifle_desert"		prob = 10,	ammo = 60,	melee_type = null	},
	{ent = "weapon_hunting_rifle"		prob = 15,	ammo = 15,	melee_type = null	},
		
	{ent = "weapon_rifle_m60"		prob = 2,	ammo = 50,	melee_type = null	},
	{ent = "weapon_grenade_launcher"	prob = 2,	ammo = 50,	melee_type = null	},
		
	{ent = "weapon_smg_silenced"		prob = 20,	ammo = 50,	melee_type = null	},
	{ent = "weapon_smg"			prob = 20,	ammo = 50,	melee_type = null	},
	{ent = "weapon_shotgun_chrome"		prob = 20,	ammo = 10,	melee_type = null	},
	{ent = "weapon_pumpshotgun"		prob = 20,	ammo = 10,	melee_type = null	},
		
	{ent = "weapon_pistol_magnum"		prob = 5,	ammo = null,	melee_type = null	},
	{ent = "weapon_pistol"			prob = 10,	ammo = null,	melee_type = null	},
		
	{ent = "weapon_adrenaline" 		prob = 10,	ammo = null,	melee_type = null	},	
	{ent = "weapon_pain_pills" 		prob = 20,	ammo = null,	melee_type = null	},
	{ent = "weapon_vomitjar" 		prob = 3,	ammo = null,	melee_type = null	},
	{ent = "weapon_molotov" 		prob = 10,	ammo = null,	melee_type = null	},
	{ent = "weapon_pipe_bomb" 		prob = 10,	ammo = null,	melee_type = null	},
	{ent = "weapon_first_aid_kit" 		prob = 1,	ammo = null,	melee_type = null	},
		
		
	// Note: These items don't retain their entities when spawned, and cannot be tracked.
	{ent = "weapon_melee_spawn"		prob = 10,	ammo = null,	melee_type = "any"	},
	{ent = "upgrade_spawn" 			prob = 3,	ammo = null,	melee_type = null	}, // Laser sight only
	{ent = "weapon_upgradepack_explosive" 	prob = 5,	ammo = null,	melee_type = null	},
	{ent = "weapon_upgradepack_incendiary"	prob = 7,	ammo = null,	melee_type = null	}	
]
I found this article helpful
I did not find this article helpful
What people are saying...
You must be logged in to post a comment.
There are no comments yet for this guide.