Jump to content

[RESOLVED] set player skin from ZScript or ACS?


Recommended Posts

Posted (edited)

I'm still researching this, but I wonder if anyone else knows of a way to set the player's skin from ZScript or ACS.

 

I've found the ZDoom.org forum post Changing a player's sprite to reflect weapon in use?, but it looks like it's setting the players "sprite" variable each frame, which only sets the sprite being shown for that frame, rather than the entire skin.

 

I've also found ZScript's PlayerInfo.GetSkin() which returns the index of the player's current skin, starting with doomguy at 0.  But there's no equivalent SetSkin() for some reason.

 

The C source for GetSkin() calls CheckKey(), which takes a key (such as "NAME_Skin") and returns a value, so I'm currently looking to see if there's an equivalent setter that can be accessed from ZScript; obviously, not anything specific to the skin, but perhaps something more generic.

Edited by violgamba

Share this post


Link to post
Posted (edited)

Ok, it looks like there's no way to do this.  The engine internals include both GetSkin(), to get the id of the current skin, and SkinNumChanged(int id), to set the current skin by id.  However, only the GetSkin() is wrapped as a native function in ZScript.  Also, there are no generic setters that could set the skin.

 

I've made a feature request to externalize this, as it'd be fun to be able to set your skin in-game, such as with a mirror and switch.

 

https://forum.zdoom.org/viewtopic.php?t=79039

Edited by violgamba

Share this post


Link to post
12 hours ago, violgamba said:

I'm still researching this, but I wonder if anyone else knows of a way to set the player's skin from ZScript or ACS.

 

I've found the ZDoom.org forum post Changing a player's sprite to reflect weapon in use?, but it looks like it's setting the players "sprite" variable each frame, which only sets the sprite being shown for that frame, rather than the entire skin.

 

I've also found ZScript's PlayerInfo.GetSkin() which returns the index of the player's current skin, starting with doomguy at 0.  But there's no equivalent SetSkin() for some reason.

 

The C source for GetSkin() calls CheckKey(), which takes a key (such as "NAME_Skin") and returns a value, so I'm currently looking to see if there's an equivalent setter that can be accessed from ZScript; obviously, not anything specific to the skin, but perhaps something more generic.

 

It has to set the sprite every tic because they're not changing the player class states, but, if you do like in this example, setting every sprite name of every frame to #### will tell the engine to keep the last sprite index used, resulting in a permanent sprite switch.

Share this post


Link to post
Posted (edited)

That's true.  This is a very useful technique for monsters and props.  I don't think it can be used for players, though, can it?  You don't define a State block for players... at least not the skinning technique that I've employed (S_SKIN lumps and sprites images).  Perhaps a custom player State block is a more modern technique, but searching has not uncovered instances of this technique.

Edited by violgamba

Share this post


Link to post

Why not? Of course you can define States for players, you just need to make a new player class and that's it, unless you mean something else

Share this post


Link to post
Posted (edited)

Ah, ok!  There it is, then.  I guess I thought the player would be more complicated then that.

 

Thanks for this link!  I'll try to remake a player in ZScript with this code and sprites turned into ####.  It seems very reasonable now.

Edited by violgamba

Share this post


Link to post
Posted (edited)

For the record.  I did get this working.  After setting all sprite id's in the player states to ####, I initialized the player to a sprite from the first skin, and it stayed with that skin through all actions.  Then I wrote a NextSkin() method which advances to the next skin in an array, setting the player's sprite property to one of that skin's sprites.  After each call to NextSkin(), the player stuck to the selected skin.

 

HOWEVER, while this feature works, it is not using the official sprite system.  The biggest ramification is that the skins are not select-able from the game settings, so can only be changed if playing on a map that is setup to handle it.  This is fine for my own maps, but less useful for a downloaded map. Also, this custom skin system doesn't include mugshots, sound effects, scaling, etc.  It simply swaps the sprite set.

Edited by violgamba

Share this post


Link to post

Yeah, unfortunately to have the "whole package" you have to use the Hexen class system and let the player choose a class before starting a game. Otherwise using a morphing powerup, although that is not a real class change.

Share this post


Link to post
Posted (edited)

FYI, I just put in a pull request to add "PlayerInfo.SetSkin(int skinId)" and "PlayerInfo.GetSkinCount()" to GZDoom's ZScript.  It's a pretty simple change, so I'm hopeful it'll go through fairly quickly.

 

I went into some depth on it here, in case your interested.

Edited by violgamba

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...