Scripting: Monster only gets damaged by one special weapon

Ask for help about creating mods and scripts for Grimrock 2 or share your tips, scripts, tools and assets with other modders here. Warning: forum contains spoilers!
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

Scripting: Monster only gets damaged by one special weapon

Post 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??
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
Eburt
Posts: 69
Joined: Thu Feb 05, 2015 5:44 am

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

Post by Eburt »

Try "if object.monster then..."

Didn't really check the whole code, but I think that should solve the issue you identified.
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

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

Post 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.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

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

Post 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.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

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

Post 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.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

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

Post 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.
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
User avatar
Isaac
Posts: 3192
Joined: Fri Mar 02, 2012 10:02 pm

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

Post 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,
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

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

Post 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.
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
User avatar
THOM
Posts: 1281
Joined: Wed Nov 20, 2013 11:35 pm
Location: Germany - Cologne
Contact:

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

Post 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. :(
THOM formaly known as tschrage
_______________________________________________
My MOD (LoG1): Castle Ringfort Thread
My MOD (LoG2): Journey To Justice Thread | Download
minmay
Posts: 2790
Joined: Mon Sep 23, 2013 2:24 am

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

Post 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?
Grimrock 1 dungeon
Grimrock 2 resources
I no longer answer scripting questions in private messages. Please ask in a forum topic or this Discord server.
Post Reply