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

(Verification needed)

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. 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 your code only try messing with that players' PlayerInfo if playeringame[] returns that they are a valid player.

Methods

  • Bool PoisonPlayer(Actor Poisoner, Actor Source, Int Poison)
    Poisons the player a certain amount 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 SetPSprite(Int ID, State Stat, Bool Pending)
    Changes the state used by a PSprite layer. (Verification needed)
    • ID
      The ID of the overlay.
    • State
      The state to make the overlay use.
    • Pending
      (Need more info)
  • Void SetSafeFlash(Weapon Weap, State FlashState, Int Index)
    (Need more info)
  • PSprite GetPSprite(Int ID)
    Get the PSprite of the specified layer.
    • ID
      The ID whose PSprite to check for.
  • PSprite FindPSprite(Int ID)
    Searches for a specific PSprite.
    • ID
      The ID of the PSprite to search for.
  • 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.
  • 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)

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.
  • 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. 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_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
    (Need more info)
  • @UserCmd Cmd
    (Need more info)
  • ReadOnly @UserCmd OriginalCmd
    (Need more info)

Examples

Below are two example uses for accessing the PlayerInfo struct. And for what it could be used for.

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)
 	{
 		Super.AttachToOwner(Other);
 		
 		If (!Other.Player) //Remove item if the actor isn't a player.
 			GoAwayAndDie();
 	}
 	
 	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;
 		}
 	}
 }