System Asyst

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
ASYST​
Version 1.0.2​

Requirements:
- Jass NewGen
- AIDS
- Damage
- TimerUtils
- GetPlayerColored

JASS:

library ASYST initializer Init requires AIDS, Damage, GetPlayerColored, TimerUtils
//
//                 _______     _______ _______ 
//          /\    / ____\ \   / / ____|__   __|
//         /  \  | (___  \ \_/ / (___    | |   
//        / /\ \  \___ \  \   / \___ \   | |   
//       / ____ \ ____) |  | |  ____) |  | |   
//      /_/    \_\_____/   |_| |_____/   |_|     
//                                           By AoW_Hun7312
//                                                                    v 1.0.2
//      What is ASYST?
//     ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//          ASYST is an assist tracking system, allowing the user to award players
//          with gold for assisting in kills. You can add up to 8190 units.
//          
//      How do I implement it?
//     ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
//          1. Create a new trigger named ASYST. Go to 'Edit -> Convert
//          to Custom Text', and replace everything that's there with this script.
//
//          2. Save the map.
//
//      Functions:
//     ¯¯¯¯¯¯¯¯¯¯¯¯
//          function ASYST_Register takes unit whichUnit returns nothing
//              - This registers a unit for use in the system.
//
//          constant function BountyFormula takes unit whichUnit returns integer
//              - The formula in which the bounty is calculated.
//
//      Thanks:
//     ¯¯¯¯¯¯¯¯¯
//          - Jesus4Lyf for this template and all of his useful systems.
//          - Ammorth for GetPlayerColored.
//          - Vexorian for TimerUtils.
//
//      Configurables:
//     ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
    globals
        // Should we display the floating text? (the +# text over the unit when it dies)
        private constant boolean DisplayFloatingText = true
        // The resource type to use.
        private constant playerstate Resource = PLAYER_STATE_RESOURCE_GOLD
        // The amount of damage from one attack/spell must be higher than this to register as an assist.
        private constant integer MinDamage = 0
        // The time before assists are no longer valid.
        private constant real DecayTime = 10.
        // The duration of the messages.
        private constant real MessageDuration  = 15.
        // Messages displayed when killed.
        private constant string AssistMessage     = "With help from: "
        private constant string BountyMessage     = " gold!"
        private constant string DenyMessage       = " denied "
        private constant string KillMessage       = " killed "
        private constant string SplitMessage      = " gold is split!"
        private constant string SuicideMessage    = " has commited suicide."
        
        // Don't touch below here!
        integer array AssistCount
        integer array KillCount
        private force array AssistGroup
        private timer array AssistTimer
        private group RegisteredGroup = CreateGroup()
        private player damagerp = null
        private player killedp = null
        private player killerp = null
        private trigger UnitDamaged = CreateTrigger()
        private trigger UnitKilled = CreateTrigger()
        private unit damaged = null
        private unit damager = null
        private unit killed = null
        private unit killer = null
    endglobals
    
    private constant function AssistFormula takes unit whichUnit returns integer
        return 25 + GetHeroLevel(whichUnit) * 5
    endfunction
    
    private constant function BountyFormula takes unit whichUnit returns integer
        return 250 + GetHeroLevel(whichUnit) * 5
    endfunction
    
    public function Register takes unit whichUnit returns nothing
        local integer index = GetUnitId(whichUnit)
        if not (IsUnitInGroup(whichUnit, RegisteredGroup)) then
            set AssistGroup[index] = CreateForce()
            set AssistTimer[index] = NewTimer()
            call SetTimerData(AssistTimer[index], index)
            call GroupAddUnit(RegisteredGroup, whichUnit)
        endif
    endfunction
    
    private function CreateFloatingText takes texttag t, string s returns nothing
        call SetTextTagText(t, "+" + s, 0.023)
        call SetTextTagPos(t, GetUnitX(killed), GetUnitY(killed), 0)
        call SetTextTagColor(t, 255, 220, 0, 255)
        call SetTextTagVelocity(t, 0, 0.036)
        call SetTextTagPermanent(t, false)
        call SetTextTagLifespan(t, 2.00)
        call SetTextTagFadepoint(t, 1.00)
    endfunction
    
    private function AssistDecay takes nothing returns nothing
        call ForceClear(AssistGroup[GetTimerData(GetExpiredTimer())])
    endfunction
    
    private function OnDamage takes nothing returns boolean
        local integer index = 0
        set damaged = GetTriggerUnit()
        set damager = GetEventDamageSource()
        set damagerp = GetOwningPlayer(damager)
        if (IsUnitInGroup(damaged, RegisteredGroup) and (GetEventDamage() > MinDamage) and (IsPlayerEnemy(damagerp, GetOwningPlayer(damaged)))) then
            set index = GetUnitId(damaged)
            call ForceAddPlayer(AssistGroup[index], damagerp)
            call TimerStart(AssistTimer[index], DecayTime, false, function AssistDecay) 
        endif
        return false
    endfunction
    
    private function OnKill takes nothing returns boolean
        local integer bounty = 0
        local integer counter = 0
        local integer index = 0
        local integer gold = 0
        local string assisters = ""
        local string bountystr = ""
        local string goldstr = ""
        local texttag t = CreateTextTag()
        set killed = GetTriggerUnit()
        if (IsUnitInGroup(killed, RegisteredGroup)) then
            set index = GetUnitId(killed)
            set killer = GetKillingUnit()
            set killedp = GetOwningPlayer(killed)
            set killerp = GetOwningPlayer(killer)
            if (killed != killer) then
                if (IsPlayerEnemy(killedp, killerp)) then
                    set bounty = BountyFormula(killed)
                    set bountystr = I2S(bounty)
                    set gold = AssistFormula(killed) / CountPlayersInForceBJ(AssistGroup[index])
                    set goldstr = I2S(gold)
                    set KillCount[GetPlayerId(killerp)] = KillCount[GetPlayerId(killerp)] + 1
                    call DestroyEffect(AddSpecialEffect("UI\\Feedback\\GoldCredit\\GoldCredit.mdl", GetUnitX(killed), GetUnitY(killed)))
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MessageDuration, GetPlayerNameColored(killerp) + KillMessage + GetPlayerNameColored(killedp) + " for " + bountystr + BountyMessage)
                    call SetPlayerState(killerp, Resource, GetPlayerState(killerp, Resource) + bounty)
                    if (killerp == GetLocalPlayer()) and (DisplayFloatingText) then
                        call CreateFloatingText(t, bountystr)
                    endif
                    loop
                        exitwhen counter > 11
                        if (IsPlayerInForce(Player(counter), AssistGroup[index]) and (Player(counter) != killerp)) then
                            set AssistCount[counter] = AssistCount[counter] + 1
                            set assisters = assisters + GetPlayerNameColored(Player(counter)) + ", "
                            call SetPlayerState(Player(counter), Resource, GetPlayerState(Player(counter), Resource) + gold)
                            if (Player(counter) == GetLocalPlayer()) and (DisplayFloatingText) then
                                call CreateFloatingText(t, goldstr)
                            endif
                        endif
                        set counter = counter + 1
                    endloop
                    if (assisters != "") then
                        call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MessageDuration, AssistMessage + assisters + goldstr + SplitMessage)
                    endif
                else
                    call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MessageDuration, GetPlayerNameColored(killerp) + DenyMessage + GetPlayerNameColored(killedp) + ".")
                endif
            else
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MessageDuration, GetPlayerNameColored(killerp) + SuicideMessage)
            endif
            call ForceClear(AssistGroup[index])
        endif
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        call Damage_RegisterEvent(UnitDamaged)
        call TriggerRegisterAnyUnitEventBJ(UnitKilled, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddCondition(UnitDamaged, function OnDamage)
        call TriggerAddCondition(UnitKilled, function OnKill)
    endfunction
    
endlibrary

Updates:
- Version 1.0.2: Added a boolean for floating text and added floating text for assists.
- Version 1.0.1: Added floating text (+#) and a function for the gold formula.
- Version 1.0.0: Release.
 

Attachments

  • ASYST.w3x
    58 KB · Views: 965

tooltiperror

Super Moderator
Reaction score
231
Well done.

Although, it could use Autoindex instead of AIDS since you don't even use the AIDS struct, it only requires indexing.

Also, what if I want bosses to give more bounty? And why don't you add the option to use floating text?
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
Well done.

Although, it could use Autoindex instead of AIDS since you don't even use the AIDS struct, it only requires indexing.

Also, what if I want bosses to give more bounty? And why don't you add the option to use floating text?

I'll add the floating text option in the next version. This system is more-so designed for hero vs. hero style maps (Hero Arenas, AoS, etc.)
 

tooltiperror

Super Moderator
Reaction score
231
Alright, I thought this was creep bounty, my mistake.

Anyways, you should add in an option for a formula (use a constant function or globals) so that they can change the amount of bounty based upon conditions. Like add this to the config:

JASS:
 private function Gold_Formula takes nothing returns integer
     return 50
 endfunction


Then award Gold_Formula() rather than a global. And it would let someone configure something like this.

JASS:
 private function Gold_Formula takes nothing returns integer
     if GetUnitTypeId(GetTriggerUnit())=='hfoo' then
         return 900000000000000
     endif
     return 50
 endfunction
 

Romek

Super Moderator
Reaction score
963
> Although, it could use Autoindex instead of AIDS since you don't even use the AIDS struct, it only requires indexing.
AIDS does indexing too... :rolleyes:
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
Alright, I thought this was creep bounty, my mistake.

Anyways, you should add in an option for a formula (use a constant function or globals) so that they can change the amount of bounty based upon conditions. Like add this to the config:

JASS:

 private function Gold_Formula takes nothing returns integer
     return 50
 endfunction


Then award Gold_Formula() rather than a global. And it would let someone configure something like this.

JASS:

 private function Gold_Formula takes nothing returns integer
     if GetUnitTypeId(GetTriggerUnit())=='hfoo' then
         return 900000000000000
     endif
     return 50
 endfunction

Done. Added the floating text as well.
 

tooltiperror

Super Moderator
Reaction score
231
> Although, it could use Autoindex instead of AIDS since you don't even use the AIDS struct, it only requires indexing.
AIDS does indexing too... :rolleyes:
Overkill, doncha think?

Also, you write [LJASS]// Don't touch below here![/LJASS] and put the configuration formulas down there. They should be above that line.
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top