Page 1 of 2

Scripting: Monster only gets damaged by one special weapon

Posted: Sat May 30, 2015 1:50 am
by THOM
I am trying to recreate a function, that I used in my LoG1 Mod. (discussion here.)

Aim is still to get a monster (ghost), that is immune to all attacks. Only one special weapon (vorpalblade) can deal physical damage to it.

Solution was to do this by a party-hook. Now I am trying to use this script again - but things have changed in scripting and the original thing doesn't work anymore.

What I have so far:

Code: Select all

defineObject{
   name = "party",
   baseObject = "party",
	components = {
	{
  	class = "Party",
   	onAttack = function (champion, weapon)
       		-- weapon efficiencies tests
          	-- define locals
          	local dx,dy = 0,0
          	local usedWeapon
          
          	-- manage case that attack is unarmed
          	if weapon == nil then usedWeapon = "unarmed"
          	else usedWeapon = weapon.name
          	end
          
          	-- get position modificators, to find cell in front of the party
          	if party.facing == 0 then dy = -1
          	elseif party.facing == 1 then dx = 1
          	elseif party.facing == 2 then dy = 1
          	elseif party.facing == 3 then dx = -1
          	end

          	-- check what is in front of the party      
          	local checkedCell = party.map:entitiesAt(party.x + dx, party.y + dy)
          	-- interate through all objects on cell
          	for object in checkedCell do
             		if object.class == "Monster" then -- it will do test only for monsters
             	   		if object.name == "ghost_THOM" then 
          	         		if usedWeapon == "dm_vorpalblade_THOM" then 
          	            		return true -- weapons is effective, attack will by computed
          	         		else
	 		      		playSound("blob_hit_receptor")
			      		return false -- weapon is uneffective
          	         		end
       	           		end
      	       		else
      	          	return true
			end
		end
  
   	end,
      }
   }
}
Problem seems to be, that it's no longer possible to check by object.class == "Monster" if the champion is attacking a monster. I have no idea what could identify a monster instead. If I comment this if-loop out, I get something to work: my ghost doesn't get damaged by any weapon - but it doesn't either get damaged by the vorpalblade. And it DOES get damaged by an unarmed attack... :?

Any ideas??

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sat May 30, 2015 3:35 am
by Eburt
Try "if object.monster then..."

Didn't really check the whole code, but I think that should solve the issue you identified.

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sat May 30, 2015 4:09 am
by minmay
Just give the monster "immune" for all resistances, e.g. if you don't add any new damage types it would look like this:

Code: Select all

resistances = {
	cold = "immune",
	fire = "immune",
	poison = "immune",
	shock = "immune",
	physical = "immune",
	dispel = "immune",
},
Then give your weapon an exclusive damage type, like "vorpal" or anything else not on that list. Now you have a monster that only takes damage from that weapon. (Note that it can still be killed by jumping on it or teleporting on it.)

PartyComponent.onAttack is a really bad way to do this and you shouldn't try.

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sat May 30, 2015 9:47 am
by THOM
okay, defining a damage-type is near to my original idea, how to solve the whole task. But I can't find out out how and where to define a damaga-type. As far as I see there is nothing written in the scripting reference and I cannot find something in the asset pack, too.

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sat May 30, 2015 9:48 am
by minmay
You don't define a damage type...it's just a string. Put "vorpal" or whatever in the damageType field or setDamageType() call, the same as you would any other damage type.

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sat May 30, 2015 11:19 am
by THOM
tried it. doesn't seem, that my ghost is immune to everything but the weapon with the vorpal-damage. still takes damage from everything (???). and adding an "attack failed" sound seems to be impossible, too.

why is using onAttack a bad way? I could get it to work right now. The only thing is to detect, if the attack is made by bare hands. if weapon == nil doesn't give a result. I proofed my mechanic with print(usedWeapon) and I always get the right weapon-name. If I do an unarmed attack I get -- nothing. attacking with bare hands doesn't seem to be an attack with weapon == nil.

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sat May 30, 2015 1:34 pm
by Isaac
THOM wrote:Aim is still to get a monster (ghost), that is immune to all attacks. Only one special weapon (vorpalblade) can deal physical damage to it.
...
Any ideas??

Code: Select all

			onDamage = function(self, damage, damageType)
						 local result = (damageType == "vorpal")
						 if not result then
							playSound("goromorg_shield_hit")
						 end
						 return result
						end,

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sat May 30, 2015 5:58 pm
by minmay
THOM wrote:tried it. doesn't seem, that my ghost is immune to everything but the weapon with the vorpal-damage. still takes damage from everything (???).
Then you put the resistances in wrong. They belong in the MonsterComponent definition. There are plentiful examples in the asset pack. If you want actual help with this, you're going to have to post your monster definition at this point because it is obviously wrong.

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sun May 31, 2015 1:16 am
by THOM
My definitions are looking like that:

Monster (part)

Code: Select all

			traits = { "undead" },
			headRotation = vec(0, 0, 90),
			immunities = { "sleep", "blinded", "frozen", "poison", "stunned", "knockback", "backstab" },
			resistances = {
				fire = "immune",
				cold = "immune",
				poison = "immune",
				shock = "immune",
				physical = "immune",
				dispel = "immune",
				},
	 		onProjectileHit = function(monster, self, projectile, damage, damageType) 
				playSoundAt("blob_hit_receptor", self.go.level, self.go.x, self.go.y)
				return false;
	 		end,
		},
		{
			class = "MeleeBrain",
			name = "brain",
			sight = 10,
			seeInvisible = true,
			morale = 100,
		},
	
The vorpalblade looks like that:

Code: Select all

defineObject{
		name = "dm_vorpalblade_THOM",
		baseObject = "base_item",
  		tags = { "THOM" },
		components = {
		{
			class = "Model",
			model = "mod_assets/rooms/THOM/vorpalblade/dm_vorpalblade.fbx",
		},
		{
			class = "Item",
			uiName = "Vorpal Blade",
			gfxAtlas = "mod_assets/rooms/THOM/vorpalblade/vorpalblade_icon.tga",
			gfxIndex = 1,
			impactSound = "impact_blade",
			weight = 3.0,
			description = "Strange dark sword - there is a magical aura around it",
			traits = { "light_weapon", "sword" },
		},
		{
			class = "MeleeAttack",
			damageType = "vorpal",
			attackPower = 18,
			accuracy = 15,
			cooldown = 5.4,
			swipe = "horizontal",
		},
	},
}
probably something is missing to look out for the vorpal-damagetype.

The suggestion of Isaac makes me feel silly. Don't know how to use this. If I copy this to the monster definition the result is still nothing.

I still do not know, why it is a problem to use my original approach. If I could solve the problem to get a unarmed attack = false everything would be fine. :(

Re: Scripting: Monster only gets damaged by one special weap

Posted: Sun May 31, 2015 1:46 am
by minmay
That works fine for me. The monster takes 0 damage from all fire, cold, poison, shock, and physical attacks, and doesn't get hit by dispel at all since it lacks the "elemental" trait.
THOM wrote:I still do not know, why it is a problem to use my original approach.
Because it stops the action entirely instead of making the monster take no damage. You don't want players to be able to hurt the monster with spells and spike traps, do you? And you do want players to be able to attempt attacks, don't you?