Assist System

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
I've currently been working on an assist system for my map, but I'm fairly certain it can be improved. Does anyone see anything that would help its performance?

JASS:
// Created by AoW_Hun7312
library ASYST initializer Init requires AIDS, Damage, TimerUtils

    globals
        // Configurable Settings
        // The gold gained from a kill
        private constant integer Bounty = 250
        // The gold to split among assisters
        private constant integer AssistBounty = 50
        // 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 KillMessage       = " killed "
        private constant string AssistMessage     = "With help from: "
        private constant string BountyMessage     = " gold!"
        private constant string SplitMessage      = " gold is split!"
        
        // Don't touch below here!
        private force array AssistGroup
        private timer array AssistTimer
        private group RegisteredGroup = CreateGroup()
        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
    
    function ASYST_Register takes unit whichUnit returns nothing
        set AssistGroup[GetUnitId(whichUnit)] = CreateForce()
        call GroupAddUnit(RegisteredGroup, whichUnit)
    endfunction
    
    private function AssistDecay takes nothing returns nothing
        local integer index = GetTimerData(GetExpiredTimer())
        call ForceClear(AssistGroup[index])
        call ReleaseTimer(AssistTimer[index])
        set AssistTimer[index] = null
    endfunction
    
    private function Damaged takes nothing returns boolean
        local integer index = 0
        set damaged = GetTriggerUnit()
        if (IsUnitInGroup(damaged, RegisteredGroup)) then
            set damager = GetEventDamageSource()
            set index = GetUnitId(damaged)
            if (AssistTimer[index] == null) then
                set AssistTimer[index] = NewTimer()
                call ForceAddPlayer(AssistGroup[index], GetOwningPlayer(damager))
                call SetTimerData(AssistTimer[index], index)
                call TimerStart(AssistTimer[index], DecayTime, false, function AssistDecay)
            else
                call ForceAddPlayer(AssistGroup[index], GetOwningPlayer(damager))
                call PauseTimer(AssistTimer[index])
                call TimerStart(AssistTimer[index], DecayTime, false, function AssistDecay) 
            endif
        endif
        return false
    endfunction
    
    private function Killed takes nothing returns boolean
        local integer counter = 0
        local integer index = 0
        local integer gold = AssistBounty
        local string assist = ""
        set killed = GetTriggerUnit()
        if (IsUnitInGroup(killed, RegisteredGroup)) then
            set killer = GetKillingUnit()
            if not (killed == killer) then
                set index = GetUnitId(killed)
                set gold = gold / CountPlayersInForceBJ(AssistGroup[index])
                set killedp = GetOwningPlayer(killed)
                set killerp = GetOwningPlayer(killer)
                loop
                    exitwhen counter > 11
                    if (IsPlayerInForce(Player(counter), AssistGroup[index]) and (Player(counter) != killerp)) then
                        call SetPlayerState(Player(counter), ConvertPlayerState(1), GetPlayerState(Player(counter), ConvertPlayerState(1)) + gold)
                        set assist = assist + GetPlayerName(Player(counter)) + ", "
                    endif
                    set counter = counter + 1
                endloop
            endif
            call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MessageDuration, GetPlayerName(killerp) + KillMessage + GetPlayerName(killedp) + " for " + I2S(Bounty) + BountyMessage)
            if (assist != "") then
                call DisplayTimedTextToPlayer(GetLocalPlayer(), 0, 0, MessageDuration, AssistMessage + assist + I2S(gold) + SplitMessage)
            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 Damaged)
        call TriggerAddCondition(UnitKilled, function Killed)
    endfunction
    
endlibrary
 

Laiev

Hey Listen!!
Reaction score
188
JASS:
function ASYST_Register takes unit whichUnit returns nothing


can be

JASS:
public function Register takes unit whichUnit returns nothing


to call it will stay the same...

JASS:
ASYST_Register (whichUnit)


also i think you could use struct
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
JASS:
function ASYST_Register takes unit whichUnit returns nothing


can be

JASS:
public function Register takes unit whichUnit returns nothing


to call it will stay the same...

JASS:
ASYST_Register (whichUnit)


also i think you could use struct

Doing this would make it error when you call it with GUI (at least in my experience.)
 

Laiev

Hey Listen!!
Reaction score
188
@AoW

...?

and why you want to use it with GUI if you're making it with vJass?
 

Hatebreeder

So many apples
Reaction score
381
I thought I saw local units somewhere o_O

I shouldn't comment when I'm up late =_=
My bad.
 

Bribe

vJass errors are legion
Reaction score
67
JASS:
call TriggerRegisterUnitEvent(UnitKilled, whichUnit, EVENT_UNIT_DEATH)


What advantage does this have over [ljass]call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)[/ljass] and a very, very simple boolean to check if the unit is a valid unit? Infinite fewer handles == undeniable.
 

Bribe

vJass errors are legion
Reaction score
67
[lJASS]ConvertPlayerState(1)[/lJASS] is slower than the built-in variable set to it;



If you prefer something of a shorter name, you can do:

JASS:
private constant playerstate GOLD_COUNT = PLAYER_STATE_RESOURCE_GOLD


The following block, you don't need to pause the timer before starting it again. When you start it again, everything the timer had going for it before it canceled. Sort of how every time you use GroupEnumUnitsIn..., the group gets cleared before adding those units.

