HeberPcL
[PowerOT.com.br]
Hey,
I have a problem that I can not understand the reason, maybe you can help me.
The below script returns error in the following line:
local n, i = getTileInfo({x=x, y=y, z=v.toPos.z}).creatures, 1
Any idea how to solve?
Thank you!
Error:
Function getTileInfo source code:
I have a problem that I can not understand the reason, maybe you can help me.
The below script returns error in the following line:
local n, i = getTileInfo({x=x, y=y, z=v.toPos.z}).creatures, 1
Any idea how to solve?
Thank you!
Error:
PHP:
[10:35:50.592] [Error - GlobalEvent Interface]
[10:35:50.592] domodlib('DTB_config')
[10:35:50.592] domodlib('DTB_lib')
[10:35:50.592] function onThink(interval)
[10:35:50.592] if getStorage(dtbConfig.eventStorage) == 1 then
[10:35:50.592] doAddScoreToBase()
[10:35:50.592] end
[10:35:50.592] return true
[10:35:50.592] end
[10:35:50.592] :onThink
[10:35:50.592] Description:
[10:35:50.592] [string " domodlib('DTB_config')..."]:12: attempt to index a boolean value
[10:35:50.592] stack traceback:
[10:35:50.593] [string " domodlib('DTB_config')..."]:12: in function 'doAddScoreToBase'
[10:35:50.593] [string "LuaInterface::loadBuffer"]:6: in function <[string "LuaInterface::loadBuffer"]:4>
PHP:
function doAddScoreToBase()
local v = dtbConfig.base
local blue, red = 0, 0
for x = v.fromPos.x, v.toPos.x do
for y = v.fromPos.y, v.toPos.y do
local n, i = getTileInfo({x=x, y=y, z=v.toPos.z}).creatures, 1
if n ~= 0 then
local t = getThingfromPos({x=x, y=y, z=v.toPos.z, stackpos=i}).uid
while t ~= 0 do
if isPlayer(t) then
if getCreatureStorage(t, dtbConfig.red.storage) > 0 then
red = red + 1
elseif getCreatureStorage(t, dtbConfig.blue.storage) > 0 then
blue = blue + 1
end
end
i = i + 1
t = getThingfromPos({x=x, y=y, z=v.toPos.z, stackpos=i}).uid
end
end
end
end
-- ustawia storage basy
local addPoints = getStorage(v.points) + (red - blue)
if math.abs(addPoints) > dtbConfig.maxBasePoints then
local t = 1
if addPoints < 0 then
if getStorage(dtbConfig.blue.currentTime) - 1 > 0 then
t = getStorage(dtbConfig.blue.currentTime) - 1
doSetStorage(dtbConfig.blue.currentTime, getStorage(dtbConfig.blue.currentTime) - 1)
else
doCloseDtbEvent('blue')
end
else
if getStorage(dtbConfig.red.currentTime) - 1 > 0 then
t = getStorage(dtbConfig.red.currentTime) - 1
doSetStorage(dtbConfig.red.currentTime, getStorage(dtbConfig.red.currentTime) - 1)
else
doCloseDtbEvent('red')
end
end
doSetStorage(v.points, (addPoints < 0 and - dtbConfig.maxBasePoints or dtbConfig.maxBasePoints))
doSendAnimatedText(v.showInfoPos, secondsToClock(t), (addPoints < 0 and COLOR_LIGHTBLUE or COLOR_RED))
else
-- Add points --
if math.abs(addPoints) < dtbConfig.basePointsToControl then
doSendAnimatedText(v.showInfoPos, 'Neutral', COLOR_WHITE)
else
local t = 0
if addPoints < 0 then
if getStorage(dtbConfig.blue.currentTime) - 1 > 0 then
t = getStorage(dtbConfig.blue.currentTime) - 1
doSetStorage(dtbConfig.blue.currentTime, getStorage(dtbConfig.blue.currentTime) - 1)
else
doCloseDtbEvent('blue')
end
else
if getStorage(dtbConfig.red.currentTime) - 1 > 0 then
t = getStorage(dtbConfig.red.currentTime) - 1
doSetStorage(dtbConfig.red.currentTime, getStorage(dtbConfig.red.currentTime) - 1)
else
doCloseDtbEvent('red')
end
end
local takeControl = addPoints < 0 and 'blue' or 'red'
doSendAnimatedText(v.showInfoPos, secondsToClock(t), (takeControl == 'blue' and COLOR_LIGHTBLUE or COLOR_RED))
end
doSetStorage(v.points, addPoints)
end
-- Top flag --
local topFlag
for _, id in pairs(v.topFlagPos.id) do
if getTileItemById(v.topFlagPos.pos, id).uid > 0 then
topFlag = getTileItemById(v.topFlagPos.pos, id).uid
break
end
end
if topFlag ~= nil then
if math.abs(addPoints) < dtbConfig.basePointsToControl then
doTransformItem(topFlag, v.topFlagPos.id[1])
else
doTransformItem(topFlag, v.topFlagPos.id[(addPoints < 0 and 3 or 2)])
end
end
-- Tapestry --
for i, flags in pairs(v.flags) do
local flag
for _, id in pairs(flags.id) do
if getTileItemById(flags.pos, id).uid > 0 then
flag = getTileItemById(flags.pos, id).uid
break
end
end
if flag ~= nil then
if i > math.abs(addPoints) then
doTransformItem(flag, flags.id[1])
else
doTransformItem(flag, flags.id[(addPoints < 0 and 3 or 2)])
end
end
end
end
Function getTileInfo source code:
PHP:
int32_t LuaInterface::luaGetTileInfo(lua_State* L)
{
//getTileInfo(pos)
PositionEx pos;
popPosition(L, pos);
if(Tile* tile = g_game.getMap()->getTile(pos))
{
ScriptEnviroment* env = getEnv();
pushThing(L, tile->ground, env->addThing(tile->ground));
setFieldBool(L, "protection", tile->hasFlag(TILESTATE_PROTECTIONZONE));
setFieldBool(L, "optional", tile->hasFlag(TILESTATE_OPTIONALZONE));
setFieldBool(L, "hardcore", tile->hasFlag(TILESTATE_HARDCOREZONE));
setFieldBool(L, "noLogout", tile->hasFlag(TILESTATE_NOLOGOUT));
setFieldBool(L, "refresh", tile->hasFlag(TILESTATE_REFRESH));
setFieldBool(L, "trashed", tile->hasFlag(TILESTATE_TRASHED));
setFieldBool(L, "magicField", tile->hasFlag(TILESTATE_MAGICFIELD));
setFieldBool(L, "trashHolder", tile->hasFlag(TILESTATE_TRASHHOLDER));
setFieldBool(L, "mailbox", tile->hasFlag(TILESTATE_MAILBOX));
setFieldBool(L, "depot", tile->hasFlag(TILESTATE_DEPOT));
setFieldBool(L, "bed", tile->hasFlag(TILESTATE_BED));
createTable(L, "floorChange");
for(int32_t i = CHANGE_FIRST; i <= CHANGE_LAST; ++i)
{
lua_pushnumber(L, i);
lua_pushboolean(L, tile->floorChange((FloorChange_t)i));
pushTable(L);
}
pushTable(L);
setFieldBool(L, "teleport", tile->hasFlag(TILESTATE_TELEPORT));
setField(L, "things", tile->getThingCount());
setField(L, "creatures", tile->getCreatureCount());
setField(L, "items", tile->getItemCount());
setField(L, "topItems", tile->getTopItemCount());
setField(L, "downItems", tile->getDownItemCount());
if(House* house = tile->getHouse())
setField(L, "house", house->getId());
}
else
{
errorEx(getError(LUA_ERROR_TILE_NOT_FOUND));
lua_pushboolean(L, false);
}
return 1;
}
Last edited: