• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • ✅ Time to vote for the top 3 models! The POLL for Hive's 6th HD Modeling Contest: Mechanical is now open! 📅 Poll close on July 16, 2024! 🔗 Cast your vote now!

[vJASS] Simple Unit Custom Data

Status
Not open for further replies.
Level 14
Joined
Oct 19, 2014
Messages
187
JASS:
scope UnitCustomData initializer init/*JC Helas*/
   
    globals
        private integer max=0
        private integer rec=0
        private integer array id[5000]
        private unit array uni[5000]
    endglobals
   
    private function recycle takes nothing returns boolean
        local unit u=GetTriggerUnit()
        local boolean b=true
        if rec!=0 then
            set rec:id:uni=u
            call SetUnitUserData(u,rec:id)
            set rec:id=0
            set rec=rec-1
            set b=false
        endif
        return b
    endfunction
   
    private function remove takes unit u returns nothing
        set rec=rec+1
        set rec:id=GetUnitUserData(u)
    endfunction
   
    private function enter takes nothing returns nothing
        local integer i=max
        local unit u=GetTriggerUnit()
        set i=i+1
        set i:uni=u
        call SetUnitUserData(u,i)
        set max=i
        set i=0
        set u=null
    endfunction
   
    private function init takes nothing returns nothing
        local region r=CreateRegion()
        local trigger t=CreateTrigger()
        call RegionAddRect(r,GetWorldBounds())
        call TriggerRegisterEnterRegion(t,r,null)
        call TriggerAddAction(t,function enter)
        call TriggerAddCondition(t,Condition(function recycle))
        set r=null
        set t=null
    endfunction
   
    hook RemoveUnit remove
endscope
 
Status
Not open for further replies.
Top