Coder Social home page Coder Social logo

razieil / l4d2_weapons Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 1.0 99 KB

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

Home Page: https://forums.alliedmods.net/showthread.php?p=2712481#post2712481

License: GNU General Public License v3.0

SourcePawn 100.00%
l4d2 sourcemod sourcepawn l4d srcds weapon weapons inc melee

l4d2_weapons's Introduction

l4d2_weapons

The API for SourceMod plugin developers that provides stock of useful weapons function. Basically here the reworked version of weapons.inc. The include file was written specifically for Left 4 Dead 2 under SourceMod platform (SourcePawn).

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 weapons 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.

Migration to v1.2 (weapons.inc compatibility)

Function suffixes have been renamed in v1.2 according to the supported game (Left 4 Dead 2).
Find and replace the following prefixes to migrate to v1.2: L4DWEP_ to L4D2WEP_, L4DWep_ to L4D2Wep_

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:

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 entity, int flags = IDENTIFY_SAFE)
void L4D2Wep_PrecacheModels()

Weapons Helpers:

void L4D2Wep_AddSpawnSuffix(char[] weaponName, char[] store, int len)
void L4D2Wep_RemoveSpawnSuffix(char[] weaponName, int 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 entity, int flags = IDENTIFY_SAFE)
void L4D2Wep_OnMapStart()
bool L4D2Wep_IsValidMelee(char[] meleeName)
bool L4D2Wep_IsValidMeleeIDEx(int meleeID)
void L4D2Wep_PrecacheMeleeModels()

Items:

int L4D2Wep_IdentifyItemByEnt(int entity, int &anyID = 0, int flags = IDENTIFY_SAFE)
int L4D2Wep_IdentifyItemByName(char[] anyName, int &anyID = 0)
int L4D2Wep_IdentifyEquipSlot(int entity)
bool L4D2Wep_IsValidItemAndID(int anyID, int itemType)
bool L4D2Wep_IsItemNoneID(int anyID, int itemType)
bool L4D2Wep_IsValidItemID(int anyID, int itemType)
void L4D2Wep_GiveItemByName(int client, char[] weaponName)
void L4D2Wep_GiveItemByID(int client, int anyID, int itemType)

Ammo:

void L4D2Wep_InitAmmoCvars()
int L4D2Wep_WepIDToAmmoID(int wepID)
int L4D2Wep_GetAmmo(int ammoID)
bool L4D2Wep_SetAmmoByID(int entity, int wepID)
int L4D2Wep_WepIDToOffset(int wepID)
int L4D2Wep_GetPlayerAmmo(int client)
bool L4D2Wep_SetPlayerAmmo(int client, int maxAmmo)

Spawn:

int L4D2Wep_SpawnItem(int anyID, int itemType, float origin[3], float angles[3] = {0.0, ...}, bool applyVecFix = true, bool spawn = true, int count = 5)
int L4D2Wep_Spawn(int wepID, float origin[3], float angles[3] = {0.0, ...}, bool applyVecFix = true, bool spawn = true, int count = 5)
int L4D2Wep_SpawnMelee(int meleeID, float origin[3], float angles[3] = {0.0, ...}, bool applyVecFix = true, bool spawn = true, int count = 5)
int L4D2Wep_ConvertWeaponSpawn(int entity, int wepID, int count = 5, const char[] model = "")

Fixes:

void L4D2Wep_FixModelVectors(int wepID, float origin[3], float angles[3])
void L4D2Wep_FixMeleeModelVectors(int meleeID, float 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:

Donation

If you want to thank us for the hard work feel free to send any amount.

l4d2_weapons's People

Contributors

razieil avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

dragokas

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.