Few questions - All solved

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
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Few questions - All solved

Post by Drakkan »

I am going credit in my dungeon anybody who will answer some of these :)

1. I´d like to clone object forest_oak_cluster just with some offset (it will be placed outside the map -it should be done with offset parameter)
SOLVED by Doridion

Code: Select all

    defineObject{
       name = "Oak_test",
       base_object = "forest_oak_cluster",
       components = {
          {
             class = "Model",
             model = "assets/models/env/forest_oak_cluster.fbx",
             -- Give the offset that you want :D
             offset = vec(0,0,0,0),
          },
       },
       placement = "floor",
       editorIcon = 168,
    }
2. I´d like to have script which will prevent party (some hud message will appear) to take out torch from torch_holder. on log1 it was something like

SOLVED by Prozail
orRemove hook conneted to script with

Code: Select all

function stopRemove(sender)
   sender.go.socket:addItem(spawn("torch").item)
   setMouseItem(nil)
end
3. Somebody figured out how to place water surface in different height than just -1 ? Id like to have surface of the water in different height.
SOLVED by Doridion

Code: Select all

defineObject{
   name = "user_water_surface",
   base_object = "water_surface",
   components = {
      {
      class = "WaterSurface",
      fogColor = vec(0.021,0.045,0.13,0),
      fogDensity = 0.2,
      -- There you'll have to modify by -1.4 or 1.4, as you wish
      planeY = -0.4,
      reflectionColor = vec(0.693,0.81,0.9,0),
      refractionColor = vec(1,1,1,0),
      },
      {
      class = "WaterSurfaceMesh",
      material = "water_surface_calm",
      underwaterMaterial = "water_surface_underwater",
      },
   },
   placement = "floor",
   editorIcon = 264,
}
4. Please some easy script where if you dig with shovel on some place, random item from some list will be digged
SOLVED - replied by ninjanerdbgm, cromcrom
Place a floor_trigger where you want the party to dig. Make it only triggerable by digging and tick "disableSelf".
Have it point to a script that's also on top of the dig location with the following code:

