Correct way to change player pawn

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
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Correct way to change player pawn

Post by Apeirogon »

I have two player pawns

Code: Select all

class master : playerpawn {}
and it dummy counterpart

Code: Select all

class puppet : playerpawn {}
Master class is actual player pawn which used by real player.

I want change actual player from master to puppet. If I understand correctly, I must do something like this, in pseudocode, assuming that I have pointers to both master and puppet

Code: Select all

puppet.player = master.player;
master.mo = puppet;
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Correct way to change player pawn

Post by Cherno »

I'm not sure it'll work like this... Player classes should be changed via ACS Morphing, methinks.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Correct way to change player pawn

Post by Apeirogon »

Actually no, here example.
player_example.zip
(608 Bytes) Downloaded 82 times
Just start new game and type in console "summon dio". It spawn new player pawn. Use it with use key and you change camera and map actors from default player pawn to new. You can pickup items and trigger monsters with it. You old "body" would stand in place where you pres use on new.

But it bugged in some ways, for example after such "reincarnation" you cant use weapons if you pickup it. Only with give cheat. Health amount also transfers from old pawn to new. But that expected.
It sometimes work as it should and sometimes broke again if I destroy previous player pawn actor. There are cvar destroy_old_pp which do so.

Or this "dont do that" case?
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Correct way to change player pawn

Post by Apeirogon »

It still importatn for me.
User avatar
LastManonEarth
Posts: 44
Joined: Mon Apr 25, 2016 4:25 pm

Re: Correct way to change player pawn

Post by LastManonEarth »

Time ago I failed to change some sprites to my playerpawn in to see in multiplayer. So Hopefully you get this solved for me to understand how this works. For some reason I am having issues with the melee action. I will post once yours is solved but you may take my response as a way to highlight the interest in this matter.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Correct way to change player pawn

Post by Cherno »

After experimenting with morphing to a different playerclass, i came to the conclusion that morphing is really only useable for the effect like it is known from Hexen (or is it Heretic?): To temporarily change the player into a special creature of sorts. I actually managed to hack myself through all kinds of problems trying to use it for permanent player class changing, such as refusing to set health and equipped weapon. In the end, I got stuck getting weapon switching to work and even a brute force approach (assigning ReadyWeapon directly) just got messy.

Long story short, I simply retainted the base player class and instead changed all neccessary values like health, maxhealth, viewheight etc. to whatever the new player class would have. This of course only works if your new sprite frames match the old ones, since in that case you can simply call sprite = GetSpriteIndex(yourSpriteBaseName) every frame (a very powerful function for situations where you have lots of different actors that all share the same functionality and behavior but look different).
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Correct way to change player pawn

Post by Apeirogon »

Well I dont want to change player entirely, just want temporary change map object of a player to make something like remote controlled robot (you press use on it and now you a robot, self destroying return player back to original player map object), which can be sacrificed in thick of battle without any harm to original player. So morphing here would not work.
User avatar
Cherno
Posts: 1337
Joined: Tue Dec 06, 2016 11:25 am

Re: Correct way to change player pawn

Post by Cherno »

You could still use morphing for that provided you experiment with overriding the Die() function and the Death states.
User avatar
Apeirogon
Posts: 1606
Joined: Mon Jun 12, 2017 12:57 am

Re: Correct way to change player pawn

Post by Apeirogon »

After some more deep investigation, looks like gzdoom "guts" just dont have correct handling for such situation, changing player pawn on fly, without destroying old player pawn.
I think it just copy playerinfo struct and then attach player to new, instead changing pointer from a to b.

For example, if you spawn new player pawn, change player from old to new and press crouch button BOTH player pawns change state from standing to crouch.
If you transfer weapon from old player pawn to new, and make it printf owner name it would print name of both player pawns. Or even more if you change player several times between several differently named player pawns.

I think I make bug report.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49234
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: Correct way to change player pawn

Post by Graf Zahl »

Have a look at the morph code, that performs a complete PlayerPawn switch. One important step in there is to perform a global pointer substitution.
Post Reply

Return to “Scripting”