Lua:func button
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 Eventsondamage()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:
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. |