Plasma Pistol Overcharge Tutorial (OpenSauce)

Getting Started
Before we start, we need to think of everything we'll need to complete this (Or, just look at my list) As we can see, this is a fairly easy script to assemble.
 * Identify Weapon
 * Is it a Plasma Pistol?
 * Is it the first weapon they're carrying?
 * See if its Charging
 * For this, OS can check Function Blocks
 * Read and Modify Battery Levels
 * OS has available, for SP
 * What happens when its empty?

Building the Script
First thing we'll do, is wait for them to have a Plasma Pistol.

(sleep_until (unit_has_weapon_readied (unit (list_get (players) 0)) "weapons\plasma pistol\plasma pistol") 1) Next, we want to know what weapon this is; we'll store in a global, so we don't have to keep track of which one it is. (global object held_pp NONE) Then we'll assign it (if (= (unit_data_get_integer (unit (list_get (players) 0)) "current_weapon_index") 0)  (set held_pp (unit_data_get_object (unit (list_get (players) 0)) "weapon0")) (if (= (unit_data_get_integer (unit (list_get (players) 0)) "current_weapon_index") 1) (set held_pp (unit_data_get_object (unit (list_get (players) 0)) "weapon1")))) Finally, we want to check our condition, and apply the correct change (if (> (object_data_get_real held_pp "function_out" "d") 0.8) ;;If it is more than 80% charged  (weapon_data_set_real held_pp "age" (min 1 (+ (weapon_data_get_real held_pp "age") 0.01)))    ;;Increase battery depletage by 1%; assign empty number, if end result would be over depleted. )

End result
(global object held_pp none) (script static unit p0 (unit (list_get (players) 0))) (script continuous charge_drainer  (sleep_until (unit_has_weapon_readied (p0) "weapons\plasma pistol\plasma pistol") 1)   ;;Wait until the player has the weapon   (if (= (unit_data_get_integer (p0) "current_weapon_index") 0) (set held_pp (unit_data_get_object (p0) "weapon0")) ;;If the weapon is 0, save a hook to that weapon in the global held_pp (if (= (unit_data_get_integer (p0) "current_weapon_index") 1)    (set held_pp (unit_data_get_object (p0) "weapon1"))))   ;;If its weapon 1, hook that one instead   (if (> (object_data_get_real held_pp "function_out" "d") 0.8) ;;If it is more than 80% charged (weapon_data_set_real held_pp "age" (min 1 (+ (weapon_data_get_real held_pp "age") 0.01))) ;;Increase battery depletage by 1%; assign empty number, if end result would be over depleted. ) )