Attachment System Challenge - KillCounter

Trollvottel

never aging title
Reaction score
262
no system, but a quite different version:
(didnt test it and now that many people dont like gamecache):

JASS:
library KillCount initializer Init

    globals
        private gamecache CACHE
    endglobals

    private function U2I takes unit u returns integer
        return u
        return 0
    endfunction
    
    public function Get takes unit u returns integer
        return GetStoredInteger(CACHE, "kills", I2S(U2I(u)))
    endfunction
    
    private function Action takes nothing returns nothing
        local unit die      = GetTriggerUnit()
        local unit kill     = GetKillingUnit()
        local integer id1   = U2I(die)
        local integer id2   = U2I(kill)
        call StoreInteger(CACHE, "kills", I2S(id2), GetStoredInteger(CACHE, "kills", I2S(id2)+1))
        
        if IsUnitType(die, UNIT_TYPE_HERO) != true then
            call StoreInteger(CACHE, "kills", I2S(id1), 0)
        endif
        
    endfunction
    
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(t, GetLocalPlayer(), EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddAction(t, function Action)
        call InitGameCache("CACHE")
    endfunction
    


endlibrary
 

Cohadar

master of fugue
Reaction score
209
It leaks and it does not even compile...

I am still waiting for someone to use some actual system....
 

Trollvottel

never aging title
Reaction score
262
oh right, that was silly to not even test if there were syntax errors, an update (still none of the systems :rolleyes:, i dont even know WHY you want us to use these systems...):

JASS:
library KillCount initializer Init

    globals
        private gamecache CACHE
    endglobals

    private function U2I takes unit u returns integer
        return u
        return 0
    endfunction
    
    public function Get takes unit u returns integer
        return GetStoredInteger(CACHE, "kills", I2S(U2I(u)))
    endfunction
    
    private function Action takes nothing returns nothing
        local unit die      = GetTriggerUnit()
        local unit kill     = GetKillingUnit()
        local integer id1   = U2I(die)
        local integer id2   = U2I(kill)
        local integer kills = GetStoredInteger(CACHE, "kills", I2S(id2))
        
        if kills != 0 and not (kills > 0) then
            set kills = 0
        endif
        
        call StoreInteger(CACHE, "kills", I2S(id2), kills+1)
        
        if IsUnitType(die, UNIT_TYPE_HERO) != true then
            call StoreInteger(CACHE, "kills", I2S(id1), 0)
        endif
        set die = null
        set kill = null
    endfunction
    
    private function True takes nothing returns boolean
        return true
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterPlayerUnitEvent(t, GetLocalPlayer(), EVENT_PLAYER_UNIT_DEATH, Condition(function True))
        call TriggerAddAction(t, function Action)
        call InitGameCache("CACHE")
    endfunction
    


endlibrary
 

Trollvottel

never aging title
Reaction score
262
i didnt.

@adamgriffith:

this is to get the unit's kills... i dont use it in the system, but you see its public ....
 

Cohadar

master of fugue
Reaction score
209
(still none of the systems :rolleyes:, i dont even know WHY you want us to use these systems...):

So you would not have to write all this big ugly codes every time you need to attach something to unit.
(and to prove that some of those systems can't really be used for unit attaching no matter what their authors claim)
 
Reaction score
333
I have given this some more thought, and think this constitutes a better solution (not thoroughly tested):

JASS:
library KillCount initializer Init
    globals
        private integer array Data
        private group G = CreateGroup()
    endglobals
    
    private function H2I takes handle h returns integer
        return h
        return 0
    endfunction
    
    private function GetHandleData takes handle h returns integer
        return Data[H2I(h)-0x100000]
    endfunction
    
    private function SetHandleData takes handle h, integer i returns nothing
        set Data[H2I(h)-0x100000] = i
    endfunction
    
    private function UnitDies takes nothing returns boolean
        local unit u = GetKillingUnit()
        local unit v = GetTriggerUnit()
        
        if (u != null and u != v) then
            if IsUnitInGroup(u, G) then
                call SetHandleData(u, GetHandleData(u)+1)
            else
                call GroupAddUnit(G, u)
                call SetHandleData(u, 1)
            endif
        endif
        
        set u = null
        set v = null
        return false
    endfunction
    
    private function Init takes nothing returns nothing
        local trigger t = CreateTrigger()
        call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_DEATH)
        call TriggerAddCondition(t, Condition(function UnitDies))
    endfunction
endlibrary


Once again the attachment system is part of the library, but it is practically identical to CSData, etc.
 

Viikuna

No Marlo no game.
Reaction score
265
Why should anyone attach anything to units? Just use SetunitUserData and give unit a unique index. You can have your data in struct arrays, just use GetUnitUserData to find witch struct belongs to that unit. If unit dies, just recycle it. Move it to some storage area and ressurect it there. If it cant be ressurected, just create a new unit for that index. When you need units for something just grab them from storage area.

Or use PUI. if Im not mistaken, it recycles indexes instead of units.

Anyways, when unit dies take killing units struct from array and save whatever data you need to it.

EDIT. Is there any relation beetween this thread and this ?
 
Reaction score
333
Custom unit data is the best way to do this. I can't think how using PUI would make this any easier - you still run into the same problems.
 

chobibo

Level 1 Crypt Lord
Reaction score
48
Maybe lol. Also cohadar stated not to use Custom Values so this is indeed quite a challenge.
@TheDamien: yes and cohadar also stated not to use custom values, PUI uses it doesn't it?
 

Viikuna

No Marlo no game.
Reaction score
265
No custom value ideed makes it hard, but when you really have a situation where you cant use custom value? This sounds like 'make a knockback without timer..' I think Cohadar himself said that units dont need attaching but indexing.

Must download some attachment system and try this..
 
Reaction score
333
@TheDamien: yes and cohadar also stated not to use custom values, PUI uses it doesn't it?

The idea behind this thread, though, was to prove that we're all n00bs for thinking that unit attachment is just as usable as PUI.
 

Viikuna

No Marlo no game.
Reaction score
265
I would not be suprised..
Lets see what Cohadar says when he gets back here.
 

Cohadar

master of fugue
Reaction score
209
Viikuna said:
Is there any relation beetween this thread and this ?
Everything in universe is connected (or at least on internet)

TheDamien said:
Once again the attachment system is part of the library, but it is practically identical to CSData, etc.
Can you please make it use CSData I would like to see that solution.

Flare said:
OK, I've run into some bother doing it with HAIL. What has worked before (in my own spells) no longer works... time to try and find a fix :D
It never worked properly, you just did not notice it in game.

chobibo said:
Maybe lol. Also cohadar stated not to use Custom Values so this is indeed quite a challenge.
@TheDamien: yes and cohadar also stated not to use custom values, PUI uses it doesn't it?
I have a proper solution for this that uses PUI that will be published after challenge is over.
Read the rules again please.

TheDamien said:
The idea behind this thread, though, was to prove that we're all n00bs for thinking that unit attachment is just as usable as PUI.
Think of it as free education.
 

Flare

Stops copies me!
Reaction score
662
It never worked properly, you just did not notice it in game.

If that was the case, my spell would be total and utter fail (don't say it is fail, because it isn't. I have tested the attachment with debug messages :D). It has stopped my spells from stacking :D

Think of it as free education.

lol, I was expecting something far more Cohadar-y (i.e. all those other systems fail but PUI doesn't [mwuahahahahahahahahahahah])

I have a proper solution for this that uses PUI that will be published after challenge is over.
Read the rules again please.

Oh joy, we have to conform to the rules, yet you don't -.-'
 

chobibo

Level 1 Crypt Lord
Reaction score
48
2. Monopolizing UnitUserData is not allowed.
I didn't see the monopolizing part sorry.
 
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