ACSUtils Wiki

An ACS library for ZDoom-based ports

User Tools

Site Tools


functions:zdoom

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
functions:zdoom [2016/09/13 17:05] – [ChangeActorFlag] korshunfunctions:zdoom [2017/06/12 18:35] (current) – removed korshun
Line 1: Line 1:
-====== ZDoom utilities ====== 
- 
-===== Constants ===== 
- 
-''int MAX_PLAYERS'' -- maximum amount of players in Zandronum multiplayer. 
- 
-===== CVar functions ===== 
- 
-==== GetCVarFixed ==== 
-''fixed a_GetCVarFixed(str name)'' 
- 
-Returns the value of the fixed-point CVar with the given name, or 0 if the cvar does not exist or is not a fixed-point number. 
- 
-<note important>This function is called ''a_GetCVarFixed'' and not ''GetCVarFixed'' because GDCC has a function with the same name.</note> 
- 
-==== GetCVarPercentage ==== 
- 
-''fixed GetCVarPercentage(str name)'' 
- 
-Returns the value of the given integer CVar divided by 100. If the integer value of the CVar could not be retrieved, returns 0. This is useful for CVars that are percentages. 
- 
-===== Internationalization ===== 
- 
-==== lang ==== 
-''str lang(str id)'' 
- 
-Returns a translated string from [[zdoom>LANGUAGE]]. Shorthand for ''StrParam(l:id)''. 
- 
-===== Functions for mappers ===== 
- 
-==== SyncSpeed ==== 
-''function int SyncSpeed(int newdistance, int syncdistance, int syncspd)'' 
- 
-[[zdoom>Syncspeed]] 
- 
-FIXME Needs proper documentation FIXME 
- 
-===== Video settings information ===== 
- 
-These functions can be used to find out the player's video settings. 
- 
-==== AspectRatio ==== 
-''fixed AspectRatio()'' 
- 
-Returns the aspect ratio of the current resolution as a fixed-point number. 
- 
-==== ScreenHeight ==== 
-''int ScreenHeight()'' 
- 
-Returns the current vertical resolution in pixels. 
- 
-==== ScreenWidth ==== 
-''int ScreenWidth()'' 
- 
-Returns the current horizontal resolution in pixels. 
- 
-==== StatusBarShown ==== 
-''bool StatusBarShown()'' 
- 
-Returns true if the status bar is currently shown. 
- 
-===== HudMessage functions ===== 
- 
-See also: [[hudlib]]. 
- 
- 
-==== ClearHudMessage ==== 
-''void ClearHudMessage(int id)'' 
- 
-Clears the HudMessage with the given id for the activator. A shorthand for ''HudMessage(s:""; HUDMSG_PLAIN, id, 0, 0, 0, 0, 0)''. 
- 
-==== ClearHudMessageBold ==== 
-''void ClearHudMessageBold(int id)'' 
- 
-Clears the HudMessage with the given id for all players (serverside) or the client (clientside). A shorthand for ''HudMessageBold(s:""; HUDMSG_PLAIN, id, 0, 0, 0, 0, 0)''. 
- 
-===== Inventory functions ===== 
- 
-==== SetInventory ==== 
-''void SetInventory(str item, int amount)'' 
- 
-Sets the amount of items of the given type in the activator's inventory to **amount**. 
- 
-**Example** 
- 
-    SetInventory("Shells", 8); // The player will now have exactly 8 shells. 
-    SetInventory("IsReloading", 0); // Set the "IsReloading" flag to 0. 
-     
-==== SetActorInventory ==== 
-''void SetActorInventory(int tid, str item, int amount)'' 
- 
-Same as SetInventory, but affects the given actor instead of the activator. 
- 
-==== GiveMaxInventory ==== 
-''void GiveMaxInventory(str item)'' 
- 
-Gives the activator the maximum amount of items of the given type it can carry. 
- 
-==== GiveMaxActorInventory ==== 
-''void GiveMaxActorInventory(int tid, str item)'' 
- 
-Same as GiveMaxInventory, but affects the given actor instead of the activator. 
- 
-==== TakeAllInventory ==== 
-''void TakeAllInventory(str item);'' 
- 
-Takes away all items of the given type from the activator's inventory. 
-     
-==== TakeAllActorInventory ==== 
-''void TakeAllActorInventory(int tid, str item)'' 
- 
-Same as TakeAllInventory, but affects the given actor instead of the activator. 
- 
-==== ToggleInventory ==== 
-''void ToggleInventory(str item)'' 
- 
-If the activator has at least one **item**, takes them all away. If he has none, gives one **item**. 
- 
-**Example** 
- 
-<code> 
-ToggleInventory("IsReloading"); 
-</code> 
- 
-==== ToggleActorInventory ==== 
-''void ToggleActorInventory(int tid, str item)'' 
- 
-Same as ToggleInventory, but affects the given actor instead of the activator. 
- 
-===== Actor property shorthands ===== 
- 
-Not only are these shorter than ''[Get/Set]ActorProperty(tid, APROP_SOMETHING)'', but the setters also don't set the value if it's the same, saving bandwidth when used serverside. 
- 
-There are shorthands for the following properties: 
-  * Health 
-  * SpawnHealth 
-  * Speed 
- 
-==== GetActor<Property> ==== 
-''int GetActor<Property>(int tid)'' 
- 
-Returns the <Property> of the actor. 
- 
-==== SetActor<Property> ==== 
-''int SetActor<Property>(int tid, int value)'' 
- 
-Sets the <Property> of the actor if the new value is not the same as the current value. This saves bandwidth when used serverside, allowing you to write the code like this: 
- 
-<code> 
-while (true) 
-{ 
-    SetActorSpeed(tid, SomeValue()); 
-    Delay(1); 
-} 
-</code> 
- 
-without wasting any bandwidth. 
- 
-===== Actor functions ===== 
- 
-==== ChangeFlag ==== 
-''void ChangeFlag(str flagname, bool value)'' 
- 
-Adds or removes a flag from the activator. This is a Zandronum replacement for [[zdoom>SetActorFlag]]. 
- 
-**Example** 
-<code> 
-ChangeFlag("SHOOTABLE", false); 
-</code> 
- 
-<note>To use this function, you need to add ''decorate/changeflag.txt'' to your decorate.</note> 
-==== ChangeActorFlag ==== 
-''void ChangeActorFlag(int tid, str flagname, bool value)'' 
- 
-Adds or removes a flag from the specified actor. This is a Zandronum replacement for [[zdoom>SetActorFlag]]. 
- 
-**Example** 
- 
-<code> 
-ChangeActorFlag(tid, "SHOOTABLE", false); 
-</code> 
- 
-<note>To use this function, you need to add ''decorate/changeflag.txt'' to your decorate.</note> 
- 
-==== ActorPlayerNumber ==== 
-''int ActorPlayerNumber(int tid)'' 
- 
-Returns the player number of the given actor, or -1 if the actor is not a player. 
- 
-==== ActorIsPlayer ==== 
-''bool ActorIsPlayer(int tid)'' 
- 
-Returns true if the given actor is a player. 
- 
-==== ActivatorName ==== 
-''str ActivatorName()'' 
- 
-Returns the activator's actor class name, or player name if the activator is a player. Shorthand for ''StrParam(n:0)''. 
- 
-==== GetActorName ==== 
-''str GetActorName(int tid)'' 
- 
-Returns the actor's class name, or player name if the actor is a player. 
- 
-==== IsAlive ==== 
-''bool IsAlive()'' 
- 
-Returns true if the activator is alive. 
- 
-==== ActorIsAlive ==== 
-''bool ActorIsAlive(int tid)'' 
- 
-Returns true if the given actor is alive. 
- 
- 
-==== HasRoom ==== 
-''bool HasRoom(str classname, fixed x, fixed y, fixed z)'' 
- 
-Returns true if an actor of the given class has enough room to occupy the specified point. 
- 
-==== LookAtPoint ==== 
-''void LookAtPoint(int tid, fixed x, fixed y, fixed z)'' 
- 
-Rotates the actor so that it looks at the specified point, taking the actor's view height into account. 
- 
-==== LookAt ==== 
-''void LookAt(int camera, int target)'' 
- 
-Rotates the "camera" actor so that it looks at the specified "target" actor, taking into account the view height of both actors. 
- 
- 
-===== Actor math functions ===== 
- 
-These functions can save you some typing when doing math on actors. 
- 
-==== ActorDistance ==== 
-''fixed ActorDistance(int tid1, int tid2)'' 
- 
-Returns the distance between two actors. 
- 
-==== ActorDistance2D ==== 
-''fixed ActorDistance2D(int tid1, int tid2)'' 
- 
-Returns the distance between two actors, ignoring the Z dimension. 
- 
-==== GetActorCurrentSpeed ==== 
-''fixed GetActorCurrentSpeed(int tid)'' 
- 
-Returns the current speed of actor. 
- 
-==== GetActorCurrentSpeed2D ==== 
-''fixed GetActorCurrentSpeed2D(int tid)'' 
- 
-Returns the current speed of actor, ignoring the Z dimension. 
- 
-===== Activator swapping ===== 
- 
-Some ZDoom functions only work on the activator. To convert them to functions that can take any tid, use this pair of functions: 
- 
-==== SwapActivator ==== 
-''int, int SwapActivator(int tid)'' 
- 
-Temporarily makes the given actor the activator of the script and returns two values, allowing you to restore the previous activator. 
- 
-[[..mulretval|This function returns multiple values.]] 
- 
-==== RestoreActivator ==== 
-''void RestoreActivator(int a, int b)'' 
- 
-Restores the activator from the two values returned by ''SwapActivator''. 
- 
-<note warning>''SwapActivator'' changes the current activator's tid, do not allow any delay between ''SwapActivator'' and ''RestoreActivator'' if you don't want tid problems!</note> 
- 
-<note important>When using ''SwapActivator'' multiple times, alwaysperform calls to ''RestoreActivator'' in the exact reverse order, or the tids won't be restored correctly.</note> 
- 
-**Example** 
- 
-[[zdoom>PlayerNumber]] can only return the activator's player number. Here's how it's converted to work on an arbitrary tid: 
- 
-<code> 
-function int ActorPlayerNumber(int tid) 
-{ 
-        // Swap the activator and save two numbers to restore it later. 
- SwapActivator(tid); 
- int a = r1; 
- int b = r2; 
- 
-        // Retrieve the result of the activator-only function. 
- int result = PlayerNumber(); 
-  
-        // Restore the previous activator using the two saved numbers. 
- RestoreActivator(a, b); 
- 
-        // Return the saved result of the activator-only function. 
- return result; 
-} 
-</code> 
- 
-<note tip>The example function is already in ACSUtils: ''[[functions:zdoom#actorplayernumber|ActorPlayerNumber]]''.</note> 
- 
-===== Player information functions ===== 
- 
-==== PlayerName ==== 
-''str PlayerName(int player)'' 
- 
-Returns the name of the specified player. A shorthand for ''StrParam(n:player+1)''. 
- 
-==== PlayerIsConnected ==== 
-''bool PlayerIsConnected(int player)'' 
- 
-Returns true if the specified player is connected to the server. 
- 
-==== BotCount ==== 
-''int BotCount()'' 
- 
-Returns the amount of ZDoom bots present on the server. 
- 
-==== ClientCount ==== 
-''int ClientCount()'' 
- 
-Returns the amount of clients connected to the server (including bots). 
- 
-==== SpectatorCount ==== 
-''int SpectatorCount()'' 
- 
-Returns the amount of spectators connected to the server. 
- 
-==== PickRandomPlayer ==== 
-''int PickRandomPlayer()'' 
- 
-Returns the player number of a random player out of those who are in game. 
- 
-==== PickRandomSpectator ==== 
-''int PickRandomSpectator()'' 
- 
-Returns the player number of a random spectator. 
- 
-==== PickRandomBot ==== 
-''int PickRandomBot()'' 
- 
-Returns the player number of a random ZDoom bot. 
- 
- 
  
functions/zdoom.1473775530.txt.gz · Last modified: 2016/09/13 17:05 by korshun