• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Adding unit spell with command

Status
Not open for further replies.
Level 5
Joined
Jul 17, 2013
Messages
128
Converting text into ability

How to convert entered chat String (text) into ability? Is it even posible? (can be everything - gui,jass,vjass and other)
 
Last edited:
Level 28
Joined
Sep 26, 2009
Messages
2,520
Dunno if it is possible to convert it, however you could make a string array and ability array
At map initialization:
Code:
string[1] = Flame Strike
string[2] = Storm Hammer
string[3] = Holy Light

ability[1] = Flame Strike
ability[2] = Storm Hammer
ability[3] = Holy Light

Then when someone writes something, you check if entered chat (sub)string is any of your defined strings and add ability with same index.
Code:
Player wrote something
For (integet LoopInt) from 1 to X (X is maximum number of indexes for your defined strings), do (actions)
    Loop
        If (conditions)
            Entered (sub)string == string[LoopInt]
        Then
            Add ability[LoopInt] to unit
 
Level 7
Joined
Mar 6, 2006
Messages
282
An ability is an integer, so for example:

Banish = 'AHbn'

and

'AHbn' = 1095262830

So if someone typed "1095262830" and then you did UnitAddAbility( S2I(GetEventPlayerChatString(), unit) then it should add that ability.

However, there's no reason to do that because you can just have the player enter something much more simple, like the ability's name. Then check the ability's name and return the ability id, which is the integer, then add it. You would probably need a hashtable unless you're only going to be using a few abilities, then you could easily do if Entered chat string = "banish" then add ability banish to unit
 
Level 5
Joined
Jul 17, 2013
Messages
128
An ability is an integer, so for example:

Banish = 'AHbn'

and

'AHbn' = 1095262830

So if someone typed "1095262830" and then you did UnitAddAbility( S2I(GetEventPlayerChatString(), unit) then it should add that ability.

However, there's no reason to do that because you can just have the player enter something much more simple, like the ability's name. Then check the ability's name and return the ability id, which is the integer, then add it. You would probably need a hashtable unless you're only going to be using a few abilities, then you could easily do if Entered chat string = "banish" then add ability banish to unit

No i cant make this for 300 spells. Thats why i am asking for this.
How can i know Integer? (that number)

PS: When i tried to change AHbn to 1095262830 in ability (UnitAddAbility) Warcraft 3 cant load map, it shows only menu. So probably no. Anyway thank you
 
Last edited:
Hi, I would do something like this maybe:

  • INIT
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Hashtabelle - Create a hashtable
      • Set Hashtable = (Last created hashtable)
      • -------- ------------------- --------
      • Set Ability_Skill[1] = Thunder Clap
      • Set Ability_Skill[2] = Slow
      • Set Ability_Skill[3] = Heal
      • -------- ------------------- --------
      • Set Abilities_Max = 3
      • -------- ------------------- --------
      • Set Abilities_Row = 0
      • For each (Integer Integer) from 1 to Abilities_Max, do (Actions)
        • Loop - Actions
          • Hashtable - Save Integer as Integer of Abilities_Row in Hashtable
  • Get Item
    • Events
      • Player - Player 1 types a chat message containing - as Sub-String
    • Conditions
    • Actions
      • Set Integer = 0
      • Set Integer = (Load (Integer((Substring((Entered chat string), 2, (Length of (Entered chat string)))))) of Abilities_Row from Hashtable)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Integer != 0
        • Then - Actions
          • Unit - Add Ability_Skill[Integer] to Hero
        • Else - Actions

So if you type "-1" --> you get Thunder Clap for example.
 
Level 5
Joined
Jan 27, 2014
Messages
164
Post#5: I believe there is no need for Hashtable for that purpose? Just use an integer loop in the second trigger will do.

@ZeroGo I reckon the idea and trigger posted in Post#2 is already the best one around. Are you not satisfied with that suggestion?
 
Status
Not open for further replies.
Top