Page 3 of 3

Re: [Scripts,Assets] Small interesting additions

Posted: Tue Jan 06, 2015 2:09 am
by Mal85
These are really quite nice additions Davey! Thanks for sharing with us, I am sure to use some of these. Hope to see more from you!

Re: [Scripts,Assets] Small interesting additions

Posted: Thu Mar 17, 2016 8:53 pm
by AndakRainor
I found something while testing some modified monsters, slimes in this case, but the problem is the same with any monster.

When you freeze them with the frostbolt spell for example, they loose their customized material after the frozen effects stops. So slimes for example become green slimes after that attack.

Does anyone know why this happens and if it can be avoided ? I looked at the FrozenMonsterComponent in the scripting reference but it is totally empty.

So a warning to all people here with custom monsters materials; think about testing the frozen condition on your monsters.

- Is there a technical solution ? A TimerComponent checking the monster conditions and material every frame would be brutal.
- Use the bug as a fun element ? All your fire theme monsters not immune to cold would loose their flammes after being frozen... Also alter some other stats of the monster with a onDamage function (changing the attacks damage type for example).
- Make all other defined monsters immune to the frozen condition ? (I don't like this solution as much, very unfair to ice wizards!)

Re: [Scripts,Assets] Small interesting additions

Posted: Thu Mar 17, 2016 11:05 pm
by Sutekh
Yeah, I noticed the same thing when re-texturing some monsters.
My solution was to go back to the old method we had to use with LoG1 - make a copy of the model and re-texture it in the GMT.

Re: [Scripts,Assets] Small interesting additions

Posted: Fri Mar 18, 2016 12:24 am
by minmay
Actually, this is pretty easy to fix, assuming that your shortest freeze duration is longer than your shortest animation. No need to waste filesize & memory on an extra copy of the model.

Code: Select all

local anims = {
	idle = "assets/animations/monsters/goromorg/goromorg_idle.fbx",
	moveForward = "assets/animations/monsters/goromorg/goromorg_walk.fbx",
	strafeLeft = "assets/animations/monsters/goromorg/goromorg_strafe_left.fbx",
	strafeRight = "assets/animations/monsters/goromorg/goromorg_strafe_right.fbx",
	turnLeft = "assets/animations/monsters/goromorg/goromorg_turn_left.fbx",
	turnRight = "assets/animations/monsters/goromorg/goromorg_turn_right.fbx",
	attack = "assets/animations/monsters/goromorg/goromorg_attack.fbx",
	getHitFrontLeft = "assets/animations/monsters/goromorg/goromorg_get_hit_front_left.fbx",
	getHitFrontRight = "assets/animations/monsters/goromorg/goromorg_get_hit_front_right.fbx",
	getHitBack = "assets/animations/monsters/goromorg/goromorg_get_hit_back.fbx",
	getHitLeft = "assets/animations/monsters/goromorg/goromorg_get_hit_left.fbx",
	getHitRight = "assets/animations/monsters/goromorg/goromorg_get_hit_right.fbx",
	fall = "assets/animations/monsters/goromorg/goromorg_get_hit.fbx",
}
for name,anim in pairs(anims) do
defineAnimationEvent{
	animation = anim,
	event = "hack",
	normalizedTime = 0,
}
end
defineObject{
	name = "poop_goromorg",
	baseObject = "goromorg",
	components = {
		{
			class = "Model",
			model = "assets/models/monsters/goromorg.fbx",
			storeSourceData = true,
			material = "poop",
		},
		{
			class = "Animation",
			animations = anims,
			currentLevelOnly = true,
			onAnimationEvent = function(self, event) if event == "hack" and not self.go.frozen then self.go.model:setMaterial(self.go.model:getMaterial()) end end, 
		},
	},
}
If you're using materialOverrides instead of material, the same solution works:

Code: Select all

onAnimationEvent = function(self, event) if event == "hack" and not self.go.frozen then self.go.model:setMaterialOverrides(self.go.model:getMaterialOverrides()) end end
If your shortest freeze duration is shorter than your shortest animation duration, just add more animationEvents until the time between them is shorter than your shortest freeze duration, like:

Code: Select all

for name,anim in pairs(anims) do
defineAnimationEvent{
	animation = anim,
	event = "hack",
	normalizedTime = 0,
}
defineAnimationEvent{
	animation = anim,
	event = "hack",
	normalizedTime = 0.5,
}
end
This solution takes advantage of the fact that monsters always finish their current animation when frozen (as far as I can tell) and play a new animation (possibly the idle animation) immediately upon becoming unfrozen.
Also, when a frozen monster finishes the animation it was playing when the freeze started, it will play frame 0 of its idle animation but not any further ones, in case that information is useful for something (it's not really relevant to this particular problem though).

The shortest freeze duration in the standard assets is 3.5 seconds (frostbolt_1, frostbolt_2, or frostbolt_3).

Re: [Scripts,Assets] Small interesting additions

Posted: Fri Mar 18, 2016 12:53 am
by AndakRainor
I tested it and there is still a problem; the material is restored on the next animation, so for a slime who stands still and does not attack immediately after the frozen condition, it stays green for the duration.

So I think the timer solution cannot be avoided in this case:

Code: Select all

    { class = "Timer",
      timerInterval = 0.001,
      triggerOnStart = true,
      onActivate = function(self) if not self.go.frozen then self.go.model:setMaterial(self.go.model:getMaterial()) end end,
    },
edit: oops missed your previous post edit, will check it

Re: [Scripts,Assets] Small interesting additions

Posted: Fri Mar 18, 2016 1:05 am
by AndakRainor
So I have to choose between two solutions;
- use a timer component as in my previous post.
- change a freeze spell I made that does not have a minimum duration (duration = power * math.random())

Do you think the timer solution is really nastier compared to animation events ?

Re: [Scripts,Assets] Small interesting additions

Posted: Fri Mar 18, 2016 1:43 am
by minmay
Nah. The advantage of the animationEvent approach is just that you're making way fewer function calls. Doing it every frame is fine if you need it.
By the way, I found that you can use a timerInterval of 0 to get one activation every frame, in case you want better compatibility with people running the game at 2000 FPS.

Re: [Scripts,Assets] Small interesting additions

Posted: Fri Mar 18, 2016 2:07 am
by AndakRainor
minmay wrote:people running the game at 2000 FPS.
The future of retro-gaming :lol: