Skip to content

Adding SF Functions

LengthenedGradient edited this page Apr 9, 2024 · 7 revisions

All your edits should go in ACF-3\lua\starfall\libs_sh\acffunctions.lua


image

The top of the file contains localized global functions and some permissions.


image

Next comes the helper functions, which can be used in the SF functions.


image

This sets up the SF library.


image

Everything here and below contains the actual functions SF will call.


Example

--- Returns current ACF drag divisor
-- @shared
-- @return number The current drag divisor
function acf_library.dragDivisor()
	return ACF.DragDiv
end

--- Returns the effective armor given an armor value and hit angle
-- @shared
-- @param number Armor The nominal armor value
-- @param number Angle The hit angle
-- @return number The effective armor
function acf_library.effectiveArmor(armor, angle)
	CheckLuaType(armor, TYPE_NUMBER)
	CheckLuaType(angle, TYPE_NUMBER)

	return math.Round(armor / math.abs(math.cos(math.rad(math.min(angle, 89.999)))), 1)
end

Each function needs to follow the above format. (Replace the <> with what you need):

  1. --- <Function Description>
  2. -- @<shared/client/server depending on the realm the
  3. -- @param <type> <Name> for every argument, if your function has inputs
  4. -- @return <type> <Description> if your function returns something.
  5. function acf_library.<functionName>(<arg1,arg2,...>) <function body> end

Clone this wiki locally