Page 2 of 3

Re: I only have Daemon Eyes for you!

Posted: Mon Oct 22, 2012 11:56 am
by Huder
In my theory this could be something like: onPickuUp destroy picked item and place new (same as before) item into slot.

Re: I only have Daemon Eyes for you!

Posted: Mon Oct 22, 2012 12:25 pm
by akroma222
Ok,
so using the onPickUpItem hook, destroy the item and then replace it into the eye socket
I may well be able to improvise on some other script I have used to destroy objects and replace them somewhere..
Let me play and I will get back to you....
Thanks again ;)

Re: I only have Daemon Eyes for you!

Posted: Mon Oct 22, 2012 12:27 pm
by Grimwold
Huder wrote:In my theory this could be something like: onPickuUp destroy picked item and place new (same as before) item into slot.
If you use the OnPickupItem hook, you can use "return false" to actually prevent the item being picked up.

So if you know exactly which gem is being picked up you can 'test' it's id and return false if it is your gem.

e.g.

Code: Select all

if item.id == "blue_gem_fake" then
  return false
else
  return true
end
of course you'd need a way to 'activate' this check once the gem is inserted, otherwise the party would never be able to pick up this gem... so possibly run a one-off destroy and spawn when the gem is initially placed in the eye socket.

e.g.

Code: Select all

function switchGems()
  blue_gem_original:destroy()
  daemon_eye_socket_left:addItem(spawn("blue_gem",nil,nil,nil,nil,"blue_gem_fake"))
end
you would need to modify the code for your own gem and eye socket names

Re: I only have Daemon Eyes for you!

Posted: Tue Oct 23, 2012 6:03 am
by akroma222
Thanks guys! No joy yet but I think I am very close.... this is what I have done so far:

1.Cloned a blue gem fake into items.lua
2.Defined a new left eye socket into objects.lua, using the onPickUpItem hook (this might be where I am not correct....)
SpoilerShow

Code: Select all

defineObject{
	name = "daemon_eye_left_hold",
	class = "Alcove",
	anchorPos = vec(0.21, 1.58, -0.45),
	targetPos = vec(0.2, 1.65, -0.45),
	targetSize = vec(0.1, 0.1, 0.1),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "blue_gem" and self:getItemCount() == 0
	end,
	onPickUpItem = function(self, item)
		if item.name == "blue_gem_fake" then
			return false
		else
			return true
		end
	end,
	editorIcon = 92,
3. Connected the new left eye socket hold > script that runs this:
SpoilerShow

Code: Select all

function gemCheckBlue()
  local itemFound = nil

  for i in daemon_eye_left_hold_1:containedItems() do
    if i .name == "blue_gem" then
      itemFound = i.id
    end
  end

  if itemFound ~= nil then
    gem = findEntity(itemFound)
    gem:destroy()
    daemon_eye_left_hold_1:addItem(spawn("blue_gem_fake", nil, nil, nil, nil))
  end
end
Now, when blue gem is inserted, it is destroyed and replaced with blue gem fake (seamlessly). However, I can still pick up the blue gem fake from the eye socket.... Have I fumbled up the onPickUpItem hook??
Thank you all again for your help :)

Re: I only have Daemon Eyes for you!

Posted: Tue Oct 23, 2012 6:16 am
by akroma222
I have also tried connecting the eye socket to a script running this code:
SpoilerShow

Code: Select all

function fakeBlueGem()
        onPickUpItem = function(self, item)
		if item.name == "blue_gem_fake" then
			return false
		else
			return true
		end
	end,

But I can still take the fake blue gem out of the socket... :oops:
---sorry spacing is messy^^ but it is correct in editor

Re: I only have Daemon Eyes for you!

Posted: Tue Oct 23, 2012 7:32 am
by J. Trudel
Is it just me or do the eye sockets need to be scripted, I can't add any connectors to the deamon_head_eye_slots.

Edit : Dumb question... I forgot to add eye_socket L or R never mind, however it seems to accept only blue gem ?

Re: I only have Daemon Eyes for you!

Posted: Tue Oct 23, 2012 8:13 am
by akroma222
Hey Trudel,
yes, from the asset pack v1.. you can see in the objects file that the eyes and mouth are coded to only accept the certain colours:
SpoilerShow

Code: Select all

defineObject{
	name = "eye_socket_left",
	class = "Alcove",
	anchorPos = vec(0.21, 1.58, -0.45),
	targetPos = vec(0.2, 1.65, -0.45),
	targetSize = vec(0.1, 0.1, 0.1),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "blue_gem" and self:getItemCount() == 0
	end,
	editorIcon = 92,
}

defineObject{
	name = "eye_socket_right",
	class = "Alcove",
	anchorPos = vec(-0.21, 1.58, -0.45),
	targetPos = vec(-0.2, 1.65, -0.45),
	targetSize = vec(0.1, 0.1, 0.1),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "blue_gem" and self:getItemCount() == 0
	end,
	editorIcon = 92,
}

defineObject{
	name = "mouth_socket",
	class = "Alcove",
	anchorPos = vec(0, 1.1, -0.38),
	targetPos = vec(0, 1.1, -0.38),
	targetSize = vec(0.3, 0.3, 0.3),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "green_gem" and self:getItemCount() == 0
	end,
	editorIcon = 92,
}
I am assuming you can change this if you like by altering the gem colour and pasting a new clone or definition of the eye/mouth socketsinto your mod assets/scripts/objects file... Eg:
SpoilerShow

Code: Select all

defineObject{
	name = "mouth_socket",
	class = "Alcove",
	anchorPos = vec(0, 1.1, -0.38),
	targetPos = vec(0, 1.1, -0.38),
	targetSize = vec(0.3, 0.3, 0.3),
	placement = "wall",
	onInsertItem = function(self, item)
		return item.name == "red_gem" and self:getItemCount() == 0
	end,
	editorIcon = 92,
So that the mouth will accept red gems (I have not tried this though....)

Re: I only have Daemon Eyes for you!

Posted: Tue Oct 23, 2012 9:27 am
by Decayer
akroma222 wrote:Now, when blue gem is inserted, it is destroyed and replaced with blue gem fake (seamlessly). However, I can still pick up the blue gem fake from the eye socket.... Have I fumbled up the onPickUpItem hook??
Thank you all again for your help :)
Alcoves (including eyes) don't have a onPickUpItem hook; you'd have to put that check in Party:onPickUpItem instead.

Re: I only have Daemon Eyes for you!

Posted: Tue Oct 23, 2012 10:24 am
by Grimwold
akroma222 wrote: Now, when blue gem is inserted, it is destroyed and replaced with blue gem fake (seamlessly). However, I can still pick up the blue gem fake from the eye socket.... Have I fumbled up the onPickUpItem hook??
Thank you all again for your help :)
I do apologise for not being very thorough in my explanation.

onPickupItem is a Party hook... so you need to create a clone of the party in your lua files (usually this is done in init.lua)

Like so:

Code: Select all

cloneObject{
  name = "party",
  baseObject = "party",
  onPickUpItem  = function(party,item)
    if item.id == "blue_gem_fake" then
      return false
    else
      return true
    end
  end,
}
This means the check is done any time the party tries to pick something up!

Re: I only have Daemon Eyes for you!

Posted: Tue Oct 23, 2012 10:56 am
by akroma222
Yes indeed! Silly me...
Ok, so I have pasted the party script into init.lua but unfortunately I have the same result: turns to blue gem fake once placed into the eye socket, and is able to picked up from the socket (as well as the ground)..
I will try to investigate further, thanks again John and Decayer!