Raised This Month: $32 Target: $400
 8% 

[TF2] Resize Heads! (1.1.1) [1/18/2013]


Post New Thread Reply   
 
Thread Tools Display Modes
captaindeterprimary
AlliedModders Donor
Join Date: Sep 2012
Old 01-28-2013 , 03:45   Re: [TF2] Resize Heads! (1.1.1) [1/18/2013]
Reply With Quote #71

Spoiler
__________________
Last edited by ; Today at 08:20 AM. Reason: Get rid of s

Last edited by captaindeterprimary; 01-29-2013 at 02:01. Reason: stupid
captaindeterprimary is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 01-28-2013 , 13:47   Re: [TF2] Resize Heads! (1.1.1) [1/18/2013]
Reply With Quote #72

Quote:
Originally Posted by vman315 View Post
I may have choose my words wrong. I mean no disrespect. I meant was the goal of his integration of head re-sizing (thus super-setting this plugin), was to no longer need the use of two plugins, that may have some conflicts when used together. I still prefer this plugin thou. 11530's is nice and all, but without re-size constraints it opens the possibility of a mass lag spike or even a server crash. This plugin how ever has said constraints, to which is why I said "What a shame". If I offended anyone I apologize.
I originally intended to include features in my plugin to allow people to resize almost anything - models, heads, weapons, props etc. Like Chaosxk, I began coding head resizing into my plugin as soon as Merasmus brought it about. Looking at Master's recent projects, he may have one of those extras covered soon. If there are two, I prefer if people use one which supersedes the other and, once that exists, it is required for the other plugin to be unapproved (also, as vman says, our commands did indeed conflict). And in the knowledge that it'll eventually be unapproved, I think there's no need to advertise it further - otherwise more people will just be left with an unapproved plugin and will need to download another.

Sounds ill-natured, but I'm just thinking logically here. Perhaps that's my weakness.

Edit: Vman, my update to the plugin is including customizable boundaries amongst other things. E.g. a convar value of "0.5, 10" will ensure admins using that particular command will only use values between 0.5 and 10 inclusive.
__________________

Last edited by 11530; 01-28-2013 at 14:06.
11530 is offline
captaindeterprimary
AlliedModders Donor
Join Date: Sep 2012
Old 01-29-2013 , 02:00   Re: [TF2] Resize Heads! (1.1.1) [1/18/2013]
Reply With Quote #73

Spoiler
__________________
Last edited by ; Today at 08:20 AM. Reason: Get rid of s

Last edited by captaindeterprimary; 01-29-2013 at 02:07. Reason: raisins
captaindeterprimary is offline
11530
Veteran Member
Join Date: Sep 2011
Location: Underworld
Old 01-29-2013 , 12:31   Re: [TF2] Resize Heads! (1.1.1) [1/18/2013]
Reply With Quote #74

I think everyone has the wish that their private messages stay private. That's why they're called that. Anyway, now that context has been cleared up and order has been restored, we can stop plaguing this thread with messages.

As a possible edit to this plugin, perhaps you guys can include Resize Hats or something. I'd likely even download that myself.
__________________
11530 is offline
captaindeterprimary
AlliedModders Donor
Join Date: Sep 2012
Old 01-29-2013 , 13:09   Re: [TF2] Resize Heads! (1.1.1) [1/18/2013]
Reply With Quote #75

Quote:
Originally Posted by 11530 View Post
As a possible edit to this plugin, perhaps you guys can include Resize Hats or something. I'd likely even download that myself.
I would prefer to able to re-size hands, that would be insane.
__________________
Last edited by ; Today at 08:20 AM. Reason: Get rid of s

Last edited by captaindeterprimary; 01-29-2013 at 13:10.
captaindeterprimary is offline
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 01-31-2013 , 11:35   Re: [TF2] Resize Heads! (1.1.1) [1/18/2013]
Reply With Quote #76

Well I haven't tested so someone will have to give this a try as I'm currently not home to try it out however this version detects if the player has a hat on and if he does his head size is altered (without OnGameFrame()).

Requires TF2ItemsInfo to detect if the player has a hat.
Requires TF2Items to alter that hat's attributes (doesn't remove any).

PHP Code:
#pragma semicolon 1

// ====[ INCLUDES ]============================================================
#include <sourcemod>
#include <sdktools>
#include <clientprefs>
#include <tf2items>
#include <tf2itemsinfo>

// ====[ DEFINES ]=============================================================
#define PLUGIN_VERSION            "1.0.0"

// ====[ HANDLES | CVARS ]=====================================================
new Handle:cvarEnabled;
new 
Handle:cvarMaxSize;
new 
Handle:cvarHeadInterval;
new 
Handle:g_hCookieHeadSize;

