Changing a player's sprite to reflect weapon in use?

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Izthat
Posts: 8
Joined: Wed Jan 23, 2019 3:49 pm

Changing a player's sprite to reflect weapon in use?

Post by Izthat »

Sorry for the confusing title. But, I was wondering how to change a players sprite so that they would "show" what weapon they were using? The only case I've seen this done was the Security Officer for Samsara. For those who still don't understand; imagine that each weapon that you could use had its own player sprite. Like how you can tell who-has-what in 3D games by looking at the model of the item/weapon they held? But instead of just swapping out the sprite the player is carrying, the whole player sprite is replaced.
So imagine the standard Doom guy sprite. Now, have said player pick up a Plasma Gun. When the player switches over to the Plasma Gun, the sprite of said player changes to a different sprite; One that actually shows Doom Guy holding a Plasma Gun.

I apolagize again for the, uh, difficulty in describing this mechanic.
User avatar
Cherno
Posts: 1311
Joined: Tue Dec 06, 2016 11:25 am

Re: Changing a player's sprite to reflect weapon in use?

Post by Cherno »

Check out this thread:

viewtopic.php?f=3&t=33147

Then you just use the right sprite frames in the weapon-specific states.
User avatar
Izthat
Posts: 8
Joined: Wed Jan 23, 2019 3:49 pm

Re: Changing a player's sprite to reflect weapon in use?

Post by Izthat »

Ok, I still don't get it. iI'll post the code thats being referenced;
Decorate

Code: Select all

GUNN A 0 A_Jump (ACS_NamedExecuteWithResult("WWWepCheck", 0), "PistolState")
GUNN A 0 A_Jump (ACS_NamedExecuteWithResult("WWWepCheck", 1), "ShotgunState")
GUNN A 0 A_Jump (ACS_NamedExecuteWithResult("WWWepCheck", 2), "ChaingunState")
ACS Lib

Code: Select all

    #library "WW Weapon Check"
    #include "zcommon.acs"

    #define WWWEAPONS 3
    str WWWepList[WWWEAPONS] = {"Pistol", "Shotgun", "Chaingun"};

    script "WWWepCheck" (int Wep) {
    int rv = 0;
    if (CheckWeapon(WWWepList[Wep]) == 1){rv = 256;}
    SetResultValue (rv);
    }
More ACs Lib?

Code: Select all

#define WWWEPCOUNT 13
str WWWeapons[WWWEPCOUNT] = {
"JudgmentPistol", "P50Pistol", "MartebaRevolver", "Derringer",
"DualPocketMagnums", "DoomHuntShotgun", "PugRifle", "Leadspitter",
"HZSniperRifle", "Shotput", "RRSM", "HZAutoPistol", "HZSniperRifle"
};

int WWLastWeapon;
script "WWLastWeapon" (int Option) {
int w;
if (Option == 0)//Store Last Weapon
   {
   WWLastWeapon = -1;//In case weapon isn't in list
   for (w = 0;w < WWWEPCOUNT;w++)
      {
      if (CheckWeapon (WWWeapons[w]) != 0){WWLastWeapon = w;}
      }
   terminate;
   }
if (Option == 1)//Select last weapon stored
   {
   if (CheckInventory (WWWeapons[WWLastWeapon]) != 0 && LastWeapon != -1)
      {
      SetWeapon (WWWeapons[WWLastWeapon]);
      terminate;
      }
   //Something went wrong, select the first weapon the player has.
   for (w = 0;w < WWWEPCOUNT;w++)
      {
      if (CheckInventory (WWWeapons[w]) != 0)
         {
         SetWeapon (WWWeapons[w]);
         terminate;
         }
      }
   //Something went really wrong, do what you want here.
   }
}
I've got all of this applied to the relevant actors. But all its done so far is just spam the console everytime a weapon is switched. Which would be: "P_StartScript: Unkown Script "WWLastWeapon."
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Changing a player's sprite to reflect weapon in use?

Post by Matt »

Here's a ZScript playerclass that swaps out the zombie sprites for the player sprites if the player is using the pistol, shotgun or chaingun. No crouch support.

Code: Select all

class SwitchingWeaponPlayer:Doomplayer{
    default{
        player.displayname "SwitchingDoomPlayer";
    }
    override void Tick(){
        super.Tick();
        if(
            player
            &&player.readyweapon
        ){
            let pw=player.readyweapon;
            if(Pistol(pw)){
                sprite=getspriteindex("POSSA1");
            }else if(Shotgun(pw)){
                sprite=getspriteindex("SPOSA1");
            }else if(Chaingun(pw)){
                sprite=getspriteindex("CPOSA1");
            }else{
                sprite=getspriteindex("PLAYA1");
            }
        }
    }
}
and the MAPINFO:

Code: Select all

gameinfo{
    playerclasses="SwitchingWeaponPlayer"
}

This is not intended to be used as-is. I have no idea how the resource sprites are organized that you want to use for this.
User avatar
Izthat
Posts: 8
Joined: Wed Jan 23, 2019 3:49 pm

Re: Changing a player's sprite to reflect weapon in use?

Post by Izthat »

Matt wrote:Here's a ZScript playerclass that swaps out the zombie sprites for the player sprites if the player is using the pistol, shotgun or chaingun. No crouch support.
Thanks for the code! But it dosen't work, or at least, it dosen't work with the sprite names swapped out.
Matt wrote:This is not intended to be used as-is. I have no idea how the resource sprites are organized that you want to use for this.
If they're in one directory, would that simplify things?
User avatar
Matt
Posts: 9696
Joined: Sun Jan 04, 2004 5:37 pm
Preferred Pronouns: They/Them
Operating System Version (Optional): Debian Bullseye
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia
Contact:

Re: Changing a player's sprite to reflect weapon in use?

Post by Matt »

.........You'll have to post a link to the entire project to get any help on this because any number of things might be wrong.
Kazudra
Posts: 126
Joined: Mon May 25, 2015 10:52 am

Re: Changing a player's sprite to reflect weapon in use?

Post by Kazudra »

I'm very interested in this (enough to Necropost);
Marine Skins has pretty much all weapons covered with crouch sprites all nicely organized and since they are all 1:1 animations this should make the process much easier.

I'm gonna play around with this and see if I can get it working; I think it would be a nice layer of Polish to pop in 3rd person or pass a mirror and find your sprite changing (Not to mention give visual distinction of those AI Marines)
Post Reply

Return to “Scripting”