• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Action [TFS 1.1] - Slot system

Status
Not open for further replies.
avoid converting all things to metatables if you already have "cid"
if you can't get cid, just use:
Code:
local cid = player:getId()
 
If ya get it working for 1.1 please post it my dear friend!
 
Script works perfectly on TFS 1.1, thought I couldn't get the onkill_slot to work..I didn't get any errors but it wouldn't drop rares. Doesn't matter too much though so Thanks a bunch!

EDIT: Upon further review Slotlogin debugs my server when a char loggs out..
This is the script I have
Code:
local conditionMP,conditionHP,conditionML,conditionCLUB,conditionSHI,conditionDIST,conditionAMP = {},{},{},{},{},{},{}
for i=1,300 do
   conditionHP[i] = createConditionObject(CONDITION_ATTRIBUTES)
   setConditionParam(conditionHP[i], CONDITION_PARAM_SUBID, 50)
   setConditionParam(conditionHP[i], CONDITION_PARAM_BUFF_SPELL, 1)
   setConditionParam(conditionHP[i], CONDITION_PARAM_TICKS, -1)
   setConditionParam(conditionHP[i], CONDITION_PARAM_STAT_MAXHITPOINTSPERCENT, 100+i)

   conditionMP[i] = createConditionObject(CONDITION_ATTRIBUTES)
   setConditionParam(conditionMP[i], CONDITION_PARAM_SUBID, 51)
   setConditionParam(conditionMP[i], CONDITION_PARAM_BUFF_SPELL, 1)
   setConditionParam(conditionMP[i], CONDITION_PARAM_TICKS, -1)
   setConditionParam(conditionMP[i], CONDITION_PARAM_STAT_MAXMANAPOINTSPERCENT, 100+i)

   conditionML[i] = createConditionObject(CONDITION_ATTRIBUTES)
   setConditionParam(conditionML[i], CONDITION_PARAM_SUBID, 52)
   setConditionParam(conditionML[i], CONDITION_PARAM_BUFF_SPELL, 1)
   setConditionParam(conditionML[i], CONDITION_PARAM_TICKS, -1)
   setConditionParam(conditionML[i], CONDITION_PARAM_STAT_MAGICPOINTSPERCENT, 100+i)


   conditionCLUB[i] = createConditionObject(CONDITION_ATTRIBUTES)
   setConditionParam(conditionCLUB[i], CONDITION_PARAM_SUBID, 53)
   setConditionParam(conditionCLUB[i], CONDITION_PARAM_BUFF_SPELL, 1)
   setConditionParam(conditionCLUB[i], CONDITION_PARAM_TICKS, -1)
   setConditionParam(conditionCLUB[i], CONDITION_PARAM_SKILL_MELEEPERCENT, 100+i)


   conditionSHI[i] = createConditionObject(CONDITION_ATTRIBUTES)
   setConditionParam(conditionSHI[i], CONDITION_PARAM_SUBID, 54)
   setConditionParam(conditionSHI[i], CONDITION_PARAM_BUFF_SPELL, 1)
   setConditionParam(conditionSHI[i], CONDITION_PARAM_TICKS, -1)
   setConditionParam(conditionSHI[i], CONDITION_PARAM_SKILL_SHIELDPERCENT, 100+i)

   conditionDIST[i] = createConditionObject(CONDITION_ATTRIBUTES)
   setConditionParam(conditionDIST[i], CONDITION_PARAM_SUBID, 55)
   setConditionParam(conditionDIST[i], CONDITION_PARAM_BUFF_SPELL, 1)
   setConditionParam(conditionDIST[i], CONDITION_PARAM_TICKS, -1)
   setConditionParam(conditionDIST[i], CONDITION_PARAM_SKILL_DISTANCEPERCENT, 100+i)
end

function getSlotType(n)
   if not n then
     return false
   end
   if n:match('%[(.+)%]') then
     n = n:match('%[(.+)%]')
     if n == '?' then
       return 0,n
     else
       return n:match('(.-)%.([+-])(%d+)%%')
     end
   else
     return false
   end
end

local function loadSet(cid)
   local t = {}
   for slot=1,9 do
     t[slot] = ''
     local s = getPlayerSlotItem(cid,slot).uid
     if s ~= 0 then
       t[slot] = Item(s):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION)
     end
   end
   return t
end

function chk(cid,f)
   if not isPlayer(cid) then return false end
   local t = loadSet(cid)
   for i=1,#f do
     if f[i] ~= t[i] then
       equip(cid,nil,slot)
       break
     end
   end
   addEvent(chk,2000,cid,t)
end

function check_slot(aab, i)
if aab == nil then return false end
if aab == 0 then return false end
   if i == 5 or i == 6 then
     if isWeapon(aab) or isShield(aab) or isBow(aab) then
       return true
     end
   else
     return true
   end
return false
end

