• 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!

rewriting

Restles

fallen human nature
Joined
Jan 30, 2014
Messages
68
Solutions
1
Reaction score
35
Location
Poland
Hello, I have a request, can I be able to keep tracking on tfs 1.1 by someone? I would be very grateful
Lua:
local protection = {}
local monster = "Demon"

function onEquip (cid, item, slot)
 
     if protection[cid] then
          protection[cid] = nil
          return true
     end
    
     protection[cid] = true
     local mid = 0
    
     if type(doSummonMonster) then
          local func_ret = doSummonMonster(cid, monster)
          if func_ret == 0 then
               return doPlayerSendCancel(cid, "There is not enough room to summon your monster.")
          end
          local s = getCreatureSummons(cid)
          mid = s[#s]       
     else
          mid = doCreateMonster(monster, getThingPos(cid), false)
          if mid == true then
               return doPlayerSendCancel(cid, "There is not enough room to summon your monster.")
          end
          doConvinceCreature(cid, mid)
     end
    
       if not isCreature(mid) then return true end
 
     if getCreatureMaster(mid) ~= cid then
          doRemoveCreature(mid)
     else
          doTeleportThing(mid, getThingPos(cid))
          doSendMagicEffect(getThingPos(mid), CONST_ME_TELEPORT)
          local function regenerateMana(mid, percents)
               local cid = (isCreature(mid) and getCreatureMaster(mid) or 0)
               if(not isCreature(cid)) then return end
               doCreatureAddMana(cid, getCreatureMaxMana(cid)/percents)
               addEvent(regenerateMana, 7000, mid, 10)
          end
          addEvent(regenerateMana, 7000, mid, 10)
     end
    
return true
end

function onDeEquip(cid, item, slot)
local monster = "Gamakichi"
if #getCreatureSummons(cid) >= 1 then
   for _, summon in ipairs(getCreatureSummons(cid)) do
       if getCreatureName(summon) == monster then
          doSendMagicEffect(getPlayerPosition(summon), 10)
          doRemoveCreature(summon)
          break
       end
   end
end
return true
end
 
Solution
thank you, there are no errors, but when I put the object in the right place, it does not create a monster that regenerates
There is some confusion in this thread.
  • Idk what the reasoning for that guy using onStepIn instead was.
  • With onEquip the script is creating a Demon yet with onDeEquip it is trying to remove a creature named Gamakichi.
So I may be confused on what you need, I assume you want on item to summon a creature for you when equipped and then remove the creature when you de-equip it, so try this, it should work for 1.1:

Lua:
local monster = "Demon" -- monster which is summon onEquip and removed onDeEquip
local mana_percent = 10 -- percent of health gain
local event_delay = 7 -- in seconds

local function...
Lua:
function onEquip(player, item, slot)
    local player = type(player) == 'userdata' and player or Player(player)
    local slots = player:getSlotItem(slot)
    if slots then
        if slots.itemid ~= item.itemid then
            return true
        end
    else
        for _, summon in pairs(player:getSummons()) do
            if summon:getName() == monster then
                return true
            end
        end

        local player_pos = player:getPosition()
        local creatureId = doSummonCreature(monster, player_pos)
        if creatureId ~= false then
            local monster = Monster(creatureId)
            monster:setMaster(player)
            player_pos:sendMagicEffect(CONST_ME_MAGIC_RED)
            addEvent(regenerateMana, event_delay * 1000, player.uid, monster.uid)
        else
            player:sendCancelMessage("There is not enough room to summon your monster.")
            player_pos:sendMagicEffect(CONST_ME_POFF)
        end
    end
    return true
end

function onDeEquip(player, item, slot)
    local player = type(player) == 'userdata' and player or Player(player)
    for _, summon in pairs(player:getSummons()) do
        if summon:getName() == monster then
            summon:getPosition():sendMagicEffect(CONST_ME_POFF)
            summon:remove()
        end
    end
    return true
end
 
I already know what is wrong, it works properly only when I am a master of the game then creates one monster, if I am a regular player creates three
 
Back
Top