AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Plugins (https://forums.alliedmods.net/forumdisplay.php?f=108)
-   -   Custom Player Skins (Core) (https://forums.alliedmods.net/showthread.php?t=240703)

Mitchell 05-20-2014 13:49

Custom Player Skins (Core)
 
Custom Player Skins
Allows other plugins to easily bonemerge a player skin to a player, with out worrying about deleting the skin on player_death, etc.
Mere warning for those who ask if this will work in tf2, the answer is no, nor am i going to make a version that works for tf2.

If you find this useful and want to use it in your plugin you should pull the code for the skins themselves and use that other then using these natives. Only one plugin can use a skin at any given time.

Natives
Inside CustomPlayerSkins.inc:
Code:

//Custom Player Skins include file

#if defined _CustomPlayerSkins_included
 #endinput
#endif
#define _CustomPlayerSkins_included

#define CPS_NOFLAGS        0
#define CPS_RENDER          (1 << 0) //Does not make the model invisible. (useful for glows) (used on RemoveSkin it will not force the player's render back to Normal.)
#define CPS_NOATTACHMENT    (1 << 1) //Does not 'SetParentAttachment' variant. (Useful for non-bone merging)
#define CPS_IGNOREDEATH    (1 << 2) //This will prevent the removal of the skin on death.
#define CPS_TRANSMIT        (1 << 3) //This will ignore the hook for Transmit

/**
 * Sets the client's skin from the given path.
 *
 * @param client Client index
 * @param model User input for model path
 * @param flags flags are used to determine what this function does and does not do.
 * @return The skin entity index
 * @error Invalid client.
 */
native int CPS_SetSkin(int client, char[] model, int flags = CPS_NOFLAGS);

/**
 * Gets the client's skin entity reference.
 *
 * @param client Client index
 * @return Returns the entity reference of the player's skin, INVALID_ENT_REFERENCE if there is no skin.
 * @error Invalid client.
 */
native int CPS_GetSkin(int client);

/**
 * Simple check if the client already has a skin.
 *
 * @param client Client index
 * @return Returns if the client has a skin currently. (will not check if the player is alive, etc.)
 * @error Invalid client.
 */
native bool CPS_HasSkin(int client);

/**
 * Removes and resets the player and their skin.
 *
 * @param client Client index
 * @noreturn
 * @error Invalid client.
 */
native void CPS_RemoveSkin(int client, int flags = CPS_NOFLAGS);


/**
 * Sets the client's transmit variable (see below)
 * NOTE: Check if the player is between 0 and MAXPLAYERS.
 *
 * @param owner Client index of the skin's owner
 * @param client Client index of the player that will see the skin.
 * @param transmit        0 - Do not transmit at all.
                                        1 - Transmit only if other cases pass.
                                        2 - Override other checks.
 * @noreturn
 * @error Invalid client.
 */
native void CPS_SetTransmit(int owner, int client, int transmit);


/**
 * Simple native to return the skin's flags
 * NOTE: Check if the player is between 0 and MAXPLAYERS.
 *
 * @param client Client index
 * @return Returns the client index's skin flags.
 */
native CPS_GetFlags(client);

public SharedPlugin:__pl_CustomPlayerSkins =
{
        name = "CustomPlayerSkins",
        file = "CustomPlayerSkins.smx",
#if defined REQUIRE_PLUGIN
        required = 1,
#else
        required = 0,
#endif
};

#if !defined REQUIRE_PLUGIN
public __pl_CustomPlayerSkins_SetNTVOptional()
{
        MarkNativeAsOptional("CPS_SetSkin");
        MarkNativeAsOptional("CPS_GetSkin");
        MarkNativeAsOptional("CPS_HasSkin");
        MarkNativeAsOptional("CPS_RemoveSkin");
        MarkNativeAsOptional("CPS_SetTransmit");
        MarkNativeAsOptional("CPS_GetFlags");
}
#endif


Planned Features
  • None Currently

Plugins
You can only use 1 plugin.
Random Player Skins (FoF, CS:GO)
ESP/WH for Admins (CS:GO)

Downloads
Plugin
Source
Include File

GitHub Link

shavit 05-20-2014 22:02

Re: Custom Player Skins (Core)
 
I like that coding commenting style, looks neat :)

Mitchell 05-20-2014 22:27

Re: Custom Player Skins (Core)
 
Quote:

Originally Posted by shavit (Post 2140536)
I like that coding commenting style, looks neat :)

Glad you read through the code!
Hopefully more people will catch on, helps other's learn coding with small projects like these with descriptive comments.
I like comments that explain what the goal of each function, and why it's unique!

Root_ 06-28-2014 16:04

Re: Custom Player Skins (Core)
 
