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

Lua Change script tfs 1.3 to 0.4

asdzx123

Member
Joined
Jul 1, 2019
Messages
37
Reaction score
8
Lua:
local baseStorage = 400000
GemsDamage =
{
   storages =
   {
      EXTRA_SPELLS_DAMAGE = {storage = baseStorage, name = 'extra spell damage', percent = 30},
      EXTRA_SPELLS_PROTECTION = {storage = baseStorage + 1, name = 'extra spell protection', percent = 20},
      EXTRA_SPEED = {storage = baseStorage + 2, name = 'extra speed'},
      --EXTRA_SPEED = ?
   },

   bonusTime = 10 * 60, --minutes in seconds,
   positions =
   {
      topLeft = Position(1101, 821, 7),
      bottomRight = Position(1219, 906, 7)
   },
   timeToCreateGems = 0.5 * 60 * 60,--5,--

   outfits =
   {
      EXTRA_SPELLS_DAMAGE = {monsterName = "juggernaut"},
      EXTRA_SPELLS_PROTECTION = {monsterName = "demon"},
      EXTRA_SPEED = {monsterName = "flamingo"}
   },


   bonusByIds =
   {
      [9565] = {name = 'EXTRA_SPELLS_DAMAGE', monsterName = "juggernaut", bonusDescription = "30% More DMG"},
      [9562] = {name = 'EXTRA_SPELLS_PROTECTION', monsterName = "demon", bonusDescription = "20% Spells Protection"},
      [9564] = {name = 'EXTRA_SPEED', monsterName = "flamingo", bonusDescription = "Extra speed"},
   },

   speedConditionId = 95590

}

function GemsDamage:removeAllBonuses(player)
   if (player) then
      if (self:hasBonusTime(player, "EXTRA_SPELLS_DAMAGE")) then
         self:removeBonus(player, "EXTRA_SPELLS_DAMAGE")
      end

      if (self:hasBonusTime(player, "EXTRA_SPELLS_PROTECTION")) then
         self:removeBonus(player, "EXTRA_SPELLS_PROTECTION")
      end

      if (self:hasBonusTime(player, "EXTRA_SPEED")) then
         self:removeBonus(player, "EXTRA_SPEED")
      end

      player:removeCondition(CONDITION_OUTFIT)
   end

end

function GemsDamage:setPlayerOutfit(player, bonusType)
   if (player) then
      local outfit = self.outfits[bonusType]
      if (outfit) then
         local mType = MonsterType(outfit.monsterName)
         if (mType) then
            local condition = Condition(CONDITION_OUTFIT)
            condition:setTicks(self.bonusTime * 1000)
            condition:setOutfit(mType:eek:utfit())
            player:addCondition(condition)
         end
      end
   end
end

function GemsDamage:getRandomPosition()
   --local pos = {}

   local from = self.positions.topLeft
   local to = self.positions.bottomRight


   local x = math.random(from.x, to.x)
   local y = math.random(from.y, to.y)
   local z = from.z
   local pos = Position(x, y, z)
   return pos
end

function GemsDamage:canBeGemAdded(pos)
   local tile = Tile(pos)
   if (tile) then
      --print(print(tostring(tile:hasFlag(TILESTATE_PROTECTIONZONE)) .."".. tostring(tile:getHouse()) .."".. tostring(tile:hasFlag(TILESTATE_BLOCKSOLID)) .."__".. tostring(tile:hasFlag(TILESTATE_BLOCKPATH))))
      if (tile:hasFlag(TILESTATE_PROTECTIONZONE) or tile:getHouse() or tile:hasFlag(TILESTATE_BLOCKSOLID) or tile:hasFlag(TILESTATE_BLOCKPATH)) then
         return false
      end
   else
      return false
   end
   local groundName = tile:getGround():getName()
   if (groundName:find("water") or groundName:find("brook")) then
      return false
   end
   return true
end

function firstToUpper(str)
   return (str:gsub("^%l", string.upper))
end

function GemsDamage:getPlayerMessage(player, itemId)
   if (player) then
      local bonusById = self.bonusByIds[itemId]
      if (bonusById) then
         local msg = string.format("%s have become a %s and have (%s)", player:getName(), firstToUpper(bonusById.monsterName), bonusById.bonusDescription)

         return msg
      end
   end
end

function GemsDamage:getMessage(itemId)
   local bonusById = self.bonusByIds[itemId]
   if (bonusById) then
      local msg = string.format("%s tile has spawned somewhere on the bridge map!\nBe the first one to become a %s! (%s)", firstToUpper(bonusById.monsterName), bonusById.monsterName, bonusById.bonusDescription)

      return msg
   end

end

function GemsDamage:sendMessageToAll(allMessage)
   local onlinePlayers = Game.getPlayers()
   for i = 1, #onlinePlayers do
      local player = onlinePlayers
      if (player) then
         player:sendTextMessage(MESSAGE_STATUS_WARNING, allMessage)
      end
   end
