Raised This Month: $12 Target: $400
 3% 

[L4D2] l4d2_weapons.inc


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
disawar1
AlliedModders Donor
Join Date: Aug 2011
Location: Russian
Old 07-31-2020 , 08:07   [L4D2] l4d2_weapons.inc
Reply With Quote #1

About:
Provides a set of functions to identify, validate and spawn weapons/melees.

Features:
- Support SourceMod 1.7, 1.11 Transitional Syntax.
- A lot of weapons/melees functions.
- Provides weapons/melees data: ID, names, models etc.

API structure:
Since the weapon_melee class contains its own melees the code has been logically divided into two parts: WEAPON and MELEE.
Both parts have functions to check for garbage value and identify their type of weapon.
The ITEM struct is needed to determine to which type (WEAPON / MELEE) an entity or weapon name belongs.

Usages:
Use L4D2Wep_Identify, L4D2Wep_NameToIDEx for WEAPON and L4D2Wep_IdentifyMelee, L4D2Wep_MeleeNameToID functions for MELEE to identify their ID by entity or class name.
If you want the code work for both types (ITEMS) use L4D2Wep_IdentifyItemByName, L4D2Wep_IdentifyItemByEnt functions to identify (See example).

When you got an WEAPON / MELEE / ITEM ID you can do following things:
- Filter weapon/melee entities.
- Grab info about: model, weapon name, weapon slot index, check for spawn class
- Create any weapons as weapon_ or _spawn class (Fixed pos/angles)
- Create any melees as weapon_melee or weapon_melee_spawn class (Fixed pos/angles)
- Give a weapon/melee to player (based on give cmd)
- Sets a weapon max ammo (based on convars)
- Sets a weapon max ammo to player (based on offsets)

API:
PHP Code:
// Weapons:
void L4D2Wep_Init()
char[] L4D2Wep_GetNameByID(int wepID)
bool L4D2Wep_HasSpawnClass(int wepID)
char[] L4D2Wep_GetModelByID(int wepID)
int L4D2Wep_GetSlotByID(int wepID)
bool L4D2Wep_IsValidID(int wepID)
bool L4D2Wep_HasValidModel(int wepID)
int L4D2Wep_NameToID(char[] weaponName)
int L4D2Wep_NameToIDEx(char[] weaponName)
int L4D2Wep_Identify(int entityint flags IDENTIFY_SAFE)
void L4D2Wep_PrecacheModels()
// Weapons Helpers:
void L4D2Wep_AddSpawnSuffix(char[] weaponNamechar[] storeint len)
void L4D2Wep_RemoveSpawnSuffix(char[] weaponNameint Len 0)
int L4D2Wep_HasSpawnSuffix(char[] weaponName)
bool L4D2Wep_IsValidAndEntity(int entity)
bool L4D2Wep_IsEntity(int entity)
// Meeles:
void L4D2Wep_InitMelees()
char L4D2Wep_GetMeleeNameByID(int meleepID)
char L4D2Wep_GetMeleeModelByID(int meleepID)
bool L4D2Wep_IsValidMeleeID(int meleeID)
int L4D2Wep_MeleeNameToID(char[] meleeName)
int L4D2Wep_IdentifyMelee(int entityint flags IDENTIFY_SAFE)
void L4D2Wep_OnMapStart()
bool L4D2Wep_IsValidMelee(char[] meleeName)
bool L4D2Wep_IsValidMeleeIDEx(int meleeID)
void L4D2Wep_PrecacheMeleeModels()
// Items:
int L4D2Wep_IdentifyItemByEnt(int entityint &anyID 0int flags IDENTIFY_SAFE)
int L4D2Wep_IdentifyItemByName(char[] anyNameint &anyID 0)
int L4D2Wep_IdentifyEquipSlot(int entity)
bool L4D2Wep_IsValidItemAndID(int anyIDint itemType)
bool L4D2Wep_IsItemNoneID(int anyIDint itemType)
bool L4D2Wep_IsValidItemID(int anyIDint itemType)
void L4D2Wep_GiveItemByName(int clientchar[] weaponName)
void L4D2Wep_GiveItemByID(int clientint anyIDint itemType)
// Ammo:
void L4D2Wep_InitAmmoCvars()
int L4D2Wep_WepIDToAmmoID(int wepID)
int L4D2Wep_GetAmmo(int ammoID)
bool L4D2Wep_SetAmmoByID(int entityint wepID)
int L4D2Wep_WepIDToOffset(int wepID)
int L4D2Wep_GetPlayerAmmo(int client)
bool L4D2Wep_SetPlayerAmmo(int clientint maxAmmo)
// Spawn:
int L4D2Wep_SpawnItem(int anyIDint itemTypefloat origin[3], float angles[3] = {0.0, ...}, bool applyVecFix truebool spawn trueint count 5)
int L4D2Wep_Spawn(int wepIDfloat origin[3], float angles[3] = {0.0, ...}, bool applyVecFix truebool spawn trueint count 5)
int L4D2Wep_SpawnMelee(int meleeIDfloat origin[3], float angles[3] = {0.0, ...}, bool applyVecFix truebool spawn trueint count 5)
int L4D2Wep_ConvertWeaponSpawn(int entityint wepIDint count 5, const char[] model "")
// Fixes:
void L4D2Wep_FixModelVectors(int wepIDfloat origin[3], float angles[3])
void L4D2Wep_FixMeleeModelVectors(int meleeIDfloat origin[3], float angles[3]) 
Note:
l4d2_weapons does not provide a way to unlock weapons, for this goal you may use any known plugins or extensions. However, if you unlock any vanilla weapons like a knife the l4d2_weapons will detect it and support.
If you want to add custom weapons support to l4d2_weapons look at line custom melee for example.

