Structs:PlayerInfo

From ZDoom Wiki
Jump to navigation Jump to search
Note: This feature is for ZScript only.


The PlayerInfo struct holds all the variables and methods pertaining to each player. It can be used to read and modify player data directly and can be accessed through the player variable, or you can globally access the PlayerInfo structs of all players (Including ones not in the game.), by using the players array.

PlayerInfo is internally known as player_t, and its internal definition can be found here.

How to access PlayerInfo

Accessing the Player variable

To access a players' PlayerInfo struct, by using the player variable, you simply need to have a pointer to the player already. Then you can access their PlayerInfo data by simply doing:

 pointername.player.variable;

Where pointername is the name of the pointer to the player actor, player is the keyword to access their PlayerInfo struct with. And variable is the name of whatever variable you want to read or write, or method you want to use.

Accessing it through the players array

To access a players' PlayerInfo struct by using the global players array, you can simply do:

 players[i].variable

Where i is the players' number subtracted by 1 (so, player #1 is 0 because it's the first element in the array). However, keep in mind that the players array also stores PlayerInfo references for players that don't exist as well. To make sure you are accessing the player number of a player who actually exists, you should use the playeringame[] array like below.

 if (PlayerInGame[i])
 {
 	players[i].variable;
 }

This will make sure your code only interacts on PlayerInfo structs of the players that exist in the game.

Setting player properties directly

Certain player properties can be set directly via the player's cheats variable. To set a property, use

player.cheats |= CF_PROPERTY;

and to unset a property, use

player.cheats &= ~CF_PROPERTY;

Multiple properties can be combined using the | operator e.g.:

player.cheats |= (CF_PROPERTY1 | CF_PROPERTY2 | CF_PROPERTY3);
player.cheats &= ~(CF_PROPERTY1 | CF_PROPERTY2 | CF_PROPERTY3);

You can also check for specific player properties, or combinations of them, like this

if (Player.Cheats & (CF_GODMODE | CF_GODMODE2))

and check for the absence of cheats like this

if (!(Player.Cheats & (CF_GODMODE | CF_GODMODE2)))

You can find the full list of available values here.

Methods

  • bool PoisonPlayer(Actor Poisoner, Actor Source, int Poison)
    Poisons the player a certain number of times.
    • Poisoner
      The actor that poisoned the player.
    • Source
      The actor who the Poisoner originated from.
    • Poison
      The amount of times to poison the player from which the function was called from.
  • void PoisonDamage(Actor Source, int Damage, bool PlayPainSound)
    Only poisons the player with an exact amount of damage.
    • Source
      The source of the calling players' poisoning.
    • Damage
      The exact amount of poison damage to deal.
    • PlayPainSound
      Should the player play their pain sound when poisoned ?
  • void SetLogNumber(int Text)
    (Need more info)
  • void SetLogText(String Text)
    (Need more info)
  • void SetSubtitleNumber(int Text, Sound Sound_ID)
    (Need more info)
  • bool Resurrect()
    Resurrects the player.
  • String GetUserName()
    Returns the players' username.
  • Color GetColor()
    Returns the players' color.
  • Color GetDisplayColor()
    (Need more info)
  • int GetColorSet()
    Returns the number of the players' color set, if any.
  • int GetPlayerClassNum()
    Returns the number of the players' current class.
  • int GetSkin()
    Returns the number of the players' current skin.
  • int GetGender()
    Returns the players' gender. 0 is male, 1 is female, 2 is neutral, 3 is object.
  • int GetTeam()
    Returns the number of the players' team. The default teams' numbers are as follows: 1 is blue, 2 is red, 3 is green, 4 is gold, 5 is black, 6 is white, 7 is orange, and 8 is purple.
  • bool GetNoAutostartMap()
    (Need more info)
  • double GetMoveBob()
    Returns the amount by which the player bobs when moving.
  • bool GetFViewBob() (New from 4.11.0)
    Returns if the players' view should bob up and down when they are flying.
  • double GetStillBob()
    Returns the amount by which the player bobs when standing still.
  • void SetFOV()
    Sets the players' FOV to the specified amount.
  • bool GetClassicFlight()
    Returns true if classic flying is on (The player can't fly in a direction by aiming their mouse at it.).
  • void SendPitchLimits()
    (Need more info)
  • bool HasWeaponsInSlot(int Slot)
    Returns true if the player has any weapon in the specified slot.
    • Slot
      The inventory slot to check for weapons.
  • bool IsTotallyFrozen()
    Returns true if the player or their playerpawn is totally frozen, or if the game is on the TITLEMAP
  • void Uncrouch()
    Uncrouches the player if they are crouching.
  • int FragSum()
    Returns all of the frags every player in the game has scored. (Verification needed)
  • double GetDeltaViewHeight()
    (Need more info)

PlayerInfo PSprite methods

The following methods are called on a PlayerInfo pointer to set up and interact with PSprites. These methods have to be called on a PlayerInfo pointer. For example, when doing it from a PlayerPawn actor, the prefix for them would be self.player (or just player). Same for calling from a Weapon state or a weapon action function, (since in the context of weapon states self is the player pawn owner, while invoker is the weapon itself).

  • PSprite FindPSprite(int id)
Finds a PSprite instance on the layer id and returns a pointer to it. If it doesn't exists, returns null. This allows modifying a PSprite instance directly, much like various A_Overlay* functions do, and also allows checking that a certain PSprite layer already exists.
  • PSprite GetPSprite(int id)
Same as FindPSprite, but if the PSprite doesn't exist, this function will create it and return a pointer to it.
  • void SetPSprite(int id, State stat, bool pending = false)
Sets the PSprite on the specified layer to the specified state (if the layer doesn't exist, it'll be created first). Basically, combines GetPSprite and SetState.
Generally, this is the same as A_Overlay, with one small difference: if A_Overlay is called on a layer that already exists, it'll reset its offsets before moving to the new state, whereas SetPSprite won't. The latter may be useful when there's a need to move a PSprite layer to a different state while retaining previously set offsets. In addition, this function can be called from anywhere, whereas A_Overlay can only be called from a weapon state or weapon action function.
  • void SetSafeFlash(Weapon weap, State flashstate, int index)
Verifies that flashstate + index exists in the state table of the passed weapon (or a weapon class it inherits from) before setting the PSP_FLASH layer. This is mainly useful for preventing crashes if an offset state isn't guaranteed to exist i.e. a child class overrides it.

Variables

  • PlayerPawn Mo
    A pointer to the PlayerPawn which the player is controlling.
  • uint8 PlayerState
    The players' current state. All the possible states are:
    • PST_LIVE — The player is alive.
    • PST_DEAD — The player is dead.
    • PST_REBORN — The player is ready to restart the map or respawn.
    • PST_ENTER — The player just entered the game.
    • PST_GONE — The player has left the game.
  • ReadOnly uint Buttons
    Stores the buttons the player is currently pressing. Possible buttons include:
    • BT_ATTACK — Player is pressing their primary fire key.
    • BT_USE — Player is pressing the use key.
    • BT_JUMP — Player is pressing the jump key.
    • BT_CROUCH — Player is pressing the crouch key.
    • BT_TURN180 — Player is pressing the 180 degree turn key.
    • BT_ALTATTACK — Player is pressing the alternate fire key.
    • BT_RELOAD — Player is pressing the reload key.
    • BT_ZOOM — Player is pressing the zoom key.
    • BT_SPEED — Player is pressing the run key.
    • BT_STRAFE — Player is pressing the strafe key.
    • BT_MOVERIGHT — Player is moving right.
    • BT_MOVELEFT — PLayer is moving left:
    • BT_BACK — Player is moving backwards.
    • BT_FORWARD — Player is moving forwards:
    • BT_RIGHT — Player is turning right.
    • BT_LEFT — Player is turning left.
    • BT_LOOKUP — Player is looking up.
    • BT_LOOKDOWN — Player is looking down.
    • BT_MOVEUP — Player is flying or swimming up.
    • BT_MOVEDOWN — Player is flying or swimming down.
    • BT_SHOWSCORES — Player is pressing the button to view the scoreboard.
    • BT_USER1 — Player is pressing the USER1 key.
    • BT_USER2 — Player is pressing the USER2 key.
    • BT_USER3 — Player is pressing the USER3 key.
    • BT_USER4 — Player is pressing the USER4 key.
    • BT_RUN — Player has toggled running on.
  • uint Original_OldButtons
    Stores the unmodified buttons that the player had pressed in the previous tic.
  • Class<PlayerPawn> Cls
    Used internally to force a new player class when the player is spawned or respawned, if they had set their class to random. (Verification needed)
  • float DesiredFOV
    Stores the FOV the player has set in their settings.
  • float FOV
    The players' current FOV.
  • double ViewZ
    The absolute Z coordinate of the players' view, also accounts for any sort of view bobbing performed on the players' view.
  • double ViewHeight
    The base height of the players' eyes/view, this is the ViewHeight property of the player pawn.
  • double DeltaViewHeight
    The speed at which the players' view squats up or down. (Verification needed)
  • double Bob
    The players current bob level, ranging from 0 to 16. (Verification needed)
  • Vector2 Vel
    A vector2 that contains the players' XY velocity.
  • bool Centering
    Returns true while the player is centering their view.
  • uint TurnTicks
    (Need more info)
  • boolAttackDown
    Returns true if the players' primary or secondary fire buttons are held down. If it remains true for 2 seconds consecutively, and the player's HUD displays a mugshot, the mugshot will enter its Rampage state.
  • bool UseDown
    Returns true if the players' use key is being held down.
  • uint OldButtons
    The players' modified buttons that they had pressed in the previous tic.
  • int Health
    The players' health.
  • int InventoryTics
    (Need more info)
  • uint8 CurrentPlayerClass
    The number of the players' current player class.
  • int Frags[MAXPLAYERS]
    Allows you to access how many frags other players have gotten. (Verification needed)
  • int FragCount
    The amount of frags the player has gotten.
  • int LastKillTime
    (Need more info)
  • uint MultiCount
    (Need more info)
  • uint SpreeCount
    (Need more info)
  • uint16 WeaponState
    The state in which the players' weapon is in, possible states include:
    • WF_WEAPONREADY — The weapon is in its' ready state, and is ready to fire its' primary attack.
    • WF_WEAPONBOBBING — The weapon is currently bobbing.
    • WF_WEAPONREADYALT — The weapon is in its' ready state, and is ready to fire its' secondary attack.
    • WF_WEAPONSWITCHOK — The player can switch away from this weapon.
    • WF_DISABLESWITCH — Weapon switching is disabled for the players' current weapon.
    • WF_WEAPONRELOADOK — The player can reload this weapon.
    • WF_WEAPONZOOMOK — The player can zoom with this weapon.
    • WF_REFIRESWITCHOK(Need more info)
    • WF_USER1OK — The player can switch to the User1 state of the current weapon.
    • WF_USER2OK — The player can switch to the User2 state of the current weapon.
    • WF_USER3OK — The player can switch to the User3 state of the current weapon.
    • WF_USER4OK — The player can switch to the User4 state of the current weapon.
  • Weapon ReadyWeapon
    Stores the pointer to the players' current weapon.
  • Weapon PendingWeapon
    Stores the pointer to the weapon the player will switch to next.
  • PSprite PSprites
    (Need more info)
  • int Cheats
    Stores the players' cheats and flags. Despite what the name may suggest, this field is actually mostly used to store player-specific flags (As opposed to ones on their player pawn) that the engine uses internally. Available "cheats" include:
    • CF_NOCLIP — The player can noclip, ignoring all collision.
    • CF_GODMODE — The player is immune to all damage. Except for things that can bypass god mode.
    • CF_NOVELOCITY — All horizontal velocity is removed from the player.
    • CF_NOTARGET — Monsters don't target the player, unless the player hurts them.
    • CF_FLY — The player can fly.
    • CF_CHASECAM — The player has a third person chasecam that follows right behind them.
    • CF_FROZEN — The player can't move, but can still perform other actions like shooting and using things.
    • CF_REVERTPLEASE — Used when the players' view is changed by ZScript or the ChangeCamera line special/ACS function. So that the camera will revert back to their view if they move.
    • CF_STEPLEFT — Does nothing.
    • CF_FRIGHTENING — Monsters will run away from the player.
    • CF_INSTANTWEAPSWITCH — The player instantly switches weapons.
    • CF_TOTALLYFROZEN — All movement is blocked, except for pressing the use key.
    • CF_PREDICTING — The players movement is predicted, useful for netgames/multiplayer.
    • CF_INTERPVIEW — Interpolates the players' view, if it was altered outside of the players' own inputs. Such as being altered by A_SetAngle.
    • CF_INTERPVIEWANGLES — Interpolates the players' view, without interpolating the entire screen.
    • CF_SCALEDNOLERP — Allows mouse movement interpolation to work properly in certain extreme scenarios like i_timescale being set to incredibly low values.
    • CF_NOFOVINTERP — Disable FOV interpolation for the player. (New from 4.11.0)
    • CF_EXTREMELYDEAD — Marks the player as having died an extreme death.
    • CF_BUDDHA2 — The player can be damaged and hurt, but their health never drops below 1.
    • CF_GODMODE2 — Absolutely nothing can hurt the player, including things that bypass the normal god mode.
    • CF_BUDDHA — The player can be damaged, but their health never drops below 1. With the exception of attacks that bypass this cheat.
    • CF_NOCLIP2 — The player can noclip and fly as well. Similar to how noclip works in Quake.
    • CF_DRAIN(deprecated)
    • CF_HIGHJUMP(deprecated)
    • CF_REFLECTION(deprecated)
    • CF_PROSPERITY(deprecated)
    • CF_DOUBLEFIRINGSPEED(deprecated)
    • CF_INFINITEAMMO(deprecated)
  • Int16 ReFire
    Used by functions such as A_ReFire to determine how much the players' accuracy should deteriorate per shot.
  • Int16 Inconsistent
    (Need more info)
  • bool Waiting
    (Need more info)
  • int KillCount
    The amount of monsters that count as kills which the player has killed. Used for intermissions.
  • int ItemCount
    The amount of items the player has picked up. Used for intermissions.
  • int SecretCount
    The amount of secrets the player has found. Used for intermissions.
  • uint DamageCount
    Controls the intensity of the screen flash the player receives after taking damage. The maximum valid value is 100.
  • uint BonusCount
    Controls the intensity of the screen flash produced when the player picks up armor or health bonuses.
  • int HazardCount
    Controls the intensity of the screen flash produced when the player is hurt by a hazardous sector that uses Strife's damage model.
  • int HazardInterval
    Retrieved from the sectors' damage interval if it is using Strife's damage model. Controls how quickly the player will begin receiving damage once they get fully poisoned.
  • Name HazardType
    The name of the damage type that will be dealt to the player, retrieved from the sectors' damage type if it is using Strife's damage model.
  • int PoisonCount
    The amount of poison the player receives, also controls the amount by which the screen flashes. (Verification needed)
  • Name PoisonType
    The name of the poison damage to apply to the player.
  • Actor Poisoner
    A pointer to the actor, if any, who is the source of the players' poisoning.
  • Actor Attacker
    A pointer to the actor that attacked the player.
  • int ExtraLight
    Used by the A_Light functions to light up the screen when the player fires.
  • Int16 FixedColorMap
    (Need more info)
  • Int16 FixedLightLevel
    (Need more info)
  • int MorphTics
    Stores the duration for which a player morph will last. (Verification needed)
  • Class<PlayerPawn> MorphedPlayerClass
    (Need more info)
  • int MorphStyle
    Specifies what effects to apply to the player when morphed, possible flags include:
    • MRF_OLDEFFECTS — The default flag, uses standard Hexen/Heretic morphing behavior.
    • MRF_ADDSTAMINA — Adds health based on the players' stamina, instead of removing health based on it.
    • MRF_FULLHEALTH — Set the morphed players' maximum health to that of the player class they morphed to.
    • MRF_UNDOBYTOMEOFPOWER — The player will unmorph when they activate the Tome of Power.
    • MRF_UNDOBYCHAOSDEVICE — The player will unmorph when they activate the Chaos Device.
    • MRF_FAILTNOTELEFRAG — The player won't be telefragged if the unmorph by the Tome of Power fails.
    • MRF_FAILNOLAUGH — The player will not laugh if the unmoprh by the Chaos Device fails.
    • MRF_WHENINVULNERABLE — The player can morph while invulnerable, but only if they were the one that morphed themselves.
    • MRF_LOSEACTUALWEAPON — When unmorphed, the player will lose the weapon they had gotten while morphed, if any. Instead of losing whatever weapon they were using before being morphed.
    • MRF_NEWTIDBEHAVIOR — Create a new TID for the player when they are morphed, instead of keeping the previous TID from prior to the morph.
    • MRF_UNDOBYDEATH — The player will unmorph when killed.
    • MRF_UNDOBYDEATHFORCED — Forces the player to unmorph when killed.
    • MRF_UNDOBYDEATHSAVES — Restore the players' health when they are killed while morphed
    • MRF_UNMORPHBYTIMEOUT — The player will unmorph once the countdown finishes.
    • MRF_UNDOALWAYS — Always undo a morph with this flag on when it expires.
    • MRF_TRANSFERTRANSLATION — Transfer the palette translation of the player to their morph as well.
    • MRF_STANDARDUNDOING — Imples MRF_UNDOBYTOMEOFPOWER, MRF_UNDOBYCHAOSDEVICE, and MRF_UNMORPHBYTIMEOUT.
  • Class<Actor> MorphExitFlash
    The actor that will be used as the exit flash when the player unmorphs.
  • Weapon PreMorphWeapon
    The readyweapon the player was using before being morphed.
  • int ChickenPeck
    (Need more info)
  • int JumpTics
    Used by the CheckJump() virtual to determine if the player should be able to jump, if it is exactly 0, the player will be able to jump.
  • bool OnGround
    Returns true if the player is currently sitting on the ground or another mobj/actor.
  • int Respawn_Time
    Used to give a delay between the player dying and automatically respawning in Deathmatch games.
  • Actor Camera
    A pointer to the actor that the player is currently looking through, by default the players' camera will be their own player pawn.
  • int Air_Finished
    Keeps track of how long it'll take before the player drowns, if the levels' maptime exceeds this variables' value, then the player will begin to drown.
  • FName LastDamageType
    The last type of damage the player had received.
  • Actor MUSINFOActor
    Pointer to keep track of the MusicChanger actor that the player activated by entering its' sector.
  • int MUSINFOTics
    The delay, in tics, that it will take before the players' music is changed by the Music Changer actor.
  • bool Settings_Controller
    Players with this boolean on can control the game settings in netgames.
  • Int8 Crouching
    Stores the crouching state of the player. 0 and 1 means the player is not crouching, and -1 means the player is crouching.
  • Int8 CrouchDir
    Behaves identically to the Crouching variable. (Verification needed)
  • Bot Bot
    Stores a reference to the bot controlling this player, if any. (Need more info) (Verification needed) Can be used to check if the player is a bot.
  • float BlendR
    This controls how red the color blend that will appear on the players' screen is. This variable along with BlendG, BlendB, and BlendA, are used by A_SetBlend and FadeRange to flash the players' screen with colors.
  • float BlendG
    Ditto, but for the color green.
  • float BlendB
    Ditto, but for the color blue.
  • float BlendA
    Ditto, but for the alpha channel/transparency of the color blend.
  • String LogText
    (Need more info)
  • double MinPitch
    This variable stores the minimum pitch that the player can have when freelooking. The default value is -90. Negative values mean upwards pitch.
  • double MaxPitch
    This variable stores the maximum pitch that the player can have when freelooking. The default value is 90. Positive values mean towards pitch.
  • double CrouchFactor
    Controls by how much the players' view and hitbox is lowered when crouched, CheckCrouch() clamps this value between 0.5 and 1.0 by default. So that the final crouched height of the player is half their normal height.
  • double CrouchOffset
    (Need more info)
  • double CrouchViewDelta
    (Need more info)
  • Actor ConversationNPC
    A pointer to the actor the player is currently in conversation with. if any.
  • Actor ConversationPC
    A pointer to the player currently having a conversation.
  • double ConversationNPCAngle
    The angle at which the NPC the player is having a conversation with is facing.
  • Actor ConversationFaceTalker
    if set to true, the player will face the NPC they are having a conversation with.
  • @WeaponSlots Weapons
    A pointer to an instance of the WeaponSlots struct attached to this player.
  • ReadOnly @UserCmd OriginalCmd
    (Need more info)

Examples

Below are two example uses for accessing the PlayerInfo struct.

Current weapon detector

This inventory item accesses the ReadyWeapon pointer of its' player to print out the name of the new ReadyWeapon, every time that the ReadyWeapon's name doesn't much the stored name.

class CurrentWeaponDetector : Inventory
{
	Default
	{
		+Inventory.Quiet;
		+Inventory.PersistentPower;
	}
	
	string CurrentWeaponName; //The name of the current weapon in the players' inventory.
	
	override void AttachToOwner(Actor other)
	{
		Super.AttachToOwner(other);
		
		if (!other.Player) //Checks if the actor has a PlayerInfo struct at all, to determine if it is a player.
			GoAwayAndDie(); //if the actor isn't a player, then despawn.
		else
			CurrentWeaponName = other.Player.ReadyWeapon.GetClassName(); //Access the players' current weapon through the ReadyWeapon pointer, and return its' class name with GetClassName().
	}
	
	override void DoEffect()
	{
		Super.DoEffect();
		
		//Check if the player even has a ReadyWeapon, to prevent VM aborts.
		//Then check if the class name of the players' ReadyWeapon no longer matches the string in CurrentWeaponName, meaning that the ReadyWeapon was changed.
		if (Owner.Player.ReadyWeapon && Owner.Player.ReadyWeapon.GetClassName() != CurrentWeaponName)
		{
			CurrentWeaponName = Owner.Player.ReadyWeapon.GetClassName(); //if it was changed, the update the name again.
			Console.PrintF ("Your current weapon is now %s",CurrentWeaponName); //Print out the name of the current weapon in the console.
		}
	}
}

Cyberdemon alarm

This inventory item directly modifies the BlendR and BlendA variables of the player it is attached to, so that it can flash their screen red to warn them of nearby Cyberdemons.

class CyberdemonAlarm : Inventory
{
	Default
	{
		+Inventory.Quiet;
		+Inventory.PersistentPower;
	}
	
	override void AttachToOwner(Actor other)
	{
		// Allow attaching to players only:
		if (other.player)
		{
			Super.AttachToOwner(other);
		}
	}
	
	bool FoundCyberdemon;
	
	override void DoEffect()
	{
		//Only run the Cyberdemon check every second.
		if (GetAge() % TICRATE == 0)
		{
			BlockThingsIterator CyberdemonSearch = BlockThingsIterator.Create (owner,2048);
			
			while (CyberdemonSearch.Next())
			{
				Actor mobj;
				mobj = CyberdemonSearch.Thing;
				
				if (mobj && mobj.Health > 0 && !mobj.bDormant && owner.IsHostile(mobj) && mobj.GetClassName() == "Cyberdemon" && owner.Distance2D (mobj) <= 2048)
				{
					FoundCyberdemon = True;
					break;
				}
			}
		}
		
		if (owner.player.BlendA) owner.player.BlendA -= 0.0071428; //if the BlendA variable in the players' playerInfo is above 0, it will be decremented to wash away the red warning color.
		
		if (FoundCyberdemon)
		{
			Console.PrintF ("There's an enemy cyberdemon nearby!");
			owner.player.BlendR = 1.0; //Set the owners' red blend color to full red.
			owner.player.BlendA = 0.4; //And set the blends' alpha to 0.4.
			owner.A_StartSound ("doors/dr2_open",CHAN_AUTO,CHANF_LOCAL); //Alarm sound, only heard by the player.
			FoundCyberdemon = False;
		}
	}
}