The title may not summarize this well enough. What I am working on currently is a type of strategy game (think age of empires, rise of nations, empire earth) that uses more than the standard 2 resources provided by starcraft 2. As a result I need to create several more resources to be used for constructing structures and training units.
I already have the syntax I would need for handling the player errors of preventing construction from lack of resources, but I am currently trying to organize an effecient way of applying these variables to each individual unit that I create.
Here is my issue, I need a trigger that checks when a play trains a unit or builds a structure, then the trigger needs to check to see if the player has enough resources for the structure, and if they don't the trigger prevents them from building or training.
I already have the actions for preventing the building and training, however with the event handling, I have not found an effecient way to get the events and conditions to check for EVERY unit in bulk.
Obviously I realize that I will have to declare the custom costs of all the units in structures in the trigger editor as I doubt theres enough variables to use in the data editor. I am prepared to create a select case for each unit and structure to give them their individual costs, my main concern is event handling.
I need the trigger to fire whenever any unit or structure is trained or built, check for the resources, then cancel or allow the action as needed. Additionally, I'll need another trigger to fire when the structure is canceled, to refund the resources.
I like my code to be neat, and I know that the trigger editor has some amazing features for making a task like this very easy to keep clean, and I want to minimalize the work necessary for getting this task done.
Alternatively, if anyone knows of a way to get more than the 4 available resources (minerals, gas, terrazine, credits) to be used in the data editor, it would be great if I could just use those instead.
Here is what I managed to make so far, it works perfectly but I want to try and make it tighter and more effecient, if anyone can think of ways to make this easier to work with please feel free to speak up as I will be very grateful.
This is a custom Action Definition that when used, will cause the unit declared in it's "Unit" parameter, to skip it's current action and continue with the rest of the actions in it's queue. When I couldn't find an action in the list that mimicked this action, I felt it would be appropriate to make one, as I feel I would use this in several more areas than just these couple triggers.
This is a custom Function designed to organize all the different unit types that will have Custom Resource costs applied too them, Units listed in this function are given custom resource costs, and the type of resource in question can be chosen with the functions declaration (Custom Presets are also used to add the names of the resources Credits, Materials, and Development)
Any unit checked that is not listed in this function will turn up 0 for all resources.
However being that starcraft 2 uses build and train orders as abilities, these cannot be used for the train and build orders. But this function is still heavily utilized in the next one.
Just like the previous function, this function lists the Custom Resource costs of every units, but uses an Ability command in the place of a Unit Type for a parameter. This is where all the train and build abilities are listed for every unit and structure. Though being that I'm a programmer at heart, I cannot stand hard coding, so in this function I made sure that it utilized the previous function. This way whenever I make adjustments to costs, I only have to edit 1 field instead of 2.
The downside of having these two functions is every time I add a new unit or structure, I need to add them to this list, which can end up being time consuming. But considering the options it opens up, it's well worth it.
This is simply a trigger used to save me the effort of copying and pasting an event 30 times. The reason that this event is copied 30 times is because abilities cannot have more than 30 commands (or at least as far as I'm concerned) This trigger merely add's the event triggers for whenever a build or train order is started.
This is the primary trigger, it controls what happens when a unit attempts to build a structure that costs a custom resource. The trigger will fire anytime a structure is built, or canceled. The custom resources are spent and refunded immediately when the unit is on the "Build - Approach" ability phase. It then checks to see if the ability is one that uses the custom resources. If the resource requirements are not met, the custom Action is used to cause the builder to skip his current action, if the resource requirements are met however, the custom resource is spent accordingly.
This trigger also functions at 2 other different points, it triggers at the "Generic - Cancel" ability phase, and the "Unit is Issued Order" event. The generic cancel goes off whenever the builder is ordered to do something else before he has placed his building at the blueprint, this causes the resources for the canceled action to be refunded. The issued order event takes place when the player presses the cancel button on the constructing structure, which also refunds the resources. And this is how I currently have my resource management.
I think I know of a way. Try using an upgrade as your resource, setting the max count to -1 (for unlimited) or like 100000. Then you can create a requirement for each unit that checks the count of that upgrade before allowing you to build the unit. You'll still need triggers to add the upgrades when a player gains that resource and subtract the upgrades when a unit is built using that resource, but that should be relatively simple.
EDIT: Oops, turns out Blizzard set an arbitrary maximum on upgrades to 255. I'll see if I can find another way.
EDIT2: Try using a hidden behavior to account for resources. Set the resource amount in a variable, then apply that number of behaviors to every builder owned by the player. Then you can use "Count Behavior" in Requirements.
EDIT2: Try using a hidden behavior to account for resources. Set the resource amount in a variable, then apply that number of behaviors to every builder owned by the player. Then you can use "Count Behavior" in Requirements.
Actually count behavior can be detected globally, so I could just have the behaviors counted on a dummy unit in that respect. Only issue with that setup is it ends up requireing work in both the trigger editor and data editor, the solution I need has to either use the data editor entirely, or use the trigger editor entirely.
Thanks for the suggestion though, it was definately worth thinking over.
Strange issue at the moment, I can't get an Event to trigger when a building is canceled, is there a special event for that? Because I tried to make the event go off of using ability "Build In Progress - Command Cancel" but it doesn't even fire once.
Edit: Well I feel dumb, the moment I post this reply I found out all I had to do was try the event "Unit issued order"
At any rate I'll post my current setup so I can get some feedback and possible suggestions. Also anyone who views it can use it for themselves
yeah sorry, I don't know the forum controls too well, is there anyway I can setup minimizations for these code segments? Also now that I'm more free than I was I can explain what each part does.
Well I guess I'll just crop screenshots then, they seem to be the best way to display the code clearly. Going to experiment now and see if I can find more ways to make this easier.
Well current step I'm on, having difficulty getting unit training to function properly, It's a little more complex than building a structure. Reason being that I need the resources to be deducted and refunded whenever a unit is trained and queued up. Problem is anytime a unit in the training queue moves to slot 1, it fires the execute stage, which in turn causes some issues. I am right now trying to find a workaround.
I would much rather have the option of going higher than 4 resources, a trigger built system is capable of this.
True it would be alot easier just to use the 4, additionally it would be alot easier if blizzard just let us add more resources to work with. But the point of this code is to act as a workaround.
Also, I plan to have certain trigger's that influence resources anyway, so having trigger's reference trigger data will save me the effort of bouncing between windows.
I'd much rather have costs and gathering rates influenced entirely through triggers, rather than trying to hybrid data editor content with trigger content, which has proven to be very time consuming.
More on topic, I found that using the Issue Order event is optimal for handling unit training instead of the use ability execute stage. Some adjustments need to be made to the structure trigger before I finish this however. Once I have got it working I will post what I have.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
The title may not summarize this well enough. What I am working on currently is a type of strategy game (think age of empires, rise of nations, empire earth) that uses more than the standard 2 resources provided by starcraft 2. As a result I need to create several more resources to be used for constructing structures and training units.
I already have the syntax I would need for handling the player errors of preventing construction from lack of resources, but I am currently trying to organize an effecient way of applying these variables to each individual unit that I create.
Here is my issue, I need a trigger that checks when a play trains a unit or builds a structure, then the trigger needs to check to see if the player has enough resources for the structure, and if they don't the trigger prevents them from building or training.
I already have the actions for preventing the building and training, however with the event handling, I have not found an effecient way to get the events and conditions to check for EVERY unit in bulk.
Obviously I realize that I will have to declare the custom costs of all the units in structures in the trigger editor as I doubt theres enough variables to use in the data editor. I am prepared to create a select case for each unit and structure to give them their individual costs, my main concern is event handling.
I need the trigger to fire whenever any unit or structure is trained or built, check for the resources, then cancel or allow the action as needed. Additionally, I'll need another trigger to fire when the structure is canceled, to refund the resources.
I like my code to be neat, and I know that the trigger editor has some amazing features for making a task like this very easy to keep clean, and I want to minimalize the work necessary for getting this task done.
Alternatively, if anyone knows of a way to get more than the 4 available resources (minerals, gas, terrazine, credits) to be used in the data editor, it would be great if I could just use those instead.
Here is what I managed to make so far, it works perfectly but I want to try and make it tighter and more effecient, if anyone can think of ways to make this easier to work with please feel free to speak up as I will be very grateful.
This is a custom Action Definition that when used, will cause the unit declared in it's "Unit" parameter, to skip it's current action and continue with the rest of the actions in it's queue. When I couldn't find an action in the list that mimicked this action, I felt it would be appropriate to make one, as I feel I would use this in several more areas than just these couple triggers.
This is a custom Function designed to organize all the different unit types that will have Custom Resource costs applied too them, Units listed in this function are given custom resource costs, and the type of resource in question can be chosen with the functions declaration (Custom Presets are also used to add the names of the resources Credits, Materials, and Development)
Any unit checked that is not listed in this function will turn up 0 for all resources.
However being that starcraft 2 uses build and train orders as abilities, these cannot be used for the train and build orders. But this function is still heavily utilized in the next one.
Just like the previous function, this function lists the Custom Resource costs of every units, but uses an Ability command in the place of a Unit Type for a parameter. This is where all the train and build abilities are listed for every unit and structure. Though being that I'm a programmer at heart, I cannot stand hard coding, so in this function I made sure that it utilized the previous function. This way whenever I make adjustments to costs, I only have to edit 1 field instead of 2.
The downside of having these two functions is every time I add a new unit or structure, I need to add them to this list, which can end up being time consuming. But considering the options it opens up, it's well worth it.
This is simply a trigger used to save me the effort of copying and pasting an event 30 times. The reason that this event is copied 30 times is because abilities cannot have more than 30 commands (or at least as far as I'm concerned) This trigger merely add's the event triggers for whenever a build or train order is started.
This is the primary trigger, it controls what happens when a unit attempts to build a structure that costs a custom resource. The trigger will fire anytime a structure is built, or canceled. The custom resources are spent and refunded immediately when the unit is on the "Build - Approach" ability phase. It then checks to see if the ability is one that uses the custom resources. If the resource requirements are not met, the custom Action is used to cause the builder to skip his current action, if the resource requirements are met however, the custom resource is spent accordingly.
This trigger also functions at 2 other different points, it triggers at the "Generic - Cancel" ability phase, and the "Unit is Issued Order" event. The generic cancel goes off whenever the builder is ordered to do something else before he has placed his building at the blueprint, this causes the resources for the canceled action to be refunded. The issued order event takes place when the player presses the cancel button on the constructing structure, which also refunds the resources. And this is how I currently have my resource management.
I think I know of a way. Try using an upgrade as your resource, setting the max count to -1 (for unlimited) or like 100000. Then you can create a requirement for each unit that checks the count of that upgrade before allowing you to build the unit. You'll still need triggers to add the upgrades when a player gains that resource and subtract the upgrades when a unit is built using that resource, but that should be relatively simple.
EDIT: Oops, turns out Blizzard set an arbitrary maximum on upgrades to 255. I'll see if I can find another way.
EDIT2: Try using a hidden behavior to account for resources. Set the resource amount in a variable, then apply that number of behaviors to every builder owned by the player. Then you can use "Count Behavior" in Requirements.
Let me know if it works!
Actually count behavior can be detected globally, so I could just have the behaviors counted on a dummy unit in that respect. Only issue with that setup is it ends up requireing work in both the trigger editor and data editor, the solution I need has to either use the data editor entirely, or use the trigger editor entirely.
Thanks for the suggestion though, it was definately worth thinking over.
Strange issue at the moment, I can't get an Event to trigger when a building is canceled, is there a special event for that? Because I tried to make the event go off of using ability "Build In Progress - Command Cancel" but it doesn't even fire once.
Edit: Well I feel dumb, the moment I post this reply I found out all I had to do was try the event "Unit issued order"
At any rate I'll post my current setup so I can get some feedback and possible suggestions. Also anyone who views it can use it for themselves
Heres what I have currently, and this time I edited it to avoid brain explosions.
Edit: Moved to the first post.
@BasicGear: Go
yeah sorry, I don't know the forum controls too well, is there anyway I can setup minimizations for these code segments? Also now that I'm more free than I was I can explain what each part does.
Sadly I don't think this forum has spoiler controls. Though I could be wrong. <spoiler> O.o </spoiler>
@BasharTeg: Go
Well I guess I'll just crop screenshots then, they seem to be the best way to display the code clearly. Going to experiment now and see if I can find more ways to make this easier.
Well current step I'm on, having difficulty getting unit training to function properly, It's a little more complex than building a structure. Reason being that I need the resources to be deducted and refunded whenever a unit is trained and queued up. Problem is anytime a unit in the training queue moves to slot 1, it fires the execute stage, which in turn causes some issues. I am right now trying to find a workaround.
It not would be easier just to enable all 4 resoucres and using them? As i did in my own AoE style game?
http://www.sc2mapster.com/maps/knm/
@TwoDie: Go
I would much rather have the option of going higher than 4 resources, a trigger built system is capable of this.
True it would be alot easier just to use the 4, additionally it would be alot easier if blizzard just let us add more resources to work with. But the point of this code is to act as a workaround.
Also, I plan to have certain trigger's that influence resources anyway, so having trigger's reference trigger data will save me the effort of bouncing between windows.
I'd much rather have costs and gathering rates influenced entirely through triggers, rather than trying to hybrid data editor content with trigger content, which has proven to be very time consuming.
More on topic, I found that using the Issue Order event is optimal for handling unit training instead of the use ability execute stage. Some adjustments need to be made to the structure trigger before I finish this however. Once I have got it working I will post what I have.