Lua:func button

From Fortress Forever Wiki
Jump to navigationJump to search


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.