// ====[ VARIABLES ]===========================================================
new bool:g_bEnabled;
new 
Float:g_fMaxSize;
new 
Float:g_fSizeInterval;
new 
bool:g_bLoadoutChanged        [MAXPLAYERS 1];
new 
Float:g_fHeadSize            [MAXPLAYERS 1];

// ====[ PLUGIN ]==============================================================
public Plugin:myinfo =
{
    
name "Head Size (TF2Items)",
    
author "ReFlexPoison",
    
description "Change your head size via menu",
    
version PLUGIN_VERSION,
    
url "http://www.sourcemod.net"
}

// ====[ FUNCTIONS ]===========================================================
public OnPluginStart()
{
    
CreateConVar("sm_headsize_version"PLUGIN_VERSION"Head Size Version"FCVAR_REPLICATED FCVAR_PLUGIN FCVAR_SPONLY FCVAR_DONTRECORD FCVAR_NOTIFY);

    
cvarEnabled CreateConVar("sm_headsize_enabled""1""Enable Head Size\n0 = Disabled\n1 = Enabled"FCVAR_PLUGINtrue0.0true1.0);
    
g_bEnabled GetConVarBool(cvarEnabled);

    
cvarMaxSize CreateConVar("sm_headsize_maxsize""2.0""Set max head size setting"FCVAR_PLUGINtrue1.0);
    
g_fMaxSize GetConVarFloat(cvarMaxSize);

    
cvarHeadInterval CreateConVar("sm_headsize_interval""0.25""Interval between settings in head size menu"FCVAR_PLUGINtrue0.5);
    
g_fSizeInterval GetConVarFloat(cvarHeadInterval);

    
HookConVarChange(cvarEnabledCVarChange);
    
HookConVarChange(cvarMaxSizeCVarChange);
    
HookConVarChange(cvarHeadIntervalCVarChange);

    
RegAdminCmd("sm_headsize"HeadSizeCmdADMFLAG_GENERIC"Open Head Size Menu");

    
HookEvent("player_death"OnPlayerDeath);

    
g_hCookieHeadSize RegClientCookie("headsize"""CookieAccess_Private);
}

public 
CVarChange(Handle:hConvar, const String:strOldValue[], const String:strNewValue[])
{
    if(
hConvar == cvarEnabled)
        
g_bEnabled GetConVarBool(cvarEnabled);
    if(
hConvar == cvarMaxSize)
        
g_fMaxSize GetConVarFloat(cvarMaxSize);
    if(
hConvar == cvarHeadInterval)
        
g_fSizeInterval GetConVarFloat(cvarHeadInterval);
}

// ====[ EVENTS ]==============================================================
public OnClientCookiesCached(iClient)
{
    
decl String:strCookie[32];
    
GetClientCookie(iClientg_hCookieHeadSizestrCookiesizeof(strCookie));
    
g_fHeadSize[iClient] = StringToFloat(strCookie);
}

public 
Action:TF2Items_OnGiveNamedItem(iClientString:strClassname[], iIndex, &Handle:hItem)
{
    if(!
g_bEnabled)
        return 
Plugin_Continue;

    if(!
IsValidClient(iClient) || !CheckCommandAccess(iClient"sm_headsize"ADMFLAG_GENERIC) || g_fHeadSize[iClient] == 0.0 || g_fHeadSize[iClient] == 1.0)
        return 
Plugin_Continue;

    
decl String:strSlot[32];
    
TF2II_GetItemSlotName(iIndexstrSlotsizeof(strSlot));
    if(
StrEqual(strSlot"head"))
    {
        
decl String:strAtts[32];
        
Format(strAttssizeof(strAtts), "444 ; %f"g_fHeadSize[iClient]);

        new 
Handle:hItemOverride PrepareItemHandle(hItem___strAtts);
        if(
hItemOverride != INVALID_HANDLE)
        {
            
hItem hItemOverride;
            return 
Plugin_Changed;
        }
    }
    return 
Plugin_Continue;
}

public 
Action:OnPlayerDeath(Handle:hEvent, const String:strName[], bool:bBroadcast)
{
    new 
iClient GetClientOfUserId(GetEventInt(hEvent"userid"));
    if(!
IsValidClient(iClient))
        return 
Plugin_Continue;

    if(
g_bLoadoutChanged[iClient])
    {
        
TF2II_RemoveItemSlot(iClientTF2ItemSlot_Hat);
        
g_bLoadoutChanged[iClient] = false;
    }
    return 
Plugin_Continue;
}

// ====[ COMMANDS | MENUS ]====================================================
public Action:HeadSizeCmd(iClientiArgs)
{
    if(!
IsValidClient(iClient) || !g_bEnabled)
        return 
Plugin_Continue;

    new 
Handle:hMenu CreateMenu(HeadSizeH);
    
SetMenuTitle(hMenu"Head Size:");
    
AddMenuItem(hMenu"1.0""Normal");
    for(new 
Float:f<= g_fMaxSize+= g_fSizeInterval)
    {
        if(
!= 0.0 && != 1.0)
        {
            
decl String:strFloat[32];
            
FloatToString(fstrFloatsizeof(strFloat));
            
AddMenuItem(hMenustrFloatstrFloat);
        }
    }
    return 
Plugin_Handled;
}

