Skip to content

Function Library

Daisy edited this page Mar 26, 2024 · 1 revision

General Functions

More Human-Readable Functions Library

DSY_rpf_fnc_createPool

-- Use --

Creates a new resource pool with the given parameters.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that you want to create a pool on
  • Index 1: _varName
    • <STRING> The name of the pool you want to create
  • Index 2: _limit
    • <NUMBER> The maximum amount of resource allowed in this pool
  • Index 3: _rd
    • <NUMBER> The renew/decay state of the pool:
      • 0 : neither renew nor decay
      • 1 : renew
      • 2 : decay
  • Index 4: _rate
    • <ARRAY> The rate used in renew/decay functions
    • Array is in format: [_amount,_time]
      • Index 0: <NUMBER> The amount by which you want to alter the pool
      • Index 1: <NUMBER> The delay between alterations in seconds

-- Return --

false on failure, true on success

-- Example --

// creates resource pool "pool" on object box1 with limit of 500 that will decay  (subtract) 20 resources every 90 seconds
[box1, "pool", 500, 2, [20,90]] call DSY_rpf_fnc_createPool;

-- CBA Events --

DSY_rpf_created

called at successful creation DSY_rpf_destroyed called at destruction or killing of resource pool object


DSY_rpf_fnc_alterPool

-- Use --

Alters pool _varName on object _obj by _amount with _methods

Adds or subtracts an amount from the given pool on the given object. Option given to choose between addition and subtraction, as well as the method of handling an overflow (see Index 3).

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool you want to alter is on
  • Index 1: _varName
    • <STRING> The name of the pool you want to alter
  • Index 2: _amount
    • <NUMBER> The amount by which you want to alter the pool
  • Index 3: _methods
    • <ARRAY> The methods of alteration.
    • Array is in format: [_mathOperation,_overflowMethod]
      • Index 0: <BOOLEAN> True if subtraction, false if addition (default false)
      • Index 1: <BOOLEAN> True if reject an alteration over the limit, false if clamp the alteration to the limit (default false) -- Return --

false on failure, final altered amount on success

-- Example --

// subtracts 20 from "pool" on box1 and clamps if it exceeds the limits. returns (current value of pool - 20) if not clamped, returns lower bound (always 0) if clamped
[box1,"pool",20,[true,false]] call DSY_rpf_fnc_alterPool;

// adds 45 to "pool" on bag12 and rejects it if it exceeds the limits. returns (current value of pool + 45) if not rejected, false if rejected
[bag12,"pool",45,[false,true]] call DSY_rpf_fnc_alterPool;

-- CBA Events --

DSY_rpf_onIce

raised on failure of alteration DSY_rpf_altered raised after object alteration DSY_rpf_clamp raised when value was clamped DSY_rpf_reject raised when value was rejected DSY_rpf_lBound raised when value exceeds lower bound (0) DSY_rpf_uBound raised when value exceeds upper bound (_limit variable)


DSY_rpf_fnc_freezePool

-- Use --

Halts all alterations (addition/subtraction) on a given pool.

NOTE: This does not interrupt delay/renew timers, it only halts the alteration call they make.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool you want to freeze is on
  • Index 1: _varName
    • <STRING> The name of the pool you want to freeze

-- Return --

true if the pool has been frozen, false if it has been unfrozen

-- Example --

// if not already frozen, returns true
[box1,"pool"] call DSY_rpf_fnc_freezePool;
// calling again after returns false
[box1,"pool"] call DSY_rpf_fnc_freezePool;

-- CBA Events --

DSY_rpf_frozen

raised if the pool was frozen DSY_rpf_unfrozen raised if the pool was unfrozen


DSY_rpf_fnc_removePool

-- Use --

Removes the pool with the given name from the object.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool you want to alter is on
  • Index 1: _varName
    • <STRING> The name of the pool you want to alter

-- Return --

false on failure, true on success

-- Example --

// removes "pool" resource pool from box1
[box1,"pool"] call DSY_rpf_fnc_removePool;

-- CBA Events --

DSY_rpf_removed

raised upon removal of a pool


DSY_rpf_fnc_renewPool

NOTE: For a more convenient alternative, see poolSetRenew.


-- Use --

Adds to a pool given the pool's internally set rate. Loops until the pool's internally set renew status changes.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool you want to begin renewing is on
  • Index 1: _varName
    • <STRING> The name of the pool you want to renew

-- Return --

none

-- Example --

// will renew by internally given rate
[box1, "pool"] call DSY_rpf_fnc_decayPool;

DSY_rpf_altered

raised when pool is altered

DSY_rpf_renewed

raised upon successful execution of renewPool


DSY_rpf_fnc_decayPool

NOTE: For a more convenient alternative, see poolSetDecay.


-- Use --

Subtracts from a pool given the pool's internally set rate. Loops until the pool's internally set decay status changes.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool you want to begin decaying is on
  • Index 1: _varName
    • <STRING> The name of the pool you want to decay

-- Return --

none

-- Example --

// will decay by internally given rate
[box1, "pool"] call DSY_rpf_fnc_decayPool;

DSY_rpf_altered

raised when pool is altered

DSY_rpf_decayed

raised upon successful execution of delayPool


Specialized Functions

DSY_rpf_fnc_alterAllPools

-- Use --

Alters all resource pools on an object by the given amount and methods.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object you want to alter all the pools of
  • Index 1: _amount
    • <NUMBER> The amount which you want to alter each pool by
  • Index 2: _methods
    • <ARRAY> The methods of alteration.
    • Array is in format: [_mathOperation,_overflowMethod]
      • Index 0: True if subtraction, false if addition (default false) <BOOLEAN>
      • Index 1: True if reject an alteration over the limit, false if clamp the alteration to the limit (default false) <BOOLEAN>

