Page 1 of 1

spawn - destroy item on a pressure plate

Posted: Tue Jul 30, 2013 12:58 pm
by bongobeat
Hello, here I am with other questions :shock:

First:
how can I destroy a pressure_plate with a item placed on it, then spawn (on the same place) a new item and the same pressure plate?

I got the code, for alcove or altar. But it makes me an error if I change the decoration type by a pressure plate

It has to simulate a forge, when placing some raw material, it transforms it into another material, with a fire emitter for simulating flame.
The flames of the fire emitter are not really high, and the altar is more tall than the flames. It works fine, but it's not very realistic.
So that's the point to have something lower like a pressure plate.
SpoilerShow

Code: Select all

function checkAlcoveForItems()
   -- Offer
   local itemName = "raw_adamantite"
   -- offer alcove
   local altarID = afor02
   -- checks if the offer alcove has an item
   if altarID:getItemCount() == 0 then
      hudPrint("You have to put a small piece of material in the altar!")
   end
 
   -- checks if the offer is equal to the item you want
   for i in altarID:containedItems() do
      if i.name == itemName then
           hudPrint("The raw material is now enriched!")
removeItem()
spawn("fireburst", 20, 5, 15, 2)
spawn("deep_temple_altar", 20, 5, 15, 2, "afor02")
			playSound("Volcano")
			afor02:addItem(spawn("adamantite_enriched"))
			else
           hudPrint("Place a small piece of raw material in the altar.")
      end
   end
end

function removeItem()
  if findEntity("afor02") ~= nil then
     for i in afor02:containedItems() do
         i:destroy()
     end
     afor02:destroy()
  end
end
Second:
is it possible to modify the script, and avoid a editor error if I put 2 or more required items on the altar?

if I use the actual script, and place 2 same items (like raw_adamantite) on the altar, the editor stop pre visualizing and I got an error "bad_object"
well I can put a text, "do not place 2 items at the same time", but if the player didn't follow this rules, He may certainly have a game crash.

Re: spawn - destroy item on a plate

Posted: Tue Jul 30, 2013 9:27 pm
by Ryeath_Greystalk
As for the issue of more than one item just add a check for more than one item,

if altarID:getItemCount() == 0 then
hudPrint("You have to put a small piece of material in the altar!")
elseif altarID:getItemCount() > 1 then
hudPrint("The forge is over loaded, please use one item only!")
else
-- provide flag that it is okay to proceed with transformation
end

As for destroying the plate, I believe the plate replaces the floor model and you will need to replace it with something or you end up with a black space. (Think I saw that in another post somewhere).

--edit
One other thing just came to mind. In the one room dungeon (pt 2) one of the submissions used destroy on pressure plate and it was crashing the game. Diarmuid figured out that the plate was being destroyed by the same script it was using and that caused a crash. The only reason I bring it up is if you are thinking about using a plate because it can trigger the script, it may not work. You might just use the plate as a decoration and trigger the script with a wall lever or button.

Re: spawn - destroy item on a plate

Posted: Wed Jul 31, 2013 10:40 pm
by bongobeat
Ryeath_Greystalk wrote:As for the issue of more than one item just add a check for more than one item,

if altarID:getItemCount() == 0 then
hudPrint("You have to put a small piece of material in the altar!")
elseif altarID:getItemCount() > 1 then
hudPrint("The forge is over loaded, please use one item only!")
else
-- provide flag that it is okay to proceed with transformation
end

As for destroying the plate, I believe the plate replaces the floor model and you will need to replace it with something or you end up with a black space. (Think I saw that in another post somewhere).

--edit
One other thing just came to mind. In the one room dungeon (pt 2) one of the submissions used destroy on pressure plate and it was crashing the game. Diarmuid figured out that the plate was being destroyed by the same script it was using and that caused a crash. The only reason I bring it up is if you are thinking about using a plate because it can trigger the script, it may not work. You might just use the plate as a decoration and trigger the script with a wall lever or button.
good evening
thanks for the answer

works with the check:

what do you mean like " -- provide flag that it is okay to proceed with transformation"

call a function who lauches the rest of the process?
I have try to add a function
but if put only one item i ve got a error message:
"attempt to index global 'altarID' (a nil value) x

well, I'm playing the sorcerer's apprentice :)
SpoilerShow

Code: Select all

function checkAlcoveForItems()
   -- Offer
   local itemName = "raw_adamantite"
   -- offer alcove
   local altarID = afor02
   -- checks if the offer alcove has an item
   if altarID:getItemCount() == 0 then
      hudPrint("You have to put a small piece of material in the altar!")
