Page 1 of 1

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

Posted: Fri Feb 08, 2019 10:05 pm
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.

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

Posted: Sat Feb 09, 2019 5:39 am
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.

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

Posted: Mon Feb 11, 2019 6:34 pm
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."

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

Posted: Mon Feb 11, 2019 7:13 pm
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.

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

Posted: Wed Feb 13, 2019 8:53 pm
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?

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

Posted: Thu Feb 14, 2019 1:59 am
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.

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

Posted: Sun May 23, 2021 8:15 pm
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)