function equip(cid,item,slot)
   local t = {}
   if item then
     local mm,sinal,qto = getSlotType(Item(item.uid):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION))
     t[mm] = tonumber(qto)
   end
   for i=1,9 do
     if i ~= slot then
       if getPlayerSlotItem(cid,i).itemid ~= 0 then
         local aab = getPlayerSlotItem(cid,i).uid
         if aab and check_slot(aab,i) then
           for _ in Item(aab):getAttribute(ITEM_ATTRIBUTE_DESCRIPTION):gmatch('(%[.-%])') do
             local mm,sinal,qto2 = getSlotType(_)
             if mm then
               if not t[mm] then
                 t[mm] = 0
               end
               t[mm] = t[mm]+tonumber(qto2)
               t[mm] = t[mm] > 300 and 300 or t[mm]
             end
           end
         end
       end
     end
   end
   local fu = 0
   local ca = {}
   local s = ''
   for sl,n in pairs(t) do
     fu = fu+1
     s = s..''..n..'% more of '..sl..'\n'
     if sl == 'hp' then
       doAddCondition(cid,conditionHP[tonumber(n)])
       ca[50] = 1
       doSendTutorial(cid,19)
     elseif sl == 'mp' then
       doAddCondition(cid,conditionMP[tonumber(n)])
       ca[51] = 1
       doSendTutorial(cid,19)
     elseif sl == 'ml' then
       doAddCondition(cid,conditionML[tonumber(n)])
       ca[52] = 1
     elseif sl == 'melee' then
       doAddCondition(cid,conditionCLUB[tonumber(n)])
       ca[53] = 1
     elseif sl == 'shield' then
       doAddCondition(cid,conditionSHI[tonumber(n)])
       ca[54] = 1
     elseif sl == 'dist' then
       doAddCondition(cid,conditionDIST[tonumber(n)])
       ca[55] = 1
     end
   end
   if fu > 0 then
     for i=50,55 do
       if not ca[i] then
         doRemoveCondition(cid,CONDITION_ATTRIBUTES,i)
       end
     end
   else
     for i=50,55 do
       doRemoveCondition(cid,CONDITION_ATTRIBUTES,i)
     end
   end
   return true
end

function onLogin(cid)
  equip(cid,nil,slot)
  addEvent(chk,2000,cid,loadSet(cid))
  return true
end
As you can see it's as posted. Any ideas as to what is causing the debug?
 
Last edited:
post error/crash log/debug output from client
 
Well the console does have any errors before debugging and I'm not really sure how to create/find an external error log from my console. But in the debugger it points me to this coding in the sources
Code:
int32_t LuaScriptInterface::luaPlayerGetSlotItem(lua_State* L)
{
    // player:getSlotItem(slot)
    const Player* player = getUserdata<const Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint32_t slot = getNumber<uint32_t>(L, 2);
    Thing* thing = player->getThing(slot);
    if (!thing) {
        lua_pushnil(L);
        return 1;
    }

    Item* item = thing->getItem();
    if (item) {
        pushUserdata<Item>(L, item);
        setItemMetatable(L, -1, item);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
Specifically pointing at Item* item = thing->getItem();
 
post error/crash log/debug output from client
Well the console does have any errors before debugging and I'm not really sure how to create/find an external error log from my console. But in the debugger it points me to this coding in the sources
Code:
int32_t LuaScriptInterface::luaPlayerGetSlotItem(lua_State* L)
{
    // player:getSlotItem(slot)
    const Player* player = getUserdata<const Player>(L, 1);
    if (!player) {
        lua_pushnil(L);
        return 1;
    }

    uint32_t slot = getNumber<uint32_t>(L, 2);
    Thing* thing = player->getThing(slot);
    if (!thing) {
        lua_pushnil(L);
        return 1;
    }

    Item* item = thing->getItem();
    if (item) {
        pushUserdata<Item>(L, item);
        setItemMetatable(L, -1, item);
    } else {
        lua_pushnil(L);
    }
    return 1;
}
Specifically pointing at Item* item = thing->getItem();

It's because he is using 1.1 and 1.1 passes userdata instead of cid now. Always the same problem for him. Please doitforthegains man know that its going to be the same problem everytime you get something for 1.0. When it says it works for 1.x or 1.1 then you won't have problems from the scripts for your server.

change this

Code:
function onLogin(cid)
  equip(cid,nil,slot)

for this

Code:
function onLogin(creature)
  local cid = creature:getId()
  equip(cid,nil,slot)

then if any more problems msg me...
 
Hmm..So something about when I edit my global.lua causes people to debug when they eat food.. :/
 
You made syntax eror somewhere.
 
These are the dofiles I'm calling in my global
Code:
dofile('data/libs.lua')
dofile('data/compat.lua')
dofile('data/lib/001_04_compat.lua')
Obviously, if I take away dofile('data/lib/001_04_compat.lua') then the slots won't work. But when I add dofile('data/lib/001_04_compat.lua') to my global I can login and use the slots however if I 'use' food it debugs regular tibia client, on OTC it takes away its functionality of an item and you can't move it anymore. It does tell me "you are full." on use but doesn't actually let me eat it.
This is the debug:
SWYArYj.png
 
Can't reproduce it.
It seems to be caused by sendTextMessage(), but talktype is correct, I think text was too long, but I don't know why. I'll check that later on clear tfs if I don't forget.

What datapack are you using? Do you get same error on clear tfs?
 
I'm using printers 1.1 datapack, but I get the same error when I use mark's clean tfs 1.1, if thats what you were meaning by clear tfs
 
anyone else have same problem with it like u?
I put it in global.lua again, started newest tfs which have data folder without changes in scripts and it works fine here.
kQ5MWk9.jpg

I still can't even find what may cause this problem. If you break global.lua syntax, it's impossible to login, if you reload broken global.lua, food still works.

Tested on 1.1, it works.
 
Last edited:
Status
Not open for further replies.
Back
Top