Difference between revisions of "Lua:info ff script"

From Fortress Forever Wiki
Jump to navigationJump to search
 
(11 intermediate revisions by one other user not shown)
Line 1: Line 1:
 +
{{Infobox_mapping}}
 
==Introduction==
 
==Introduction==
An info_ff_script is a point-based scriptable entity.  If you are familiar with TFC's entities, this entity is ''somewhat'' similiar to [http://tf.valve-erc.com/kbase.php?id=1 info_tfgoals] and [http://tf.valve-erc.com/kbase.php?id=2 item_tfgoals]; however, the scriptability behind this entity makes it a great deal more flexibile.
+
info_ff_script is used to represent items that can affect, and be affected by players. Such items might be the flags in a CTF map, or the armor, health and ammo packs in a respawn room.
  
info_ff_script entities represent items that can affect, and be affected by players. Such items might be the flags in a CTF map, or the armor, health and ammo packs in a respawn room.
+
These entities are placed in a map editor, such as Hammer, and must be given a name in order to function correctly. This name will be used to link it into the map's corresponding Lua file.  So, whenever you put a named info_ff_script entity in your map, the game attempts to find a correspondingly named object in '''mapname'''.lua.
  
These entities are placed in a map editor, such as Hammer, and must be given a name inorder to function correctly.  This name will be used to tie it into the map's corresponding Lua file.  So, whenever you put a named info_ff_script entity in your map, the game attempts to find a correspondingly named function in mapname.lua.
+
FF includes a number of pre-existing game modes that require very little work to implement in your own maps--that is, assuming your map's gameplay is similar enough to one of these templates.  You'll simply need to add the appropriate entities, give them the proper names, and you're all set. More on that can be found by looking at the available [[map templates]].
 
+
====Example====  
Part of the idea behind the functionality with this entity is the concept of creating a "base" item in Lua, and then setting the different values for different items that you might have. FF includes a number of pre-existing game-modes that require very little work to implement in your own maps; that is, assuming your map's gameplay mirrors the gameplay setup in the particular template you use.  You'll simply need to add the appropriate entities, given them a particular name, and you're all set. More on that can be found by looking at the available [[map templates]].
 
====Example====
 
 
Let's assume you don't want to use one of FF's pre-existing base items, and you just want to make your own. For the sake of the example let's say we're setting up our own flag as a learning experience.  First, put two info_ff_script entities in your map, and give them the names: ''myfirstflag'' and ''mysecondflag''. Now, create a new text file, and save the file as ''yourmapname''.lua.
 
Let's assume you don't want to use one of FF's pre-existing base items, and you just want to make your own. For the sake of the example let's say we're setting up our own flag as a learning experience.  First, put two info_ff_script entities in your map, and give them the names: ''myfirstflag'' and ''mysecondflag''. Now, create a new text file, and save the file as ''yourmapname''.lua.
  
Line 21: Line 20:
 
You're probably noticing that nothing in the above bit of Lua has anything directly related to the two named entities you put in your map. We're creating a new info_ff_script object in Lua, and setting some default parameters. For our example, the model won't be changing, but we have two flags and we're going to easily change it's name and skin.  This ''baseflag'' is our blank that we'll copy and modify to create other team-specific flags that are sitting in our map.
 
You're probably noticing that nothing in the above bit of Lua has anything directly related to the two named entities you put in your map. We're creating a new info_ff_script object in Lua, and setting some default parameters. For our example, the model won't be changing, but we have two flags and we're going to easily change it's name and skin.  This ''baseflag'' is our blank that we'll copy and modify to create other team-specific flags that are sitting in our map.
  
Ok, fuck this for now, I'm tired.
+
--We're extending our baseflag!
 +
myfirstflag = baseflag:new({
 +
        name = "Flag one",
 +
        modelskin = 2
 +
})
  
==Functions & Events==
+
Any functions and variables we define in baseflag will be inherited by those entities which use it as a base. We can redefine functions and variables in the derived entites, to override the basic functionality.
info_ff_scripts have various functions and events that handle specific behavior of the entity, or provide you information that may be useful elsewhere in your scripting.
+
==Events, or callbacks==
 +
info_ff_script has various callbacks that allow your Lua script to detect events that happen in the game.
  
Access to these various methods is typically in the following format:
+
Access to events is typically in the following format:
  
  function item:'''methodname'''( ''parameters'' )
+
  function item:'''eventname'''( ''parameters'' )
 
   --What to do when this method is called
 
   --What to do when this method is called
 
   --return anything, if necessary
 
   --return anything, if necessary
 
  end
 
  end
 
   
 
   
Obviously, different methods will accept different parameters. Some methods may not take any parameters, or may not return any valuesAll of the passed parameters, returned values and examples of usage can be found for all of the info_ff_script methods in the following links.
+
Different methods may provide data by passing on a number of parameters.  The types of these parameters, returned values and examples of usage can be found in the following links.
 +
 
 +
==="On" Events===
 +
These callbacks are available to detect when certain events happen to the info_ff_script.
 +
*[[Info_ff_script:spawn|ondrop( owner_entity )]]--The flag is dropped, either intentionally or by death.
 +
*[[Info_ff_script:onloseitem|onloseitem( owner_entity )]]--The item is taken from the player for any reason.
 +
*[[Info_ff_script:onreturn|onreturn()]]--The flag returns to its origin.
 +
*[[Info_ff_script:onownerdie|onownerdie( owner_entity )]]--A player dies while holding the item.
 +
*[[Info_ff_script:onownerforcerespawn|onownerforcerespawn( owner_entity )]]--The player is forced to respawn while holding the item.
 +
*[[Info_ff_script:ownercloak|ownercloak( owner_entity )]]--A spy activates his cloak while holding the item. NOTE: This one doesn't start with "on".
 +
 
 +
===Other Events===
 +
*[[Info_ff_script:dropitemcmd|dropitemcmd(owner_entity)]]--The player holding the item presses the dropitems key.
 +
*[[Info_ff_script:touch|touch( player_entity )]]--The info_ff_script is touched by a player.
 +
*[[Info_ff_script:precache|precache()]]--Called on each info_ff_script when the map is loaded, but before it starts. See [[Lua:precache]].
 +
*[[Info_ff_script:materialize|materialize()]]--Called when an item respawns.
 +
 
 +
===Options===
 +
*dropatspawn()--Return true to make the object drop to the ground when the map loads. Return false to leave it floating where it was placed in Hammer.
 +
*hasanimation()--Return true if the model used is animated.
 +
*usephysics()--Return true for dropped items to act as physics props. Default behavior is for the item to stop when it hits the ground.
 +
 
 +
==Functions==
 +
Whenever you have a reference to a particular entity, you can use its functions to control its behavior.
 +
 
 +
===Example===
 +
-- find the flag and cast it to an info_ff_script
 +
local flag = GetInfoScriptByName("redflag")
 +
      -- Make sure flag isn't nil
 +
      if flag then
 +
          -- check if the player is carrying the flag
 +
          if player:HasItem(flag:GetName()) then
 +
-- return the flag
 +
          flag:Return()
 +
          end   
 +
      end
  
 
===Attachment Functions===
 
===Attachment Functions===
These functions can be used to change the offset by which an item is attached to a player. These offsets are relative to the player's absolute origin. (?)  (Patty, what are the conditions for these? Like, when do the apply and shit? You were talkin' about it one day, but yeah, this is just a description for the attachment functions. America, FUCK YEAH!)
+
These functions can be used to change the offset by which an item is attached to a player. These offsets are relative to the player's absolute origin.  
*[[LUA:attachoffsetforward|attachoffsetforward]]
+
*[[Info_ff_script:attachoffsetforward|attachoffsetforward]]
*[[LUA:attachoffsetright|attachoffsetright]]
+
*[[Info_ff_script:attachoffsetright|attachoffsetright]]
*[[LUA:attachoffsetup|attachoffsetup]]
+
*[[Info_ff_script:attachoffsetup|attachoffsetup]]
 +
 
 
===Get Functions===
 
===Get Functions===
Generalized description of Get functions, and how they relate to an info_ff_script entity goes here.
+
Get functions return some information. Information you can use.
*[[LUA:GetAngles|GetAngles]]
+
{| border="1" cellspacing="0"
*[[LUA:GetOrigin|GetOrigin]]
+
! Command !! Description
 +
|-
 +
|[[Info_ff_script:GetAngles]]() || Returns an orientation array. (p,y,r, I believe)
 +
|-
 +
|[[Info_ff_script:GetOrigin]] () || Returns a location array. (x,y,z)
 +
|-
 +
|[[Info_ff_script:GetName]] () || Returns a string containing the name of the info_ff_script.
 +
|-
 +
|[[Info_ff_script:gettouchsizes]] ( mins, maxs )  || Passes min and max vectors by reference for the function to alter in place.
 +
|-
 +
|[[Info_ff_script:getphysicssizes]] ( mins, maxs )  || Passes min and max vectors by reference for the function to alter in place.
 +
|-
 +
|[[Info_ff_script:getbloatsize]] () || Expects a float return value, uses the value to inflate the touch bounding box (default bloat is 12).
 +
|}
  
===On Events===
+
===Set Functions===
These callbacks are available to detect when certain events happen to the info_ff_script.
+
These functions change some property of the info_ff_script.
*[[Info_ff_script:ondrop|ondrop]]--The item is dropped, either by death or intentionally.
+
*[[info_ff_script:SetAngles|SetAngles]](angles) Turns the item to a specific angle.
*[[Info_ff_script:onloseitem|onloseitem]]--The item is taken from the player for any reason.
+
*[[info_ff_script:SetModel|SetModel]](string) Sets the model of the item. Remember to [[Lua:Precache|precache]].
*[[Info_ff_script:onreturn|onreturn]]--The flag returns to its origin.
+
*[[info_ff_script:SetOrigin|SetOrigin]](origin) Moves the item to a specific spot on the map.
*[[Info_ff_script:onownerdie|onownerdie]]--A player dies while holding the item.
+
*[[info_ff_script:SetSkin|SetSkin]](int) Changes the skin of the model.
*[[Info_ff_script:onownerforcerespawn|onownerforcerespawn]]--A lua script makes the player respawn while holding the item.
+
*[[info_ff_script:SetStartAngles|SetStartAngles]](angles) Sets the orientation of the item for when it respawns.
*[[Info_ff_script:ownercloak|ownercloak]]--A spy activates his cloak while holding the item.
+
*[[info_ff_script:SetStartOrigin|SetOrigin]](origin) Sets the location of the item for when it respawns.
*[[Info_ff_script:dropitemcmd|dropitemcmd]]--The player holding the item presses the dropitems key.
 
  
===Set Functions===
 
Generalized description of Set functions, and how they relate to an info_ff_script entity goes here.
 
*[[LUA:SetAngles|SetAngles]]
 
*[[LUA:SetModel|SetModel]]
 
*[[LUA:SetOrigin|SetOrigin]]
 
*[[LUA:SetSkin|SetSkin]]
 
 
===State Checking Functions===
 
===State Checking Functions===
Generalized description of State checking functions, and how they relate to an info_ff_script entity goes here.
+
These all return true or false. You'll generally use them in a conditional statement.
*[[LUA:IsActive|IsActive]]
+
*[[Info_ff_script:IsActive|IsActive]]
*[[LUA:IsCarried|IsCarried]]
+
*[[Info_ff_script:IsCarried|IsCarried]]
*[[LUA:IsDropped|IsDropped]]
+
*[[Info_ff_script:IsDropped|IsDropped]]
*[[LUA:IsInactive|IsInactive]]
+
*[[Info_ff_script:IsInactive|IsInactive]]
*[[LUA:IsRemoved|IsRemoved]]
+
*[[Info_ff_script:IsRemoved|IsRemoved]]
*[[LUA:IsReturned|IsReturned]]
+
*[[Info_ff_script:IsReturned|IsReturned]]
 
 
==This shit below here still needs to be categorized like the above==
 
===addnotouch()===
 
Defined in base_teamplay. Default behavior is to prevent the player from picking up the flag for 2 seconds after dropping it. Disabling this behavior will prevent players from being able to throw the flag at all.
 
 
 
===dropatspawn()===
 
Return true to make the object drop to the ground when the map loads. Return false to leave it floating where it was placed in Hammer
 
  
===Drop()===
+
===Misc. Functions===
===hasanimation()===
+
*addnotouch() Defined in base_teamplay. Default behavior is to prevent the player from picking up the flag for 2 seconds after dropping it. Disabling this behavior will prevent players from being able to throw the flag at all--or rather, they will throw it, and pick it up an instant later.
===new()===
+
*new({collection}) creates a new type of info_ff_script. See [[Lua:info_ff_script#Example]]
===Pickup()===
+
*Drop(FLAG_RETURN_TIME, FLAG_THROW_SPEED) Causes the player to throw/drop the flag.
===precache()===
+
*Pickup(player) Causes the specified player to carry this item.
===Respawn()===
+
*Respawn(int) Causes the item to disappear, and reappear after a specified number of seconds.
===Return()===
+
*Return() Causes the item to return to its starting point.
===spawn()===
+
*EmitSound(String) Causes the item to make a sound.
===touch()===
+
*Remove() Causes the item to disappear from the map.
===usephysics()===
+
*Restore() Re-enables an item that has been removed.
[[Category:Lua]]
+
[[Category:Lua]][[Category:Lua_Commands]][[Category:Lua_Callbacks]]

Latest revision as of 13:09, 5 April 2015

Mapping for FF
The Basics

Setting up Hammer
Getting Started With Lua
Releasing a map

FF-specific Entities

Lua location system

Map Templates
FF Lua Documentation

Entity Typing
Entity Collections

Commands
Callbacks

Introduction

info_ff_script is used to represent items that can affect, and be affected by players. Such items might be the flags in a CTF map, or the armor, health and ammo packs in a respawn room.

These entities are placed in a map editor, such as Hammer, and must be given a name in order to function correctly. This name will be used to link it into the map's corresponding Lua file. So, whenever you put a named info_ff_script entity in your map, the game attempts to find a correspondingly named object in mapname.lua.

FF includes a number of pre-existing game modes that require very little work to implement in your own maps--that is, assuming your map's gameplay is similar enough to one of these templates. You'll simply need to add the appropriate entities, give them the proper names, and you're all set. More on that can be found by looking at the available map templates.

Example

Let's assume you don't want to use one of FF's pre-existing base items, and you just want to make your own. For the sake of the example let's say we're setting up our own flag as a learning experience. First, put two info_ff_script entities in your map, and give them the names: myfirstflag and mysecondflag. Now, create a new text file, and save the file as yourmapname.lua.

So far, we don't have much of anything. We'll need to let Lua know that these entities are in our map. As you might expect, there's other options you can specify here, but this is our first script so we're going to keep it simple. This is how we'd get it started in our previously created Lua file.

-- This is my first base flag!
baseflag = info_ff_script:new({
       name = "base flag",
       model = "models/flag/flag.mdl",
       modelskin = 1
})

You're probably noticing that nothing in the above bit of Lua has anything directly related to the two named entities you put in your map. We're creating a new info_ff_script object in Lua, and setting some default parameters. For our example, the model won't be changing, but we have two flags and we're going to easily change it's name and skin. This baseflag is our blank that we'll copy and modify to create other team-specific flags that are sitting in our map.

--We're extending our baseflag!
myfirstflag = baseflag:new({
       name = "Flag one",
       modelskin = 2
})

Any functions and variables we define in baseflag will be inherited by those entities which use it as a base. We can redefine functions and variables in the derived entites, to override the basic functionality.

Events, or callbacks

info_ff_script has various callbacks that allow your Lua script to detect events that happen in the game.

Access to events is typically in the following format:

function item:eventname( parameters )
  --What to do when this method is called
  --return anything, if necessary
end

Different methods may provide data by passing on a number of parameters. The types of these parameters, returned values and examples of usage can be found in the following links.

"On" Events

These callbacks are available to detect when certain events happen to the info_ff_script.

Other Events

Options

  • dropatspawn()--Return true to make the object drop to the ground when the map loads. Return false to leave it floating where it was placed in Hammer.
  • hasanimation()--Return true if the model used is animated.
  • usephysics()--Return true for dropped items to act as physics props. Default behavior is for the item to stop when it hits the ground.

Functions

Whenever you have a reference to a particular entity, you can use its functions to control its behavior.

Example

-- find the flag and cast it to an info_ff_script
local flag = GetInfoScriptByName("redflag")
     -- Make sure flag isn't nil
     if flag then
          -- check if the player is carrying the flag
          if player:HasItem(flag:GetName()) then
		-- return the flag
          	flag:Return()
          end     
     end

Attachment Functions

These functions can be used to change the offset by which an item is attached to a player. These offsets are relative to the player's absolute origin.

Get Functions

Get functions return some information. Information you can use.

Command Description
Info_ff_script:GetAngles() Returns an orientation array. (p,y,r, I believe)
Info_ff_script:GetOrigin () Returns a location array. (x,y,z)
Info_ff_script:GetName () Returns a string containing the name of the info_ff_script.
Info_ff_script:gettouchsizes ( mins, maxs ) Passes min and max vectors by reference for the function to alter in place.
Info_ff_script:getphysicssizes ( mins, maxs ) Passes min and max vectors by reference for the function to alter in place.
Info_ff_script:getbloatsize () Expects a float return value, uses the value to inflate the touch bounding box (default bloat is 12).

Set Functions

These functions change some property of the info_ff_script.

  • SetAngles(angles) Turns the item to a specific angle.
  • SetModel(string) Sets the model of the item. Remember to precache.
  • SetOrigin(origin) Moves the item to a specific spot on the map.
  • SetSkin(int) Changes the skin of the model.
  • SetStartAngles(angles) Sets the orientation of the item for when it respawns.
  • SetOrigin(origin) Sets the location of the item for when it respawns.

State Checking Functions

These all return true or false. You'll generally use them in a conditional statement.

Misc. Functions

  • addnotouch() Defined in base_teamplay. Default behavior is to prevent the player from picking up the flag for 2 seconds after dropping it. Disabling this behavior will prevent players from being able to throw the flag at all--or rather, they will throw it, and pick it up an instant later.
  • new({collection}) creates a new type of info_ff_script. See Lua:info_ff_script#Example
  • Drop(FLAG_RETURN_TIME, FLAG_THROW_SPEED) Causes the player to throw/drop the flag.
  • Pickup(player) Causes the specified player to carry this item.
  • Respawn(int) Causes the item to disappear, and reappear after a specified number of seconds.
  • Return() Causes the item to return to its starting point.
  • EmitSound(String) Causes the item to make a sound.
  • Remove() Causes the item to disappear from the map.
  • Restore() Re-enables an item that has been removed.