How do I replace the player with ZScript? [SOLVED]

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.

How do I replace the player with ZScript? [SOLVED]

Postby RederickDeathwill » Tue Oct 12, 2021 7:49 am

So, I have a custom actor:

Code: Select allExpand view
class CustomDoomPlayer : DoomPlayer
{

   private
   void initialize()
   {
      CustomThinker t = new("CustomThinker");
      // t.a = actorPointer;
   }

   Default
   {
      Speed 8;
      Health 300;
      Radius 16;
      Height 56;
      Mass 100;
      PainChance 255;
      Player.DisplayName "CustomDoomPlayer";
      Player.CrouchSprite "PLYC";
      Player.StartItem "Pistol";
      Player.StartItem "Shotgun";
      Player.StartItem "Fist";
      Player.StartItem "Clip", 50;
      Player.WeaponSlot 1, "Fist", "Chainsaw";
      Player.WeaponSlot 2, "Pistol";
      Player.WeaponSlot 3, "Shotgun", "SuperShotgun";
      Player.WeaponSlot 4, "Chaingun";
      Player.WeaponSlot 5, "RocketLauncher";
      Player.WeaponSlot 6, "PlasmaRifle";
      Player.WeaponSlot 7, "BFG9000";
      
      Player.ColorRange 112, 127;
      Player.Colorset 0, "$TXT_COLOR_GREEN",      0x70, 0x7F,  0x72;
      Player.Colorset 1, "$TXT_COLOR_GRAY",      0x60, 0x6F,  0x62;
      Player.Colorset 2, "$TXT_COLOR_BROWN",      0x40, 0x4F,  0x42;
      Player.Colorset 3, "$TXT_COLOR_RED",      0x20, 0x2F,  0x22;
      // Doom Legacy additions
      Player.Colorset 4, "$TXT_COLOR_LIGHTGRAY",   0x58, 0x67,  0x5A;
      Player.Colorset 5, "$TXT_COLOR_LIGHTBROWN",   0x38, 0x47,  0x3A;
      Player.Colorset 6, "$TXT_COLOR_LIGHTRED",   0xB0, 0xBF,  0xB2;
      Player.Colorset 7, "$TXT_COLOR_LIGHTBLUE",   0xC0, 0xCF,  0xC2;
   }

   States
   {
   Spawn:
      PLAY A -1;
      Loop;
   See:
      PLAY ABCD 4;
      Loop;
   Missile:
      PLAY E 12;
      Goto Spawn;
   Melee:
      PLAY F 6 BRIGHT;
      Goto Missile;
   Pain:
      PLAY G 4;
      PLAY G 4 A_Pain;
      Goto Spawn;
   Death:
      PLAY H 0 A_PlayerSkinCheck("AltSkinDeath");
   Death1:
      PLAY H 10;
      PLAY I 10 A_PlayerScream;
      PLAY J 10 A_NoBlocking;
      PLAY KLM 10;
      PLAY N -1;
      Stop;
   XDeath:
      PLAY O 0 A_PlayerSkinCheck("AltSkinXDeath");
   XDeath1:
      PLAY O 5;
      PLAY P 5 A_XScream;
      PLAY Q 5 A_NoBlocking;
      PLAY RSTUV 5;
      PLAY W -1;
      Stop;
   AltSkinDeath:
      PLAY H 6;
      PLAY I 6 A_PlayerScream;
      PLAY JK 6;
      PLAY L 6 A_NoBlocking;
      PLAY MNO 6;
      PLAY P -1;
      Stop;
   AltSkinXDeath:
      PLAY Q 5 A_PlayerScream;
      PLAY R 0 A_NoBlocking;
      PLAY R 5 A_SkullPop;
      PLAY STUVWX 5;
      PLAY Y -1;
      Stop;
   }
}


I can summon it inside the game using the summon command, but I'm not the custom player. How can I play as the custom player that I've just defined?

Edit:

By the way, I've tried adding to the mapinfo (As seen here: https://zdoom.org/wiki/Creating_new_player_classes) and it doesn't work:

Code: Select allExpand view
gameinfo
{

  AddEventHandlers = "pc_EventHandler"
  PlayerClasses = "CustomDoomPlayer"

} // gameinfo



Edit2:

The class inside the game still is the default "marine":



Conclusion:

DO NOT use KEYINFO (Even if it works). If MAPINFO is not working, check if you have any additional mods that implement MAPINFO and merge/remove them. You can't have 2 PlayerClasses definitions.
Last edited by RederickDeathwill on Tue Oct 12, 2021 10:46 am, edited 7 times in total.
User avatar
RederickDeathwill
 