Examples:
l4d2_weapons_test.sp plugin provides examples of how this API can be used.

Credits:
- Forked from MatthewClair/sourcemod-plugins
- Thanks Electr0 for method to detect valid melees via string table.

Source Code:
l4d2_weapons.inc
__________________

Last edited by disawar1; 09-26-2020 at 16:09.
disawar1 is offline
disawar1
AlliedModders Donor
Join Date: Aug 2011
Location: Russian
Old 09-26-2020 , 16:10   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #2

Updated! Added The Last Stand melee weapons.
__________________
disawar1 is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 10-10-2020 , 15:16   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #3

Thank you. Looks very useful for me.
That's great you updated it with the latest stuff.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 10-10-2020 , 19:24   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #4

Sounds great I've been wanting something like this over the years, thank you!

When you say "Name" is that actual weapon name like "Grenade Launcher" or classname like "weapon_grenade_launcher"? If the former is that only in English or based on server language? Would be useful to get weapon names depending on specific clients language since I've never wanted to hard code weapon names in translations. I've never looked into getting them from translations though but that could be very useful.
__________________
Silvers is offline
fdxx
Member
Join Date: Oct 2020
Location: 0xdeadbeef
Old 05-20-2021 , 02:45   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #5

thanks
fdxx is offline
fdxx
Member
Join Date: Oct 2020
Location: 0xdeadbeef
Old 05-20-2021 , 02:54   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #6

But when I spawning weapon, what is the difference between "weapon_..._spawn" and "weapon_..."?

That is, Difference between have "_spawn" and not have "_spawn".
fdxx is offline
Silvers
SourceMod Plugin Approver
Join Date: Aug 2010
Location: SpaceX
Old 05-20-2021 , 03:29   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #7

"_spawn" allows you to set a weapon count and pickup the same weapon multiple times by different survivors. It also swallows the same weapon if dropped nearby when picking up a different weapon type of the same slot.
__________________
Silvers is offline
fdxx
Member
Join Date: Oct 2020
Location: 0xdeadbeef
Old 05-20-2021 , 22:17   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #8

Quote:
Originally Posted by Silvers View Post
"_spawn" allows you to set a weapon count and pickup the same weapon multiple times by different survivors. It also swallows the same weapon if dropped nearby when picking up a different weapon type of the same slot.
Understand, Silvers, thank you.
fdxx is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 08-05-2021 , 10:19   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #9

disawar1, a question: is it by intension "l_sMeleeNames" array has weapon names without "weapon_" prefix, and "l_sWeaponNames" array has?
Such a way L4D2Wep_GetNameByID() mostly always returns "weapon_*",
and L4D2Wep_GetMeleeNameByID() without.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Dragokas
Veteran Member
Join Date: Nov 2017
Location: Ukraine on fire
Old 08-05-2021 , 10:35   Re: [L4D2] l4d2_weapons.inc
Reply With Quote #10

Also, as an improvement. I found quite non-convenient to create plugin uses your weapon Id system, if I need to store settings per-slot, because you have collision between melee id and primary weapon array id for slot 1, e.g.:

1 - weapon_pistol
20 - weapon_chainsaw
32 - weapon_pistol_magnum
0-16 - all melee (e.g. 1 = baseball_bat)

So, e.g. if I store weapon id = 1 in player's cookie for slot 1, there is no way to identify what weapon is it (pistol or baseball_bat).
Maybe, it make sense to shift indeces or rearrange them a bit to prevent those single collision.
__________________
Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch & FreeZone)
[My plugins] [My tools] [GitHub] [Articles] [HiJackThis+] [Donate]
Dragokas is offline
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 19:57.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode