Okay, I've recently been creating a Survival Map. You need Food, Water, and Rest to keep yourself alive.
I want to add a Hunger Bar using Triggers, then apply a negative behavior when starving. I'd like the hunger bar to look like a Boss Bar, but the bar diminishes as you continue not eating.
How would I pull this off? And how would Items restore the bar?
There's a ton of ways to do this. You could actually use the "boss bar" trigger functions for a simple solution, you could create a progress bar dialog item, or you could create your own bar artwork and export that into them map. I would create a hunger variable which keeps track of your "food level". Every few seconds you lower that variable, and whenever the player uses a food item, you increase it. Whenever that variable changes, you would then set your hunger bar's "fill level".
Like I said above, the easiest way to do this is to just use a boos bar. You can just use the "Display boss bar action to create a bar, then use the "Set boss bar current/maximum" value functions to set it up. Here's the list of boss bar functions if you're interested. These functions are great because they're a very simple way to create a quick bar. If you're interested in making something more fancy, then you'll need dialogs- you can create a progress bar dialog item or you could create images in an outside program and use them in your dialog.
Rollback Post to RevisionRollBack
Feel free to Send me a PM if you have any questions/concerns!
When you display the boss bar, there's a player group parameter that you can use. Like you said, just show it for only the person you want to see it. Use "convert player to player group" to convert one player into a player group with just him in it. Try something like this:
I made a test map using data and triggers that could be of some help.
It has a attribute like hunger for the unit and a unit status bar
the system could be used to create dialogs to show the status as well pretty simply i think depends if you want it all triggers
The Map is Here the forum is Here
Yeah, you can totally do that. I would create a hunger variable. Make it an integer, and then make it an size-15 array (instead of 15 you can use however many players you'll be allowing in one lobby) . Set the default value to 100. Now you've got 15 "slots" in your hunger variable, one for each player, and you can update them separately. If you haven't used arrays before, take a look at this post.
You should be able to change the boss bar icon although I don't remember how off the top of my head. If not, you can (worst-case) recreate the boss bar with a new portrait.
Make a trigger like this:
Event:PeriodicEvent,every10seconds// Make this how many seconds you want it to take to lower the bar by 1 pointConditions:NoneActions:Pickeachplayerinplayergroup(activeplayers)anddoactions:{ModifyVariableHunger[PickedPlayer]:-1// Lower hunger for each player by 1 pointIf(Hunger[PickedPlayer}<50){// Here's where you would set the icon for picked player to the "low hunger value"}else{// Here's where you would set the icon for picked player to the "high hunger value"}}
Rollback Post to RevisionRollBack
Feel free to Send me a PM if you have any questions/concerns!
How would I link the Hunger bar to the integer, your code uses it's own. Or will it automatically link? I'm still putting it in the game.
EDIT: Okay, I think I have all of the Variable sided stuff setup. I just need to get the boss bar to lose a point/base it off the variable, and be able to change the portrait on any number below 50. Then figure out how to apply the Hunger behaviors to my units.
If they get below 50% I want to apply a warning, when they get to 25% they get a Starving behavior.
General - Pick each integer from 1 to 8, and do (Actions)
Actions:
UI - Display boss bar (Picked integer) with title "Hunger", portrait (Picture name) and maximum value 100 for (PlayerGroup((Picked integer)))
General - If (Conditions) then do (Actions) else do (Actions)
If
(Triggering Player) == 1
Then
UI - Set boss bar 1 current value to Hunger[1] (Do refresh the boss bar)
I do the If Then Else eight times, increasing the numbers each time... Will this work?
Note that this is in my Hero Create trigger, which is entirely based off of Triggering Player options. I then add all the heroes to a Unit Group, if all heroes die the game ends.
I did this to allow the addition of more players easily, without making the main code any different.
I did this to allow the addition of more players easily, without making the main code any different.
That's a really good idea, but there's an easier way to handle it :) Put the dialog refreshing action inside the loop. That way you don't need to write anything 8 times, and you also don't need to worry about having different player numbers. Unless you can't for some reason, it's almost always faster to put everything inside a loop. You're the programmer, not the computer, so let it do the monotonous work for you ;)
That way you don't need to modify the code at all if more players are added. It just picks the ones who are in the game and ignores any other player slots. Does that clear things up?
Rollback Post to RevisionRollBack
Feel free to Send me a PM if you have any questions/concerns!
EDIT: Will this work? This is the Hunger decrease trigger.
Hunger
Events
Timer - Every 10.0 seconds of Game Time
Local Variables
Conditions
Actions
Player Group - Pick each player in (All players) and do (Actions)
Actions
Variable - Modify Hunger[1]: - 1
UI - Set boss bar 1 current value to Hunger[1] (Do refresh the boss bar)
General - If (Conditions) then do (Actions) else do (Actions)
If
Hunger[1] < 25
Then
Unit Group - Pick each unit in (Any units in (Entire map) owned by player 1 matching Required: Heroic; Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)
Actions
Unit - Add 1 Hungry to (Picked unit) from Critter - Automaton 2000 [146.49, 169.43]
Else
(I'm only concerned about the Set Boss Bar 1 Current Value to Hunger(1). I'm not sure it will work... it might not bring up the correct boss bar in multiplayer (there are going to be eight boss bars). I'm using it as a refresh.
well if that is your current trigger it is lowering the hunger for player 1 each time it is run
Hunger[1]: - 1 would reduce the hunger value for player 1 for the number of players if its happening 10 times then you probably have 10 players
try changing Player Group - Pick each player in (All players) and do (Actions)
to
Player Group - Pick each player in (Active Players) and do (Actions)
should be Hunger[picked player]: - 1
if thats not your current trigger you should post it
Also if you are only having a boss bar for hunger and you will need one for each player you may want to make the boss bar an array to make it easier so
UI - Set boss bar 1 current value to Hunger[1] (Do refresh the boss bar)
would become
UI - Set boss bar 1[picked player] current value to Hunger[picked player] (Do refresh the boss bar)
Also something you might want to think about is using unit groups
well this does work
Unit Group - Pick each unit in (Any units in (Entire map) owned by player (Picked player) matching Required: Heroic; Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)
depending on how your map is setup when you create the character for the player you could add them to a unit group for easy referencing.
so instead of having the unit group pick each unit you could just say
Unit Group - Add (Last created unit) to Heroes[(Picked player)]
Unit Group - Pick each unit in Heroes[(Picked player)] and do (Actions)
Unit - Add 1 Hungry to (Unit 1 from Heroes[(Picked player)]) from Marauder [65.03, 65.47]
not sure if it would save time or reduce lag just might make it easier
Okay, I've recently been creating a Survival Map. You need Food, Water, and Rest to keep yourself alive. I want to add a Hunger Bar using Triggers, then apply a negative behavior when starving. I'd like the hunger bar to look like a Boss Bar, but the bar diminishes as you continue not eating.
How would I pull this off? And how would Items restore the bar?
@Alnatair: Go
There's a ton of ways to do this. You could actually use the "boss bar" trigger functions for a simple solution, you could create a progress bar dialog item, or you could create your own bar artwork and export that into them map. I would create a hunger variable which keeps track of your "food level". Every few seconds you lower that variable, and whenever the player uses a food item, you increase it. Whenever that variable changes, you would then set your hunger bar's "fill level".
Like I said above, the easiest way to do this is to just use a boos bar. You can just use the "Display boss bar action to create a bar, then use the "Set boss bar current/maximum" value functions to set it up. Here's the list of boss bar functions if you're interested. These functions are great because they're a very simple way to create a quick bar. If you're interested in making something more fancy, then you'll need dialogs- you can create a progress bar dialog item or you could create images in an outside program and use them in your dialog.
Thank you, a boss bar is exactly what I want it to look like. However, how would I make this times 8? I have an eight player map.
1 bar per player.
Should I create it then hide it to the players that won't be using it?
When you display the boss bar, there's a player group parameter that you can use. Like you said, just show it for only the person you want to see it. Use "convert player to player group" to convert one player into a player group with just him in it. Try something like this:
I made a test map using data and triggers that could be of some help.
It has a attribute like hunger for the unit and a unit status bar
the system could be used to create dialogs to show the status as well pretty simply i think depends if you want it all triggers
The Map is Here the forum is Here
I'll try it in a bit, thank you very much.
EDIT: Not what I'm looking for, thanks for offering it up though.
@Zeldarules - I'll try your method next, thanks again for all the help guys.
Going to try and do this with Triggering player, as I want them to get the hunger bar when they pick their hero.
EDIT: Got the code you gave me, Zelda. Testing it now, I just need to know how to make the actual hunger part.
On a side note, is there a way to change the Boss Bar icon if the hunger gets to... 50%?
Got the Hunger bar to work upon Triggering Player commands, using your code. How would I setup the Variable/Feed/Drain part?
On a side note, I'd like to change that icon to another icon upon Hunger below 50. Any idea how?
@Alnatair: Go
Yeah, you can totally do that. I would create a hunger variable. Make it an integer, and then make it an size-15 array (instead of 15 you can use however many players you'll be allowing in one lobby) . Set the default value to 100. Now you've got 15 "slots" in your hunger variable, one for each player, and you can update them separately. If you haven't used arrays before, take a look at this post.
You should be able to change the boss bar icon although I don't remember how off the top of my head. If not, you can (worst-case) recreate the boss bar with a new portrait.
Make a trigger like this:
How would I link the Hunger bar to the integer, your code uses it's own. Or will it automatically link? I'm still putting it in the game.
EDIT: Okay, I think I have all of the Variable sided stuff setup. I just need to get the boss bar to lose a point/base it off the variable, and be able to change the portrait on any number below 50. Then figure out how to apply the Hunger behaviors to my units.
If they get below 50% I want to apply a warning, when they get to 25% they get a Starving behavior.
http://www.sc2mapster.com/wiki/galaxy/triggers/category-ui/#w-boss-bar
That doesn't show anything to change the portrait... So I'd have to recreate it I'm guessing?
Thank you very much for all the help so far.
If the Portrait isn't possible, that's fine too.. I mainly just need to find out how to link the bar to the variable to the unit (via apply behavior.)
Will this work?
General - Pick each integer from 1 to 8, and do (Actions)
Actions:
UI - Display boss bar (Picked integer) with title "Hunger", portrait (Picture name) and maximum value 100 for (PlayerGroup((Picked integer)))
General - If (Conditions) then do (Actions) else do (Actions)
If
(Triggering Player) == 1
Then
UI - Set boss bar 1 current value to Hunger[1] (Do refresh the boss bar)
I do the If Then Else eight times, increasing the numbers each time... Will this work?
Note that this is in my Hero Create trigger, which is entirely based off of Triggering Player options. I then add all the heroes to a Unit Group, if all heroes die the game ends.
I did this to allow the addition of more players easily, without making the main code any different.
Bump
That's a really good idea, but there's an easier way to handle it :) Put the dialog refreshing action inside the loop. That way you don't need to write anything 8 times, and you also don't need to worry about having different player numbers. Unless you can't for some reason, it's almost always faster to put everything inside a loop. You're the programmer, not the computer, so let it do the monotonous work for you ;)
That way you don't need to modify the code at all if more players are added. It just picks the ones who are in the game and ignores any other player slots. Does that clear things up?
EDIT: Will this work? This is the Hunger decrease trigger.
Hunger
Events
Timer - Every 10.0 seconds of Game Time
Local Variables
Conditions
Actions
Player Group - Pick each player in (All players) and do (Actions)
Actions
Variable - Modify Hunger[1]: - 1
UI - Set boss bar 1 current value to Hunger[1] (Do refresh the boss bar)
General - If (Conditions) then do (Actions) else do (Actions)
If
Hunger[1] < 25
Then
Unit Group - Pick each unit in (Any units in (Entire map) owned by player 1 matching Required: Heroic; Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)
Actions
Unit - Add 1 Hungry to (Picked unit) from Critter - Automaton 2000 [146.49, 169.43]
Else
(I'm only concerned about the Set Boss Bar 1 Current Value to Hunger(1). I'm not sure it will work... it might not bring up the correct boss bar in multiplayer (there are going to be eight boss bars). I'm using it as a refresh.
Okay, I see now that I can make it all into one trigger instead of making this eight times. I'll try to make it all based off of Picked Player.
Also, the trigger is lowering the bar 10 points or more each time. I don't know why.
well if that is your current trigger it is lowering the hunger for player 1 each time it is run
Hunger[1]: - 1 would reduce the hunger value for player 1 for the number of players if its happening 10 times then you probably have 10 players
try changing Player Group - Pick each player in (All players) and do (Actions)
to
Player Group - Pick each player in (Active Players) and do (Actions)
should be Hunger[picked player]: - 1
if thats not your current trigger you should post it
Also if you are only having a boss bar for hunger and you will need one for each player you may want to make the boss bar an array to make it easier so
UI - Set boss bar 1 current value to Hunger[1] (Do refresh the boss bar)
would become
UI - Set boss bar 1[picked player] current value to Hunger[picked player] (Do refresh the boss bar)
http://www.sc2mapster.com/paste/7401/
I fixed it, hopefully. Anyone mind checking and seeing if it will work?
Thank you zaysite, I noticed your post after I 'fixed' the code.
Also something you might want to think about is using unit groups
well this does work
Unit Group - Pick each unit in (Any units in (Entire map) owned by player (Picked player) matching Required: Heroic; Excluded: Missile, Dead, Hidden, with at most Any Amount) and do (Actions)
depending on how your map is setup when you create the character for the player you could add them to a unit group for easy referencing.
so instead of having the unit group pick each unit you could just say
Unit Group - Add (Last created unit) to Heroes[(Picked player)]
Unit Group - Pick each unit in Heroes[(Picked player)] and do (Actions)
Unit - Add 1 Hungry to (Unit 1 from Heroes[(Picked player)]) from Marauder [65.03, 65.47]
not sure if it would save time or reduce lag just might make it easier
I have a unit group called Heroes, I just used it as a Defeat checker though.
So everything works? Awesome, thanks for all the help. Zaysite, Zeldarules.