JASS:
//
            if (AssistTimer[index] == null) then
                set AssistTimer[index] = NewTimer()
                call ForceAddPlayer(AssistGroup[index], GetOwningPlayer(damager))
                call SetTimerData(AssistTimer[index], index)
                call TimerStart(AssistTimer[index], DecayTime, false, function AssistDecay)
            else
                call ForceAddPlayer(AssistGroup[index], GetOwningPlayer(damager))
                call PauseTimer(AssistTimer[index]) // useless
                call TimerStart(AssistTimer[index], DecayTime, false, function AssistDecay) 
            endif


The following block does the exact same thing, but with less text. Whenever you have the opportunity to recycle text, I recommend you take it. Smaller map file size = smaller download size. For that matter, you should also get Vexorian's Map Optimizer, as it strips out all of the comments from the war3map.j file (don't worry, they will be there again next time you open world editor).

JASS:
//
    if (AssistTimer[index] == null) then
        set AssistTimer[index] = NewTimer()
        call SetTimerData(AssistTimer[index], index)
    endif
    call ForceAddPlayer(AssistGroup[index], GetOwningPlayer(damager))
    call TimerStart(AssistTimer[index], DecayTime, false, function AssistDecay)
 

AoW_Hun7312

I'm a magic man, I've got magic hands.
Reaction score
76
Changed as well. Thanks for that tip, I had to change a few other triggers I set up that way.
 
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Ghan Ghan:
    Still lurking
    +3
  • The Helper The Helper:
    I am great and it is fantastic to see you my friend!
    +1
  • The Helper The Helper:
    If you are new to the site please check out the Recipe and Food Forum https://www.thehelper.net/forums/recipes-and-food.220/
  • Monovertex Monovertex:
    How come you're so into recipes lately? Never saw this much interest in this topic in the old days of TH.net
  • Monovertex Monovertex:
    Hmm, how do I change my signature?
  • tom_mai78101 tom_mai78101:
    Signatures can be edit in your account profile. As for the old stuffs, I'm thinking it's because Blizzard is now under Microsoft, and because of Microsoft Xbox going the way it is, it's dreadful.
  • The Helper The Helper:
    I am not big on the recipes I am just promoting them - I use the site as a practice place promoting stuff
    +2
  • Monovertex Monovertex:
    @tom_mai78101 I must be blind. If I go on my profile I don't see any area to edit the signature; If I go to account details (settings) I don't see any signature area either.
  • The Helper The Helper:
    You can get there if you click the bell icon (alerts) and choose preferences from the bottom, signature will be in the menu on the left there https://www.thehelper.net/account/preferences
  • The Helper The Helper:
    I think I need to split the Sci/Tech news forum into 2 one for Science and one for Tech but I am hating all the moving of posts I would have to do
  • The Helper The Helper:
    What is up Old Mountain Shadow?
  • The Helper The Helper:
    Happy Thursday!
    +1
  • Varine Varine:
    Crazy how much 3d printing has come in the last few years. Sad that it's not as easily modifiable though
  • Varine Varine:
    I bought an Ender 3 during the pandemic and tinkered with it all the time. Just bought a Sovol, not as easy. I'm trying to make it use a different nozzle because I have a fuck ton of Volcanos, and they use what is basically a modified volcano that is just a smidge longer, and almost every part on this thing needs to be redone to make it work
  • Varine Varine:
    Luckily I have a 3d printer for that, I guess. But it's ridiculous. The regular volcanos are 21mm, these Sovol versions are about 23.5mm
  • Varine Varine:
    So, 2.5mm longer. But the thing that measures the bed is about 1.5mm above the nozzle, so if I swap it with a volcano then I'm 1mm behind it. So cool, new bracket to swap that, but THEN the fan shroud to direct air at the part is ALSO going to be .5mm to low, and so I need to redo that, but by doing that it is a little bit off where it should be blowing and it's throwing it at the heating block instead of the part, and fuck man
  • Varine Varine:
    I didn't realize they designed this entire thing to NOT be modded. I would have just got a fucking Bambu if I knew that, the whole point was I could fuck with this. And no one else makes shit for Sovol so I have to go through them, and they have... interesting pricing models. So I have a new extruder altogether that I'm taking apart and going to just design a whole new one to use my nozzles. Dumb design.
  • Varine Varine:
    Can't just buy a new heatblock, you need to get a whole hotend - so block, heater cartridge, thermistor, heatbreak, and nozzle. And they put this fucking paste in there so I can't take the thermistor or cartridge out with any ease, that's 30 dollars. Or you can get the whole extrudor with the direct driver AND that heatblock for like 50, but you still can't get any of it to come apart
  • Varine Varine:
    Partsbuilt has individual parts I found but they're expensive. I think I can get bits swapped around and make this work with generic shit though
  • Ghan Ghan:
    Heard Houston got hit pretty bad by storms last night. Hope all is well with TH.
  • The Helper The Helper:
    Power back on finally - all is good here no damage
    +2
  • V-SNES V-SNES:
    Happy Friday!
    +1
  • The Helper The Helper:
    New recipe is another summer dessert Berry and Peach Cheesecake - https://www.thehelper.net/threads/recipe-berry-and-peach-cheesecake.194169/

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top