• 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 Script problem, Im stuck - need help please

FLE

Member
Joined
Oct 5, 2008
Messages
422
Reaction score
24
Location
Vancouver Canada
IM USING TFS 1.1 - COMPILED APR 11

This script is part of Colors Revive script - Colors Awesome Revive Script


The errors are in screenshot below with lines 87-119 from the script! thanks!

modaldeath.lua -
Code:
--Function Stop Movement by Printer
local function allowMovementEvent(cid, allow, oldPosition)
  local creature = Creature(cid)
  if not creature then
  return false
  end

  if allow then
  return stopEvent(event)
  else
  stopEvent(event)
  end

  creature:teleportTo(oldPosition, true)

  event = addEvent(allowMovementEvent, 100, cid, allow, oldPosition)
end

function Creature.allowMovement(self, allow)
  allowMovementEvent(self:getId(), allow, self:getPosition())
end
--End

local condition = Condition(CONDITION_OUTFIT)
condition:setTicks(-1)

local deathStorage = 19098
local deathGroupId = 25
local deathItemRevive = 13529
local eldinFunction = false --Eldin said: Now a 5-10 Second timer on the Corpse (before window pops up?) and a Spell for a Druid to revive you within that time on the same place and we got a succes!

function Player.applyDeathAttributes(self, boolean, teleport)
   if boolean then
     self:setGroup(Group(deathGroupId))
     self:setHiddenHealth(true)
     if teleport then
       self:teleportTo(self:getTown():getTemplePosition())
       self:teleportTo(teleport)
     end
     self:allowMovement(false)
   else
     self:setGroup(Group(1))
     self:setHiddenHealth(false)
     self:allowMovement(true)
   end
end

function sendFirstCountdown(cid, times)
   local player = Player(cid)
   if player then
     if player:getGroup():getId() ~= deathGroupId then return true end
     --player:say("REVIVE ME!", TALKTYPE_MONSTER_SAY)
     player:sendTextMessage(MESSAGE_EXPERIENCE, player:getName().." have "..times.." seconds left to revive, please help "..(player:getSex() == PLAYERSEX_FEMALE and "her" or "him").."!", player:getPosition(), times, TEXTCOLOR_YELLOW)
     if times == 0 then
       buildModalWindow(cid)
       sendSecondCountdown(cid, 10)
       return true
     end
     addEvent(sendFirstCountdown, 1000, cid, times - 1)
   end
end

function sendSecondCountdown(cid, times)
   local player = Player(cid)
   if player then
     if player:getGroup():getId() ~= deathGroupId then return true end
     player:sendCancelMessage("Time left to die: "..times.." seconds.")
     if times == 0 then
       player:applyDeathAttributes(false)
       player:setStorageValue(deathStorage, 1)
       player:addHealth(-player:getHealth())
       return true
     end
     addEvent(sendSecondCountdown, 1000, cid, times - 1)
   end
end

function onLogin(player)
   player:setStorageValue(deathStorage, 0)

   if player:getGroup():getId() == deathGroupId then
     player:applyDeathAttributes(false)
   end
   return true
end

function buildModalWindow(cid)
   local player = Player(cid)
   local modal = ModalWindow(999, "You are dead!", "Which option do you want to use?\n\nTeleport:\nTeleport to the selected town for free.\n\nKill Me:\nIf you use this option you are going to die immediately.\n\nUse Item:\nUse this as payment to revive in the same place you died.\n\nYou have "..player:getItemCount(deathItemRevive).." "..ItemType(deathItemRevive):getName().." left to use.\n\n")

   for i = 1, #Game.getTowns() do
     modal:addChoice(i, Town(i):getName())
   end

   modal:addButton(1, "Teleport")
   modal:setDefaultEnterButton(1)
   modal:addButton(2, "Kill Me")
   modal:setDefaultEscapeButton(2)

   if player:getItemCount(deathItemRevive) >= 1 then
     modal:addButton(3, "Use Item")
   end

   return modal:sendToPlayer(player)
end

function onPrepareDeath(creature, killer)
   if creature:isPlayer() then
     local deathPos = creature:getPosition()

     if creature:getStorageValue(deathStorage) == 0 then
       creature:applyDeathAttributes(true, deathPos)

       if eldinFunction then
         sendFirstCountdown(creature:getId(), 5)
       else
         buildModalWindow(creature:getId())
         sendSecondCountdown(creature:getId(), 10)
       end

       condition:setOutfit(creature:getSex() == PLAYERSEX_FEMALE and 3065 or 3058)
       creature:addCondition(condition)
       return false
     else
       return true
     end
   end
   return true
end

function onModalWindow(player, modalWindowId, buttonId, choiceId)
   if modalWindowId ~= 999 then
     return false
   end

   if buttonId == 1 then
     player:applyDeathAttributes(false)
     player:removeCondition(CONDITION_OUTFIT)
     player:teleportTo(Town(choiceId):getTemplePosition())
     player:addHealth(player:getMaxHealth())
     player:addMana(player:getMaxMana())
     player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "[onModalWindow] USED THE FUCKING REVIVE.")
   end

   if buttonId == 2 then
     player:applyDeathAttributes(false)
     player:setStorageValue(deathStorage, 1)
     player:addHealth(-player:getHealth())
     player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "[onModalWindow] USED THE FUCKING GET KILLED.")
   end

   if buttonId == 3 then
     local item = player:getItemById(deathItemRevive, true)

     if player:getItemCount(deathItemRevive) == 0 then
       player:sendCancelMessage("You don't have any item revive.")
       return true
     end

     player:applyDeathAttributes(false)
     player:removeCondition(CONDITION_OUTFIT)
     player:addHealth(player:getMaxHealth())
     player:addMana(player:getMaxMana())
     item:remove(1)
     player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "[onModalWindow] USED THE FUCKING ITEM REVIVE.")
   end
   return true
end

help%20me%20revive_zpsyrikezj6.png
 
Last edited:
what does function Town(int) do?
Does not look like you need elaborate metadata generator.
I assume you ment to write:
Town[ i ]
 
For k,v in pairs(Town) do
If k then print(k) end
If v then print(v) end
Print()
End

Put instead of your loop right now and let us know if it prints something.

Another thing what you could try is. Put this inside your original for loop instead of addchoice
If Town(i) then
Print(Town(i):getName())
End

Typeing from android.
 
Back
Top