krafttomten
Well-Known Member
Hello otworld!
So, in short what I'm trying to achieve - check game tile for item and if it is the right item: sacrifice item and open hole (and switch lever and open ladder and transform fence etc). The opening a hole and switching lever, fence etc is no probs, got that covered yaow, but the checking game tile stuff is beyond my comprehension for now. I'm learning lua just by doing stuff and I could basically use some help to understand what I'm doing wrong.
I don't actually know which verson of TFS I'm running because I don't know how to find that out lol, but I'll post the game scripts and that should be enough, right? The verson is maybe 3 years old and is named theforgottenserver - 8.6
Anyway, here is my code:
I believe I'm trying to use this function in compat.lua
which, if I understand it correctly, uses this pushThing() code
I don't get any error messages, it just doesn't interpret the "if sacrifice == 2260 then" as being true, I guess I'm trying to call something from inside a table, so I need to format it properly, because the output from my code won't simply be the top item, it will be.. all of it?, but there are so many variables at play so I suppose it's a bit overwhelming for a lua noob such as myself. Also, I haven't even added any code to remove the item that was found, because I haven't found the item yet... and the doRemove code seems to need a uid, which the item won't have since I want to sacrifice a blank rune, so that one I'm totally lost on how to solve that...
So yeah, help would be great!
So, in short what I'm trying to achieve - check game tile for item and if it is the right item: sacrifice item and open hole (and switch lever and open ladder and transform fence etc). The opening a hole and switching lever, fence etc is no probs, got that covered yaow, but the checking game tile stuff is beyond my comprehension for now. I'm learning lua just by doing stuff and I could basically use some help to understand what I'm doing wrong.
I don't actually know which verson of TFS I'm running because I don't know how to find that out lol, but I'll post the game scripts and that should be enough, right? The verson is maybe 3 years old and is named theforgottenserver - 8.6
Anyway, here is my code:
Lua:
local sacrifice = getThingfromPos(1000, 1000, 10) -- Here I'm trying to check whatever is on the position and return whatever is there as 'sacrifice'
function onUse(player, item, fromPosition, target, toPosition, isHotkey)
if item.itemid == 1945 then
doTransformItem(20001, 1484) -- This is a different part of the script, nvm about this.
doTransformItem(20002, 1386) -- This is a different part of the script, nvm about this.
doTransformItem(20005, 1485) -- Here I'm transforming the beacon into an unlit beacon, it's working as intended.
doTransformItem(20006, 777) -- Here I'm shutting the hole, it's working as intended.
Item(item.uid):transform(1946) -- This is a different part of the script, nvm about this.
elseif item.itemid == 1946 then
doTransformItem(20001, 1481) -- This is a different part of the script, nvm about this.
doTransformItem(20002, 1905) -- This is a different part of the script, nvm about this.
Item(item.uid):transform(1945) -- This is a different part of the script, nvm about this.
if sacrifice == 2260 then -- Here I'm trying to check if it is the right item on the position, if so, then go on with commands below
doTransformItem(20005, 1484) -- Here I'm trying to light the beacon where the sacrifice happens to take place, it's working as intended.
doTransformItem(20006, 459) -- Here I'm opening a hole in the ground, working as intended.
end
end
return true
end
I believe I'm trying to use this function in compat.lua
Lua:
function getThingfromPos(pos)
local tile = Tile(pos)
if tile == nil then
return pushThing(nil)
end
local thing
if stackpos == STACKPOS_TOP_MOVEABLE_ITEM_OR_CREATURE then
thing = tile:getTopCreature()
if thing == nil then
local item = tile:getTopDownItem()
if item ~= nil and item:getType():isMovable() then
thing = item
end
end
elseif stackpos == STACKPOS_TOP_FIELD then
thing = tile:getFieldItem()
elseif stackpos == STACKPOS_TOP_CREATURE then
thing = tile:getTopCreature()
else
thing = tile:getThing(pos.stackpos)
end
return pushThing(thing)
end
which, if I understand it correctly, uses this pushThing() code
Lua:
function pushThing(thing)
local t = {uid = 0, itemid = 0, type = 0, actionid = 0}
if thing ~= nil then
if thing:isItem() then
t.uid = thing:getUniqueId()
t.itemid = thing:getId()
if ItemType(t.itemid):hasSubType() then
t.type = thing:getSubType()
end
t.actionid = thing:getActionId()
elseif thing:isCreature() then
t.uid = thing:getId()
t.itemid = 1
if thing:isPlayer() then
t.type = THING_TYPE_PLAYER
elseif thing:isMonster() then
t.type = THING_TYPE_MONSTER
else
t.type = THING_TYPE_NPC
end
end
end
return t
end
I don't get any error messages, it just doesn't interpret the "if sacrifice == 2260 then" as being true, I guess I'm trying to call something from inside a table, so I need to format it properly, because the output from my code won't simply be the top item, it will be.. all of it?, but there are so many variables at play so I suppose it's a bit overwhelming for a lua noob such as myself. Also, I haven't even added any code to remove the item that was found, because I haven't found the item yet... and the doRemove code seems to need a uid, which the item won't have since I want to sacrifice a blank rune, so that one I'm totally lost on how to solve that...
So yeah, help would be great!