System Aggro System

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
Version 1.0, everything is in the Read Me.

Pictures:


AggroSystem.jpg


Read Me:

Code:
===================================================================================================

Foreword:

This is a simple system that helps importing a simple, yet effecting feature into your map. What the
system will allow basically is making certain units effected by the damage dealt to them. Those 
units (which will be chosen by you by modifing the trigger) will attack the unit the dealt the most
damage to them in range of 30 (this value is editable as well), this will allow realistic play and
more stratigic play, especially in RPGs, ORPGs, AoSes, Hero Sieges and so on.

You should note though that the system is a little slow becuase it uses H2I function alot. The H2I
allows us to refer to a single unit with an ease by attaching an integer to it.

Credits to KaTTaNa for the local handle system, parts of it are used.

===================================================================================================

Import:

Inorder to import this system all you have to do is to copy the trigger, done. If you have KaTTaNa
handle system imported into your map already, don't copy the upper part of the system, only the part
from " // AGGRO SYSTEM -- BY RHEIAS \\ " and down.

===================================================================================================

History:

Version 1 (June,14,2007)
    
    - First release.

===================================================================================================

I would love to hear comments, suggestions and bugs found, just post them in the thread made!

                                            Rheias

Code:

JASS:

// LOCAL HANDLE SYSTEM == BY KaTTaNa \\
function H2I takes handle h returns integer
    return h
    return 0
endfunction


function LocalVars takes nothing returns gamecache
    if udg_AS_Cache == null then
        set udg_AS_Cache = InitGameCache("jasslocalvars.w3v")
    endif
    return udg_AS_Cache
endfunction

function SetHandleReal takes handle subject, string name, real value returns nothing
    if value==0 then
        call FlushStoredReal(LocalVars(), I2S(H2I(subject)), name)
    else
        call StoreReal(LocalVars(), I2S(H2I(subject)), name, value)
    endif
endfunction

function GetHandleReal takes handle subject, string name returns real
    return GetStoredReal(LocalVars(), I2S(H2I(subject)), name)
endfunction

function FlushHandleLocals takes handle subject returns nothing
    call FlushStoredMission(LocalVars(), I2S(H2I(subject)) )
endfunction

// AGGRO SYSTEM -- BY RHEIAS \\

constant function AggroSys_Range takes nothing returns real
    // Returns by how much the new damage needs to be bigger then the last maximum damage.
    return 30.
endfunction

constant function AggroSys_Cool takes nothing returns real
    // Returns by how much the max value is reduces every second
    return 5.
endfunction

function AggroSysGrp_Cons takes nothing returns boolean
    // Returns the condition for the units pre-placed that will fit in the system.
    return GetPlayerController(GetOwningPlayer(GetFilterUnit()))!=MAP_CONTROL_USER or GetPlayerSlotState(GetOwningPlayer(GetFilterUnit()))!=PLAYER_SLOT_STATE_PLAYING
    // At the moment it is every unit that is not controlled by a user or that it's controller is not in-game
endfunction

function AggroSysTrg_Cons takes nothing returns boolean
     // Returns the condition for the unit that are created in-game that will fit the system.
     return GetPlayerController(GetOwningPlayer(GetTriggerUnit()))!=MAP_CONTROL_USER or GetPlayerSlotState(GetOwningPlayer(GetTriggerUnit()))!=PLAYER_SLOT_STATE_PLAYING
    // At the moment it is every unit that is not controlled by a user or that it's controller is not in-game
endfunction

function AggroSysCool_Acts takes nothing returns boolean
    local group victims = CreateGroup()
    local boolexpr con = Condition(function AggroSysGrp_Cons)
    local unit picked
    local real max

    call GroupEnumUnitsInRect(victims,GetWorldBounds(),con)

    loop
        set picked = FirstOfGroup(victims)
        exitwhen picked == null
        set max = GetHandleReal(picked,"max") - AggroSys_Cool()
        call SetHandleReal(picked,"max",max)
        call GroupRemoveUnit(victims,picked)
    endloop
    set victims = null
    set picked = null
    return true
endfunction