Code: Select all

    items = {"dagger","rapier","leather_cap","leather_cuisse","note","letter"} -- as many items as you want.

    function digRandomStuff()
      local item = math.random(1,#items)  -- The second number is the amount of items in the list.
        item = items[item]
        local j = self.go:spawn(item)
        playSound("secret")
        hudPrint("You found a "..j.item:getUiName().."!")
        -- If you need to define component parameters for your items...
        if item == "note" then j.scrollitem:setScrollText("I am a note!") end
        if item == "letter" then j.scrollitem:setScrollText("I am a letter!") end
        -- If you want to give the party a bonus for finding the items...
        hudPrint("Gain 250 xp!")
        for i=1,4 do
            party.party:getChampion(i):gainExp(250)
        end
    end
Last edited by Drakkan on Fri Nov 21, 2014 6:21 pm, edited 7 times in total.
Breath from the unpromising waters.
Eye of the Atlantis
ninjanerdbgm
Posts: 28
Joined: Tue Nov 04, 2014 6:53 pm

Re: Few questions

Post by ninjanerdbgm »

For number 4:

Place a floor_trigger where you want the party to dig. Make it only triggerable by digging and tick "disableSelf".

Have it point to a script that's also on top of the dig location with the following code:

Code: Select all

items = {"dagger","rapier","leather_cap","leather_cuisse","note","letter"} -- as many items as you want.

function digRandomStuff()
    local item = math.random(1,6) -- The second number is the amount of items in the list.
    item = items[item]
    local j = self.go:spawn(item)
    playSound("secret")
    hudPrint("You found a "..j.item:getUiName().."!")
    -- If you need to define component parameters for your items...
    if item == "note" then j.scrollitem:setScrollText("I am a note!") end
    if item == "letter" then j.scrollitem:setScrollText("I am a letter!") end
    -- If you want to give the party a bonus for finding the items...
    hudPrint("Gain 250 xp!")
    for i=1,4 do
        party.party:getChampion(i):gainExp(250)
    end
end
I just wrote this out now and haven't tested it, but it should work. Let me know if it doesn't.
User avatar
cromcrom
Posts: 549
Joined: Tue Sep 11, 2012 7:16 am
Location: Chateauroux in a socialist s#!$*&% formerly known as "France"

Re: Few questions

Post by cromcrom »

if I may:
instead of

Code: Select all

local item = math.random(1,6) -- The second number is the amount of items in the list.
try

Code: Select all

local item = math.random(1,#items) 


#items is the number of items in your table, so you just have to add items, and not morry about that line :-)
A trip of a thousand leagues starts with a step.
ninjanerdbgm
Posts: 28
Joined: Tue Nov 04, 2014 6:53 pm

Re: Few questions

Post by ninjanerdbgm »

cromcrom wrote:if I may:
instead of

Code: Select all

local item = math.random(1,6) -- The second number is the amount of items in the list.
try

Code: Select all

local item = math.random(1,#items) 


#items is the number of items in your table, so you just have to add items, and not morry about that line :-)
Brilliant. I'm actually new to lua (tho I've had some intense practice the last few weeks), so I had no idea you could do that. Thanks!
User avatar
Prozail
Posts: 158
Joined: Mon Oct 27, 2014 3:36 pm

Re: Few questions

Post by Prozail »

no good way to stop the removal of the torch, but you can hide it pretty much with:

onRemoveItem connected to:

Code: Select all

function stopRemove(sender)
	sender.go.socket:addItem(spawn("torch").item)
	setMouseItem(nil)
end
User avatar
Doridion
Posts: 256
Joined: Tue Jun 10, 2014 9:23 pm

Re: Few questions

Post by Doridion »

Drakkan, in the WaterSurface component, you got the setPlaneY() propertie, just put it on the heigh number that you want ;)

For you Oak, you can test something like that ( i've tested it and its ok ;) )

Code: Select all

defineObject{
	name = "Oak_test",
	base_object = "forest_oak_cluster",
	components = {
		{
			class = "Model",
			model = "assets/models/env/forest_oak_cluster.fbx",
			-- Give the offset that you want :D
			offset = vec(0,0,0,0),
		},
	},
	placement = "floor",
	editorIcon = 168,
}
Ah, and for credits, give my place to better modder than me ;)
User avatar
Eleven Warrior
Posts: 745
Joined: Thu Apr 18, 2013 2:32 pm
Location: Australia

Re: Few questions

Post by Eleven Warrior »

Hi guys. These scripts are awesome thxs for cred's to you all :) I have been after the Torch script for ages.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Few questions - All solved

Post by Drakkan »

ninjanerdbgm wrote:For number 4:

I just wrote this out now and haven't tested it, but it should work. Let me know if it doesn't.
tested, working cool, thanks a lot
Prozail wrote:no good way to stop the removal of the torch, but you can hide it pretty much with:

onRemoveItem connected to:

Code: Select all

function stopRemove(sender)
	sender.go.socket:addItem(spawn("torch").item)
	setMouseItem(nil)
end
wonderful, thanks a lot, working good
Doridion wrote:Drakkan, in the WaterSurface component, you got the setPlaneY() propertie, just put it on the heigh number that you want ;)

For you Oak, you can test something like that ( i've tested it and its ok ;) )

Ah, and for credits, give my place to better modder than me ;)
its kind of interesting that model is not animated, but I am ok even with that as for now, because its just background. As for water component I am missing asset, but once released I think it will be no problem just to modify as you stated. Thanks a lot, definitely will be credited as well :)
Breath from the unpromising waters.
Eye of the Atlantis
ninjanerdbgm
Posts: 28
Joined: Tue Nov 04, 2014 6:53 pm

Re: Few questions - All solved

Post by ninjanerdbgm »

Hey Drakkan, I modified the dig random script a bit for use in my own mod. Here's the code I ended up going with:

By adding the target (c) to the function, the script no longer needs to be on top of the floor_trigger, and
multiple floor_triggers can point to the same function.

Code: Select all

items = {"baked_maggot","boiled_beetle","blooddrop_cap","falconskyre","mudwort","skull","potion_energy","potion_cure_poison","potion_cure_disease","potion_greater_energy","potion_greater_healing","potion_healing","potion_shield","potion_resurrection","bread","cheese","borra","mole_jerky","warg_meat"} 

