• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

Damage Add System

This bundle is marked as useful / simple. Simplicity is bliss, low effort and/or may contain minor bugs.
  • Like
Reactions: Renly Baratheon
Hi, i'm already put this system earlier, but it used cJass. So i'm update it and delete all cJass syntax (now it's usual jass with some vjass).

In game pick any unit you want and type "-d value from -million to million". Example : -d -2534 or -d 51263. Max damage - -million to +million

For example: you need to make skill:
Unit cast skill and he'll get 3* his INT damage.

You need to copy my library into your map, then copy all object skills and change their id inside library globals, and then in skill trigger write function
Damage_Add_Damage(3*INT, GetTriggerUnit())

1. Damage - library name (then goes _ )
2. Add_Damage - function inside the library which is count real lenght and set bonus damage level
3. 3*INT - first argument for Add_Damage function, this is the damage you want to give to unit
4. 2-nd argument it's a casting unit (who will get damage bonus)
JASS:
library Damage initializer InitDamageFunction

// Sorry for my bad english, i'm only studying it ^^

    globals
        hashtable hash = InitHashtable() // hashtable
        boolean Player_Name_Cond = false // if you'll change "false" on "true" it will active boolean on the player name which gives the damage, so only you will can to give damage
// you can change the name in the function: Player_Name_Condition
        integer Spell_Book = 'A003' // spellbook id ( from 0 to million)
        integer Spell_Book2 = 'A00D' // spellbook id ( from 0 to - million )
        integer Spell_1 = 'A00C' // spell id from 0 to 9
        integer Spell_2 = 'A001' // spell id from 0 to 90
        integer Spell_3 = 'A002' // spell id from 0 to 900
        integer Spell_4 = 'A004' // spell id from 0 to 9000
        integer Spell_5 = 'A005' // spell id from 0 to 90000
        integer Spell_6 = 'A006' // spell id from 0 to million
        integer Spell_7 = 'A000' // spell id from - 1 to - 9
        integer Spell_8 = 'A00B' // spell id from - 10 to - 90
        integer Spell_9 = 'A00A' // spell id from - 100 to - 900
        integer Spell_10 = 'A009' // spell id from - 1000 to - 9000
        integer Spell_11 = 'A008' // spell id from - 10000 to - 90000
        integer Spell_12 = 'A007' // spell id from - 100000 to - milliom
    endglobals

    private function IsUnitWithSkill takes unit a returns boolean
        return GetUnitAbilityLevel(a, Spell_Book) > 0
    endfunction

    public function Add_Damage takes real str, unit a returns nothing
        local string e
        local integer lenght
        local integer array spellLevel
        if str >= -1000000 and str <= 1000000 then
            if not IsUnitWithSkill(a) then
                call UnitAddAbility(a, Spell_Book)
                call UnitAddAbility(a, Spell_Book2)
            endif
            set e = I2S(R2I(str))
            set lenght = StringLength(e)
            if str >= 0 then
                if lenght == 1 then
                    set spellLevel[1] = S2I(SubString(e, 0, 1)) + 1
                else
                    if lenght == 2 then
                        set spellLevel[1] = S2I(SubString(e, 1, 2)) + 1
                        set spellLevel[2] = S2I(SubString(e, 0, 1)) + 1
                    else
                        if lenght == 3 then
                            set spellLevel[1] = S2I(SubString(e, 2, 3)) + 1
                            set spellLevel[2] = S2I(SubString(e, 1, 2)) + 1
                            set spellLevel[3] = S2I(SubString(e, 0, 1)) + 1
                        else
                            if lenght == 4 then
                                set spellLevel[1] = S2I(SubString(e, 3, 4)) + 1
                                set spellLevel[2] = S2I(SubString(e, 2, 3)) + 1
                                set spellLevel[3] = S2I(SubString(e, 1, 2)) + 1
                                set spellLevel[4] = S2I(SubString(e, 0, 1)) + 1
                            else
                                if lenght == 5 then
                                    set spellLevel[1] = S2I(SubString(e, 4, 5)) + 1
                                    set spellLevel[2] = S2I(SubString(e, 3, 4)) + 1
                                    set spellLevel[3] = S2I(SubString(e, 2, 3)) + 1
                                    set spellLevel[4] = S2I(SubString(e, 1, 2)) + 1
                                    set spellLevel[5] = S2I(SubString(e, 0, 1)) + 1
                                else
                                    if lenght == 6 then
                                        set spellLevel[1] = S2I(SubString(e, 5, 6)) + 1
                                        set spellLevel[2] = S2I(SubString(e, 4, 5)) + 1
                                        set spellLevel[3] = S2I(SubString(e, 3, 4)) + 1
                                        set spellLevel[4] = S2I(SubString(e, 2, 3)) + 1
                                        set spellLevel[5] = S2I(SubString(e, 1, 2)) + 1
                                        set spellLevel[6] = S2I(SubString(e, 0, 1)) + 1
                                    else
                                        if lenght == 7 then
                                            set spellLevel[6] = S2I(SubString(e, 0, 1)) + 10
                                        endif
                                    endif
                                endif
                            endif
                        endif
                    endif
                endif
                call SetUnitAbilityLevel(a, Spell_1, spellLevel[1])
                call SetUnitAbilityLevel(a, Spell_2, spellLevel[2])
                call SetUnitAbilityLevel(a, Spell_3, spellLevel[3])
                call SetUnitAbilityLevel(a, Spell_4, spellLevel[4])
                call SetUnitAbilityLevel(a, Spell_5, spellLevel[5])
                call SetUnitAbilityLevel(a, Spell_6, spellLevel[6])
                call SetUnitAbilityLevel(a, Spell_7, 0)
                call SetUnitAbilityLevel(a, Spell_8, 0)
                call SetUnitAbilityLevel(a, Spell_9, 0)
                call SetUnitAbilityLevel(a, Spell_10, 0)
                call SetUnitAbilityLevel(a, Spell_11, 0)
                call SetUnitAbilityLevel(a, Spell_12, 0)
            else
                set lenght = lenght - 1
                if lenght == 1 then
                    set spellLevel[1] = S2I(SubString(e, 1, 2)) + 1
                else
                    if lenght == 2 then
                        set spellLevel[1] = S2I(SubString(e, 2, 3)) + 1
                        set spellLevel[2] = S2I(SubString(e, 1, 2)) + 1
                    else
                        if lenght == 3 then
                            set spellLevel[1] = S2I(SubString(e, 3, 4)) + 1
                            set spellLevel[2] = S2I(SubString(e, 2, 3)) + 1
                            set spellLevel[3] = S2I(SubString(e, 1, 2)) + 1
                        else
                            if lenght == 4 then
                                set spellLevel[1] = S2I(SubString(e, 4, 5)) + 1
                                set spellLevel[2] = S2I(SubString(e, 3, 4)) + 1
                                set spellLevel[3] = S2I(SubString(e, 2, 3)) + 1
                                set spellLevel[4] = S2I(SubString(e, 1, 2)) + 1
                            else
                                if lenght == 5 then
                                    set spellLevel[1] = S2I(SubString(e, 5, 6)) + 1
                                    set spellLevel[2] = S2I(SubString(e, 4, 5)) + 1
                                    set spellLevel[3] = S2I(SubString(e, 3, 4)) + 1
                                    set spellLevel[4] = S2I(SubString(e, 2, 3)) + 1
                                    set spellLevel[5] = S2I(SubString(e, 1, 2)) + 1
                                else
                                    if lenght == 6 then
                                        set spellLevel[1] = S2I(SubString(e, 6, 7)) + 1
                                        set spellLevel[2] = S2I(SubString(e, 5, 6)) + 1
                                        set spellLevel[3] = S2I(SubString(e, 4, 5)) + 1
                                        set spellLevel[4] = S2I(SubString(e, 3, 4)) + 1
                                        set spellLevel[5] = S2I(SubString(e, 2, 3)) + 1
                                        set spellLevel[6] = S2I(SubString(e, 1, 2)) + 1
                                    else
                                        if lenght == 7 then
                                            set spellLevel[6] = S2I(SubString(e, 1, 2)) + 10
                                        endif
                                    endif
                                endif
                            endif
                        endif
                    endif
                endif
                call SetUnitAbilityLevel(a, Spell_1, 0)
                call SetUnitAbilityLevel(a, Spell_2, 0)
                call SetUnitAbilityLevel(a, Spell_3, 0)
                call SetUnitAbilityLevel(a, Spell_4, 0)
                call SetUnitAbilityLevel(a, Spell_5, 0)
                call SetUnitAbilityLevel(a, Spell_6, 0)
                call SetUnitAbilityLevel(a, Spell_7, spellLevel[1])
                call SetUnitAbilityLevel(a, Spell_8, spellLevel[2])
                call SetUnitAbilityLevel(a, Spell_9, spellLevel[3])
                call SetUnitAbilityLevel(a, Spell_10, spellLevel[4])
                call SetUnitAbilityLevel(a, Spell_11, spellLevel[5])
                call SetUnitAbilityLevel(a, Spell_12, spellLevel[6])
            endif
            if str > 0 then
                call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl", a, "origin"))
            else
                if str < 0 then
                    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl", a, "origin"))
                else
                    if str == 0 then
                        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl", a, "origin"))
                    endif
                endif
            endif
            set a = null
        else
            call DisplayTextToPlayer(GetOwningPlayer(a), 0, 0, "You can give damage only from -million to million" )
        endif
    endfunction

    private function Trig_String_Actions takes nothing returns nothing
        local unit a = LoadUnitHandle(hash, GetPlayerId(GetTriggerPlayer()), StringHash("target"))
        call Add_Damage(S2R(SubString(GetEventPlayerChatString(), 3, 11)), a)
        set a = null
// you can change "S2R(SubString(GetEventPlayerChatString(),3,11))" on your own any real variable (from -mill to +mill) and it'll
// be given to unit, also you can change unit a on your unit (for skill maybe))
    endfunction

    private function Trig_Pick_Actions takes nothing returns nothing
        call FlushChildHashtable(hash, GetPlayerId(GetTriggerPlayer())) // flush hash
        call SaveUnitHandle(hash, GetPlayerId(GetTriggerPlayer()), StringHash("target"), GetTriggerUnit()) // save picked unit in handle
    endfunction

    private function Trig_String_Conditions takes nothing returns boolean
        return StringCase(SubString(GetEventPlayerChatString(), 0, 2), false) == "-d" //check on stringcase
    endfunction

    private function Player_Name_Condition takes nothing returns boolean
        return GetPlayerName(GetTriggerPlayer()) == "Your name" // Change your player name here
    endfunction

    private function InitDamageFunction takes nothing returns nothing
        local unit a
        local integer i = 0
        local trigger Pick = CreateTrigger()
        local trigger String = CreateTrigger()
        if Player_Name_Cond then
            call TriggerAddCondition( String, Condition(function Player_Name_Condition))
        endif
        call TriggerAddCondition( String, Condition( function Trig_String_Conditions ) )
        call TriggerAddAction( String, function Trig_String_Actions )
        set a = CreateUnit(Player(14), 'hfoo', 0, 0, 0)
        call UnitAddAbility(a, Spell_1)
        call UnitAddAbility(a, Spell_2)
        call UnitAddAbility(a, Spell_3)
        call UnitAddAbility(a, Spell_4)
        call UnitAddAbility(a, Spell_5)
        call UnitAddAbility(a, Spell_6)
        call UnitAddAbility(a, Spell_Book)
        call UnitAddAbility(a, Spell_Book2)
        call RemoveUnit(a)
        set a = null
        loop
            exitwhen i > 11
            call TriggerRegisterPlayerChatEvent( String, Player(i), "-", false )
            call TriggerRegisterPlayerUnitEvent(Pick, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
            call SetPlayerAbilityAvailable( Player( i ), Spell_Book, false )
            call SetPlayerAbilityAvailable( Player( i ), Spell_Book2, false )
            set i = i + 1
        endloop
        call TriggerAddAction( Pick, function Trig_Pick_Actions )
    endfunction
endlibrary
Contents

Damage system (Map)

Reviews
12th Dec 2015 IcemanBo: Too long as NeedsFix. Rejected. 13:47, 21st Feb 2014 BPower: Requires a lot of changes. Also focus on what TriggerHappy pointed out in his post above mine

Moderator

M

Moderator

12th Dec 2015
IcemanBo: Too long as NeedsFix. Rejected.

13:47, 21st Feb 2014
BPower:
Requires a lot of changes. Also focus on what TriggerHappy pointed out in his post above mine
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
Now I suggest privating all the members of your library so we can't get them outside the library :)

if IsUnitWithSkill(a) == false
->
if not IsUnitWithSkill(a)

if Player_Name_Cond == true
->
if Player_Name_Cond

Outside this two boolean equations there is no flaw.
There is a little optimization in merging actions/conditions of triggers into one condition and use only triggercondition but oh whatever it is fine like this ;)
 
Not bad for the beginning, simple, maybe useful if people are lazy, but jass....
I hate jass but
-1 for so many posts before you (there are many, let's say... better systems)
-1 too short (you need to create more options, and make it more user friendly)
-1 jass.... Ignored
+1 useful (for lazy people)
5 - 2 + 1 =
4/5 :p
 
Last edited:

Kazeon

Hosted Project: EC
Level 34
Joined
Oct 12, 2011
Messages
3,449
okay, I will review it.. I don't understand vJass so much, so this is my simple review/suggestions:
- give example how to add damage using another event/action
- isn't it better to store TriggerPlayer in local first?
JASS:
    private function Trig_Pick_Actions takes nothing returns nothing
        call FlushChildHashtable(hash, GetPlayerId(GetTriggerPlayer())) // flush hash
        call SaveUnitHandle(hash, GetPlayerId(GetTriggerPlayer()), StringHash("target"), GetTriggerUnit()) // save picked unit in handle
    endfunction
- give instruction how to import
- Y U no use power of 2 (1,2,4,8,...) and one big negative valued damage ability as bonuses than those multi-leveled damage ability?
example: if you want to add 90 damage, give the unit 64+16+8+2 bonus.. then if you want to give -30 damage, give the unit -128+64+32+2.. this way looks more simple than you set those ability level...
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
I don't understand why the hell are you saying this :
Andser said:
-1 for so many posts before you
-1 too short
-1 jass....
Could you give a valid argument before downgraded this ressource ?

@..... : missed the GetTriggerPlayer thing you're right.
To import JASS it is like this : copy 'n paste then make the rawcodes fit but you're right he needs to post them too.
You can use power of 2 that could be better but he don't have to use it.
 
Level 5
Joined
Aug 23, 2013
Messages
42
For example: you need to make skill:
Unit cast skill and he'll get 3* his INT damage.

You need to copy my library into your map, then copy all object skills and change their id inside library globals, and then in skill trigger write function
Damage_Add_Damage(3*INT, GetTriggerUnit())

1. Damage - library name (then goes _ )
2. Add_Damage - function inside the library which is count real lenght and set bonus damage level
3. 3*INT - first argument for Add_Damage function, this is the damage you want to give to unit
4. 2-nd argument it's a casting unit (who will get damage bonus)
 
Level 18
Joined
Sep 14, 2012
Messages
3,413
What the matter oO ?
You didn't forget the 'then' ?
Because I didn't quote it ...

Btw you forgot to change one cJASS syntax.
In the init function -> i = i+1 -> set i = i + 1

And I changed what I told in your code and I got no problem !!

JASS:
library Damage initializer InitDamageFunction

// Sorry for my bad english, i'm only studying it ^^

    globals
        hashtable hash = InitHashtable() // hashtable
        boolean Player_Name_Cond = false // if you'll change "false" on "true" it will active boolean on the player name which gives the damage, so only you will can to give damage
// you can change the name in the function: Player_Name_Condition
        integer Spell_Book = 'A003' // spellbook id ( from 0 to million)
        integer Spell_Book2 = 'A00D' // spellbook id ( from 0 to - million )
        integer Spell_1 = 'A00C' // spell id from 0 to 9
        integer Spell_2 = 'A001' // spell id from 0 to 90
        integer Spell_3 = 'A002' // spell id from 0 to 900
        integer Spell_4 = 'A004' // spell id from 0 to 9000
        integer Spell_5 = 'A005' // spell id from 0 to 90000
        integer Spell_6 = 'A006' // spell id from 0 to million
        integer Spell_7 = 'A000' // spell id from - 1 to - 9
        integer Spell_8 = 'A00B' // spell id from - 10 to - 90
        integer Spell_9 = 'A00A' // spell id from - 100 to - 900
        integer Spell_10 = 'A009' // spell id from - 1000 to - 9000
        integer Spell_11 = 'A008' // spell id from - 10000 to - 90000
        integer Spell_12 = 'A007' // spell id from - 100000 to - milliom
    endglobals

    private function IsUnitWithSkill takes unit a returns boolean
        return GetUnitAbilityLevel(a, Spell_Book) > 0
    endfunction

    public function Add_Damage takes real str, unit a returns nothing
        local string e
        local integer lenght
        local integer array spellLevel
        if str >= -1000000 and str <= 1000000 then
            if not IsUnitWithSkill(a) then
                call UnitAddAbility(a, Spell_Book)
                call UnitAddAbility(a, Spell_Book2)
            endif
            set e = I2S(R2I(str))
            set lenght = StringLength(e)
            if str >= 0 then
                if lenght == 1 then
                    set spellLevel[1] = S2I(SubString(e, 0, 1)) + 1
                else
                    if lenght == 2 then
                        set spellLevel[1] = S2I(SubString(e, 1, 2)) + 1
                        set spellLevel[2] = S2I(SubString(e, 0, 1)) + 1
                    else
                        if lenght == 3 then
                            set spellLevel[1] = S2I(SubString(e, 2, 3)) + 1
                            set spellLevel[2] = S2I(SubString(e, 1, 2)) + 1
                            set spellLevel[3] = S2I(SubString(e, 0, 1)) + 1
                        else
                            if lenght == 4 then
                                set spellLevel[1] = S2I(SubString(e, 3, 4)) + 1
                                set spellLevel[2] = S2I(SubString(e, 2, 3)) + 1
                                set spellLevel[3] = S2I(SubString(e, 1, 2)) + 1
                                set spellLevel[4] = S2I(SubString(e, 0, 1)) + 1
                            else
                                if lenght == 5 then
                                    set spellLevel[1] = S2I(SubString(e, 4, 5)) + 1
                                    set spellLevel[2] = S2I(SubString(e, 3, 4)) + 1
                                    set spellLevel[3] = S2I(SubString(e, 2, 3)) + 1
                                    set spellLevel[4] = S2I(SubString(e, 1, 2)) + 1
                                    set spellLevel[5] = S2I(SubString(e, 0, 1)) + 1
                                else
                                    if lenght == 6 then
                                        set spellLevel[1] = S2I(SubString(e, 5, 6)) + 1
                                        set spellLevel[2] = S2I(SubString(e, 4, 5)) + 1
                                        set spellLevel[3] = S2I(SubString(e, 3, 4)) + 1
                                        set spellLevel[4] = S2I(SubString(e, 2, 3)) + 1
                                        set spellLevel[5] = S2I(SubString(e, 1, 2)) + 1
                                        set spellLevel[6] = S2I(SubString(e, 0, 1)) + 1
                                    else
                                        if lenght == 7 then
                                            set spellLevel[6] = S2I(SubString(e, 0, 1)) + 10
                                        endif
                                    endif
                                endif
                            endif
                        endif
                    endif
                endif
                call SetUnitAbilityLevel(a, Spell_1, spellLevel[1])
                call SetUnitAbilityLevel(a, Spell_2, spellLevel[2])
                call SetUnitAbilityLevel(a, Spell_3, spellLevel[3])
                call SetUnitAbilityLevel(a, Spell_4, spellLevel[4])
                call SetUnitAbilityLevel(a, Spell_5, spellLevel[5])
                call SetUnitAbilityLevel(a, Spell_6, spellLevel[6])
                call SetUnitAbilityLevel(a, Spell_7, 0)
                call SetUnitAbilityLevel(a, Spell_8, 0)
                call SetUnitAbilityLevel(a, Spell_9, 0)
                call SetUnitAbilityLevel(a, Spell_10, 0)
                call SetUnitAbilityLevel(a, Spell_11, 0)
                call SetUnitAbilityLevel(a, Spell_12, 0)
            else
                set lenght = lenght - 1
                if lenght == 1 then
                    set spellLevel[1] = S2I(SubString(e, 1, 2)) + 1
                else
                    if lenght == 2 then
                        set spellLevel[1] = S2I(SubString(e, 2, 3)) + 1
                        set spellLevel[2] = S2I(SubString(e, 1, 2)) + 1
                    else
                        if lenght == 3 then
                            set spellLevel[1] = S2I(SubString(e, 3, 4)) + 1
                            set spellLevel[2] = S2I(SubString(e, 2, 3)) + 1
                            set spellLevel[3] = S2I(SubString(e, 1, 2)) + 1
                        else
                            if lenght == 4 then
                                set spellLevel[1] = S2I(SubString(e, 4, 5)) + 1
                                set spellLevel[2] = S2I(SubString(e, 3, 4)) + 1
                                set spellLevel[3] = S2I(SubString(e, 2, 3)) + 1
                                set spellLevel[4] = S2I(SubString(e, 1, 2)) + 1
                            else
                                if lenght == 5 then
                                    set spellLevel[1] = S2I(SubString(e, 5, 6)) + 1
                                    set spellLevel[2] = S2I(SubString(e, 4, 5)) + 1
                                    set spellLevel[3] = S2I(SubString(e, 3, 4)) + 1
                                    set spellLevel[4] = S2I(SubString(e, 2, 3)) + 1
                                    set spellLevel[5] = S2I(SubString(e, 1, 2)) + 1
                                else
                                    if lenght == 6 then
                                        set spellLevel[1] = S2I(SubString(e, 6, 7)) + 1
                                        set spellLevel[2] = S2I(SubString(e, 5, 6)) + 1
                                        set spellLevel[3] = S2I(SubString(e, 4, 5)) + 1
                                        set spellLevel[4] = S2I(SubString(e, 3, 4)) + 1
                                        set spellLevel[5] = S2I(SubString(e, 2, 3)) + 1
                                        set spellLevel[6] = S2I(SubString(e, 1, 2)) + 1
                                    else
                                        if lenght == 7 then
                                            set spellLevel[6] = S2I(SubString(e, 1, 2)) + 10
                                        endif
                                    endif
                                endif
                            endif
                        endif
                    endif
                endif
                call SetUnitAbilityLevel(a, Spell_1, 0)
                call SetUnitAbilityLevel(a, Spell_2, 0)
                call SetUnitAbilityLevel(a, Spell_3, 0)
                call SetUnitAbilityLevel(a, Spell_4, 0)
                call SetUnitAbilityLevel(a, Spell_5, 0)
                call SetUnitAbilityLevel(a, Spell_6, 0)
                call SetUnitAbilityLevel(a, Spell_7, spellLevel[1])
                call SetUnitAbilityLevel(a, Spell_8, spellLevel[2])
                call SetUnitAbilityLevel(a, Spell_9, spellLevel[3])
                call SetUnitAbilityLevel(a, Spell_10, spellLevel[4])
                call SetUnitAbilityLevel(a, Spell_11, spellLevel[5])
                call SetUnitAbilityLevel(a, Spell_12, spellLevel[6])
            endif
            if str > 0 then
                call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Human\\HolyBolt\\HolyBoltSpecialArt.mdl", a, "origin"))
            else
                if str < 0 then
                    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\AnimateDead\\AnimateDeadTarget.mdl", a, "origin"))
                else
                    if str == 0 then
                        call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Undead\\DarkRitual\\DarkRitualTarget.mdl", a, "origin"))
                    endif
                endif
            endif
            set a = null
        else
            call DisplayTextToPlayer(GetOwningPlayer(a), 0, 0, "You can give damage only from -million to million" )
        endif
    endfunction

    private function Trig_String_Actions takes nothing returns nothing
        local unit a = LoadUnitHandle(hash, GetPlayerId(GetTriggerPlayer()), StringHash("target"))
        call Add_Damage(S2R(SubString(GetEventPlayerChatString(), 3, 11)), a)
        set a = null
// you can change "S2R(SubString(GetEventPlayerChatString(),3,11))" on your own any real variable (from -mill to +mill) and it'll
// be given to unit, also you can change unit a on your unit (for skill maybe))
    endfunction

    private function Trig_Pick_Actions takes nothing returns nothing
        call FlushChildHashtable(hash, GetPlayerId(GetTriggerPlayer())) // flush hash
        call SaveUnitHandle(hash, GetPlayerId(GetTriggerPlayer()), StringHash("target"), GetTriggerUnit()) // save picked unit in handle
    endfunction

    private function Trig_String_Conditions takes nothing returns boolean
        return StringCase(SubString(GetEventPlayerChatString(), 0, 2), false) == "-d" //check on stringcase
    endfunction

    private function Player_Name_Condition takes nothing returns boolean
        return GetPlayerName(GetTriggerPlayer()) == "Your name" // Change your player name here
    endfunction

    private function InitDamageFunction takes nothing returns nothing
        local unit a
        local integer i = 0
        local trigger Pick = CreateTrigger()
        local trigger String = CreateTrigger()
        if Player_Name_Cond then
            call TriggerAddCondition( String, Condition(function Player_Name_Condition))
        endif
        call TriggerAddCondition( String, Condition( function Trig_String_Conditions ) )
        call TriggerAddAction( String, function Trig_String_Actions )
        set a = CreateUnit(Player(14), 'hfoo', 0, 0, 0)
        call UnitAddAbility(a, Spell_1)
        call UnitAddAbility(a, Spell_2)
        call UnitAddAbility(a, Spell_3)
        call UnitAddAbility(a, Spell_4)
        call UnitAddAbility(a, Spell_5)
        call UnitAddAbility(a, Spell_6)
        call UnitAddAbility(a, Spell_Book)
        call UnitAddAbility(a, Spell_Book2)
        call RemoveUnit(a)
        set a = null
        loop
            exitwhen i > 11
            call TriggerRegisterPlayerChatEvent( String, Player(i), "-", false )
            call TriggerRegisterPlayerUnitEvent(Pick, Player(i), EVENT_PLAYER_UNIT_SELECTED, null)
            call SetPlayerAbilityAvailable( Player( i ), Spell_Book, false )
            call SetPlayerAbilityAvailable( Player( i ), Spell_Book2, false )
            set i = i + 1
        endloop
        call TriggerAddAction( Pick, function Trig_Pick_Actions )
    endfunction
endlibrary
 
I don't think this is approvable in it's current state. The system shouldn't run off player chat, but allow people to utilize any event or simple function call. Also, the code needs a lot of improvement.
  • Your globals should be private and constant.
  • Consider using Table so you don't create a new hashtable each spell.
  • Spell_# globals should be a single array possibly inside an optional textmacro. Or reconfigure your spell to not need so much object data. I also don't understand the comments.
  • You should place your actions inside your conditions block and remove TriggerAddAction.
  • Preloading should be optional and should probably only utilize dummy recycling, considering units cause irremovable leaks.
Those are just some things you should focus on first.
 
Level 5
Joined
Aug 23, 2013
Messages
42
Oh yes, now it works, thank you

I don't think this is approvable in it's current state. The system shouldn't run off player chat, but allow people to utilize any event or simple function call. Also, the code needs a lot of improvement.
  • Your globals should be private and constant.
  • Consider using Table so you don't create a new hashtable each spell.
  • Spell_# globals should be a single array possibly inside an optional textmacro. Or reconfigure your spell to not need so much object data. I also don't understand the comments.
  • You should place your actions inside your conditions block and remove TriggerAddAction.
  • Preloading should be optional and should probably only utilize dummy recycling, considering units cause irremovable leaks.
Those are just some things you should focus on first.

It's run not only from player chat, there is a second argument in function - unit, you can choose any unit (from skill) and give damage to him
 
Last edited by a moderator:
Level 19
Joined
Mar 18, 2012
Messages
1,716
The current way damage can be added to an unit is not acceptable.
The user should decide in which way he wants to access the system.
If he/she really wants to use the ChatEvent, which I highly doubt, it can be coded and processed in a external scope/library and then added via function.

Probably the best would be something like:
call ModifyDamageForUnit(unit, amount) or
call DamageModification.apply(unit, amount)
I for one prefer the last because of the .

The library name Damage should be changed into something more unique for instance DamageStatModification or DamageModification (not so sure if this does already exist).
It's most likely that the name Damage could interfere with any DamageDetectionSystem.

Check out what TriggerHappy posted. You only commented on the not so important one.

The required ability-raws could be created via textmacro, that would look similiar to:
JASS:
//! textmacro DamageAbility takes RAWCODE, DISPLAYVALUE, VALUE
//! external ObjectMerger w3a AItg $RAWCODE$ Iatt 1 $VALUE$ anam "Damage Modifier ($DISPLAYVALUE$)" aite 0 ansf "" aart ReplaceableTextures\CommandButtons\BTNClawsOfAttack.blp
//! endtextmacro

//! runtextmacro DamageAbility("Enter raw code here", "enter display value", "enter value")
//! runtextmacro DamageAbility("AAAA", "000001", "1")

You can still process all values with substrings internally, but there are also other ways for example with loops and integer values. (check out how it is done in CSS)

You can ask someone for help with the comments once you are finished, because I literally don't understand them.
 
Level 19
Joined
Mar 18, 2012
Messages
1,716
Yes it is just like copy and paste.
JASS:
    //! textmacro Example takes TYPE
        private function $TYPE$ takes nothing returns nothing
            call BJDebugMsg("Hello World")
        endfunction
    //! endtextmacro
JASS:
    //! runtextmacro Example("Hi")
will result in --->
JASS:
        private function Hi takes nothing returns nothing
            call BJDebugMsg("Hello World")
        endfunction
 
Top