Raised This Month: $ Target: $400
 0% 

[SOLVED] [TF2] All the tag mismaches


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-25-2015 , 11:00   [SOLVED] [TF2] All the tag mismaches
Reply With Quote #1

PHP Code:
// Translates a class index to a TFClassType enum value (1 ----> TFClass_Scout)
// Since the current TFClassType enum doesn't map 1-to-1 with the order of the classes on the class menu,
// this native attempts to correct for this problem.
// 
// Prototype: TFClassType ClassIndexToTFClass(int iClient, int ClassIndex)

public int Native_ClassIndexToTFClass(Handle pluginint nParams)
{
    
// Get the client index and the class index:
    
int iClient GetNativeCell(1);
    
int ClassIndex GetNativeCell(2);
    
    
// Then determine the appropriate return value:
    
switch (ClassIndex)
    {
        case -
1:     return TFClass_Unknown;                        // All 9 classes.
        
case 0:        return TF2_GetPlayerClass(iClient);            // The client's current class.
        
case 1:        return TFClass_Scout;
        case 
2:        return TFClass_Soldier;
        case 
3:        return TFClass_Pyro;
        case 
4:        return TFClass_DemoMan;
        case 
5:        return TFClass_Heavy;
        case 
6:        return TFClass_Engineer;
        case 
7:        return TFClass_Medic;
        case 
8:        return TFClass_Sniper;
        case 
9:        return TFClass_Spy;
    }
    return 
TF2_GetPlayerClass(iClient);            // Fail-safe method.

Code:
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1852) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1853) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1854) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1855) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1856) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1857) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1858) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1859) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1860) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1861) : warning 213: tag mismatch
E:\Servers\Management Tools\Sourcemod Plugins\Done\mvm_itemsinfo.sp(1862) : warning 213: tag mismatch
Line #1852 is the "case -1:" section, and it complains at all the TFClassType values that are returned. Moreover, if I put view_as<int>() around them all, it works fine. I can't change the "int" from the function prototype since it's a native function call and they have to be tagged as an int. Any suggestions?

Last edited by Potato Uno; 09-25-2015 at 11:26.
Potato Uno is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 09-25-2015 , 11:25   Re: [TF2] All the tag mismaches
Reply With Quote #2

Any time you're returning something from a native that's not an int, you have to use _:value (old syntax) or view_as<int>(value) (new syntax)

It's an artifact of all non-array types (except Function in SM 1.7 and newer) really being cell_ts (aka 32-bit integers) behind the scenes.1

As long as you have to return type set correct in the native definition, the plugin on the other end will change it back into the correct type.

1Which is also why you can't return arrays or Functions from natives. Instead, you have to pass in a reference (which arrays implicitly are) and populate that instead.
__________________
Not currently working on SourceMod plugin development.
Powerlord is offline
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 09-25-2015 , 11:26   Re: [TF2] All the tag mismaches
Reply With Quote #3

Makes sense now. Thanks Ross!

PHP Code:
public int Native_ClassIndexToTFClass(Handle pluginint nParams)
{
    
// Get the client index and the class index:
    
int iClient GetNativeCell(1);
    
int ClassIndex GetNativeCell(2);
    
    
// Variable to store the output TFClassType:
    
TFClassType ReturnVal;
    
    
// Then determine the appropriate return value:
    
switch (ClassIndex)
    {
        case -
1:     ReturnVal TFClass_Unknown;                        // All 9 classes.
        
case 0:        ReturnVal TF2_GetPlayerClass(iClient);            // The client's current class.
        
case 1:        ReturnVal TFClass_Scout;
        case 
2:        ReturnVal TFClass_Soldier;
        case 
3:        ReturnVal TFClass_Pyro;
        case 
4:        ReturnVal TFClass_DemoMan;
        case 
5:        ReturnVal TFClass_Heavy;
        case 
6:        ReturnVal TFClass_Engineer;
        case 
7:        ReturnVal TFClass_Medic;
        case 
8:        ReturnVal TFClass_Sniper;
        case 
9:        ReturnVal TFClass_Spy;
        default:    
ReturnVal TF2_GetPlayerClass(iClient);            // Fail-safe method.
    
}
    return 
view_as<int>(ReturnVal);


Last edited by Potato Uno; 09-25-2015 at 11:28.
Potato Uno 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 15:07.


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