Interesting stuff. That's really a cool thing, because I can enable glow on specific players in CS:GO. Gotta mess with it. :P
EDIT: I havent tested plugin yet, but got some notes.
Reading through the code, dont use MAXMODELLENGTH, use PLATFORM_MAX_PATH instead.
On a death event, why you initialize client instead of doing RemoveSkin(GetClientOfUserId(GetEventInt(even t, "userid"))) ?
I would switch to player_hurt event and check if (GetClientHealth(client) < 1) if necessary. Because sometimes props wont be removed on player_death event (its late), or it may looks weird in some cases.
Also, does ShouldTransmit hook is really doing something?
Thanks for plugin.

Mitchell 07-02-2014 15:48

Re: Custom Player Skins (Core)
 
Quote:

Originally Posted by Root_ (Post 2158900)
Reading through the code, dont use MAXMODELLENGTH, use PLATFORM_MAX_PATH instead.

Will do.

Quote:

Originally Posted by Root_ (Post 2158900)
On a death event, why you initialize client instead of doing RemoveSkin(GetClientOfUserId(GetEventInt(even t, "userid"))) ?

Good point.

Quote:

Originally Posted by Root_ (Post 2158900)
I would switch to player_hurt event and check if (GetClientHealth(client) < 1) if necessary. Because sometimes props wont be removed on player_death event (its late), or it may looks weird in some cases.

hmm, ill look into that, shouldnt matter if the player_death event is late or not though..

Quote:

Originally Posted by Root_ (Post 2158900)
Also, does ShouldTransmit hook is really doing something?
Thanks for plugin.

Nice catch! seems like I forgot to remove that commented out code there from testing!
Should be stopping the model from being transmitted to the client.

Root_ 07-06-2014 20:37

Re: Custom Player Skins (Core)
 
Hey I am using this in my Admin ESP plugin.
Please update it on github to latest changes described here, otherwise players will able to see themselves from first person.
It works perfectly though. :)

Mitchell 07-07-2014 09:43

Re: Custom Player Skins (Core)
 
Commit updated :)

Root_ 07-07-2014 10:29

Re: Custom Player Skins (Core)
 
Quote:

Originally Posted by Mitchell (Post 2163376)
Commit updated :)

Thanks! Developers can really mess with this plugin, which is nice. You dont mind adding precache for custom player model automatically? So plugin makers will not be confused what crashes the server. Also add something like this to transmit hook to prevent players from seeing custom player skin of observed target.
Code:
new target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget"); if (IsValidEdict(target) && entity == EntRefToEntIndex(CPS_GetSkin(target))) {     return Plugin_Handled; }
I also got a question about SetVariantString("forward"). I used it for hats plugin, cant see reason of using it here. AFAIK DoD:S have an attachment 'head' instead of generic 'forward' or 'eyes', so I would check engine version just to be clear.
And SetEntityRenderMode(client, RENDER_NONE) added for preventing double model on a player or 'misanimations', right?
Thanks in advance.

Mitchell 07-07-2014 15:52

Re: Custom Player Skins (Core)
 
Quote:

Originally Posted by Root_ (Post 2163388)
Thanks! This plugin really can be very useful. You dont mind adding precache for custom player model automatically? So plugin developers will not be confused why it crashes. Also add something like this to OnShouldProp hook to prevent players from seeing custom player skin from firstperon of observed target.
Code:
new target = GetEntPropEnt(client, Prop_Send, "m_hObserverTarget"); if (IsValidClient(target) && entity == EntRefToEntIndex(CPS_GetSkin(target))) {     return Plugin_Handled; }
I also got a question about SetVariantString("forward"). I used it for hats plugin, cant see reason of using it here. AFAIK DoD:S have an attachment 'head' instead of generic 'forward' or 'eyes', so I would check engine version just to be clear. And SetEntityRenderMode(client, RENDER_NONE) is for preventing double model on a player or 'misanimations', right?
Thanks in advance.

As for the precache, i will not be adding this, since all this plugin does is set the skin based on the path, and you should precache your models on MapStart() (or OnPluginStart, which ever one...)
I can add the observer target.
The "forward" attachment is so the prop will bonemerge to the model, I don't think i had tested it without though.
The RenderMode is so the prop and the player is not rendered, as i didnt plan for it to be used for glows. I'll add in an argument that you can pass to ignore that feature.

Root_ 07-07-2014 16:51

Re: Custom Player Skins (Core)
 
Quote:

Originally Posted by Mitchell (Post 2163549)
As for the precache, i will not be adding this, since all this plugin does is set the skin based on the path, and you should precache your models on MapStart() (or OnPluginStart, which ever one...)

Oh yeah, that makes sense. Didnt though bout that lol.
Quote:

Originally Posted by Mitchell (Post 2163549)
I can add the observer target.
I'll add in an argument that you can pass to ignore that feature.

I made a pull request, review it and accept changes please.


All times are GMT -4. The time now is 04:12.

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