PDA

View Full Version : [Support] Night/Day Cycles



Nytemair
07-25-2011, 01:11 AM
Hey team, is it possible to create a spell based around the Night and Day cycles? I've decided to script a hero based on Drasha's Hero Suggestion Exercise, in which we must create a hero based on the Day/Night Cycle in HoN. (Think Balanar from DotA).

I'm not really sure if it's possible yet, although I have a hunch that the Neutral Creeps have a similar script. (Sleeping during night time).

If anyone can get me started, it would make you the best person ever. :D

tojooko
07-25-2011, 02:52 AM
Well, as you mentioned Neutral Creeps have a similar script. To do it you must simply modify this code.

Creep's code:


<modifier key="neutralsleeping" condition="night idle !player_controlled !player_controlled" modpriority="100"
aggrorange="0"
passiveeffect="/shared/effects/sleep.effect"
/>
Only thing you need to use is condition="night". I'm not sure how does <modifierkey> tag with condition works but I've used it in my Archer Wars:


<state
name="State_Wet"
icon=""
passiveeffect=""
ishidden="true"
effecttype=""
healthregen="-2.0"
>
<modifier key="wet" condition="night" modpriority="100" healthregen="5.0" />
</state>
So your final code can look like it:

hero.entity:


<hero
...
>
<modifier key="isnight" condition="night" modpriority="100" modifierkey="nighttime"/>

</hero>

Nytemair
07-25-2011, 03:24 AM
Awesome, thanks heaps Tojooko! I'll play around with this hero and if I need some more help I'll get back to you :D

Nytemair
07-25-2011, 03:57 AM
Oooookay another quick question, I've had this problem every now and again and am unsure how to fix it. Basically my hero doesn't attack :s

I copied Maliken so I didn't have to re-write all the coding, and added one custom ability and now his attack doesn't work. Anyone else have this problem? I'm looking through his script atm

Oloko
07-25-2011, 05:44 AM
If you overwrite an existing hero, you will need to load your map twice for everything to work.

Jonathan
07-25-2011, 05:32 PM
Since this is related to the day/night cycle...

How do I control the day/night cycle? both for testing(change to day/night with a command?) and for map(set duration of day and night?)

tojooko
07-25-2011, 07:19 PM
About setting duration there are 3 variables in game_settings.cfg file


Set "g_dayLength" "900000"
Set "g_dayStartTime" "225000"
Set "g_dayTransitionTime" "6000"
About controlling day/night cycles I've no idea how to do it. I suppose only way to get it is to beg S2 for such command... There may be some way by using UI commands but realy not sure about it, maybe Oloko will know something more:)

EDIT
I've made some research and there is way to do it. It requires some math, becouse you can change these variables in console, what changes time in game. I suggest trying it in practice. All in all you can check Tutorial code how is made connection between game entities and console commands and with some calculations you can set requested time in game. I've never tried it (yet) so I can't help you (now) :P

Jonathan
07-26-2011, 07:53 AM
About setting duration there are 3 variables in game_settings.cfg file


Set "g_dayLength" "900000"
Set "g_dayStartTime" "225000"
Set "g_dayTransitionTime" "6000"
About controlling day/night cycles I've no idea how to do it. I suppose only way to get it is to beg S2 for such command... There may be some way by using UI commands but realy not sure about it, maybe Oloko will know something more:)

EDIT
I've made some research and there is way to do it. It requires some math, becouse you can change these variables in console, what changes time in game. I suggest trying it in practice. All in all you can check Tutorial code how is made connection between game entities and console commands and with some calculations you can set requested time in game. I've never tried it (yet) so I can't help you (now) :P
I can't get the day/night cycle to work..
I think it is because the time at the top of the screen is stuck at 37591:24
How would I fix this?

Oloko
07-26-2011, 09:53 AM
This often happen if you skip the lobby/picking screen.
Because you skipped them, your game isn't in the right game phase.
I think you can change your game phase using: <setgamephase name="THE_GAME_PHASE" duration="THE_DURATION" />

For example: <setgamephase name="pre_match" duration="3000" /> to set the game phase to "pre_match" that will last 3sec.

Jonathan
07-26-2011, 10:18 AM
This often happen if you skip the lobby/picking screen.
Because you skipped them, your game isn't in the right game phase.
I think you can change your game phase using: <setgamephase name="THE_GAME_PHASE" duration="THE_DURATION" />

For example: <setgamephase name="pre_match" duration="3000" /> to set the game phase to "pre_match" that will last 3sec.
perfect, thanks

Jonathan
07-26-2011, 01:23 PM
I need more help:
I have a simple ability where I use the code tojooko posted and it works perfectly.
Now I have a more complicated ability where I need to check whether it is night or not inside the <onframe>. I tried create a modifier with condition="night"(the modifier works) and using <hasmodifier> to check for the modifier but it doesn't work..
Like this:


