This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
functions:zdoom [2016/08/10 13:06] – [RestoreActivator] korshun | functions:zdoom [2017/06/12 18:35] (current) – removed korshun | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== ZDoom utilities ====== | ||
- | |||
- | ===== Constants ===== | ||
- | |||
- | '' | ||
- | |||
- | ===== Engine information ===== | ||
- | |||
- | ==== IsZandronum ==== | ||
- | '' | ||
- | |||
- | Returns true if the mod is being played in Zandronum. | ||
- | |||
- | **Example** | ||
- | |||
- | if (IsZandronum()) | ||
- | // Use workarounds | ||
- | else | ||
- | // Use ZDoom 2.7.1 features | ||
- | | ||
- | ===== CVar functions ===== | ||
- | |||
- | ==== GetCVarFixed ==== | ||
- | '' | ||
- | |||
- | 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> | ||
- | |||
- | ==== GetCVarPercentage ==== | ||
- | |||
- | '' | ||
- | |||
- | 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. | ||
- | |||
- | |||
- | ===== Video settings information ===== | ||
- | |||
- | These functions can be used to find out the player' | ||
- | |||
- | ==== AspectRatio ==== | ||
- | '' | ||
- | |||
- | Returns the aspect ratio of the current resolution as a fixed-point number. | ||
- | |||
- | ==== IsOpenGL ==== | ||
- | '' | ||
- | |||
- | Returns true if the OpenGL renderer is being used at the moment, false if software. | ||
- | |||
- | When used serverside, this function always returns true and emits a ProgramError. | ||
- | |||
- | <note important> | ||
- | * '' | ||
- | * A config from GZDoom or Zandronum used in ZDoom and having '' | ||
- | </ | ||
- | |||
- | ==== ScreenHeight ==== | ||
- | '' | ||
- | |||
- | Returns the current vertical resolution in pixels. | ||
- | |||
- | ==== ScreenWidth ==== | ||
- | '' | ||
- | |||
- | Returns the current horizontal resolution in pixels. | ||
- | |||
- | ==== StatusBarShown ==== | ||
- | '' | ||
- | |||
- | Returns true if the status bar is currently shown. | ||
- | |||
- | ===== HudMessage functions ===== | ||
- | |||
- | See also: [[hudlib]]. | ||
- | |||
- | |||
- | ==== ClearHudMessage ==== | ||
- | '' | ||
- | |||
- | Clears the HudMessage with the given id. A shorthand for '' | ||
- | |||
- | ===== Inventory functions ===== | ||
- | |||
- | ==== SetInventory ==== | ||
- | '' | ||
- | |||
- | Sets the amount of items of the given type in the activator' | ||
- | |||
- | **Example** | ||
- | |||
- | SetInventory(" | ||
- | SetInventory(" | ||
- | | ||
- | ==== SetActorInventory ==== | ||
- | '' | ||
- | |||
- | Same as SetInventory, | ||
- | |||
- | ==== GiveMaxInventory ==== | ||
- | '' | ||
- | |||
- | Gives the activator the maximum amount of items of the given type it can carry. | ||
- | |||
- | ==== GiveMaxActorInventory ==== | ||
- | '' | ||
- | |||
- | Same as GiveMaxInventory, | ||
- | |||
- | ==== TakeAllInventory ==== | ||
- | '' | ||
- | |||
- | Takes away all items of the given type from the activator' | ||
- | | ||
- | ==== TakeAllActorInventory ==== | ||
- | '' | ||
- | |||
- | Same as TakeAllInventory, | ||
- | |||
- | ==== ToggleInventory ==== | ||
- | '' | ||
- | |||
- | If the activator has at least one **item**, takes them all away. If he has none, gives one **item**. | ||
- | |||
- | **Example** | ||
- | |||
- | < | ||
- | ToggleInventory(" | ||
- | </ | ||
- | |||
- | ==== ToggleActorInventory ==== | ||
- | '' | ||
- | |||
- | Same as ToggleInventory, | ||
- | |||
- | ===== Player information functions ===== | ||
- | |||
- | ==== PlayerName ==== | ||
- | '' | ||
- | |||
- | Returns the name of the specified player. A shorthand for '' | ||
- | |||
- | ==== PlayerIsConnected ==== | ||
- | '' | ||
- | |||
- | Returns true if the specified player is connected to the server. | ||
- | |||
- | ==== BotCount ==== | ||
- | '' | ||
- | |||
- | Returns the amount of ZDoom bots present on the server. | ||
- | |||
- | ==== ClientCount ==== | ||
- | '' | ||
- | |||
- | Returns the amount of clients connected to the server (including bots). | ||
- | |||
- | ==== SpectatorCount ==== | ||
- | '' | ||
- | |||
- | Returns the amount of spectators connected to the server. | ||
- | |||
- | ==== PickRandomPlayer ==== | ||
- | '' | ||
- | |||
- | Returns the player number of a random player out of those who are in game. | ||
- | |||
- | ==== PickRandomSpectator ==== | ||
- | '' | ||
- | |||
- | Returns the player number of a random spectator. | ||
- | |||
- | ==== PickRandomBot ==== | ||
- | '' | ||
- | |||
- | Returns the player number of a random ZDoom bot. | ||
- | |||
- | ===== Actor utility functions ===== | ||
- | |||
- | ==== ActorPlayerNumber ==== | ||
- | '' | ||
- | |||
- | Returns the player number of the given actor, or -1 if the actor is not a player. | ||
- | |||
- | ==== ActorIsPlayer ==== | ||
- | '' | ||
- | |||
- | Returns true if the given actor is a player. | ||
- | |||
- | ==== ActivatorName ==== | ||
- | '' | ||
- | |||
- | Returns the activator' | ||
- | |||
- | ==== GetActorName ==== | ||
- | '' | ||
- | |||
- | Returns the actor' | ||
- | |||
- | ==== IsAlive ==== | ||
- | '' | ||
- | |||
- | Returns true if the activator is alive. | ||
- | |||
- | ==== ActorIsAlive ==== | ||
- | '' | ||
- | |||
- | Returns true if the given actor is alive. | ||
- | |||
- | |||
- | ===== Actor math functions ===== | ||
- | |||
- | These functions can save you some typing when doing math on actors. | ||
- | |||
- | ==== ActorDistance ==== | ||
- | '' | ||
- | |||
- | Returns the distance between two actors. | ||
- | |||
- | ==== ActorDistance2D ==== | ||
- | '' | ||
- | |||
- | Returns the distance between two actors, ignoring the Z dimension. | ||
- | |||
- | ==== GetActorCurrentSpeed ==== | ||
- | '' | ||
- | |||
- | Returns the current speed of actor. | ||
- | |||
- | ==== GetActorCurrentSpeed2D ==== | ||
- | '' | ||
- | |||
- | Returns the current speed of actor, ignoring the Z dimension. | ||
- | |||
- | ===== Actor utility functions ===== | ||
- | |||
- | ==== HasRoom ==== | ||
- | '' | ||
- | |||
- | Returns true if an actor of the given class has enough room to occupy the specified point. | ||
- | |||
- | ==== LookAtPoint ==== | ||
- | '' | ||
- | |||
- | Rotates the actor so that it looks at the specified point, taking the actor' | ||
- | |||
- | ==== LookAt ==== | ||
- | '' | ||
- | |||
- | Rotates the " | ||
- | |||
- | ===== 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 ==== | ||
- | '' | ||
- | |||
- | 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 ==== | ||
- | '' | ||
- | |||
- | Restores the activator from the two values returned by '' | ||
- | |||
- | <note warning>'' | ||
- | |||
- | <note important> | ||
- | |||
- | **Example** | ||
- | |||
- | [[zdoom> | ||
- | |||
- | < | ||
- | 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, | ||
- | |||
- | // Return the saved result of the activator-only function. | ||
- | return result; | ||
- | } | ||
- | </ | ||
- | |||
- | <note tip>The example function is already in ACSUtils: '' | ||
- | ===== Internationalization ===== | ||
- | |||
- | ==== lang ==== | ||
- | '' | ||
- | |||
- | Returns a translated string from [[zdoom> | ||
- | |||
- | |||
- | ===== Multiplayer functions ===== | ||
- | |||
- | ==== IsServer ==== | ||
- | '' | ||
- | |||
- | Returns true if the script is running on a server or in a non-network game. Use this function to check whether **server** logic needs to be run. | ||
- | |||
- | ==== IsClient ==== | ||
- | '' | ||
- | |||
- | Returns true if the script is running on a client or in a non-network game. Use this function to check whether **client** logic needs to be run. | ||
- | |||
- | <note tip>A player is considered **both a server and a client** in a non-network game (including singleplayer games and multiplayer emulation).</ | ||
- | |||
- | **Example** | ||
- | |||
- | < | ||
- | // This code will work both in true multiplayer and in singleplayer. | ||
- | if (IsServer()) | ||
- | DoServersideStuff(); | ||
- | | ||
- | if (IsClient()) | ||
- | DoClientsideStuff(); | ||
- | </ | ||
- | |||
- | ===== Actor property shorthands ===== | ||
- | |||
- | Not only are these shorter than '' | ||
- | |||
- | There are shorthands for the following properties: | ||
- | * Health | ||
- | * SpawnHealth | ||
- | * Speed | ||
- | |||
- | ==== GetActor< | ||
- | '' | ||
- | |||
- | Returns the < | ||
- | |||
- | ==== SetActor< | ||
- | '' | ||
- | |||
- | Sets the < | ||
- | |||
- | < | ||
- | while (true) | ||
- | { | ||
- | SetActorSpeed(tid, | ||
- | Delay(1); | ||
- | } | ||
- | </ | ||
- | |||
- | without wasting any bandwidth. | ||