Script - Return Weapon to Alter

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
User avatar
undeaddemon
Posts: 157
Joined: Fri Mar 02, 2012 3:38 pm

Script - Return Weapon to Alter

Post by undeaddemon »

Do anyone have some idea of how to get an item/weapon placed on the ground to return to a location?
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Script - Return Weapon to Alter

Post by Komag »

you'll probably do a destroy/spawn deal
Finished Dungeons - complete mods to play
User avatar
undeaddemon
Posts: 157
Joined: Fri Mar 02, 2012 3:38 pm

Re: Script - Return Weapon to Alter

Post 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.
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Script - Return Weapon to Alter

Post 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
Finished Dungeons - complete mods to play
User avatar
undeaddemon
Posts: 157
Joined: Fri Mar 02, 2012 3:38 pm

Re: Script - Return Weapon to Alter

Post 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
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Script - Return Weapon to Alter

Post by Neikun »

Well for that, you might want to use an onDie hook for the champion.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
undeaddemon
Posts: 157
Joined: Fri Mar 02, 2012 3:38 pm

Re: Script - Return Weapon to Alter

Post by undeaddemon »

Well.. I meant.. like from a story perspective.. not for the champions.. as they dont drop items when they die... right?

:)
User avatar
Neikun
Posts: 2457
Joined: Thu Sep 13, 2012 1:06 pm
Location: New Brunswick, Canada
Contact:

Re: Script - Return Weapon to Alter

Post by Neikun »

Nope. Champions retain all inventory even in death by default.
"I'm okay with being referred to as a goddess."
Community Model Request Thread
See what I'm working on right now: Neikun's Workshop
Lead Coordinator for Legends of the Northern Realms Project
  • Message me to join in!
User avatar
Komag
Posts: 3659
Joined: Sat Jul 28, 2012 4:55 pm
Location: Boston, USA

Re: Script - Return Weapon to Alter

Post 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
Finished Dungeons - complete mods to play
User avatar
undeaddemon
Posts: 157
Joined: Fri Mar 02, 2012 3:38 pm

Re: Script - Return Weapon to Alter

Post 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
Post Reply