-- Return --

false on error, true on successful execution

-- Example --

// assuming box1 has pools: "pool", "pool1", and "pool2",
// this code subtracts 30 from "pool", "pool1", and "pool2", and clamps it to 0 if the alteration would exceed it
[box1,30,[true,false]] call DSY_rpf_fnc_alterAllPools;

-- CBA Events --

DSY_rpf_alteredAll

called once at the end of the alterAll execution DSY_rpf_altered called for every alteration


DSY_rpf_fnc_removeAllPools

-- Use --

Removes all pools from the given object.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that you want to remove all pools from

-- Return --

false on failure, true on success

-- Example --

// removes all pools from object box1
box1 call DSY_rpf_fnc_removeAllPools;

-- CBA Events --

DSY_rpf_removedAll

raised upon removal of all pools from an object


Quality-of-Life Functions

DSY_rpf_fnc_poolSetLimit

-- Use --

Allows manual editing of an initialized pool's limit.

Will clamp to 2^16 (65,536). If you need more you should reconsider your situation.

If the new limit is lower than the current value stored in the pool, it can be freely subtracted from. However: If you use both the add & clamp methods, it will clamp to the new limit.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool whose limit you want to change is on
  • Index 1: _varName
    • <STRING> The name of the pool whose limit you want to change
  • Index 2: _newLimit
    • <NUMBER> The new maximum amount of resource allowed in this pool

-- Return --

false on error, true on success

-- Example --

// whatever the limit was before, it sets it to 5000
[box1,"pool",5000] call DSY_rpf_fnc_poolSetLimit;

// clamps to 65536
[box1,"pool",70000] call DSY_rpf_fnc_poolSetLimit;

-- CBA Events --

DSY_rpf_setLimit

raised upon successful execution of poolSetLimit


DSY_rpf_fnc_poolSetRate

-- Use --

Allows for manual changing of the internally stored rate values without calling any functions.

Can be used for altering the rate of renew/decay while the pool is renewing/decaying.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that you want to create a pool on
  • Index 1: _varName
    • <STRING> The name of the pool you want to create
  • Index 2: _rate
    • <ARRAY> The rate used in renew/decay functions
    • Array is in format: [_amount,_time]
      • Index 0: <NUMBER> The amount by which you want to alter the pool
      • Index 1: <NUMBER> The delay between alterations in seconds

-- Return --

false on failure, true on success

-- Example --

// sets rate to 50 resources every 2 seconds.
[box1,"pool",[50,2]] call DSY_rpf_fnc_poolSetRate;

-- CBA Events --

DSY_rpf_setRate

raised upon successful execution of poolSetRate


DSY_rpf_fnc_poolSetRenew

-- Use --

Sets the pool's internal renew/decay status to renew and calls renewPool with an optional given rate.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool you want to renew is on
  • Index 1: _varName
    • <STRING> The name of the pool you want to renew
  • Index 3: _rate
    • <ARRAY> The rate you want to renew by. Leave blank to use the internally set rate array.
    • Array in format: [_amount,_time]
      • Index 0: <NUMBER> the amount you want to add to the pool each time
      • Index 1: <NUMBER> the amount of time between additions

-- Return --

false on error, true on success

-- Example --

// adds 50 every 2 seconds
[box1,"pool",[50,2]] call DSY_rpf_fnc_poolSetRenew;

// uses the internal array
[box1,"pool",[]] call DSY_rpf_fnc_poolSetRenew;

-- CBA Events --

DSY_rpf_setRenew

raised on successful execution of poolSetRenew


DSY_rpf_fnc_poolSetDecay

-- Use --

Sets the pool's internal renew/decay status and calls decayPool with a given rate.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool you want to decay is on
  • Index 1: _varName
    • <STRING> The name of the pool you want to decay
  • Index 3: _rate
    • <ARRAY> The rate you want to decay by. Leave blank to use the internally set rate array.
    • Array in format: [_amount,_time]
      • Index 0: <NUMBER> the amount you want to subtract from the pool each time
      • Index 1: <NUMBER> the amount of time between subtractions

-- Return --

false on error, true on success

-- Example --

// subtracts 50 every 2 seconds
[box1,"pool",[50,2]] call DSY_rpf_fnc_poolSetDecay;

// uses the internal array
[box1,"pool",[]] call DSY_rpf_fnc_poolSetDecay;

-- CBA Events --

DSY_rpf_setDecay

raised on successful execution of poolSetDecay


DSY_rpf_fnc_poolStopRD

-- Use --

Halts any currently looping renew/decay functions. Leaves rate unaffected.

-- Parameters --

  • Index 0: _obj
    • <OBJECT> The object that the pool you want to stop R/D looping on is on
  • Index 1: _varName
    • <STRING> The name of the pool you want to stop R/D looping for

-- Return --

false on failure, true on success

-- Example --

// stops renew/decay loops, if any.
// otherwise will just set the renew/decay identifier value (see below) to 0
[box1,"pool"] call DSY_rpf_fnc_poolStopRD;

R/D identifier value

-- CBA Events --

DSY_rpf_poolStopRD

raised upon successful execution of poolStopRD


Miscellaneous Functions

DSY_rpf_fnc_raiseEvent

You may absolutely take and use this in your own mods if you like. No credit necessary. -- Use --

Shorthand method of calling CBA Events --** on different machines.

-- Parameters --

-- Return --

none

-- Example --

// raises "eventName" on the local machine and passes [_param1,_param2] to the event handler function (see below)
["eventName",[_param1,_param2],0] call DSY_rpf_fnc_raiseEvent;

Event Handlers (Bohemia)

[Event Handlers (CBA)](https://cbateam.github.io/CBA_A3/docs/files/CBA events/fnc_addEventHandler-sqf.html)

-- CBA Events --

none