Page 1 of 1
Script Spell forge
Posted: Wed Oct 30, 2013 2:51 am
by LocalFire
So I'm trying to build a spell forge, two items on the correct alcoves, then activate a receptor to spawn a new item destroying the old ones
So heres what I'm using
Code: Select all
function ndItemNameInside(entity, itemName)
if (entity == nil or itemName == nil) then
print("need two variables")
return false
end
for i in entity:containedItems() do
if (i.name == itemName) then
return true
end
end
return false
end
Code: Select all
function ArcanePotion()
if (f.ndItemNameInside(reciever, "potion_healing") and
(f.ndItemNameInside(agent, "potion_energy")))
then
forge: addItem (spawn "potion_greater")
playSound("level_up")
end
end
So those two handle checking for the correct items and spawning the new item (just 1 example)
the problem appears to be with this script :
Code: Select all
function Check1()
for i in reciever:containedItems() do
if i.name == "potion_healing" then
i:destroy()
end
end
reciever = "none"
end
function Check2()
for i in agent:containedItems() do
if i.name == "potion_energy" then
i:destroy()
end
end
agent = "none"
end
This works but only for the first time, Attempting to spawn a second item of the same type gives the error: attempt to call method "containedItems" a nil value
adding the line
Code: Select all
if reciever == "none" then return end
to the above script seems to fix this but the items are no longer destroyed as they were before, Any help would be great.
Re: Script Help-Spell forge
Posted: Wed Oct 30, 2013 3:15 am
by DesperateGames
Hello Local Fire,
I think the error lies within the lines
reciever = "none"
agent="none"
From what I have understood "reciever" and "agent" represent the alcoves, where you put the items in, right? I think the error occurs because the script sets these to "none" in these lines and therefore on the next call these variables do not contain the reference to the alcove instance anymore, instead they only contain the string "none". This is why he cannot execute :containedItems() for these variables anymore. I'm not 100% sure on this, but try to remove the above "=none" lines from the functions. I think it should work every time then.
Re: Script Help-Spell forge
Posted: Wed Oct 30, 2013 3:31 am
by LocalFire
Thank you I will give it a try
Re: Script Help-Spell forge
Posted: Wed Oct 30, 2013 3:34 am
by LocalFire
It works! Thank you
Re: Script Help_ Pressure plate order
Posted: Thu Dec 19, 2013 2:38 am
by Mysterious
Hi LocalFire
This Forge idea is very good and I would like to no more on how it work.
Do you connect alcoves to the Code you created, I have tried to get it to work, but failed badly lol. I would really like to put this in my Mod as well if it's ok by you.
Thank you
EDIT: Ok I have connect the 2 alcoves to Check1 and Check2 the 2 potions are destroyed but the greater potion does not spawn on the Altar called forge.
I put 1 of each potions in each alcoves name agent and receiver.
Alcoves are set to activate.
Do you know where I am going wrong? I have created a new potion call greater potion by cloning a healing potion and rename it.
EDIT: Sorry about this, but I don't know how to get this forge to work I have tried everything

Re: Script Spell forge
Posted: Thu Dec 19, 2013 9:03 am
by LocalFire
I think it may be the name of the greater potion, is it the uiName or Name that you are calling? if it helps this is my setup below
Heres how its set up so I've got the functions above but I'll repeat them anyway
first this in a script entity called f
Code: Select all
function ndItemNameInside(entity, itemName)
if (entity == nil or itemName == nil) then
print("need two variables")
return false
end
for i in entity:containedItems() do
if (i.name == itemName) then
return true
end
end
return false
end
function ndItemIDInside(entity, itemID)
if (entity == nil or itemID == nil) then
print("need two variables")
return false
end
for i in entity:containedItems() do
if (i.id == itemID) then
return true
end
end
return false
end
them these 3 functions hooked up to a receptor (sub out the names as required)
Code: Select all
function ManaChannel()
if (f.ndItemNameInside(reciever, "blank_scroll") and
(f.ndItemNameInside(agent, "Arcane_bottle")))
then
forge: addItem (spawn "scroll_Channel")
playSound("level_up")
end
end
Code: Select all
function Check1()
if reciever == "none" then return end
for i in reciever:containedItems() do
if i.name == "blank_scroll" then
i:destroy()
end
end
end
function Check2()
if agent == "none" then return end
for i in agent:containedItems() do
if i.name == "Arcane_bottle" then
i:destroy()
end
end
end
The so the script is connected to a receptor which activates the forge when the player is sure that the items are correct. obiviously there are two alcoves named receiver and agent and an altar named forge for the result to spawn onto.
In this form it will also destroy any correct items even if the wrong combination is put in so for the above section if a blank scroll was placed with a dagger it would destroy the scroll but leave the dagger and create no new item. I've set this up so there is some trial and error available with more common reagents, but if you wanted you could add a timer that activates only if the correct two items are present and then runns the check functions.
Also if it helps heres the definition for the greater potion, obviously using a custom icon atlas so remove that part or make one with the same name
Code: Select all
defineObject{
name = "potion_greater",
model ="assets/models/items/flask.fbx",
uiName = "Arcane Potion",
class= "Item",
gfxAtlas = "mod_assets/textures/icon_atlasS.tga",
gfxIndex = 3,
description = "Liquid swirls constantly about the bottle, even when you leave it at rest",
consumable = true,
potion= true,
weight= 0.1,
onUseItem = function(self,champion)
champion:modifyStat("health", 150)
champion:modifyStat("energy",50)
playSound("consume_potion")
return true
end
}
Re: Script Spell forge
Posted: Thu Dec 19, 2013 1:57 pm
by Mysterious
Hi LocalFire
Thank you very much for the help i got it to work now and i love it so much that i begun working on new recipies. Ithink thats what you would call them.
I found that thing called a receptor and really dont know what it does lol. I checked it out and something about a Blob activating the script you made, sorry i am not sure how the receptor works. I did however use a wall switch to activate the 3 scripts you said and it works. Does the Monster blob have to be near the receptor or does the blob activate it some how??
Is there somewhere i can find out how a receptor works??
Thank you for the help, i love this script and function alot, will make good use of it.

Re: Script Spell forge
Posted: Thu Dec 19, 2013 11:23 pm
by LocalFire
The receptor is activated when its hit by a spell, where it says blob you can type in the name of the spell you want to activate the receptor, ie. fireball, think of as a button that is switched on by magic
Re: Script Spell forge
Posted: Sun Dec 22, 2013 7:52 pm
by Mysterious
Hi LocalFire
Sorry for being so late to post you. So much work going on here, Xmas and all. Thank you for that info it works. And now I know what receptor does. I tried the Spell like you said and it works to thxs again and Merry Xmas and Happy New Year.
