Ask a simple question, get a simple answer

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!
alois
Posts: 112
Joined: Mon Feb 18, 2013 7:29 am

Re: Ask a simple question, get a simple answer

Post by alois »

st1nger wrote:hi everyone

is it possible to check if the party moves against a wall?
i want script the system from DM to damage the party.
or has anyone else these system already?
Try this :)

Code: Select all

defineObject{
	name = "party",
	baseObject = "party",
	components = {
		{
			class = "Party",
			onMove = function(self,direction)
				local dx,dy = getForward(direction)
				if self.go.map:isBlocked(self.go.x+dx,self.go.y+dy,self.go.elevation) then
					-- add your damage routine here
					return true -- if you want the "bumping effect"; otherwise return false
				else
					return true -- let the party move freely
				end
			end,
		},
	},
}
Alois :)
User avatar
st1nger
Posts: 19
Joined: Wed May 29, 2013 8:44 pm
Location: Germany

Re: Ask a simple question, get a simple answer

Post by st1nger »

Wonderful. Thank you :)
User avatar
Isaac
Posts: 3185
Joined: Fri Mar 02, 2012 10:02 pm

Re: Ask a simple question, get a simple answer

Post by Isaac »

Here is an alternative that allows setting it via function call; and optionally limits damage to the two closest PCs (that actually touch the wall).

example usage: hurt.script:setActive(true, 10, "fire") The last two arguments are optional.
hurt.script:setSelective(false) causes indiscriminate party damage instead of the default (selective).

Code: Select all

-- script name: hurt
wall_damage = 2
damage_type = "physical"
selective = true

function dmgWall(self, dir)
	local dX,dY = getForward(dir)
	local x,y = party.x+dX, party.y+dY
	if party.map:isWall(x,y) then
		if selective then
			local injured = {{1,2},{2,4},{3,4},{1,3}}
			local rank = 2
			for x = 1,2 do
				local move = (dir - (party.facing))%4 +1
				local champion = party.party:getChampion(injured[move][x])
				 if champion:isAlive() then
					champion:damage(wall_damage, damage_type)
				 else
					rank = rank - 1
						if rank < 1 then
						    for x = 1,4 do
								party.party:getChampion(x):damage(wall_damage, damage_type)
							end
						end
				 end
			end
		else 
			for x = 1,4 do
				local champion = party.party:getChampion(x)
				if champion:isAlive() then
					champion:damage(wall_damage, damage_type)	
				end
			end
		end	
	end
end

function setActive(self, bool, damage, dmgType)
	if type(bool) == "boolean" then

		if type(dmgType) == "string" and type(damage) == "number" then
			wall_damage = damage
			damage_type = dmgType
		end
		
		if bool then
		 party.party:addConnector("onMove", self.go.id, "dmgWall")
		 return
		end
		party.party:removeConnector("onMove", self.go.id, "dmgWall")			
	end
end

function setSelective(self,bool)
	if type(bool) == "boolean" then
			selective = bool
	end
	print(selective, bool)
end
Last edited by Isaac on Sun May 31, 2015 6:34 pm, edited 1 time in total.
User avatar
spectre900
Posts: 124
Joined: Fri Sep 14, 2012 1:47 am

Re: Ask a simple question, get a simple answer

Post by spectre900 »

Can ammo (say arrows) be able to be programmed to have a chance to break when hitting something?
User avatar
Zo Kath Ra
Posts: 937
Joined: Sat Apr 21, 2012 9:57 am
Location: Germany

Re: Ask a simple question, get a simple answer

Post by Zo Kath Ra »

spectre900 wrote:Can ammo (say arrows) be able to be programmed to have a chance to break when hitting something?
Do you want the arrow to disappear from the game, or do you want it to turn into a broken_arrow object that can be repaired later? I can only help you with the former:

Code: Select all

defineObject{
    name = "fragile_arrow",
    baseObject = "base_item",
    components = {
        {
            class = "Model",
            model = "assets/models/items/arrow.fbx",
        },
        {
            class = "Item",
            uiName = "Fragile Arrow",
            gfxIndex = 107,
            impactSound = "impact_arrow",
            stackable = true,
            sharpProjectile = false,
            projectileRotationY = 90,
            weight = 0.1,
            onThrowAttackHitMonster = function(self, monster)
                if (math.random() <= 0.5) then
                    hudPrint("The arrow breaks!")
                    self.go:destroyDelayed()
                end
            end,
        },
        {
            class = "AmmoItem",
            ammoType = "arrow",
        },
    },
}
Problems:
- the arrow only has a chance of breaking when it hits a monster (not if you miss and the arrow falls to the ground in front of the monster, or if you hit a wall)
- if you set "sharpProjectile = true", the game will crash when the arrow is destroyed

The function "onThrowAttackHitMonster" gets triggered if you *fire* the arrow at a monster and hit (despite the function's name)
Last edited by Zo Kath Ra on Fri May 29, 2015 10:06 pm, edited 2 times in total.
User avatar
spectre900
Posts: 124
Joined: Fri Sep 14, 2012 1:47 am

Re: Ask a simple question, get a simple answer

Post by spectre900 »

Zo Kath Ra wrote:
spectre900 wrote:Can ammo (say arrows) be able to be programmed to have a chance to break when hitting something?
Do you want the arrow to disappear from the game, or do you want it to turn into a broken_arrow object that can be repaired later? I can only help you with the former:

Code: Select all

defineObject{
	name = "fragile_arrow",
	baseObject = "base_item",
	components = {
		{
			class = "Model",
			model = "assets/models/items/arrow.fbx",
		},
		{
			class = "Item",
			uiName = "Fragile Arrow",
			gfxIndex = 107,
			impactSound = "impact_arrow",
			stackable = true,
			sharpProjectile = false,
			projectileRotationY = 90,
			weight = 0.1,
            onThrowAttackHitMonster = function(self, monster)
                if (math.random() <= 0.5) then
                    hudPrint("The arrow breaks!")
                    self.go:destroyDelayed()
                end
            end,
		},
		{
			class = "AmmoItem",
			ammoType = "arrow",
		},
	},
}
Problems:
- the arrow only has a chance of breaking when it hits a monster (not if you miss and the arrow falls to the ground in front of the monster, and not if you hit a wall)
- if you set "sharpProjectile = true", the game will crash when the arrow is destroyed

The function "onThrowAttackHitMonster" gets triggered if you *fire* the arrow at a monster and hit (despite the function's name)
Dude that is perfect, exactly what I needed! Many thanks. :D
User avatar
AndakRainor
Posts: 674
Joined: Thu Nov 20, 2014 5:18 pm

Re: Ask a simple question, get a simple answer

Post by AndakRainor »

Is it possible to dynamically update any visual element of a custom condition ?

I tried to change the icon or description field but it raises a "read only" error. I would like to update the description, if possible, as the game does for example for the rage condition (it shows the detail of the bonus strength in real time). It would be used to shows stats details or time remaining, or even changing the icon when the condition is about to expire.
User avatar
spectre900
Posts: 124
Joined: Fri Sep 14, 2012 1:47 am

Re: Ask a simple question, get a simple answer

Post by spectre900 »

Another question. is there any way to make a character class with a trait for "CastSpell" weapons such as the fire blade, similar to that of the Fighter class?

I tried applying the Fighter trait to a custom class but that trait doesn't apply to spell casting weapons which is what I wanted to the class to use. (sure the charge time isn't that horribly slow but less cost and faster casting would have been a good trait for the class and an actual reason to pick it.)

Also is it possible to even make custom traits for character classes?
User avatar
zimberzimber
Posts: 432
Joined: Fri Feb 08, 2013 8:06 pm

Re: Ask a simple question, get a simple answer

Post by zimberzimber »

A few questions here: (I'm not sure how simple they are or how simple will the answer be, but hey! Why not?)

1) How do I create a script that would check each character for a certain property* but so it will skip on empty character slots?
* - level, race, class, perks, etc...

2) How do I force on a party to delete all characters and replace them all with one (or more) characters so there will be 3 empty slots and 1 character inside the 1st slot?

3) How would I add a character to a party in case there is an empty slot and set their level to the parties average?

4) How to I print a message on the middle of the screen like the one when you are fighting the Lyndworm, and is it possible to give it a different fade-in effect and/or change its color and/or font?

5) If possible, how do you change the hudPrint text color and/or font?
My asset pack [v1.10]
Features a bit of everything! :D
User avatar
Duncan1246
Posts: 404
Joined: Mon Jan 19, 2015 7:42 pm

Re: Ask a simple question, get a simple answer

Post by Duncan1246 »

zimberzimber wrote:
2&3: How do I force on a party to delete all characters and replace them all with one (or more) characters so there will be 3 empty slots and 1 character inside the 1st slot?
How would I add a character to a party in case there is an empty slot and set their level to the parties average?
See this thread:

viewtopic.php?f=22&t=8464&hilit=replace ... =10#p86822)
4) How to I print a message on the middle of the screen like the one when you are fighting the Lyndworm, and is it possible to give it a different fade-in effect and/or change its color and/or font?
See this thread: viewtopic.php?f=22&t=9128&hilit=grim+tk&start=80#p92839 and the tool made by JohnWordsworth http://www.nexusmods.com/legendofgrimrock2/mods/23/?

For the others, I think some answers can be found in the threads also

Duncan
The Blue Monastery (LOG1)
download at:http://www.nexusmods.com/grimrock/mods/399/?

Finisterrae(LOG2)
download at:http://www.nexusmods.com/legendofgrimrock2/mods/61/?
Post Reply