onPickItem with sound help
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
onPickItem with sound help
Hi all.. I have notice that when you pick up EG: Golden_Orb it plays a sound, not Consume or OnUseItem, but I assume onPickUp..I have searched the Assetsv2 and cant find the function..
So I guess its built into the main code (engine) This is my object below, the player can pick it up but the Sound does not play don't know why??
defineObject{
name = "undead2",
baseObject = "scroll",
uiName = "Book Of The Undead Volume 2",
class = "Item",
model = "assets/models/items/tome.fbx",
gfxIndex = 30,
scroll = true,
weight = 0.3,
onPickUpItem = function(self, champion) ---- This what I added from the Script Reference TXT ----
playSound("level_up")
return true
end,
description = "This book has blood stains on it and radiates with Evil",
}
Any help and THXS....
So I guess its built into the main code (engine) This is my object below, the player can pick it up but the Sound does not play don't know why??
defineObject{
name = "undead2",
baseObject = "scroll",
uiName = "Book Of The Undead Volume 2",
class = "Item",
model = "assets/models/items/tome.fbx",
gfxIndex = 30,
scroll = true,
weight = 0.3,
onPickUpItem = function(self, champion) ---- This what I added from the Script Reference TXT ----
playSound("level_up")
return true
end,
description = "This book has blood stains on it and radiates with Evil",
}
Any help and THXS....
- JohnWordsworth
- Posts: 1397
- Joined: Fri Sep 14, 2012 4:19 pm
- Location: Devon, United Kingdom
- Contact:
Re: onPickItem with sound help
Unfortunately, it's a little bit more complicated than that. The 'Item' class of entities do not have an onPickupItem function, but the Party class does. What that means is that, you have to scan for every item that the player party picks up to see if it's an item of the certain type and then play the sound effect. So, a solution becomes...
Define the item itself in items.lua say;
Then, you need to add the following to your init.lua. However, you almost definitely already have a 'cloneObject{baseObject="party"...' section in your code, so you would probably want to add this function to your existing cloneObject code instead, just to keep it all in one place. Anyway, here is the code/function - I'll leave you to decide where you want to put it.
Enjoy!
Define the item itself in items.lua say;
Code: Select all
defineObject{
name = "book_undead_v2",
baseObject = "scroll",
uiName = "Book Of The Undead Volume 2",
class = "Item",
model = "assets/models/items/tome.fbx",
gfxIndex = 30,
scroll = true,
weight = 0.3,
description = "This book has blood stains on it and radiates with Evil",
}
Code: Select all
cloneObject{
name="party",
baseObject="party",
onPickUpItem = function(champion, item)
if ( item.name == "book_undead_v2" ) then
playSound("level_up")
end,
end
}
My Grimrock Projects Page with links to the Grimrock Model Toolkit, GrimFBX, Atlas Toolkit, QuickBar, NoteBook and the Oriental Weapons Pack.
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: onPickItem with sound help
Hi John.. Thank You for the help, i will give it a try after Work..
Ps: I like your Tool Kit Program.. Ineed more practice with it and how did you go the Scripting for the Pages in Spell Book?? I was posted by someone a week or two ago..
Ps: I like your Tool Kit Program.. Ineed more practice with it and how did you go the Scripting for the Pages in Spell Book?? I was posted by someone a week or two ago..
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: onPickItem with sound help PART 2 LOL
Hi John this is how I see it thx for help.. I know this works below (init.lua).
I thought with the cloneObject thing see below.... it would also work but unfortunately it didn't (--- SEE HERE --- ).
Also if you don't mind where would I put the following lines of code in my init.lua.. I have tried and failed...
-- Quick Bar Hook---
if ( qb_script ~= nil and qb_script.onDrawGui ~= nil ) then
qb_script.onDrawGui(g);
end
--search on floor Script--
onDrawGui = function(g)
if ( search_script ~= nil and search_script.onDrawGui ~= nil ) then
search_script.onDrawGui(g);
end
end,
-- import standard assets
import "assets/scripts/standard_assets.lua"
import "mod_assets/framework/framework.lua" --Log Framework--
fw_setShowWarnings(false) -- don't show warning about script entites found from dungeon
fw_loadModule('fw_magic')
fw_loadModule('add_spells')
fw_loadModule('illusion_walls')
import "mod_assets/grimwidgets/grimwidgets.lua"
import "mod_assets/gui/initgui.lua"
cloneObject {
name = "party",
baseObject = "party",
onDrawGui = function(g)
return gui.onDrawGui(g)
end,
onMove = function(self)
if (gui.globalVars["shopOn"]) then
return false
else
return true
end
end,
onPickUpItem = function(champion, item)
if ( item.name == "book_undead_v2" ) then --- Ps: how do I put multiple books here
if ( item.name == "the_king" ) then ---- Is this Correct John ----
playSound("level_up")
end
end
}
(--- SEE HERE ---) This does not work.. Did I miss something lol
defineObject{
name = "book_undead_v2",
baseObject = "scroll",
uiName = "Book Of The Undead Volume 2",
class = "Item",
model = "assets/models/items/tome.fbx",
gfxIndex = 30,
scroll = true,
weight = 0.3,
description = "This book has blood stains on it and radiates with Evil",
}
cloneObject{
name="Book Of The Undead Volume 2", -- I think this wrong
baseObject="book_undead_v2", -- and this wrong
onPickUpItem = function(champion, item)
if ( item.name == "book_undead_v2" ) then
playSound("level_up")
end
end
}
I thought with the cloneObject thing see below.... it would also work but unfortunately it didn't (--- SEE HERE --- ).
Also if you don't mind where would I put the following lines of code in my init.lua.. I have tried and failed...
-- Quick Bar Hook---
if ( qb_script ~= nil and qb_script.onDrawGui ~= nil ) then
qb_script.onDrawGui(g);
end
--search on floor Script--
onDrawGui = function(g)
if ( search_script ~= nil and search_script.onDrawGui ~= nil ) then
search_script.onDrawGui(g);
end
end,
-- import standard assets
import "assets/scripts/standard_assets.lua"
import "mod_assets/framework/framework.lua" --Log Framework--
fw_setShowWarnings(false) -- don't show warning about script entites found from dungeon
fw_loadModule('fw_magic')
fw_loadModule('add_spells')
fw_loadModule('illusion_walls')
import "mod_assets/grimwidgets/grimwidgets.lua"
import "mod_assets/gui/initgui.lua"
cloneObject {
name = "party",
baseObject = "party",
onDrawGui = function(g)
return gui.onDrawGui(g)
end,
onMove = function(self)
if (gui.globalVars["shopOn"]) then
return false
else
return true
end
end,
onPickUpItem = function(champion, item)
if ( item.name == "book_undead_v2" ) then --- Ps: how do I put multiple books here
if ( item.name == "the_king" ) then ---- Is this Correct John ----
playSound("level_up")
end
end
}
(--- SEE HERE ---) This does not work.. Did I miss something lol
defineObject{
name = "book_undead_v2",
baseObject = "scroll",
uiName = "Book Of The Undead Volume 2",
class = "Item",
model = "assets/models/items/tome.fbx",
gfxIndex = 30,
scroll = true,
weight = 0.3,
description = "This book has blood stains on it and radiates with Evil",
}
cloneObject{
name="Book Of The Undead Volume 2", -- I think this wrong
baseObject="book_undead_v2", -- and this wrong
onPickUpItem = function(champion, item)
if ( item.name == "book_undead_v2" ) then
playSound("level_up")
end
end
}
Re: onPickItem with sound help
just add an "or" in there - if item name blah blah of if item name blue blue then blow blow.
Finished Dungeons - complete mods to play
- Dr.Disaster
- Posts: 2876
- Joined: Wed Aug 15, 2012 11:48 am
Re: onPickItem with sound help
aye, make it a one-liner, like
if ((item.name == "book_undead_v2") or (item.name == "the_king")) then ---
if ((item.name == "book_undead_v2") or (item.name == "the_king")) then ---
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: onPickItem with sound help
Thank you, thank you, thank you Doc...
Yours makes alot of sense to me.. Thank you Komag but to be honest if it was typed out like the way Doc did, i would
understand it better eg: Athe end is )) i would not have guessed that in a million years true story..
Thaxs again for your help much appreciated..
PS: Is it the same for my init.lua file?? or is that more complex, something about 1 ondraw, 1 onmove functions, not sure... I have asked John wordsworth to help me woth the init file problem, is there someone out there who can help me thxs again..Dont mean to be a pain, but all your help is not wasted..My Mod is big and its taking time as its just me making it with all your's help
Eleven warrior
Yours makes alot of sense to me.. Thank you Komag but to be honest if it was typed out like the way Doc did, i would
understand it better eg: Athe end is )) i would not have guessed that in a million years true story..
Thaxs again for your help much appreciated..
PS: Is it the same for my init.lua file?? or is that more complex, something about 1 ondraw, 1 onmove functions, not sure... I have asked John wordsworth to help me woth the init file problem, is there someone out there who can help me thxs again..Dont mean to be a pain, but all your help is not wasted..My Mod is big and its taking time as its just me making it with all your's help
Eleven warrior
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: onPickItem with sound help
It works thxsEleven Warrior wrote:Thank you, thank you, thank you Doc...
Yours makes alot of sense to me.. Thank you Komag but to be honest if it was typed out like the way Doc did, i would
understand it better eg: Athe end is )) i would not have guessed that in a million years true story..
Thaxs again for your help much appreciated..![]()
PS: Is it the same for my init.lua file?? or is that more complex, something about 1 ondraw, 1 onmove functions, not sure... I have asked John wordsworth to help me woth the init file problem, is there someone out there who can help me thxs again..Dont mean to be a pain, but all your help is not wasted..My Mod is big and its taking time as its just me making it with all your's help
Eleven warrior
How do I make a list eg: Say I wanted the (the_king) to play a diferent sound from the (book_undead_V2)
Sorry for asking thxs again
onPickUpItem = function(champion, item)
if ( item.name == "book_undead_v2" ) or (item.name == "the_king") then
playSound("mine_horror10")
party:shakeCamera(1.5,2)
end
end
}
- Dr.Disaster
- Posts: 2876
- Joined: Wed Aug 15, 2012 11:48 am
Re: onPickItem with sound help
You can add a modified onPickUpItem function to the cloneObject call.
Now if you want to finish all possible item names inside the defineObject you can used some kind of chained "if () then .. elseif ()" or maybe "case "item.name" in .. " statements; depends on what LUA offers here.
It would look like this but as said no idea if/what LUA has here; i usually do shell script
if ( condition ) then
action
else if ( condition2 ) then
action2
else
action3
endif
case "item.name" in
'book_undead_v1')
playSound("undead1")
;;
'book_undead_v2')
playSound("undead2")
;;
*)
-- anything else
playsound('horror1")
;;
esac
Now if you want to finish all possible item names inside the defineObject you can used some kind of chained "if () then .. elseif ()" or maybe "case "item.name" in .. " statements; depends on what LUA offers here.
It would look like this but as said no idea if/what LUA has here; i usually do shell script
if ( condition ) then
action
else if ( condition2 ) then
action2
else
action3
endif
case "item.name" in
'book_undead_v1')
playSound("undead1")
;;
'book_undead_v2')
playSound("undead2")
;;
*)
-- anything else
playsound('horror1")
;;
esac
Last edited by Dr.Disaster on Tue Sep 17, 2013 11:52 pm, edited 1 time in total.
- Eleven Warrior
- Posts: 752
- Joined: Thu Apr 18, 2013 2:32 pm
- Location: Australia
Re: onPickItem with sound help
Hi again not sure what you mean
i'd add a modified onPickUpItem function to the cloneObject call.
i'd add a modified onPickUpItem function to the cloneObject call.
