Page 1 of 2

Monster throwing items

Posted: Sun Jun 05, 2016 2:03 pm
by vieuxchat
I created a bomb-like item. It converts to a trap on hit. When I use the item, it works.
But when I create a monster that uses a ranged attack with that item, the item is thrown but doesn't convert to a trap on hit.

The item :
SpoilerShow

Code: Select all

defineObject{
	name = "trap_bomb_fire",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/essence_fire.fbx",
		},
		{
			class = "Item",
			uiName = "Trap Bomb",
			gfxIndex = 346,
			impactSound = "impact_blunt",
			stackable = false,
			sharpProjectile = false,
			projectileRotationY = 90,
			weight = 0.1,
			convertToItemOnImpact = "trap_rune_dispelable_fire"
		},
		{
			class = "Particle",
			particleSystem = "essence_fire",
		},
		{
			class = "ThrowAttack",
			attackPower = 4,
			cooldown = 5,
		},
	},
	tags = { "weapon", "weapon_throwing", "custom_vieuxchat" },
}
The monster :
SpoilerShow

Code: Select all

defineObject{
	name = "giant_snake_trap_thrower",
	baseObject = "base_monster",
	components = {
		{
			class = "Model",
			model = "assets/models/monsters/snake.fbx",
			storeSourceData = true,
			enabled = false,
		},
		{
			class = "Animation",
			animations = {
				idle = "assets/animations/monsters/snake/snake_idle.fbx",
				moveForward = "assets/animations/monsters/snake/snake_walk.fbx",
				turnLeft = "assets/animations/monsters/snake/snake_turn_left.fbx",
				turnRight = "assets/animations/monsters/snake/snake_turn_right.fbx",
				moveForwardTurnLeft = "assets/animations/monsters/snake/snake_walk_turn_left.fbx",
				moveForwardTurnRight = "assets/animations/monsters/snake/snake_walk_turn_right.fbx",
				attack = "assets/animations/monsters/snake/snake_attack.fbx",
				attackFromBehind = "assets/animations/monsters/snake/snake_attack_from_behind.fbx",
				getHitFrontLeft = "assets/animations/monsters/snake/snake_get_hit_front_left.fbx",
				getHitFrontRight = "assets/animations/monsters/snake/snake_get_hit_front_right.fbx",
				getHitBack = "assets/animations/monsters/snake/snake_get_hit_back.fbx",
				getHitLeft = "assets/animations/monsters/snake/snake_get_hit_left.fbx",
				getHitRight = "assets/animations/monsters/snake/snake_get_hit_right.fbx",
				fall = "assets/animations/monsters/snake/snake_get_hit_front_left.fbx",
			},
			currentLevelOnly = true,
		},
		{
			class = "Monster",
			meshName = "snake_mesh",
			hitSound = "snake_hit",
			dieSound = "snake_die",
			hitEffect = "hit_goo",
			capsuleHeight = 0.2,
			capsuleRadius = 0.7,
			health = 300,
			evasion = 10,
			exp = 200,
			lootDrop = { 50, "snake_tail" },
			traits = { "animal" },
			headRotation = vec(90, 0, 0),
		},
		{
			class = "UggardianBrain",
			name = "brain",
			sight = 10,
			allAroundSight = true,
			morale = 100,
		},
		{
			class = "MonsterMove",
			name = "move",
			sound = "snake_walk",
			cooldown = 3,
		},
		{
			class = "MonsterMove",
			name = "moveForwardAndTurnRight",
			animations = { forward="moveForwardTurnRight" },
			sound = "snake_walk",
			turnDir = 1,
			cooldown = 2,
			resetBasicAttack = true,
		},
		{
			class = "MonsterMove",
			name = "moveForwardAndTurnLeft",
			animations = { forward="moveForwardTurnLeft" },
			sound = "snake_walk",
			turnDir = -1,
			cooldown = 2,
			resetBasicAttack = true,
		},
		{
			class = "MonsterTurn",
			name = "turn",
			sound = "snake_walk",
			resetBasicAttack = true,
		},
		{
			class = "MonsterAttack",
			name = "basicAttack",
			attackFromBehindAnimation = "attackFromBehind",
			attackPower = 26,
			accuracy = 20,
			cooldown = 4,
			sound = "snake_attack",
			woundChance = 30,
			causeCondition = "poison",
			conditionChance = 20,
		},
    		{
			class = "MonsterAttack",
			name = "rangedAttack",
			animation = "attack",
			attackType = "projectile",
			shootProjectile = "trap_bomb_fire",
			attackPower = 5,
			cooldown = 5,
			sound = "snake_attack",
		},
		{
			class = "UggardianFlames",
			particleSystem = "air_elemental_vieuxchat",
			emitFromMaterial = "*",
		},
	},
	tags = { "custom_vieuxchat" }
}
Thanks in advance :)

Re: Monster throwing items

Posted: Sun Jun 05, 2016 6:43 pm
by Isaac
Does this work for you?

Code: Select all

defineObject{
   name = "trap_bomb_fire",
   baseObject = "base_item",
   components = {
      {
         class = "Model",
         model = "assets/models/items/essence_fire.fbx",
      },
      {
         class = "Item",
         uiName = "Trap Bomb",
         gfxIndex = 346,
         impactSound = "impact_blunt",
         stackable = false,
         sharpProjectile = false,
         projectileRotationY = 90,
         weight = 0.1,
      },
      {
         class = "Particle",
         particleSystem = "essence_fire",
      },
	{
		class = "ThrowAttack",
		cooldown = 4,
	},
      {
         class = "BombItem",
         bombType = "fire",
         bombPower = 4,
         onExplode = function(self,level,x,y,facing,elevation) spawn("trap_rune_dispelable_fire",level,x,y,facing,elevation) end, 
      },
   },
   tags = { "weapon", "weapon_throwing", "custom_vieuxchat" },
}

Re: Monster throwing items

Posted: Sun Jun 05, 2016 8:04 pm
by minmay
I strongly advise against using convertToItemOnImpact. It really doesn't work properly - items ending up on the wrong side of obstacles, etc.
BombItemComponent or ProjectileImpactComponent can do the job better.

Re: Monster throwing items

Posted: Sun Jun 05, 2016 8:12 pm
by vieuxchat
You're right. I'll fiddle with a bombitem component.
Thanks to you two.

Re: Monster throwing items

Posted: Sun Jun 05, 2016 8:39 pm
by vieuxchat
What's the use of "bombtype" if I create a custom onExplode function ?
EDIT: and ItemComponent.onThrowAttackHitMonster(self, monster) can it be used to check if the "monster" hit is the party ? (It would be better if there were an "onThrowAttackHitParty" hook)

Re: Monster throwing items

Posted: Sun Jun 05, 2016 8:55 pm
by Isaac
AFAIK, it has to have a valid bombType to avoid printing an error... If your bomb does fire damage, might as well use bombType fire.

Though you can use the others instead. [frost, shock, poison, fire]

It's a shame that omitting the bombType prints a console error for type nil. Offhand, I don't know if one can create custom bombTypes... Their names are probably hard coded.

Re: Monster throwing items

Posted: Sun Jun 05, 2016 10:04 pm
by kelly1111
trap_rune_dispelable_fire must be: fire_trap_rune

that made it work for me

Re: Monster throwing items

Posted: Mon Jun 06, 2016 7:11 am
by vieuxchat
But I created new traps based on the fire_trap_rune.
My trap_rune_dispelable_fire is also a spell with a different model. If fire_trap_rune work, my trap_rune_dispelable_fire should also work...

Re: Monster throwing items

Posted: Mon Jun 06, 2016 8:17 am
by Isaac
Aha... So you meant that the rune doesn't explode ~at first? [Why bombType= "fire" was a problem]

(Strange... I don't remember ever encountering the fire_trap_rune in the game; I didn't know it existed before tonight.)

Re: Monster throwing items

Posted: Mon Jun 06, 2016 8:22 am
by minmay
Just return false from the onExplode hook and no explosion will be created. (The item will still be destroyed.)