In the map I'm making, each player has a hero, and the hero's spells are shown on dialog boxes at the bottom of the screen.
Note that there will be many different kinds of spells - for instance a targeted fireball, a non-targeted cone of fire, a teleport spell that teleports the hero to a location on the map, a buff that can be applied to self or others, etc.
My question is, what general solution can I use for 'casting' a spell when a dialog box is clicked. The issue I'm having is that some 'spells' are effects, some are scripts, some require targets, some need to know the casting player as a parameter, etc. My initial thought was to use triggers - so that when a dialog box for a spell is clicked, it runs a trigger corresponding to that spell; however, the issue there is that I can't pass parameters to the trigger, so I can't specify the target, etc.
My next thought was, 'well, I'll just use a function or action definition instead of a trigger'. However, I can't figure out how to have a specific function run with dynamic parameters upon a dialog click. There are built-in functions for triggers based on a parameter ("Run Trigger (trigger name parameter)"), but none for running functions or action definitions...
EDIT: To clarify, I am using a single trigger to detect dialog clicks, which then has a single function that runs the proper spell trigger (as all the spell triggers are stored in an array). I can't seem to store action definitions or functions in an array as I can with triggers, so my current fix, which seems a bit messy (I swear I know exactly how I'd do this in Python) is to have a switch statement with a different action for each spell.
Are there many spells or why are they not in the command card box? It think it would be better to make the spells in data. In triggers u can have the event Button pressed and then choose the button, but i hv no idea how to initiate a spell this way, especially a targeted spell.
I have many spells and due to the design of the game it doesn't make sense to use the command box as they are constantly changing and being re-ordered. I'm looking for a solution that just involves dialogs.
I'm thinking that perhaps I may need to look at the game-link types, which I currently don't understand. I suppose using game-link ability commands might (??) be similar behavior to using the command card, and perhaps I will be forced to do that. I was hoping this was a solved problem with a straightforward solution though.
1) Can you specify how I can dynamically add and remove abilities for a unit using triggers? Should I just add all 300+ abilities to the unit initially and enable/disable them as necessary?
2) How to I tell the hero unit to use the ability when the corresponding dialog is clicked?
I'm afraid there is no UnitAddAbility function in Starcraft 2 like there was in Warcraft 3. I believe that there is a way to link dialogs and other data (such as items) in 1.5 that is currently being looked into, most of the progress done by Renee I believe in this post. Maybe you'll have better luck with this than I did.
My way of doing is. Setting command card ability info by catalog set value (images, tooltips, names etc...).
Then I save the spell I wana use to data table (I use trigger based spells to make this work). And when the spell is cast it runs the trigger that is stored in the data table (it does transfer triggering unit, triggering player and all that good stuff if you run other triggers)
And I disable/allow abilities depending what type of spell it is (Unit target, Point target or Instant). So basically you need 3 different types of spells on unit and modify them with triggers.
This is only sollution for my own game. So if you think its something you could use, go ahead. I think its way easier to manage levels/damage etc...with triggers than in data.
This is sort of a work around stuff for sure. But it does function perfectly fine for me.
My way of doing is. Setting command card ability info by catalog set value (images, tooltips, names etc...).
Then I save the spell I wana use to data table (I use trigger based spells to make this work). And when the spell is cast it runs the trigger that is stored in the data table (it does transfer triggering unit, triggering player and all that good stuff if you run other triggers)
And I disable/allow abilities depending what type of spell it is (Unit target, Point target or Instant). So basically you need 3 different types of spells on unit and modify them with triggers.
This is only sollution for my own game. So if you think its something you could use, go ahead. I think its way easier to manage levels/damage etc...with triggers than in data.
This is sort of a work around stuff for sure. But it does function perfectly fine for me.
So assume that each player has 5 ability slots, which are changing throughout the game. Are you suggesting that I:
1) create three dummy effects for each slot (one for unit target, one for point target, and one for instant) - call them DE[1-5][a-c], 15 total since I'm assuming there are 5 ability slots
2) have a data table (call it DataTable) correlating each dummy ability to a spell trigger
3) when I wish to give a player a new spell trigger "PewPew" in slot 3, use Catalog Set to update the UI of commandbutton03 and update the effect (to say, DE3a), and then update the data table to so that DataTable[DE3a] = "PewPew" (the spell trigger that I want to run when the ability is used by clicking commandbutton03)
4) for each of the 15 dummy effects, there is a separate trigger. So if the player clicks commandbutton03, TriggerDE3a picks up that the dummy effect DE3a was just used, and then runs the trigger stored in DataTable[DE3a], which is the "PewPew" spell.
I think this would work, but I think my implementation is too complex, especially with the need for 3 effects for each command button and then a separate trigger for every event. Is there a way that I can append some metadata on to the events to at least consolidate the number of triggers I need?
1) I only use 3 effects. 1 instant, 1 target point, 1 unit (only to get the target reference, If I left the effect empty I dont think it will work properly.) If you have 4 same type of spells it doesnt really matter if they have the same effect (atleast in my case).
2) You can use variables too, but data tables were more handy in my case.
3) something like that. I think its only matter of preference/need how you want to do this.
4) for each SPELL there needs to be seperate triggers. Ofc you can do workarounds if you want to dump them in same triggers (like all target spells on same, but doesnt really matter).
Seems pretty fine to me. I havent explored the 1.5 editor too much, there are atleast more values that you can change with catalog set now than before. I think you mixed up effects and spells in your post. But you should try it out if you feel like its somethign you could need. Cant really tell if it fits your purposes or not. But currently dialogs are not good for casting spells.
Zenx showed you the way, but since I'm also doing similar thing I thought I'd share it:
I have all my abilities made with data (some are mixture of triggers/data, but it doesn't mater) + dummy abilities (for hero).
When you chose to assign ability to a spellslot, you replace buttons info, ability costs (cooldowns/charges/vitals) and launch/cursor effect.
Button and Info are done through catalog get/set functions, launch/cursor effects need to be replaced with "Catalog Link Replace".
Since you're replacing effect links you'll only need 10 dummy abilities (5 for target spells, 5 for instant effect spells). All of your target spells will need to have a range indicator and cursor AOE effect. For spells which don't use AOE cursor simply assign a dummy search effect where all players are excluded (player/ally/enemy/neutral).
If you want to have a toggle-able abilities (like ghosts cloak) you can emulate them with Effect-Instant.
There are limitations which come with such system, since catalogs can't really modify anything other than cost, cast/finish times, launch/cursor effects. You won't be able to adjust flags, auto-validators, placement units, spell phases and other things. So design your spells accordingly (for example if you have a multiphase spell, make phases with behavior chains). Another painful thing is that you can't transfer requirments. So if you have a spell which originally summons up to 5 units (and if all 5 units are alive you can't summon more and icon is grayed out), if you transfer spell into this system you'll need to use triggers to manually disable/re-enable spell.
So, some thinking is required, but overall it's nothing complicated =D
Edit: that link to Renees topic is interesting, I would wait to see if you can achieve your goals by playing with spell-items, too bad I know nothing about that and since I've already made my catalog system I'm sticking with it :D
In the map I'm making, each player has a hero, and the hero's spells are shown on dialog boxes at the bottom of the screen.
Note that there will be many different kinds of spells - for instance a targeted fireball, a non-targeted cone of fire, a teleport spell that teleports the hero to a location on the map, a buff that can be applied to self or others, etc.
My question is, what general solution can I use for 'casting' a spell when a dialog box is clicked. The issue I'm having is that some 'spells' are effects, some are scripts, some require targets, some need to know the casting player as a parameter, etc. My initial thought was to use triggers - so that when a dialog box for a spell is clicked, it runs a trigger corresponding to that spell; however, the issue there is that I can't pass parameters to the trigger, so I can't specify the target, etc.
My next thought was, 'well, I'll just use a function or action definition instead of a trigger'. However, I can't figure out how to have a specific function run with dynamic parameters upon a dialog click. There are built-in functions for triggers based on a parameter ("Run Trigger (trigger name parameter)"), but none for running functions or action definitions...
EDIT: To clarify, I am using a single trigger to detect dialog clicks, which then has a single function that runs the proper spell trigger (as all the spell triggers are stored in an array). I can't seem to store action definitions or functions in an array as I can with triggers, so my current fix, which seems a bit messy (I swear I know exactly how I'd do this in Python) is to have a switch statement with a different action for each spell.
My sollution. Dont use dialog items for casting spells. Use them for setting spells on command card and then cast it from command card.
I dont think there is good way of handling spells on dialog items (atleast not prior to 1.5, havent investigated 1.5 that much)
@kappyd23s: Go
Are there many spells or why are they not in the command card box? It think it would be better to make the spells in data. In triggers u can have the event Button pressed and then choose the button, but i hv no idea how to initiate a spell this way, especially a targeted spell.
I have many spells and due to the design of the game it doesn't make sense to use the command box as they are constantly changing and being re-ordered. I'm looking for a solution that just involves dialogs.
I'm thinking that perhaps I may need to look at the game-link types, which I currently don't understand. I suppose using game-link ability commands might (??) be similar behavior to using the command card, and perhaps I will be forced to do that. I was hoping this was a solved problem with a straightforward solution though.
@zenx1: Go
Alright, this may be what I end up doing.
1) Can you specify how I can dynamically add and remove abilities for a unit using triggers? Should I just add all 300+ abilities to the unit initially and enable/disable them as necessary?
2) How to I tell the hero unit to use the ability when the corresponding dialog is clicked?
I'm afraid there is no UnitAddAbility function in Starcraft 2 like there was in Warcraft 3. I believe that there is a way to link dialogs and other data (such as items) in 1.5 that is currently being looked into, most of the progress done by Renee I believe in this post. Maybe you'll have better luck with this than I did.
@kappyd23s: Go
My way of doing is. Setting command card ability info by catalog set value (images, tooltips, names etc...).
Then I save the spell I wana use to data table (I use trigger based spells to make this work). And when the spell is cast it runs the trigger that is stored in the data table (it does transfer triggering unit, triggering player and all that good stuff if you run other triggers)
And I disable/allow abilities depending what type of spell it is (Unit target, Point target or Instant). So basically you need 3 different types of spells on unit and modify them with triggers.
This is only sollution for my own game. So if you think its something you could use, go ahead. I think its way easier to manage levels/damage etc...with triggers than in data.
This is sort of a work around stuff for sure. But it does function perfectly fine for me.
So assume that each player has 5 ability slots, which are changing throughout the game. Are you suggesting that I:
1) create three dummy effects for each slot (one for unit target, one for point target, and one for instant) - call them DE[1-5][a-c], 15 total since I'm assuming there are 5 ability slots
2) have a data table (call it DataTable) correlating each dummy ability to a spell trigger
3) when I wish to give a player a new spell trigger "PewPew" in slot 3, use Catalog Set to update the UI of commandbutton03 and update the effect (to say, DE3a), and then update the data table to so that DataTable[DE3a] = "PewPew" (the spell trigger that I want to run when the ability is used by clicking commandbutton03)
4) for each of the 15 dummy effects, there is a separate trigger. So if the player clicks commandbutton03, TriggerDE3a picks up that the dummy effect DE3a was just used, and then runs the trigger stored in DataTable[DE3a], which is the "PewPew" spell.
I think this would work, but I think my implementation is too complex, especially with the need for 3 effects for each command button and then a separate trigger for every event. Is there a way that I can append some metadata on to the events to at least consolidate the number of triggers I need?
@kappyd23s: Go
1) I only use 3 effects. 1 instant, 1 target point, 1 unit (only to get the target reference, If I left the effect empty I dont think it will work properly.) If you have 4 same type of spells it doesnt really matter if they have the same effect (atleast in my case).
2) You can use variables too, but data tables were more handy in my case.
3) something like that. I think its only matter of preference/need how you want to do this.
4) for each SPELL there needs to be seperate triggers. Ofc you can do workarounds if you want to dump them in same triggers (like all target spells on same, but doesnt really matter).
Seems pretty fine to me. I havent explored the 1.5 editor too much, there are atleast more values that you can change with catalog set now than before. I think you mixed up effects and spells in your post. But you should try it out if you feel like its somethign you could need. Cant really tell if it fits your purposes or not. But currently dialogs are not good for casting spells.
Zenx showed you the way, but since I'm also doing similar thing I thought I'd share it:
I have all my abilities made with data (some are mixture of triggers/data, but it doesn't mater) + dummy abilities (for hero).
When you chose to assign ability to a spellslot, you replace buttons info, ability costs (cooldowns/charges/vitals) and launch/cursor effect. Button and Info are done through catalog get/set functions, launch/cursor effects need to be replaced with "Catalog Link Replace".
Since you're replacing effect links you'll only need 10 dummy abilities (5 for target spells, 5 for instant effect spells). All of your target spells will need to have a range indicator and cursor AOE effect. For spells which don't use AOE cursor simply assign a dummy search effect where all players are excluded (player/ally/enemy/neutral).
If you want to have a toggle-able abilities (like ghosts cloak) you can emulate them with Effect-Instant.
There are limitations which come with such system, since catalogs can't really modify anything other than cost, cast/finish times, launch/cursor effects. You won't be able to adjust flags, auto-validators, placement units, spell phases and other things. So design your spells accordingly (for example if you have a multiphase spell, make phases with behavior chains). Another painful thing is that you can't transfer requirments. So if you have a spell which originally summons up to 5 units (and if all 5 units are alive you can't summon more and icon is grayed out), if you transfer spell into this system you'll need to use triggers to manually disable/re-enable spell.
So, some thinking is required, but overall it's nothing complicated =D
Edit: that link to Renees topic is interesting, I would wait to see if you can achieve your goals by playing with spell-items, too bad I know nothing about that and since I've already made my catalog system I'm sticking with it
:D