PDA

View Full Version : [STOCKS] Useful TF2 Functions


bl4nk
03-23-2008, 15:03
#define CLASS_SCOUT 1
#define CLASS_SNIPER 2
#define CLASS_SOLDIER 3
#define CLASS_DEMOMAN 4
#define CLASS_MEDIC 5
#define CLASS_HEAVY 6
#define CLASS_PYRO 7
#define CLASS_SPY 8
#define CLASS_ENGINEER 9
#define CLASS_RANDOM 69 // Used in my ClassChooser plugin.

stock TF_LoadOffsets() // Used for anything to do with the m_iClass offset.
stock TF_LoadGameData() // Used for the Weapon_Equip SDKCall.
stock RemoveWeaponSlot(client, slot) // Removes all weapons on the chosen slot for a client
stock RemoveAllWeapons(client)
stock GetPlayerClass(client) // Requires TF_LoadOffsets() to be called during plugin start
stock SetPlayerClass(client, class) // Requires TF_LoadOffsets() to be called during plugin start
stock EquipWeapons(client, class) // Requires TF_LoadGameData() to be called during plugin start
stock FindClass(const String:className[]) // Input class name such as "engineer" or "scout" and will output the correct CLASS_* symbol, 0 on failureThese are just a few useful stocks until pRED releases his TF2 extension (which should be sometime later this week hopefully). If you have any ideas for any other stocks, just shoot them my way and I'll see what I can do.

Nican
03-23-2008, 16:51
Did you test this functions?

bl4nk
03-23-2008, 17:47
Yup. I've used them all before. I use half of them in my ClassChooser plugin (see the New Plugins forum). Also, a good thing to note is that when you equip a class with another class's weapons, the models might have problems. Most of the weapons are not compatible with all classes so there will be some glitches involved.

bl4nk
03-26-2008, 19:30
Updated the library a bit.

Changes:
Changed handle hGameConf to hGameConfTF to avoid any conflicting issues where someone would use the former.
Added a check for if the sdktools library is loaded in TF_LoadGameData() to avoid any complications
Added a new function: RemoveWeaponSlot()Download it in the main post.

p3tsin
03-26-2008, 21:08
You might wanna create the global variables using 'static' instead to avoid variable naming conflicts (as described here (http://wiki.alliedmods.net/Introduction_to_SourcePawn#Global_static)).

Also, what the f* is this? :D
if (!LibraryExists("sdktools"))
#include <sdktools>
hGameConfTF = LoadGameConfigFile("include.tf");

The file is getting included at compile time and the if clause causes hGameConfTF to be assigned to a gameconfigfile handle only if sdktools is NOT running at the time. Probably not what you want.

bl4nk
03-26-2008, 21:15
That's not how it works. Only the following line is inside of the if statement. All that statement does is check if sdktools is already included, and if it isn't, it includes it. As for the static thing, the global variables are needed in the main file, so using static would eliminate that because it limits it to that one include file. At least that's how I understand it. I guess I could use it for the hGameConfTF part, but the hWeaponEquip might be needed elsewhere.

[edit]

To better explain the if statement, if I were to have used brackets there, it would look like this:
stock TF_LoadGameData()
{
if (!LibraryExists("sdktools"))
{
#include <sdktools>
}
hGameConf = LoadGameConfigFile("include.tf");

StartPrepSDKCall(SDKCall_Player);
PrepSDKCall_SetFromConf(hGameConf, SDKConf_Virtual, "WeaponEquip");
PrepSDKCall_AddParameter(SDKType_CBaseEntity, SDKPass_Pointer);
hWeaponEquip = EndPrepSDKCall();
}They work exactly the same way.

p3tsin
03-26-2008, 21:50
Sorry, but you cant include files during runtime. They simply inform the compiler a function is defined elsewhere (referring to natives), so doing that doesnt make much sense. :?

EDIT:

That's not how it works. Only the following line is inside of the if statement.

Sure, but the line immediately below is ignored since its a compiler directive, and so the line below that one is taken in instead.

EDIT 2:

If you wanna check whether the file is already included or not, do

#if !defined _sdktools_included
#include <sdktools>
#endif

Though it doesnt hurt even if sdktools was included twice cause it uses that define too.

bl4nk
03-26-2008, 22:54
Ah, I see what you're saying now. I don't know why I thought that would have worked (the plugin I was using already included the file so I guess I wasn't getting any errors because of it). The thing is that I only want the file included if that one function is used. I guess I'm just going to have to have it loaded always then.

[edit]

Updated with the info p3tsin gave.