Difference between revisions of "Lua:func button"

From Fortress Forever Wiki
Jump to navigationJump to search
(New page: {{Infobox manual/Header}} func_button is a standard Source brush entity, that creates a button the player can press. Fortress Forever gives mappers some more options when using func_button...)
 
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
 
{{Infobox manual/Header}}
 
{{Infobox manual/Header}}
func_button is a standard Source brush entity, that creates a button the player can press. Fortress Forever gives mappers some more options when using func_button. See [http://developer.valvesoftware.com/wiki/Func_button|func_button on Valve SDK Docs] for general usage info.
+
func_button is a standard Source brush entity, that creates a button the player can press. Fortress Forever gives mappers some more options when using func_button. See [http://developer.valvesoftware.com/wiki/Func_button | func_button on Valve SDK Docs] for general usage info.
 
==Example==
 
==Example==
 
  --from well.lua. This button opens the flagroom bars.
 
  --from well.lua. This button opens the flagroom bars.
Line 16: Line 16:
 
The following variables are set in the global lua namespace before this function is called:
 
The following variables are set in the global lua namespace before this function is called:
 
*info_damage: The amount of damage that the button will recieve.
 
*info_damage: The amount of damage that the button will recieve.
*info_attacker: The player that fired the attack.
+
*info_attacker: The ID of the player that fired the attack.
 
*info_classname: The classname of the weapon that hit the button. Note that this may be the classname of the projectile for projectile weapons, or the classname of the weapon for non-projectile weapons.
 
*info_classname: The classname of the weapon that hit the button. Note that this may be the classname of the projectile for projectile weapons, or the classname of the weapon for non-projectile weapons.
 
This function may modify the info_damage global variable in the global scope. If it does, the damage the button takes will be changed. This means that the script for a map can make buttons recieve more or less damage through scripting. Additionally, if info_damage is set to 0, or if the function returns false, the button will not be pressed.
 
This function may modify the info_damage global variable in the global scope. If it does, the damage the button takes will be changed. This means that the script for a map can make buttons recieve more or less damage through scripting. Additionally, if info_damage is set to 0, or if the function returns false, the button will not be pressed.
Line 22: Line 22:
 
An example of allowing only spanners to hit a button:
 
An example of allowing only spanners to hit a button:
 
<pre>
 
<pre>
bob = func_button:new({})
+
spanner_button = func_button:new({})
function bob:ondamage()
+
function spanner_button:ondamage()
ConsoleToAll(GetPlayerName(info_attacker).." shot button with a "..info_classname.." for "..info_damage.." damage")
+
if IsPlayer( GetPlayerByID(info_attacker) ) then
if info_classname == "ff_weapon_spanner" then
+
local player = CastToPlayer( GetPlayerByID(info_attacker) )
PressButton(entname)
+
ConsoleToAll(player:GetName().." shot button with a "..info_classname.." for "..info_damage.." damage")
 +
if info_classname == "ff_weapon_spanner" then
 +
PressButton(entname)
 +
end
 
end
 
end
 
end
 
end
Line 39: Line 42:
 
===OnOut()===
 
===OnOut()===
 
Called when the button "pops out" and can be pressed again.
 
Called when the button "pops out" and can be pressed again.
 +
 +
[[Category:Lua]][[Category:Entities]]
 +
{{Infobox manual/Footer}}

Latest revision as of 16:30, 28 June 2009


func_button is a standard Source brush entity, that creates a button the player can press. Fortress Forever gives mappers some more options when using func_button. See | func_button on Valve SDK Docs for general usage info.

Example

--from well.lua. This button opens the flagroom bars.
blue_fr_button = func_button:new({}) 
function blue_fr_button:ondamage() OutputEvent( "blue_fr_grate_r", "Open" ) end 
function blue_fr_button:ondamage() OutputEvent( "blue_fr_grate_l", "Open" ) end 
function blue_fr_button:ontouch() OutputEvent( "blue_fr_grate_r", "Open" ) end 
function blue_fr_button:ontouch() OutputEvent( "blue_fr_grate_l", "Open" ) end 

Events

ondamage()

This event is fired when a player shoots or otherwise causes damage to the button. In FF, use of this callback is required for any button which should activate when shot. Omitting ondamage() will cause a shootable button to not work.

The following variables are set in the global lua namespace before this function is called:

  • info_damage: The amount of damage that the button will recieve.
  • info_attacker: The ID of the player that fired the attack.
  • info_classname: The classname of the weapon that hit the button. Note that this may be the classname of the projectile for projectile weapons, or the classname of the weapon for non-projectile weapons.

This function may modify the info_damage global variable in the global scope. If it does, the damage the button takes will be changed. This means that the script for a map can make buttons recieve more or less damage through scripting. Additionally, if info_damage is set to 0, or if the function returns false, the button will not be pressed.

An example of allowing only spanners to hit a button:

spanner_button = func_button:new({})
function spanner_button:ondamage()
	if IsPlayer( GetPlayerByID(info_attacker) ) then
		local player = CastToPlayer( GetPlayerByID(info_attacker) )
		ConsoleToAll(player:GetName().." shot button with a "..info_classname.." for "..info_damage.." damage")
		if info_classname == "ff_weapon_spanner" then
			PressButton(entname)
		end
	end
end

allowed( player_entity )

This function will be called whenever this button is attempting to be pressed. If it returns true, then the button will activate, otherwise it will not.

OnIn()

Called when the button has been pressed and has moved to the "in" position.

OnOut()

Called when the button "pops out" and can be pressed again.