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

[STOCKS] Useful TF2 Functions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 03-23-2008 , 15:03   [STOCKS] Useful TF2 Functions
Reply With Quote #1

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.
Attached Files
File Type: zip tf.zip (2.1 KB, 235 views)

Last edited by bl4nk; 03-27-2008 at 04:14.
bl4nk is offline
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 03-23-2008 , 16:51   Re: [STOCKS] Useful TF2 Functions
Reply With Quote #2

Did you test this functions?
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 03-23-2008 , 17:47   Re: [STOCKS] Useful TF2 Functions
Reply With Quote #3

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.

Last edited by bl4nk; 03-23-2008 at 17:50.
bl4nk is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 03-26-2008 , 19:30   Re: [STOCKS] Useful TF2 Functions
Reply With Quote #4

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.

Last edited by bl4nk; 03-26-2008 at 19:36.
bl4nk is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 03-26-2008 , 21:08   Re: [STOCKS] Useful TF2 Functions
Reply With Quote #5

You might wanna create the global variables using 'static' instead to avoid variable naming conflicts (as described here).

Also, what the f* is this?
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.
__________________
plop

Last edited by p3tsin; 03-26-2008 at 21:12.
p3tsin is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 03-26-2008 , 21:15   Re: [STOCKS] Useful TF2 Functions
Reply With Quote #6

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.

Last edited by bl4nk; 03-26-2008 at 21:36.
bl4nk is offline
p3tsin
Senior Member
Join Date: Sep 2005
Location: Finland
Old 03-26-2008 , 21:50   Re: [STOCKS] Useful TF2 Functions
Reply With Quote #7

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 View Post
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.
__________________
plop

Last edited by p3tsin; 03-26-2008 at 22:01.
p3tsin is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 03-26-2008 , 22:54   Re: [STOCKS] Useful TF2 Functions
Reply With Quote #8

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.

Last edited by bl4nk; 03-27-2008 at 04:14.
bl4nk is offline
Reply



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 14:21.


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