Magical Melee weapon code

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!
Post Reply
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Magical Melee weapon code

Post by LordGarth »

Here is code for magical melee weapons. It will do physical and magic damage both.
Fireburst can be change to what ever spell.

GfxIndex and Gfx Atlas will have to be changed to your own.

Party will not be awareded exp though if monster is killed by the spell effect on the melee weapon.



defineObject{
name = "fflail",
baseObject = "base_item",
components = {
{
class = "Model",
model = "assets/models/items/flail.fbx",
},
{
class = "Item",
uiName = "Fire Knight Flail",
gfxIndex = 34,
gfxAtlas = "mod_assets/textures/ikons2.tga",
gfxIndexPowerAttack = 423,
impactSound = "impact_blunt",
weight = 6.5,
traits = { "heavy_weapon", "mace" },
},
{
class = "MeleeAttack",
attackPower = 52,
pierce = 10,
accuracy = 10,
cooldown = 5,
swipe = "vertical",
attackSound = "swipe_heavy",
reachWeapon = true,
requirements = { "heavy_weapons", 2 },
powerAttackTemplate = "stun",
onAttack = function(self)

local obj = spawn("fireburst")

end,
},
},
tags = { "weapon" },
}
Dungeon Master and DOOM will live forever.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Magical Melee weapon code

Post by Isaac »

An alternative onAttack() that grants XP for monsters killed by the spell; that also checks for walls, and for closed doors.
Casting against walls and closed doors now targets the party's cell (as per the game's default). The wall check also prevents casting the spell outside of the map.

Code: Select all

onAttack = function(self, champion, slot, chainIndex)
	local dX,dY = getForward(party.facing) --Directional offsets
	local tile = {party.x+dX, party.y+dY, party.elevation}
	local doorCheck = true 
	local doorFound = false
	if party.map:isWall(unpack(tile)) then
		dX,dY = 0,0 --Targets Party's cell if cast on a wall
		doorCheck = false	
	end
	if doorCheck then
		for obj in party.map:entitiesAt(unpack(tile)) do
			if obj.door and obj.facing == (party.facing+2)%4 and obj.door:isClosed() then
				dX,dY = 0,0 --Targets Party's cell if cast on a wall
				doorFound = true
				break
			end 
		end
		if not doorFound then
			tile[1], tile[2] = party.x, party.y
			for obj in party.map:entitiesAt(unpack(tile)) do
				if obj.door and obj.facing == party.facing and obj.door:isClosed() then
					dX,dY = 0,0 --Targets Party's cell if cast on a wall
					break
				end 
			end
		end
	end
	spawn("fireburst", party.level, party.x+dX, party.y+dY, party.facing, party.elevation).tiledamager:setCastByChampion(champion:getOrdinal())
end,
User avatar
LordGarth
Posts: 500
Joined: Mon Jun 18, 2012 5:07 pm
Location: Colorado USA

Re: Magical Melee weapon code

Post by LordGarth »

will try that code

thankyou
Dungeon Master and DOOM will live forever.
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Magical Melee weapon code

Post by Isaac »

After playtesting a bit, I thought I should include a version that doesn't target the party when striking doors and walls... The fireburst effect is not a secondary [deliberate] attack like the spell, or as with the fire_blade. This version simply omits the fireburst effect from the attack if the player strikes at a door, or a wall.

Code: Select all

onAttack = function(self, champion)
	local dX,dY = getForward(party.facing) --Directional offsets
	local tile = {party.x+dX, party.y+dY, party.elevation}
	local doorCheck = true 
	local doorFound = false
	if party.map:isWall(unpack(tile)) then
		return	
	end
		for obj in party.map:entitiesAt(unpack(tile)) do
			if obj.door and obj.facing == (party.facing+2)%4 and obj.door:isClosed() then
				return
			end 
		end
		if not doorFound then
			tile[1], tile[2] = party.x, party.y
			for obj in party.map:entitiesAt(unpack(tile)) do
				if obj.door and obj.facing == party.facing and obj.door:isClosed() then
					return
				end 
			end
		end
	spawn("fireburst", party.level, party.x+dX, party.y+dY, party.facing, party.elevation).tiledamager:setCastByChampion(champion:getOrdinal())
end,
Post Reply