Do you have
player cast to something? Do remember, it's not a globally accessible value.
Player is a pointer to the PlayerInfo-type struct that is attached to every player pawn. More importantly, this PlayerInfo struct doesn't actually contain health; health is part of the player pawn.
So, first you need to figure out how to get a pointer to the player. Naturally, there can be multiple players in the game.
You could access it via the global players array. For example,
players[0].mo will return a pointer to the player pawn controlled by the first player. But this will make it incompatible with multiplayer.
So, doing this the proper way depends on the intended purpose. For example, if this is a companion mod, then I'd spawn a separate companion for every player, and I'd just give every companion a pointer to every player. For example, in an event handler:
- Code:
class CompanionsForEveryoneHandler : EventHandler
{
// This is called for every player that enters the game:
override void PlayerSpawned (playerEvent e)
{
// Cast the player pawn for this player to ppawn:
let ppawn = players[e.PlayerNumber].mo;
// Null-check:
if (!ppawn)
return;
// Spawn the companion at the location of the player pawn
// and cast it to comp:
let comp = Actor.Spawn("MyFriendlyCompanion", ppawn.pos);
// If the monster spawned successfully, set the player pawn
// as its master:
if (comp)
comp.master = ppawn;
}
}
If you do the above, a separate MyFriendlyCompanion will be spawned for every player, and the corresponding player pawn will be accessible to MyFriendlyCompanion via the 'master' pointer. From there on, you can just check master.health from MyFriendlyCompanion whenever you want.
Also, I can't imagine a good reason to use A_SpawnProjectile for your case. First, the CMF_CHECKTARGETDEAD flag won't do anything sensible here because the player is not the target here—since the monster is friendly, it'll be targeting other monsters. Second, it's generally not a function for spawning anything but projectiles. If you want to spawn it with an offset (and perhaps even give it some velocity),
A_SpawnItemEx is what you need.
Last edited by Jekyll Grim Payne on Mon Feb 07, 2022 1:16 pm, edited 1 time in total.