Page 1 of 2

onPickItem with sound help

Posted: Mon Sep 16, 2013 4:27 am
by Eleven Warrior
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....

Re: onPickItem with sound help

Posted: Mon Sep 16, 2013 10:10 am
by JohnWordsworth
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;

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",
}
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.

Code: Select all

cloneObject{
  name="party",
  baseObject="party",
  onPickUpItem = function(champion, item)
    if ( item.name == "book_undead_v2" ) then
      playSound("level_up")
    end,
  end
}
Enjoy!

Re: onPickItem with sound help

Posted: Mon Sep 16, 2013 7:00 pm
by Eleven Warrior
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..

Re: onPickItem with sound help PART 2 LOL

Posted: Tue Sep 17, 2013 4:50 am
by Eleven Warrior
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 :mrgreen:

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

Posted: Tue Sep 17, 2013 2:46 pm
by Komag
just add an "or" in there - if item name blah blah of if item name blue blue then blow blow.

Re: onPickItem with sound help

Posted: Tue Sep 17, 2013 3:15 pm
by Dr.Disaster
aye, make it a one-liner, like

if ((item.name == "book_undead_v2") or (item.name == "the_king")) then ---

Re: onPickItem with sound help

Posted: Tue Sep 17, 2013 5:55 pm
by Eleven Warrior
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.. :mrgreen:

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

Re: onPickItem with sound help

Posted: Tue Sep 17, 2013 11:36 pm
by Eleven Warrior
Eleven 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.. :mrgreen:

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
It works thxs

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
}

Re: onPickItem with sound help

Posted: Tue Sep 17, 2013 11:39 pm
by Dr.Disaster
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

Re: onPickItem with sound help

Posted: Tue Sep 17, 2013 11:44 pm
by Eleven Warrior
Hi again not sure what you mean

i'd add a modified onPickUpItem function to the cloneObject call.