elseif altarID:getItemCount() > 1 then
hudPrint("The forge is over loaded, please use one item only!")
else
-- provide flag that it is okay to proceed with transformation
forge()
end

end

function forge() 
   -- checks if the offer is equal to the item you want
   for i in altarID:containedItems() do
      if i.name == itemName then
           hudPrint("The raw material is now enriched!")
removeItem()
spawn("fireburst", 20, 5, 15, 2)
spawn("deep_temple_altar", 20, 5, 15, 2, "afor02")
			playSound("Volcano")
			afor02:addItem(spawn("adamantite_enriched"))
			else
           hudPrint("Place a small piece of raw material in the altar.")
      end
   end
end


function removeItem()
  if findEntity("afor02") ~= nil then
     for i in afor02:containedItems() do
         i:destroy()
     end
     afor02:destroy()
  end
end

Re: spawn - destroy item on a plate

Posted: Thu Aug 01, 2013 12:58 am
by Ryeath_Greystalk
I think I see what is happening.

In the first post your script has two functions, checkAlcovesFor Items() and removeItems, and it worked ok except for when multiple items are used it crashes.

In the second post you added a function forge(). You initialized the local variable altarID in the checkAlcovesForItems() function, and then tried to use it in the forge() function, which Lua will not allow. The local variable altarID is only good for the function in which it is created.

What I meant by adding a flag is just putting in someway to let the script know there was only one item in the forge. The checks for 0 and >1 only informed the player that something was not right, but did not tell the next part of the script. It would still try to process every item in the forge.

So try something like this,

function checkAlcoveForItems()
local quantity = false
-- Offer
local itemName = "raw_adamantite"
-- offer alcove
local altarID = afor02
-- checks if the offer alcove has an item
if altarID:getItemCount() == 0 then
hudPrint("You have to put a small piece of material in the altar!")
quantity = false
elseif altarID:getItemCount() > 1 then
hudPrint("The forge is over loaded, please use one item only!")
quantity = false
else
-- provide flag that it is okay to proceed with transformation
quantity = true
end

-- checks if the offer is equal to the item you want
if quantity == true then
for i in altarID:containedItems() do
if i.name == itemName then
hudPrint("The raw material is now enriched!")
removeItem()
spawn("fireburst", 20, 5, 15, 2)
spawn("deep_temple_altar", 20, 5, 15, 2, "afor02")
playSound("Volcano")
afor02:addItem(spawn("adamantite_enriched"))
else
hudPrint("Place a small piece of raw material in the altar.")
end
end
end


function removeItem()
if findEntity("afor02") ~= nil then
for i in afor02:containedItems() do
i:destroy()
end
afor02:destroy()
end


give that a shot. All I did was remove the forge() function and make it part of the checkAlcoveForItems() function like in the original post, then added the quantity variable as a check before it processes the adamantite.

I did not test the code.

Re: spawn - destroy item on a plate

Posted: Thu Aug 01, 2013 10:29 am
by bongobeat
thanks a lot!
it works, there is just two "end" missing at the end of the script

thankkkksssss :)
SpoilerShow

Code: Select all

function checkAlcoveForItems()
local quantity = false
-- Offer
local itemName = "raw_adamantite"
-- offer alcove
local altarID = afor02
-- checks if the offer alcove has an item
if altarID:getItemCount() == 0 then
hudPrint("You have to put a small piece of material in the altar!")
quantity = false
elseif altarID:getItemCount() > 1 then
hudPrint("The forge is over loaded, please use one item only!")
quantity = false
else
-- provide flag that it is okay to proceed with transformation
quantity = true
end

-- checks if the offer is equal to the item you want
if quantity == true then
for i in altarID:containedItems() do
if i.name == itemName then
hudPrint("The raw material is now enriched!")
removeItem()
spawn("fireburst", 20, 5, 15, 2)
spawn("deep_temple_altar", 20, 5, 15, 2, "afor02")
playSound("Volcano")
afor02:addItem(spawn("adamantite_enriched"))
else
hudPrint("Place a small piece of raw material in the altar.")
end
end
end


function removeItem()
if findEntity("afor02") ~= nil then
for i in afor02:containedItems() do
i:destroy()
end
afor02:destroy()
end
end
end
By the way:
I tried to add a new pressure plate decoration with an altar base.
there was an issue with the floor, it "merges" not correctly.
And if I add an object it was placed like in a real altar position, tall over the pressure plate. Not really aesthetic!
Well definitely I will keep the altar like it was in the beginning.