мне нужно создать свой GetUnitUserData потому что GetUnitUserData уже занет другим

Принятый ответ

library UnitDataBase

    globals
		UNITDATA array UnitData
	endglobals


	struct UNITDATA
		private static integer count = 0
		private integer id
		private unit unitId

		real    critical_chance
        real    critical_power
        real    miss_chance
        real    evade_chance
        real    spell_resist
        real    physical_resist
        real    spell_damage
        real    physical_damage
        boolean can_absorb
        boolean stun_immune
        real    heal_bonus
        boolean armor_ignore
        boolean damage_immune
        boolean is_bubled
        real cast_speed
	
    static method Create takes unit u, real cc, real cp, real mc, real ec, real sr, real pr, real sd, real pd, boolean ca, boolean si, real hb returns UNITDATA
        local UNITDATA this = .allocate()
        set .id = .count
        set .count = .count + 1
        set UnitData[.id] = this
        set .unitId = u
        set .critical_chance = cc
        set .critical_power = cp
        set .miss_chance = mc
        set .evade_chance = ec
        set .spell_resist = sr
        set .physical_resist = pr
        set .spell_damage = sd
        set .physical_damage = pd
        set .can_absorb = ca
        set .stun_immune = si
        set .heal_bonus = hb
        set .armor_ignore = false
        set .damage_immune = false
        set .is_bubled = false
        set .cast_speed = 0.00
        return this
    endmethod
    
    method operator setCriticalChance= takes real i returns nothing
        set .critical_chance = .critical_chance + i
    endmethod
    
    method operator getCriticalChance takes nothing returns real
        return .critical_chance
    endmethod
    
    method operator setCriticalPower= takes real i returns nothing
        set .critical_power = .critical_power
    endmethod
    
    method operator getCriticalPower takes nothing returns real
        return .critical_power
    endmethod
    
    method operator setMissChance= takes real i returns nothing
        set .miss_chance = .miss_chance + i
    endmethod
    
    method operator getMissChance takes nothing returns real
        return .miss_chance
    endmethod
    
    method operator setEvadeChance= takes real i returns nothing
        set .evade_chance = .evade_chance + i
    endmethod
    
    method operator getEvadeChance takes nothing returns real
        return .evade_chance
    endmethod
    
    method operator setSpellResist= takes real i returns nothing
        set .spell_resist = .spell_resist + (i/100.00)
    endmethod
    
    method operator getSpellResist takes nothing returns real
        return .spell_resist
    endmethod
    
    method operator setPhysicalResist= takes real i returns nothing
        set .physical_resist = .physical_resist + (i/100.00)
    endmethod
    
    method operator getPhysicalResist takes nothing returns real
        return .physical_resist
    endmethod
    
    method operator setSpellDamage= takes real i returns nothing
        set .spell_damage = .spell_damage + (i/100.00)
    endmethod
    
    method operator getSpellDamage takes nothing returns real
        return .spell_damage
    endmethod
    
    method operator setPhysicalDamage= takes real i returns nothing
        set .physical_damage = .physical_damage + (i/100.00)
    endmethod
    
    method operator getPhysicalDamage takes nothing returns real
        return .physical_damage
    endmethod
    
    method operator setAbsorbStatus= takes boolean i returns nothing
        set .can_absorb = i
    endmethod
    
    method operator getAbsorbStatus takes nothing returns boolean
        return .can_absorb
    endmethod
    
    method operator setStunImmune= takes boolean i returns nothing
        set .stun_immune = i
    endmethod
    
    method operator getStunImmune takes nothing returns boolean
        return .stun_immune
    endmethod
    
    method operator setHealBonus= takes real i returns nothing
        set .heal_bonus = .heal_bonus + (i/100.00)
    endmethod
    
    method operator getHealBonus takes nothing returns real
        return .heal_bonus
    endmethod
    
    method operator setArmorIgnore= takes boolean i returns nothing
        set .armor_ignore = i
    endmethod
    
    method operator getArmorIgnore takes nothing returns boolean
        return .armor_ignore
    endmethod
    
    method operator setDamageImmune= takes boolean i returns nothing
        set .damage_immune = i
    endmethod
    
    method operator getDamageImmune takes nothing returns boolean
        return .damage_immune
    endmethod
    
    method operator setBubled= takes boolean i returns nothing
        set .is_bubled = i
    endmethod
    
    method operator getBubled takes nothing returns boolean
        return .is_bubled
    endmethod
    
    method operator setCastSpeed= takes real i returns nothing
        set .cast_speed = .cast_speed + i
    endmethod
    
    method operator getCastSpeed takes nothing returns real
        return .cast_speed
    endmethod
        
    static method GetData takes unit u returns UNITDATA
        local integer i = .count - 1
        loop
            exitwhen i < 0
            if UnitData[i].unitId == u then
                return UnitData[i]
            endif
            set i = i - 1
        endloop
        return 0
    endmethod

    method Destroy takes nothing returns nothing
	    set .count = .count -  1
	    set UnitData[.id] = UnitData[.count]
	    set UnitData[.id].id = .id
	    call .destroy()
    endmethod

    endstruct

