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

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!
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.

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

Postby Izthat » Fri Feb 08, 2019 11:05 pm

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
Izthat
 
Joined: 23 Jan 2019

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

Postby Cherno » Sat Feb 09, 2019 6:39 am

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
Cherno
 
Joined: 06 Dec 2016

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

Postby Izthat » Mon Feb 11, 2019 7:34 pm

Ok, I still don't get it. iI'll post the code thats being referenced;
Decorate
Code: Select allExpand view
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 allExpand view
    #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 allExpand view
#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
Izthat
 
Joined: 23 Jan 2019

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

Postby Matt » Mon Feb 11, 2019 8:13 pm

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 allExpand view
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 allExpand view
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
Matt
Putting the XD into *xdeath since 2007
 
 
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia

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

Postby Izthat » Wed Feb 13, 2019 9:53 pm

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
Izthat
 
Joined: 23 Jan 2019

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

Postby Matt » Thu Feb 14, 2019 2:59 am

.........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.
User avatar
Matt
Putting the XD into *xdeath since 2007
 
 
 
Joined: 04 Jan 2004
Location: Gotham City SAR, Wyld-Lands of the Lotus People, Dominionist PetroConfederacy of Saudi Canadia


Return to Scripting

Who is online

Users browsing this forum: No registered users and 1 guest