<onframe>
<setcharges a="40"/>
<setvar2 a="768"/>
<hasmodifier name="ability_night">
<setcharges a="0"/>
<setvar2 a="512"/>
</hasmodifier>
<do other stuff>
</onframe>
<modifier key="ability_night" condition="night" modpriority="100""/>

I also tried using the <condition> tag, but it doesnt work
Like this:

<onframe>
<setcharges a="40"/>
<setvar2 a="768"/>
<condition test="night">
<setcharges a="0"/>
<setvar2 a="512"/>
</condition>
<do other stuff>
</onframe>

(charges always 40 and var2 always 768)

Oloko
07-26-2011, 01:56 PM
I don't know if its your condition that is wrong, because the script you are doing to test it isn't good.

First thing you should know is the range of the "variables" used with <setvar />.
Here is a little example I posted in another thread:



<onimpact>
<setvar0 a="3" /> <!-- var0 value is 3 -->
<condition test="random test">
<!-- var0 value is still 3 -->
<setvar0 a="var0" b="2" op="add" /> <!-- var0 value is now 5 (3+2) -->
</condition><!-- current var0 value is lost -->
<!-- var0 value here is 3 -->
<setvar0 a="var0" b="1" op="add" /> <!-- var0 value is now 4 (3+1) -->
</onimpact><!-- var0 value is lost -->
Also, the number of charge shouldn't change, since at the start of your <onframe> event you have a <setcharges /> action. So on each frame you set it back.

If you want to test your condition do it like this:



<onframe>
<setcharges a="40"/>
<setvar2 a="768"/>
<hasmodifier name="ability_night">
<!-- Use a debug command to see some output in the console -->
<print text="condition works fine!" />
<setvar2 a="512" />
<printdebuginfo />
<printvalue label="myvar2" value="var2" />
</hasmodifier>
<do other stuff>
</onframe>
<modifier key="ability_night" condition="night" modpriority="100""/>


Using one of the "debug" action, you should see some output in your console (CTRL+F8). Since its on a <onframe> event, it should be pretty hard to miss. :p
With this you should at least know if your condition actually work or not.

Jonathan
07-26-2011, 02:19 PM
I don't know if its your condition that is wrong, because the script you are doing to test it isn't good.

First thing you should know is the range of the "variables" used with <setvar />.
Here is a little example I posted in another thread:



<onimpact>
<setvar0 a="3" /> <!-- var0 value is 3 -->
<condition test="random test">
<!-- var0 value is still 3 -->
<setvar0 a="var0" b="2" op="add" /> <!-- var0 value is now 5 (3+2) -->
</condition><!-- current var0 value is lost -->
<!-- var0 value here is 3 -->
<setvar0 a="var0" b="1" op="add" /> <!-- var0 value is now 4 (3+1) -->
</onimpact><!-- var0 value is lost -->
Also, the number of charge shouldn't change, since at the start of your <onframe> event you have a <setcharges /> action. So on each frame you set it back.

If you want to test your condition do it like this:



<onframe>
<setcharges a="40"/>
<setvar2 a="768"/>
<hasmodifier name="ability_night">
<!-- Use a debug command to see some output in the console -->
<print text="condition works fine!" />
<setvar2 a="512" />
<printdebuginfo />
<printvalue label="myvar2" value="var2" />
</hasmodifier>
<do other stuff>
</onframe>
<modifier key="ability_night" condition="night" modpriority="100""/>


Using one of the "debug" action, you should see some output in your console (CTRL+F8). Since its on a <onframe> event, it should be pretty hard to miss. :p
With this you should at least know if your condition actually work or not.
How can I have a variable that is modified inside a <condition>(or any other)tag then?

For the <setcharges>, I calculate the other charges afterwards in my onframe and add them with <addcharges>.

If I use <print text="condition works fine!" /> inside either the <condition test="night"> or the <hasmodifier name="ability_night"> nothing is printed in the console(if I put it outside then the console is spammed with "condition works fine!"). I know for a fact that my unit has the ability_night modifier at night because if I do

<modifier key="ability_night" condition="night" modpriority="100" healthregen="-1"/>
then my unit has -1 health regen at night

Jonathan
07-26-2011, 02:29 PM
I got it working by using the <onframe> inside the modifier, and a modifier for daytime too(but the script for calculating charges needs to be in both :( ).

Oloko
07-26-2011, 02:36 PM
To keep variables in a condition or other tags, you can use an accumulator (<setaccumulator />). I think you can also use <pushstack /> action (and <popstack />) but I never tried that one. If it does work, I would probably recommend the stack over the accumulator, because the accumulator value will persist even after the event, it can be accessed by other entities and you can only have one by entity.

You can probably create a <onframe /> action in the <modifier /> too, so that it will have its own <onframe /> event with custom script.


<onframe>
<!-- stuff -->
</onframe>

<modifier
...
>
<onframe>
<!-- night stuff-->
</onframe>
</modifier>But its quite annoying to have two copy of the same script when the script only need to do one or two extra stuff.

Edit: Looks like you already found that solution. I'll try to look at this when I get home since I don't have anything right now, I'm only doing it by memory.