endlibrary
когда то так делал.
`
ОЖИДАНИЕ РЕКЛАМЫ...
5
29
5 лет назад
5
Сохраняте в хэштаблице по GetHandleId(unit).
0
32
5 лет назад
0
или структуры, тока не помню уже как точно там но код будет вида "unit.userdata1"
На крайняк можно под юзердату использовать некие поля из РО, смотря какой патч, если 126 и нужно хранить в юзердате к примеру родную броню юнита, то можно поместить броню в GetunitCostGold (в золотостоимость), разумеется если она не используется, но тогда рпидётся делать много манипуляций с РО, смотря для чего в общем, вариантов решения крайне много и смотря какой патч
0
29
5 лет назад
0
Bergi_Bear, к структуре же id юнита привязать нужно через таблицы или использовать unit indexer.
local CustomUnitData u = GetUnitUserData(GetTriggerUnit())
u.data1 = 'data1'
u.data2 = 'data2'
0
32
5 лет назад
Отредактирован Берги
0
Нужно вызвать специалиста по структурам? но код примерно такой будет:
struct AB
int userdata1
int userdata2
int userdataN
endstruct

function ACTIONS takes nothing returns nothing
int total
AB u=AB.create()
u.userdata1=5
u.userdata2=6
total=u.userdata1+u.userdata2 // =>11 вроде всё работает так-то
endfunction
P.s. я не спец по структурам
и тут нет метода delete, он потерялся =)
4
11
5 лет назад
4
library UnitDataBase

    globals
		UNITDATA array UnitData
	endglobals


	struct UNITDATA
		private static integer count = 0
		private integer id
		private unit unitId

		real    critical_chance
        real    critical_power
        real    miss_chance
        real    evade_chance
        real    spell_resist
        real    physical_resist
        real    spell_damage
        real    physical_damage
        boolean can_absorb
        boolean stun_immune
        real    heal_bonus
        boolean armor_ignore
        boolean damage_immune
        boolean is_bubled
        real cast_speed
	
    static method Create takes unit u, real cc, real cp, real mc, real ec, real sr, real pr, real sd, real pd, boolean ca, boolean si, real hb returns UNITDATA
        local UNITDATA this = .allocate()
        set .id = .count
        set .count = .count + 1
        set UnitData[.id] = this
        set .unitId = u
        set .critical_chance = cc
        set .critical_power = cp
        set .miss_chance = mc
        set .evade_chance = ec
        set .spell_resist = sr
        set .physical_resist = pr
        set .spell_damage = sd
        set .physical_damage = pd
        set .can_absorb = ca
        set .stun_immune = si
        set .heal_bonus = hb
        set .armor_ignore = false
        set .damage_immune = false
        set .is_bubled = false
        set .cast_speed = 0.00
        return this
    endmethod
    
    method operator setCriticalChance= takes real i returns nothing
        set .critical_chance = .critical_chance + i
    endmethod
    
    method operator getCriticalChance takes nothing returns real
        return .critical_chance
    endmethod
    
    method operator setCriticalPower= takes real i returns nothing
        set .critical_power = .critical_power
    endmethod
    
    method operator getCriticalPower takes nothing returns real
        return .critical_power
    endmethod
    
    method operator setMissChance= takes real i returns nothing
        set .miss_chance = .miss_chance + i
    endmethod
    
    method operator getMissChance takes nothing returns real
        return .miss_chance
    endmethod
    
    method operator setEvadeChance= takes real i returns nothing
        set .evade_chance = .evade_chance + i
    endmethod
    
    method operator getEvadeChance takes nothing returns real
        return .evade_chance
    endmethod
    
    method operator setSpellResist= takes real i returns nothing
        set .spell_resist = .spell_resist + (i/100.00)
    endmethod
    
    method operator getSpellResist takes nothing returns real
        return .spell_resist
    endmethod
    
    method operator setPhysicalResist= takes real i returns nothing
        set .physical_resist = .physical_resist + (i/100.00)
    endmethod
    
    method operator getPhysicalResist takes nothing returns real
        return .physical_resist
    endmethod
    
    method operator setSpellDamage= takes real i returns nothing
        set .spell_damage = .spell_damage + (i/100.00)
    endmethod
    
    method operator getSpellDamage takes nothing returns real
        return .spell_damage
    endmethod
    
    method operator setPhysicalDamage= takes real i returns nothing
        set .physical_damage = .physical_damage + (i/100.00)
    endmethod
    
    method operator getPhysicalDamage takes nothing returns real
        return .physical_damage
    endmethod
    
    method operator setAbsorbStatus= takes boolean i returns nothing
        set .can_absorb = i
    endmethod
    
    method operator getAbsorbStatus takes nothing returns boolean
        return .can_absorb
    endmethod
    
    method operator setStunImmune= takes boolean i returns nothing
        set .stun_immune = i
    endmethod
    
    method operator getStunImmune takes nothing returns boolean
        return .stun_immune
    endmethod
    
    method operator setHealBonus= takes real i returns nothing
        set .heal_bonus = .heal_bonus + (i/100.00)
    endmethod
    
    method operator getHealBonus takes nothing returns real
        return .heal_bonus
    endmethod
    
    method operator setArmorIgnore= takes boolean i returns nothing
        set .armor_ignore = i
    endmethod
    
    method operator getArmorIgnore takes nothing returns boolean
        return .armor_ignore
    endmethod
    
    method operator setDamageImmune= takes boolean i returns nothing
        set .damage_immune = i
    endmethod
    
    method operator getDamageImmune takes nothing returns boolean
        return .damage_immune
    endmethod
    
    method operator setBubled= takes boolean i returns nothing
        set .is_bubled = i
    endmethod
    
    method operator getBubled takes nothing returns boolean
        return .is_bubled
    endmethod
    
    method operator setCastSpeed= takes real i returns nothing
        set .cast_speed = .cast_speed + i
    endmethod
    
    method operator getCastSpeed takes nothing returns real
        return .cast_speed
    endmethod
        
    static method GetData takes unit u returns UNITDATA
        local integer i = .count - 1
        loop
            exitwhen i < 0
            if UnitData[i].unitId == u then
                return UnitData[i]
            endif
            set i = i - 1
        endloop
        return 0
    endmethod

    method Destroy takes nothing returns nothing
	    set .count = .count -  1
	    set UnitData[.id] = UnitData[.count]
	    set UnitData[.id].id = .id
	    call .destroy()
    endmethod

    endstruct

endlibrary
когда то так делал.
Принятый ответ
2
29
5 лет назад
2
и тут нет метода delete, он потерялся =)
Метод create тоже потерялся)
А на lua всё ещё проще)
Чтобы оставить комментарий, пожалуйста, войдите на сайт.