end

function createGemsOnPlaces()
   local pos
   repeat
      pos = GemsDamage:getRandomPosition()
   until(GemsDamage:canBeGemAdded(pos))

   local items = {9565, 9562, 9564}
   local item = items[math.random(#items)]
   Game.createItem(item, 1, pos)
   local allMessage = GemsDamage:getMessage(item)
   if (allMessage) then
      GemsDamage:sendMessageToAll(allMessage)
   end
   local msg = string.format("A new %s have been created on pos %d, %d, %d", ItemType(item):getName(), pos.x, pos.y, pos.z)
   GemsDamage.sendMessageToAll(msg)
   --print(msg)
   addEvent(createGemsOnPlaces, GemsDamage.timeToCreateGems * 1000)
end

function GemsDamage:getTypeBonus(typeBonus)
   return self.storages[typeBonus]
end

function GemsDamage:getBonusTime(player, typeBonus)
   if (player) then
      local bonus = self:getTypeBonus(typeBonus)
      if (bonus) then
         local value = player:getStorageValue(bonus.storage)
         return value and math.max(value, 0) or 0
      end
   end
end

function GemsDamage:setBonusTime(player, typeBonus, time)
   if (player) then
      local bonus = self:getTypeBonus(typeBonus)
      if (bonus) then
         --print("bonus")
         player:setStorageValue(bonus.storage, time)
      else
         --print("not bonus")
      end
   end
end

function GemsDamage:addSpeedCondition(player)
   if (player) then
      local condition = Condition(CONDITION_HASTE, self.speedConditionId)
      condition:setParameter(CONDITION_PARAM_TICKS, self.bonusTime * 1000 )
      condition:setFormula(0.3 * 5, -24 * 5, 0.3 * 5, -24 * 5)
      player:addCondition(condition)
   end
end

function GemsDamage:updateBonus(player, typeBonus)
   if (player) then
      local msg = string.format("You have received %s bonus for %d minutes.", typeBonus, self.bonusTime / 60)
      self:setPlayerOutfit(player, typeBonus)
      --player:sendTextMessage(MESSAGE_EVENT_ADVANCE, msg)
      if (typeBonus == "EXTRA_SPEED") then
         GemsDamage:addSpeedCondition(player)
      end
      self:setBonusTime(player, typeBonus, self.bonusTime + os.time())

   end
end

function GemsDamage:removeBonus(player, typeBonus)
   if (player) then
      local msg = string.format("You have lost %s bonus.", typeBonus)
      --player:sendTextMessage(MESSAGE_EVENT_ADVANCE, msg)
      self:setBonusTime(player, typeBonus, 0)
   end
end

function GemsDamage:hasBonusTime(player, typeBonus)
   if (player) then

      local bonus = self:getTypeBonus(typeBonus)
      if (bonus) then
         --print(self:getBonusTime(player, typeBonus).."__"..os.time())
         return self:getBonusTime(player, typeBonus) > os.time()
      end
   end
end

and this
Lua:
local gems = {
   [9565] = {name = 'EXTRA_SPELLS_DAMAGE'},
   [9562] = {name = 'EXTRA_SPELLS_PROTECTION'},
   [9564] = {name = 'EXTRA_SPEED'},
}

function gems:addBonus(player, aid, item)
   local gem = gems[aid]
   if (gem and player) then
      local typeBonus = gem.name
      --print(typeBonus)
      if (GemsDamage:hasBonusTime(player, typeBonus)) then
         return false
      end

      item:remove()
      if (typeBonus == 'EXTRA_SPELLS_DAMAGE') then
         GemsDamage:updateBonus(player, 'EXTRA_SPELLS_DAMAGE')
         GemsDamage:removeBonus(player, 'EXTRA_SPELLS_PROTECTION')
         GemsDamage:removeBonus(player, 'EXTRA_SPEED')
      elseif (typeBonus == 'EXTRA_SPELLS_PROTECTION') then
         GemsDamage:updateBonus(player, 'EXTRA_SPELLS_PROTECTION')
         GemsDamage:removeBonus(player, 'EXTRA_SPELLS_DAMAGE')
         GemsDamage:removeBonus(player, 'EXTRA_SPEED')
      elseif (typeBonus == 'EXTRA_SPEED') then
         GemsDamage:updateBonus(player, 'EXTRA_SPEED')
         GemsDamage:removeBonus(player, 'EXTRA_SPELLS_PROTECTION')
         GemsDamage:removeBonus(player, 'EXTRA_SPELLS_DAMAGE')
      end
      --print(aid)

      local allMessage = GemsDamage:getPlayerMessage(player, aid)
      GemsDamage:sendMessageToAll(allMessage)
   end
end

function onStepIn(creature, item, position, fromPosition)
   if (creature:isPlayer()) then
      local player = creature
      gems:addBonus(player, item:getId(), item)
   end
   return true
end
 
Back
Top