function AggroSysPre_Acts takes nothing returns boolean
    local group victims = CreateGroup()
    local boolexpr con = Condition(function AggroSysGrp_Cons)
    local unit picked

    call GroupEnumUnitsInRect(victims,GetWorldBounds(),con)

    loop
        set picked = FirstOfGroup(victims)
        exitwhen picked == null
        call TriggerRegisterUnitEvent(gg_trg_AggroSys,picked,EVENT_UNIT_DAMAGED)
        call GroupRemoveUnit(victims,picked)
    endloop

    call DestroyGroup(victims)
    set victims = null
    set picked = null

    return true
endfunction

function AggroSysDmg_Acts takes nothing returns boolean
    local unit triggerer = GetTriggerUnit()
    if AggroSysTrg_Cons() then
        call TriggerRegisterUnitEvent(gg_trg_AggroSys,triggerer,EVENT_UNIT_DAMAGED)
    endif

    set triggerer = null

    return true
endfunction

function AggroSysExe_Acts takes nothing returns boolean
    local unit source = GetEventDamageSource()
    local unit victim = GetTriggerUnit()
    local real max = GetHandleReal(victim,"max")
    local real damage = GetHandleReal(victim,I2S(H2I(source))) + GetEventDamage()

    call SetHandleReal(victim,I2S(H2I(source)),damage)

    if damage > max + AggroSys_Range() then
        call SetHandleReal(victim,"max",damage)
        call IssueTargetOrder(victim,"attack",source)
    endif

    set source = null
    set victim = null

    return true
endfunction
//===========================================================================
function InitTrig_AggroSys takes nothing returns nothing
    local trigger AggroSysDmg = CreateTrigger()
    local trigger AggroSysPre = CreateTrigger()
    local trigger AggroSysCool = CreateTrigger()

    set gg_trg_AggroSys = CreateTrigger()

    call TriggerRegisterTimerEventSingle(AggroSysPre,0.)
    call TriggerRegisterEnterRectSimple(AggroSysDmg,GetWorldBounds())

    call TriggerAddCondition(gg_trg_AggroSys,Condition(function AggroSysExe_Acts))
    call TriggerAddCondition(AggroSysDmg,Condition(function AggroSysDmg_Acts))
    call TriggerAddCondition(AggroSysPre,Condition(function AggroSysPre_Acts))
    call TriggerAddCondition(AggroSysCool,Condition(function AggroSysCool_Acts))

    set AggroSysDmg = null
    set AggroSysPre = null
    set AggroSysCool = null
endfunction
 

elmstfreddie

The Finglonger
Reaction score
203
I don't see why anyone would want this, because it's part of strategy to get another unit to just attack once and lure the creep away from a weak ally. If the weak ally did most of the damage with your system, he couldn't escape.
I like Warcraft's default system o_O
 

Rheias

New Helper (I got over 2000 posts)
Reaction score
232
The creeps in default WC3 tend to stick on one unit, this system makes the targets of creeps change faster, depending on the damage they deal.
 

waaaks!

Zinctified
Reaction score
255
i really dont know how to make systems, im impressed
+rep but i cant.. sorry, maybe next time...
 

Steel

Software Engineer
Reaction score
109
I recommend making an addition of a few constants that will be spells that increase or decrease as unit's threat/agro.
 

Matemeo

New Member
Reaction score
20
Perfect, just what I've been looking for, though, I'll have to modify to add in spells that lower and increase aggro, but this is a great base, + REP, goodjob.
 
S

schilling

Guest
i want to test this jass thingy, but when i add it my world editor map, but when i'm off to save the world editor shuts down :confused:

anyways, the jass looks very very cool:)
 

Deadeyeflint

New Member
Reaction score
0
could someone tell me how to add spells that incrase/decrase aggro to this trigger, or just give me some funktions to copy? ^^
i'm trying to use JASS2 since yesterday, and that would just be too difficult to me. :(
 

Magentix

if (OP.statement == false) postCount++;
Reaction score
107
You could scope/library the whole lot, making the handle functions private...

If you leave it like that, people with handle var functions elsewhere in their map will get double function errors.
 

~GaLs~

† Ғσſ ŧħə ѕαĸε Φƒ ~Ğ䣚~ †
Reaction score
180
Not he don't have, he is not using it.
It is tend to be easy to implent by newbies that uses normal editor.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top