public 
HeadSizeH(Handle:hMenuMenuAction:iActioniParam1iParam2)
{
    if(
iAction == MenuAction_End)
        
CloseHandle(hMenu);

    if(!
IsValidClient(iParam1))
        return;

    if(
iAction == MenuAction_Select)
    {
        
decl String:strInfo[32];
        
GetMenuItem(hMenuiParam2strInfosizeof(strInfo));
        
SetClientCookie(iParam1g_hCookieHeadSizestrInfo);
        
g_fHeadSize[iParam1] = StringToFloat(strInfo);

        
g_bLoadoutChanged[iParam1] = true;
        
PrintToChat(iParam1"\x01[SM] You have set your head size to \x05%f\x01."g_fHeadSize[iParam1]);
    }
}

// ====[ STOCKS ]==============================================================
stock bool:IsValidClient(iClientbool:bReplay true)
{
    if(
iClient <= || iClient MaxClients || !IsClientInGame(iClient))
        return 
false;
    if(
bReplay && (IsClientSourceTV(iClient) || IsClientReplay(iClient)))
        return 
false;
    return 
true;
}

stock bool:IsValidEnt(iEntity)
{
    if(
iEntity <= MaxClients || !IsValidEntity(iEntity))
        return 
false;
    return 
true;
}

stock TF2II_RemoveItemSlot(iClientTF2ItemSlot:iSlot)
{
    new 
iEntity = -1;
    while((
iEntity FindEntityByClassname(iEntity"tf_wearable")) != -1)
    {
        if(
IsValidEnt(iEntity))
        {
            if(
GetEntPropEnt(iEntityProp_Send"m_hOwnerEntity") == iClient && _:TF2II_GetItemSlot(GetEntProp(iEntityProp_Send"m_iItemDefinitionIndex")) == _:iSlot)
                
AcceptEntityInput(iEntity"Kill");
        }
    }
}