Joined: 06 Sep 2020
Github ID: https://github.com/EricsonWillians
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: How do I replace the player with ZScript?

Postby Blue Shadow » Tue Oct 12, 2021 8:09 am

User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: How do I replace the player with ZScript?

Postby RederickDeathwill » Tue Oct 12, 2021 8:23 am

Maybe I'm missing something, but my custom player has a custom speed of 8 and 300 health and that's not what I experience as the player. When I summon a normal DoomPlayer and kill it with the same gun as I kill a CustomDoomPlayer, the CustomDoomPlayer clearly has much more health.

Setting the Player.DisplayName and the PlayerClasses is not working, I don't see it as a class, just the default "Marine", nor am I the CustomDoomPlayer. Unfortunately, the great majority of examples use DECORATE only.
User avatar
RederickDeathwill
 
Joined: 06 Sep 2020
Github ID: https://github.com/EricsonWillians
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: How do I replace the player with ZScript?

Postby RederickDeathwill » Tue Oct 12, 2021 8:39 am

So, I guess the documentation is wrong when it says that using KEYCONF is deprecated. As soon as I added a KEYCONF file:

Code: Select allExpand view
// This command clears the player classes' list.
clearplayerclasses

// Add your player class to the list
addplayerclass CustomDoomPlayer


It worked like a charm.

User avatar
RederickDeathwill
 
Joined: 06 Sep 2020
Github ID: https://github.com/EricsonWillians
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: How do I replace the player with ZScript?

Postby Blue Shadow » Tue Oct 12, 2021 8:50 am

When it didn't work, how did you set things up?

Since you have your player class set up, all you need is the following in a MAPINFO file:

Code: Select allExpand view
gameinfo
{
    PlayerClasses = "<your_player_class_name_here>"
}
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: How do I replace the player with ZScript?

Postby RederickDeathwill » Tue Oct 12, 2021 9:00 am

Blue Shadow wrote:When it didn't work, how did you set things up?

Since you have your player class set up, all you need is the following in a MAPINFO file:

Code: Select allExpand view
gameinfo
{
    PlayerClasses = "<your_player_class_name_here>"


Well, without the KEYCONF file inside the .pk3 or .zip, it just doesn't work, and I'm using the latest GZDoom version (4.7.0). I've added the PlayerClasses inside MAPINFO and nothing happened.
User avatar
RederickDeathwill
 
Joined: 06 Sep 2020
Github ID: https://github.com/EricsonWillians
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: How do I replace the player with ZScript? [SOLVED]

Postby Blue Shadow » Tue Oct 12, 2021 9:07 am

Are you loading your mod with another mod? If that mod replaces player classes using KEYCONF then your attempt at replacing player classes in your mod using the MAPINFO method won't work, as the KEYCONF method has the last say (this is why the KEYCONF method should not be used for such a thing).
User avatar
Blue Shadow
 
Joined: 14 Nov 2010
Operating System: Windows 10/8.1/8/201x 64-bit
OS Test Version: No (Using Stable Public Version)
Graphics Processor: ATI/AMD (Modern GZDoom)

Re: How do I replace the player with ZScript? [SOLVED]

Postby RederickDeathwill » Tue Oct 12, 2021 10:31 am

Blue Shadow wrote:Are you loading your mod with another mod? If that mod replaces player classes using KEYCONF then your attempt at replacing player classes in your mod using the MAPINFO method won't work, as the KEYCONF method has the last say (this is why the KEYCONF method should not be used for such a thing).


I'm loading it with another mod, but the only KEYCONF present is the one I created. I have no idead why mapinfo didn't work.
User avatar
RederickDeathwill
 
Joined: 06 Sep 2020
Github ID: https://github.com/EricsonWillians
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: nVidia (Modern GZDoom)

Re: How do I replace the player with ZScript? [SOLVED]

Postby RederickDeathwill » Tue Oct 12, 2021 10:45 am

@Blue Shadow, you were right! Inside my third_person.wad there was a MAPINFO that was overwriting my previous MAPINFO. I removed the KEYINFO and removed the MAPINFO from the additional mod and it worked. Nice, I've earned some experience from this, thanks for the help.
User avatar
RederickDeathwill
 
Joined: 06 Sep 2020
Github ID: https://github.com/EricsonWillians
Operating System: Debian-like Linux (Debian, Ubuntu, Mint, etc) 64-bit
Graphics Processor: nVidia (Modern GZDoom)


Return to Scripting

Who is online

Users browsing this forum: No registered users and 0 guests