• 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...
Not tested.
Lua:
local function regenerateMana(monsterId, percents)
     local creature = Creature(monsterId)
     local master = creature:getMaster()
     if creature and master then
       master:addMana(master:getMaxMana() / 10)
       addEvent(regenerateMana, 7000, monsterId, 10)
     end
end

local protection = {}
local monster = "Demon"

function onStepIn(creature, item, position, fromPosition)
  local player = creature:getPlayer()
  if not player then
    return true
  end

  local playerId = player:getId()
  if protection[playerId] then
    protection[playerId] = nil
    return true
  end

  protection[playerId] = true

  local summon = Game.createMonster(monster, player:getPosition())
  if not summon then
    return player:sendCancelMessage("There is not enough room to summon your monster.")
  end

  player:addSummon(summon)

  if not summon:isMonster() then
    return true
  end

  if summon:getMaster() ~= player then
    summon:remove()
  else
    summon:teleportTo(player:getPosition())
    summon:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
    addEvent(regenerateMana, 7000, summon:getId(), 10)
  end
  return true
end

function onDeEquip(creature, item, position, fromPosition)
  local player = creature:getPlayer()
  if not player then
    return true
  end

  local monster = "Gamakichi"
  if player:getSummons() >= 1 then
    for ,_ summon in ipairs(player:getSummons()) do
      if summon:getName() == monster then
        summon:getPosition():sendMagicEffect(10)
        summon:remove()
        break
      end
    end
  end
  return true
end
 
thank you, there are no errors, but when I put the object in the right place, it does not create a monster that regenerates
 
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 regenerateMana(cid, summon_uid)
    local player, summon = Player(cid), Creature(summon_uid)
    if not player or not summon or summon:getMaster() ~= player then
        return
    end

    player:addMana(player:getMaxMana() / mana_percent)
    addEvent(regenerateMana, event_delay * 1000, cid, summon_uid)
end


function onEquip(player, item, slot)
    local player = type(player) == 'userdata' and player or Player(player)
    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
    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()
            break
        end
    end
    return true
end
 
Last edited by a moderator:
Solution
thank you very much, but I have a small problem, because he creates three monsters for me and when I download the item, it removes one
 
I guess its because you use the break with no reason at all :p
I figured that was what was up, I assumed there was only one demon to remove. Maybe if there is something in his sources that is causing the onEquip to summon multiple demons and he doesn't want that. If that's the case I'll add a condition to only allow one demon summoned at a time.
 
the problem is that it creates three and has one
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 regenerateMana(cid, summon_uid)
    local player, summon = Player(cid), Creature(summon_uid)
    if not player or not summon or summon:getMaster() ~= player then
        return
    end

    player:addMana(player:getMaxMana() / mana_percent)
    addEvent(regenerateMana, event_delay * 1000, cid, summon_uid)
end


function onEquip(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
            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
    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
 
my code
XML:
<movevent event="Equip" itemid="2125" slot="necklace" script="gamakichi.lua" />
<movevent event="DeEquip" itemid="2125" slot="necklace" script="gamakichi.lua" />
Lua:
local monster = "Gamakichi"
local mana_percent = 10
local event_delay = 7

local function regenerateMana(cid, summon_uid)
    local player, summon = Player(cid), Creature(summon_uid)
    if not player or not summon or summon:getMaster() ~= player then
        return
    end
    player:addMana(player:getMaxMana() / mana_percent)
    addEvent(regenerateMana, event_delay * 1000, cid, summon_uid)
end

function onEquip(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
            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
    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
How does it work for you? mi creates three
 
Back
Top