Page 1 of 3

Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 12:17 am
by undeaddemon
Do anyone have some idea of how to get an item/weapon placed on the ground to return to a location?

Re: Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 2:24 am
by Komag
you'll probably do a destroy/spawn deal

Re: Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 2:43 am
by undeaddemon
Thanks.. any chance you have some example of that type of script? I am not great at the scripting, and I have no idea how to cause a destroy on setting an item on the ground.

Re: Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 2:57 pm
by Komag
do you mean on setting it anywhere, or a certain spot? If it's a certain spot, that will be much easier, because you can use a hidden plate with a script. If it needs to be anywhere you drop it, that's a little harder but doable, maybe through a constant tick-timer searching for item in inventory or in dungeon level, etc.

either way, you would call the item and have it destroy(), like by id:

Code: Select all

hammer_1:destroy()
or by entity:

Code: Select all

if findEntity(hammer) then findEntity(hammer):destroy()
or maybe:

Code: Select all

local thething = findEntity(hammer)
if thething then
   thething:destroy()
end

Re: Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 3:13 pm
by undeaddemon
That is what I am looking for... set the the item down anywhere, and it returns to an alter. The logic being anyone who wields the weapon, should they die, it would return to the place.

Thanks

Re: Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 3:43 pm
by Neikun
Well for that, you might want to use an onDie hook for the champion.

Re: Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 3:54 pm
by undeaddemon
Well.. I meant.. like from a story perspective.. not for the champions.. as they dont drop items when they die... right?

:)

Re: Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 4:01 pm
by Neikun
Nope. Champions retain all inventory even in death by default.

Re: Script - Return Weapon to Alter

Posted: Sat Dec 01, 2012 5:27 pm
by Komag
then you can have a constantly running timer with a short duration like 0.5s, always triggering a script that checks all the slots of all the champions and also checks the mouse, looking for the item. if it's not found in any of those places, it must have been dropped within the past 0.5s, then do the destroy/spawn

Re: Script - Return Weapon to Alter

Posted: Fri Dec 28, 2012 4:39 pm
by undeaddemon
Hi, I need [please please please] some help here - as when I exported my dungeon to playtest some stuff, I got a crash from a script I use.
Can someone look at this to see if it is explainable?
Script:RemoveBladeDrop_1

Code: Select all

function itemCheck(item)
   for champ = 1,4 do
   for slot = 7,8 do
      x = party:getChampion(champ):getItem(slot)
      if x ~= nil then
      if x.name == item then
         party:getChampion(champ):removeItem(slot)
         returnItem(item,champ)
      end
      end   
   end   
   end   
end

function returnItem(item,champ)
            altar_1:addItem(spawn("BladeOfLightning"))
            hudPrint("The Blade of Lightning yanks from your hand,")
            hudPrint("and flies through the air, out of sight!")
            playSound("lightning_bolt_hit")
end

function checkBlade()
   itemCheck("BladeOfLightning")
end
ErrorLog:

Code: Select all

scriptRemoveBladeDrop_1: cannot serialize table 'x' with metatable
stack traceback:
	[C]: in function 'error'
	[string "ScriptEntity.lua"]: in function 'saveValue'
	[string "ScriptEntity.lua"]: in function 'saveState'
	[string "GameMode.lua"]: in function 'saveGame'
	[string "GameMode.lua"]: in function 'autoSave'
	[string "Crystal.lua"]: in function 'onClick'
	[string "GameMode.lua"]: in function 'mousePressed'
	[string "GameMode.lua"]: in function 'update'
	[string "Grimrock.lua"]: in function 'display'
	[string "Grimrock.lua"]: in main chunk

OS Version 6.2

OEM ID: 0
Number of processors: 8
Page size: 4096
Processor type: 586

Total memory: 16349 MB
Free memory: 8289 MB

Display device 0:
  Device name: \\.\DISPLAY1
  Device string: NVIDIA GeForce GTX 670
  State flags: 08000005

Display device 1:
  Device name: \\.\DISPLAY2
  Device string: NVIDIA GeForce GTX 670
  State flags: 00000001

Display device 2:
  Device name: \\.\DISPLAY3
  Device string: NVIDIA GeForce GTX 670
  State flags: 00000000

Display device 3:
  Device name: \\.\DISPLAY4
  Device string: NVIDIA GeForce GTX 670
  State flags: 00000000

And to add a little more detail - the script was called via hidden plate - just before I clicked on the crystal, which explains the log portion where you see savegame and autosave.


Thanks!
UD