AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [L4D2] Weapon, Survivor, Gamemode identification includes (Trie) (https://forums.alliedmods.net/showthread.php?t=159784)

ProdigySim 06-21-2011 13:11

[L4D2] Weapon, Survivor, Gamemode identification includes (Trie)
 
3 Attachment(s)
Description
There are a lot of plugins that don't take full advantage of the wonderful ADT_Trie Sourcemod provides us. I've made three includes that will help L4D2 plugin makers take advantage of the efficiency of Tries. These will also help people simplify identification of survivors, weapons, and gamemodes.

survivors.inc
Very simply, survivors.inc allows you to identify survivors quicky based on their player model. It also contains string arrays that will let you lookup the character names and models from a character ID.

weapons.inc
This will help you identify weapons quickly based on their classname. It works on weapon_spawn, weapon_X_spawn, and weapon_X style entities. As far as I know, it can identify any weapon entity.

Also included is a function to "convert" a weapon spawn. If you want to, say, convert all SMGs into M60s, it is very simple. You can also lookup weapon names and models from the arrays in the .inc.

gamemodes.inc
This will help you identify gamemodes and base gamemodes. Right now, the content is static, but I may eventually switch it to read from the live gamemodes.txt on the system. Basically, if you're writing a plugin that will behave differently on different gamemodes, then this is very useful. Instead of doing 20+ string compares in a row, you can simply do GameModeStringToId(), and maybe follow up with GetBaseGameMode(), and determine your plugin behavior from there.

Headers
The .incs are short and well commented, so I'm not sure there's use to put these here. I'll consider it later.

Examples
I'll put up more of these later, but for now, here's a Test Plugin I've been using to test out these .incs:
https://bitbucket.org/ProdigySim/mis.../testplugin.sp
L4D2 Double-standup fix

Installation/Usage
Place these .incs in your sourcemod/scripting/include/ folder and then include them in your project with
#include <survivors>
#include <weapons>
#include <gamemodes>

You can also place them in a local directory and use #include "survivors.inc" if you want.

tl; dr - If you need to identify gamemodes, weapons, or survivors in your plugins, you should use these .incs or something similar!

ProdigySim 06-22-2011 13:18

Re: [L4D2] Weapon, Survivor, Gamemode identification includes (Trie)
 
Here's a diff of a plugin of DieTeeTasse's that I adapted to use survivors.inc.

https://bitbucket.org/ProdigySim/mis...d2_getupfix.sp

Notice how GetSurvivorIndex(), a series of string compares, has been completely replaced by IdentifySurvivor().

ZzZombo 05-20-2012 03:41

Re: [L4D2] Weapon, Survivor, Gamemode identification includes (Trie)
 
I don't like your way of determining survivor characters by model name, you should check m_survivorCharacter netprop instead.

Silvers 05-20-2012 03:59

Re: [L4D2] Weapon, Survivor, Gamemode identification includes (Trie)
 
It depends what you want the check for... the netprop will allow them to vocalize as that character, but the model could be different... look at CSM. I think the model check is best, since people will most likely want to do something with the character they look like, and not some other character because their voice is different. For example some plugins use Bill model only to prevent crashes.

Edit: Regarding the gamemodes, I personally create the info_gamemode entity and fire it's PostSpawnActivate input, to determine gamemode. Regardless of the mp_gamemode (for example mutation12 is still Versus), it reports back if the mode is: Coop,Survival,Versus,Scavenge. Not realism.

ZzZombo 06-03-2012 03:02

Re: [L4D2] Weapon, Survivor, Gamemode identification includes (Trie)
 
Quote:

Originally Posted by Silvers (Post 1712690)
It depends what you want the check for... the netprop will allow them to vocalize as that character, but the model could be different... look at CSM. I think the model check is best, since people will most likely want to do something with the character they look like, and not some other character because their voice is different. For example some plugins use Bill model only to prevent crashes.

You should check netprop just because tehnically it's possible to change model to any other model.

Silvers 06-03-2012 11:21

Re: [L4D2] Weapon, Survivor, Gamemode identification includes (Trie)
 
Quote:

Originally Posted by ZzZombo (Post 1721879)
You should check netprop just because tehnically it's possible to change model to any other model.

So for Incapped Crawling, instead of taking the model name and creating a clone of that, I should use the netprop and create the clone of another Survivor? No, it all depends on what you want to do.

ProdigySim 06-10-2012 05:34

Re: [L4D2] Weapon, Survivor, Gamemode identification includes (Trie)
 
There could be a use for having both of those detection methods. Using the model was needed for what I used this inc for originally.

Now the functionality of these are being moved to other projects so I probably won't be updating them directly.

Others interested can check out https://github.com/Jahze/l4d2util


All times are GMT -4. The time now is 10:09.

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