Introduction
Smart Item Selector (sIs) is based on
[L4D & L4D2] Round Start Items Giver by kwski43, but takes "item giving" to another level.
sIs intelligently gives selected items to survivors each time they spawn and includes an option to give different items to VIP/admins.
This is my first public plugin so constructive feedback is welcome.
sIs Goals
Simplify: by eliminating the need for numerous timers there are fewer cvars to set and hopefully, increased reliability.
Add intelligence: only give items if they are needed or according to a prioritization system. No brute-force item giving and no excess item spawns.
Add VIP/admin options: offer server operators the option to give different items to VIP/admins based on one or more flags.
Add flexibility: give items anytime a player spawns (first spawn, bot takeover, rescue closet, re-spawn, joining an in-progress map, etc.) not just at round start.
The Prioritization System
sIs uses a 3-tier prioritization system comprised of base, random, and VIP item selections.
A base item selection is overridden by a random item selection and both of those are overridden by a VIP item selection.
However, an override will only occur for the same item type (i.e. a VIP primary weapon selection only overrides the other primary weapon selections).
1. Example: if you configure a base primary weapon and a random primary weapon and a vip primary weapon, survivors will receive a random primary weapon (overrides the base item)
but VIPs will receive the VIP weapon (overrides the base and random item).
2. Example: if you configure a base primary weapon and a random SECONDARY weapon and a VIP primary weapon, survivors will receive the base primary weapon and a random secondary weapon.
VIPs will receive the VIP primary weapon (overrides the base item) and a random secondary weapon.
Item Replacement Logic
1. Health Items: These always have priority. If a survivor has an ammo upgrade pack on their back and a health item is configured (base, random or VIP),
the health item will replace (but not destroy) the upgrade pack.
2. Default pistol: when a player spawns on the first map of a new campaign, he receives a default pistol. If you configured a secondary weapon selection AND set
l4d2_sis_remove_pistol "1", sIs
will remove (destroy) the default pistol and replace it with the selected secondary weapon. This is done primarily to eliminate pistol drop clutter on large co-op servers when new items are given.
3. All other weapons/items: sIs looks at each survivor's weapon slots and if they are occupied (other than with a default pistol) it will not give them a new item.
VIP selections are the exception. If the VIP's existing weapon/item is not the configured VIP item, it will be replaced by the VIP selection, but not destroyed.
Note: incendiary and explosive ammo upgrades are treated as equal and mutually exclusive. If a survivor has either one of them and your item configuration calls for the other
ammo upgrade, the existing ammo upgrade will not be replaced. An argument can be made that either incendiary or explosive should have priority (I think explosive should), but I chose
not to make that judgement call for this first release. If there is sufficient need for a prioritized ammo selection, I will try to add it.
Using Vip/Admin flags:
Add one or more admin flags that should receive Vip/admin items to
l4d2_sis_vip_flags Multiple flags are accepted, just don't separate them with spaces or other characters.
Players with
any of those flags will receive the VIP/Admin items. This was done to provide greater flexibility for server operators when configuring VIP options.
To disable the VIP option, just set the VIP item cvars to zero. No need to remove the flag(s) from
l4d2_sis_vip_flags setting.
1. Example: if you set
l4d2_sis_vip_flags "a", only players with the "a" flag will recieve VIP items.
2. Example: if you set
l4d2_sis_vip_flags "abo", players with either the "a", "b" or "o" (custom1) flag will receive VIP items.
Chat Message:
l4d2_sis_info_message 1 will display a message like this to each player if they are given items. The message is customized to only show the item(s) they received.
Thank You:
Dragokas - code review, help and ideas, and the Russian translation.
nosoop - example code to handle the weapon upgrade bitvec and optimization
Crasher_3637 - code review and optimization
Lux - code review
Silvers - for his great formatting
l4d Competitive community for creating the original l4d2_weapon_stocks.inc
Optional dependency for the Knife:
To use the knife option for a secondary weapon, your must have the
[L4D2] Knife Unlock plugin by Silvers installed on your server.
Smart Item Selector checks for the Knife Unlock plugin and if it is not found, substitutes another melee weapon for the knife.
Bugs:
None so far...
To Do:
1. Add server message that reports if the knife unlock plugin is not running and which melee weapon will be substituted for the knife.
2. Release an update with support for l4d.
Possible Future Upgrade:
1. Add a menu for VIP/admins to configure a personalized equipment load-out. Data storage method TBD.
2. Add Silvers game mode toggle code so server operators can chose in which modes sIs is enabled.
CVars:
- All cvars, except for the plugin enable, VIP/admin flag,pistol replace, & active weapon slot cvars are set to 0 or off by default for easier configuration.
PHP Code:
// [L4D2] Smart Item Selector by Patriot Games
// Selectively gives items to survivors when they spawn and inlcudes VIP/admin options.
// ConVars for plugin "l4d2_smart_item_selector.smx"
/* ========== Settings ========== */
// Is the Smart Item Selector plugin enabled? 0=Plugin off, 1=Plugin on.
// -
// Default: "1"
l4d2_sis_enable "1"
// Send each player a message informing them which item(s) they recieved?. 0=off, 1=on.
// -
// Default: "0"
l4d2_sis_info_message "0"
// Weapon slot to equip after all weapons/items are given.
// 1=primary, 2=secondary, 3=throwable, 4=healthkit, 5=meds
// -
// Default: "1"
// Minimum: "1"
// Maximum: "5"
l4d2_sis_lastslot "1"
// Remove the default pistol before giving another secondary weapon?. 0=No, 1=Yes.
// Eliminates pistol drop clutter when another secondary is given.
// -
// Default: "1"
l4d2_sis_remove_pistol "1"
// Survivors with any of these flags will receive VIP/admin items. Multiple flags are accepted (e.g. "abc")
// [example admin flags: a=Reservation, b=Generic, c=Kick, d=Ban, o=custom1, etc.]
// -
// Default: "a"
l4d2_sis_vip_flags "a"
/* ========== Base Item Selections ========== */
// Give survivors a Primary Weapon?
// 0=disable, 1=pump shotgun, 2=chrome shotgun, 3=spas shotgun, 4=autoshotgun, 5=smg, 6=smg silenced, 7=smg mp5, 8=M16, 9=AK47, 10=Desert rifle, 11=SG552, 12=Hunting rifle, 13=Scout sniper, 14=Military sniper, 15=AWP sniper
// -
// Default: "0"
l4d2_sis_primary_choice "0"
// Give survivors a Secondary Weapon?
// 0=disable, 1=magnum pistol, 2=knife (requires [L4D2]Knife Unlock plugin), 3=frying pan, 4=tonfa, 5=crowbar, 6=cricket bat, 7=baseball bat, 8=machete, 9=katana, 10=golf club, 11=fire axe, 12=electric guitar
// -
// Default: "0"
l4d2_sis_secondary_choice "0"
// Give survivors a Health Item? 0=disable, 1=medkit, 2=defib
// -
// Default: "0"
l4d2_sis_health_choice "0"
// Give survivors Meds? 0=disable, 1=pills, 2=adrenaline
// -
// Default: "0"
l4d2_sis_meds_choice "0"
// Give survivors a Throwable? 0=disable, 1=pipe bomb, 2=molotov, 3=bile jar
// -
// Default: "0"
l4d2_sis_throwable_choice "0"
// Give survivors an Upgrade? 0=disable, 1=laser, 2=incendiary ammo, 3=explosive ammo
// -
// Default: "0"
l4d2_sis_upgrade_choice "0"
/* ========== Random Item Selections ========== */
// Give survivors a random Primary Weapon? Overrides base primary weapon setting. 0=disable, 1=enable.
// -
// Default: "0"
l4d2_sis_random_primary "0"
// Give survivors a random Secondary Weapon? Overrides base secondary weapon setting. 0=disable, 1=enable.
// -
// Default: "0"
l4d2_sis_random_secondary "0"
// Give survivors a random Health item? Overrides base health item setting. 0=disable, 1=enable.
// -
// Default: "0"
l4d2_sis_random_health "0"
// Give survivors random Meds? Overrides base meds setting. 0=disable, 1=enable.
// -
// Default: "0"
l4d2_sis_random_meds "0"
// Give survivors a random Throwable? Overrides base throwable setting. 0=disable, 1=enable.
// -
// Default: "0"
l4d2_sis_random_throwable "0"
// Give survivors a random Upgrade? Overrides base upgrade settings. 0=disable, 1=enable.
// -
// Default: "0"
l4d2_sis_random_upgrade "0"
/* ========== VIP Item Selections ========== */
// Give VIPs a Primary Weapon? Overrides base and random primary settings.
// 0=disable, 1=pump shotgun, 2=chrome shotgun, 3=spas shotgun, 4=autoshotgun, 5=smg, 6=smg silenced, 7=smg mp5, 8=M16, 9=AK47, 10=Desert rifle, 11=SG552, 12=Hunting rifle, 13=Scout sniper, 14=Military sniper, 15=AWP sniper
// -
// Default: "0"
l4d2_sis_vip_primary_choice "0"
// Give VIPs a Secondary Weapon? Overrides base and random secondary settings.
// 0=disable, 1=magnum pistol, 2=knife (requires [L4D2]Knife Unlock plugin), 3=frying pan, 4=tonfa, 5=crowbar, 6=cricket bat, 7=baseball bat, 8=machete, 9=katana, 10=golf club, 11=fire axe, 12=electric guitar
// -
// Default: "0"
l4d2_sis_vip_secondary_choice "0"
// Give VIPs a Health Item? Overrides base and random health settings.
// 0=disable, 1=medkit, 2=defib
// -
// Default: "0"
l4d2_sis_vip_health_choice "0"
// Give VIPs Meds? Overrides base and random meds settings.
//0=disable, 1=pills, 2=adrenaline
// -
// Default: "0"
l4d2_sis_vip_meds_choice "0"
// Give VIPs a Throwable? Overrides base and random throwable settings.
//0=disable, 1=pipe bomb, 2=molotov, 3=bile jar
// -
// Default: "0"
l4d2_sis_vip_throwable_choice "0"
// Give VIPs an Upgrade? Overrides base and random upgrade settings.
// 0=disable, 1=laser, 2=incendiary ammo, 3=explosive ammo
// -
// Default: "0"
l4d2_sis_vip_upgrade_choice "0"
Changes:
PHP Code:
v1.2 (5-Mar-2019)
- Added cvar to choose which weapon is active after items are given.
- Added code to change game cvar "survivor_respawn_with_guns" value to "0"
- Added chat message that prints if the knife is selected but knife unlock plugin is not running
- Removed duplicate chainsaw entries in l4d2_weapon_stocks_sis.inc so sIs will compile on sm 1.10
- Updated translation file with new knife_warning chat message
- Added a formatted l4d2_smart_item_selector.cfg with all cvars in logical groups.
1.1 (1-Mar-2019)
- corrected mismatched config and selection values for primary and melee weapons
- reformatted & wrapped cvar descriptions so all values print in the cfg file
1.0 (24-Feb-2019)
- Initial release.
Compiling:
1. Put the l4d2_weapon_stocks_sis.inc include into your \addons\sourcemod\scripting\include\ folder.
2. Put the plugins .sp file into your scripting folder and compile the plugin.
Installation: individual files
1. Put the l4d2_smart_item_selector.smx file in your server's \addons\sourcemod\plugins\ folder.
2. Put the l4d2_smart_item_phrases.txt file in your server's \addons\sourcemod\translations\ folder.
3. Restart your server and then set your item preferences in the \cfg\sourcemod\l4d2_smart_item_selector.cfg file.
4. Restart your server or change the map.
Installation: zip file
1. Extract the SmartItemSelector.zip file.
2. Copy/upload all the files into their respective folders on your server.
3. Restart your server.