stock Handle:PrepareItemHandle(Handle:hItemString:strName[] = ""iIndex = -1iQuality = -1, const String:strAtts[] = ""bool:bPreserve true)
{
    static 
Handle:hWeapon;
    new 
iAddAtts;

    new 
String:strAtts2[32][32];
    new 
iAttsCount ExplodeString(strAtts" ; "strAtts23232);

    new 
iFlags OVERRIDE_ATTRIBUTES;
    if(
bPreserve)
        
iFlags |= PRESERVE_ATTRIBUTES;

    if(
hWeapon == INVALID_HANDLE)
        
hWeapon TF2Items_CreateItem(iFlags);
    else
        
TF2Items_SetFlags(hWeaponiFlags);

    if(
hItem != INVALID_HANDLE)
    {
        
iAddAtts TF2Items_GetNumAttributes(hItem);
        if(
iAddAtts 0)
        {
            for(new 
0iAddAtts+= 2)
            {
                new 
bool:bDontAdd;
                new 
iAttIndex TF2Items_GetAttributeId(hItemi);
                for(new 
0iAttsCount i+= 2)
                {
                    if(
StringToInt(strAtts2[z]) == iAttIndex)
                    {
                        
bDontAdd true;
                        break;
                    }
                }
                if(!
bDontAdd)
                {
                    
IntToString(iAttIndexstrAtts2[iAttsCount], 32);
                    
FloatToString(TF2Items_GetAttributeValue(hItemi), strAtts2[iAttsCount], 32);
                }
            }
            
iAttsCount += iAddAtts;
        }
        
CloseHandle(hItem);
    }

    if(
strName[0] != '\0')
    {
        
iFlags |= OVERRIDE_CLASSNAME;
        
TF2Items_SetClassname(hWeaponstrName);
    }
    if(
iIndex != -1)
    {
        
iFlags |= OVERRIDE_ITEM_DEF;
        
TF2Items_SetItemIndex(hWeaponiIndex);
    }
    if(
iQuality != -1)
    {
        
iFlags |= OVERRIDE_ITEM_QUALITY;
        
TF2Items_SetQuality(hWeaponiQuality);
    }
    if(
iAttsCount 0)
    {
        
TF2Items_SetNumAttributes(hWeapon, (iAttsCount 2));
        new 
z;
        for(new 
0iAttsCount && 32+= 2)
        {
            
TF2Items_SetAttribute(hWeaponzStringToInt(strAtts2[i]), StringToFloat(strAtts2[1]));
            
z++;
        }
    }
    else
        
TF2Items_SetNumAttributes(hWeapon0);
    
TF2Items_SetFlags(hWeaponiFlags);
    return 
hWeapon;

Attached Files
File Type: sp Get Plugin or Get Source (headsize.sp - 126 views - 7.7 KB)
File Type: smx headsize.smx (7.7 KB, 146 views)
ReFlexPoison is offline
Powerlord
AlliedModders Donor
Join Date: Jun 2008
Location: Seduce Me!
Old 01-31-2013 , 11:45   Re: [TF2] Resize Heads! (1.1.1) [1/18/2013]
Reply With Quote #77

Quote:
Originally Posted by ReFlexPoison View Post
Well I haven't tested so someone will have to give this a try as I'm currently not home to try it out however this version detects if the player has a hat on and if he does his head size is altered (without OnGameFrame()).
You forgot to pass true to the preserve attributes argument in your PrepareItemHandle call.

For that matter, isn't PrepareItemHandle overly complicated for what you need?

PHP Code:
ublic Action:TF2Items_OnGiveNamedItem(iClientString:strClassname[], iIndex, &Handle:hItem)
{
    static 
Handle:hWeapon;

    
// TF2Items should auto-close weapon handles, but it doesn't
    
if (hWeapon != INVALID_HANDLE)
    {
        
CloseHandle(hWeapon);
        
hWeapon INVALID_HANDLE;
    }

    if(!
g_bEnabled)
        return 
Plugin_Continue;

    if(!
IsValidClient(iClient) || !CheckCommandAccess(iClient"sm_headsize"ADMFLAG_GENERIC) || g_fHeadSize[iClient] == 0.0 || g_fHeadSize[iClient] == 1.0)
        return 
Plugin_Continue;

    
decl String:strSlot[32];
    
TF2II_GetItemSlotName(iIndexstrSlotsizeof(strSlot));
    if(
StrEqual(strSlot"head"))
    { 
        
hWeapon TF2Items_CreateItem(OVERRIDE_ATTRIBUTES PRESERVE_ATTRIBUTES);
        if (
hWeapon == INVALID_HANDLE)
        {
            return 
Plugin_Continue;
        }
        
TF2Items_SetNumAttributes(hWeapon1);
        
TF2Items_SetAttribute(hWeapon0444g_fHeadSize[iClient]);
        
hItem hWeapon;
        return 
Plugin_Changed;
    }
    return 
Plugin_Continue;

__________________
Not currently working on SourceMod plugin development.

Last edited by Powerlord; 01-31-2013 at 11:59.
Powerlord is offline
ReFlexPoison
☠☠☠
Join Date: Jul 2011
Location: ☠☠☠
Old 01-31-2013 , 16:27   Re: [TF2] Resize Heads! (1.1.1) [1/18/2013]
Reply With Quote #78

Quote:
Originally Posted by Powerlord View Post
You forgot to pass true to the preserve attributes argument in your PrepareItemHandle call.

For that matter, isn't PrepareItemHandle overly complicated for what you need?

PHP Code:
ublic Action:TF2Items_OnGiveNamedItem(iClientString:strClassname[], iIndex, &Handle:hItem)
{
    static 
Handle:hWeapon;

    
// TF2Items should auto-close weapon handles, but it doesn't
    
if (hWeapon != INVALID_HANDLE)
    {
        
CloseHandle(hWeapon);
        
hWeapon INVALID_HANDLE;
    }

    if(!
g_bEnabled)
        return 
Plugin_Continue;

    if(!
IsValidClient(iClient) || !CheckCommandAccess(iClient"sm_headsize"ADMFLAG_GENERIC) || g_fHeadSize[iClient] == 0.0 || g_fHeadSize[iClient] == 1.0)
        return 
Plugin_Continue;

    
decl String:strSlot[32];
    
TF2II_GetItemSlotName(iIndexstrSlotsizeof(strSlot));
    if(
StrEqual(strSlot"head"))
    { 
        
hWeapon TF2Items_CreateItem(OVERRIDE_ATTRIBUTES PRESERVE_ATTRIBUTES);
        if (
hWeapon == INVALID_HANDLE)
        {
            return 
Plugin_Continue;
        }
        
TF2Items_SetNumAttributes(hWeapon1);
        
TF2Items_SetAttribute(hWeapon0444g_fHeadSize[iClient]);
        
hItem hWeapon;
        return 
Plugin_Changed;
    }
    return 
Plugin_Continue;

It's a stock, why not use it? It allows you too preserve atts too while also adding new ones.
Just something I use regularly. (Ill send it to Chaos after I fix the not preserving)

Also I don't think it is required to close the handles in OnGive as hItemOverride is closed in the stock. I tested by dumping the handles into a text file and no handles existed after receiving the weapon.

Last edited by ReFlexPoison; 01-31-2013 at 16:31.
ReFlexPoison 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 08:11.


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