AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Snippets and Tutorials (https://forums.alliedmods.net/forumdisplay.php?f=112)
-   -   [STOCKS] Useful TF2 Functions (https://forums.alliedmods.net/showthread.php?t=68840)

bl4nk 03-23-2008 15:03

[STOCKS] Useful TF2 Functions
 
2 Attachment(s)
PHP Code:

#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(clientslot// 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 failure 

These 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

Re: [STOCKS] Useful TF2 Functions
 
Did you test this functions?

bl4nk 03-23-2008 17:47

Re: [STOCKS] Useful TF2 Functions
 
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

Re: [STOCKS] Useful TF2 Functions
 
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

Re: [STOCKS] Useful TF2 Functions
 
You might wanna create the global variables using 'static' instead to avoid variable naming conflicts (as described here).

Also, what the f* is this? :D
Code:
    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

Re: [STOCKS] Useful TF2 Functions
 
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:
PHP Code:

stock TF_LoadGameData()
{
    if (!
LibraryExists("sdktools"))
    {
        
#include <sdktools>
    
}
    
hGameConf LoadGameConfigFile("include.tf");

    
StartPrepSDKCall(SDKCall_Player);
    
PrepSDKCall_SetFromConf(hGameConfSDKConf_Virtual"WeaponEquip");
    
PrepSDKCall_AddParameter(SDKType_CBaseEntitySDKPass_Pointer);
    
hWeaponEquip EndPrepSDKCall();


They work exactly the same way.

p3tsin 03-26-2008 21:50

Re: [STOCKS] Useful TF2 Functions
 
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:

Quote:

Originally Posted by bl4nk (Post 602516)
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

Code:
#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

Re: [STOCKS] Useful TF2 Functions
 
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.


All times are GMT -4. The time now is 14:41.

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