-- Give the player a small chance to dig up more than one item, or no item at all --
itemchance = {"0","1","1","1","1","1","1","1","1","1","1","1","1","1","2","2","2","2","3"}

function digRandomStuff(c)
	local itemamt = itemchance[math.random(1,#items)]
	if itemamt == "0" then hudPrint("You found nothing...") end
	for i=1,itemamt do
		local item = math.random(1,#items)
		item = items[item]
		local j = c.go:spawn(item)
		playSound("secret")
                -- You can add the code to add text to notes/letter or whatever other component necessity here --
		hudPrint("You found "..getArticle(j.item:getUiName())..j.item:getUiName().."!")
	end
        -- You can add code to give xp here --
end

--[[

I got really sick of seeing "You got a Energy Potion!" or "You got a Cheese!", so I decided to generate the articles.
The following code finds out what item was dug up and returns the proper article, or no article at all.

--]]

function getArticle(name)
	local fletter = name:sub(1,1) -- Get the first letter of the item's UI name
	fletter = string.byte(fletter,1) -- Convert it to ASCII
	if fletter < 97 then fletter = fletter + 32 end -- Convert it to lowercase.
	if string.char(fletter) == "a" or string.char(fletter) == "e" or string.char(fletter) == "i" or string.char(fletter) == "o" or string.char(fletter) == "u" then
		return "an "
	elseif name:sub(1,3) == "Fal" or name:sub(1,3) == "Mud" or name:sub(1,3) == "Bre" or name:sub(1,3) == "Che" or name:sub(1,3) == "Bor" or name:sub(1,3) == "Mol" or name:sub(1,3) == "War" then
		return ""
	else
		return "a "
	end
end
Last edited by ninjanerdbgm on Fri Nov 14, 2014 7:34 pm, edited 1 time in total.
User avatar
Drakkan
Posts: 1318
Joined: Mon Dec 31, 2012 12:25 am

Re: Few questions - All solved

Post by Drakkan »

ninjanerdbgm wrote:Hey Drakkan, I modified the dig random script a bit for use in my own mod. Here's the code I ended up going with:

By adding the target (c) to the function, the script no longer needs to be on top of the floor_trigger, and
multiple floor_triggers can point to the same function.

Code: Select all

items = {"baked_maggot","boiled_beetle","blooddrop_cap","falconskyre","mudwort","skull","potion_energy","potion_cure_poison","potion_cure_disease","potion_greater_energy","potion_greater_healing","potion_healing","potion_shield","potion_resurrection","bread","cheese","borra","mole_jerky","warg_meat"} 

-- Give the player a small chance to dig up more than one item, or no item at all --
itemchance = {"0","1","1","1","1","1","1","1","1","1","1","1","1","1","2","2","2","2","3"}

function digRandomStuff(c)
	for i=1,itemchance[math.random(1,#items)] do
		local item = math.random(1,#items)
		item = items[item]
		local j = c.go:spawn(item)
		playSound("secret")
                -- You can add the code to add text to notes/letter or whatever other component necessity here --
		hudPrint("You found "..getArticle(j.item:getUiName())..j.item:getUiName().."!")
	end
        -- You can add code to give xp here --
end

--[[

I got really sick of seeing "You got a Energy Potion!" or "You got a Cheese!", so I decided to generate the articles.
The following code finds out what item was dug up and returns the proper article, or no article at all.

--]]

function getArticle(name)
	local fletter = name:sub(1,1) -- Get the first letter of the item's UI name
	fletter = string.byte(fletter,1) -- Convert it to ASCII
	if fletter < 97 then fletter = fletter + 32 end -- Convert it to lowercase.
	if string.char(fletter) == "a" or string.char(fletter) == "e" or string.char(fletter) == "i" or string.char(fletter) == "o" or string.char(fletter) == "u" then
		return "an "
	elseif name:sub(1,3) == "Fal" or name:sub(1,3) == "Mud" or name:sub(1,3) == "Bre" or name:sub(1,3) == "Che" or name:sub(1,3) == "Bor" or name:sub(1,3) == "Mol" or name:sub(1,3) == "War" then
		return ""
	else
		return "a "
	end
end
advanced digging, impressive. thanks a lot
Breath from the unpromising waters.
Eye of the Atlantis
Post Reply