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

CreatureEvent [TFS 1.1] Revive System

I don't even know if this is possible, but maybe something like this?
Code:
function onCastSpell(creature, var)
    local player = Player(var)
    if player:getGroup():getId() == deathGroupId then
        player:applyDeathAttributes(false)
        player:removeCondition(CONDITION_OUTFIT)
        player:addHealth(player:getMaxHealth())
        player:addMana(player:getMaxMana())
    else
        --not "dead"
    end
    return true
end
 
I made mine with a talkaction. just have it check if player is in the death group id and if he is revive if not fail ez
 
Hello, i have a issue.

I'm using the last commit of TFS and everything works but when i die and select "use item" the windows just dissapears and die after the time ends...
There's no error on console, what can i do? >.<

Either doesn't teleport to towns
 
I made mine with a talkaction. just have it check if player is in the death group id and if he is revive if not fail ez
Post the script then!
Hello, i have a issue.

I'm using the last commit of TFS and everything works but when i die and select "use item" the windows just dissapears and die after the time ends...
There's no error on console, what can i do? >.<

Either doesn't teleport to towns

Maybe you didn't registered the event on the login.lua? It sounds like it.
 
Post the script then!


Maybe you didn't registered the event on the login.lua? It sounds like it.

It's on the events :(

Code:
function onLogin(player)
   
    --if getPlayerAccess(cid) > 3 then
      --doPlayerSendCancel(cid, "$@$Administrador")
      --doPlayerSendCancel(cid, " ")
    --end
   
    -- Free bless config
    freeBless = {
        level = 200,
        blesses = {1, 2, 3, 4, 5}
    }
    -- Free Bless config END

    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end

        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
   
    -- Free bless system
    if player:getLevel() <= freeBless.level then
        for i=1,#freeBless.blesses do
            player:addBlessing(freeBless.blesses[i])
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You received the free blessings available untill level 200.")
        end
    end
    -- Free bless system END

    -- Stamina
    nextUseStaminaTime[player.uid] = 0

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(STORAGEVALUE_PROMOTION)
        if not promotion and value ~= 1 then
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        elseif value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end

    -- Events
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    --Custom
    player:registerEvent("modalDeath")
    player:registerEvent("deathMW")
    player:registerEvent("loginDeath")
    player:registerEvent("tp_pad")
    player:registerEvent("tp_pad_register")
    player:registerEvent("modalAD")
    player:registerEvent("modalMD")
    return true
end
 
If is registered on creaturescripts.xml as well you should put some prints on the script so you can really check if is executed.
 
After "function onModalWindow(player, modalWindowId, buttonId, choiceId)"
You can add something like: print(modalWindowId.." - "..buttonId.." - "..choiceId) to see the info which the player selected on the window, and you can add more prints with random text just to keep track where the script is stopping or failing.
 
After "function onModalWindow(player, modalWindowId, buttonId, choiceId)"
You can add something like: print(modalWindowId.." - "..buttonId.." - "..choiceId) to see the info which the player selected on the window, and you can add more prints with random text just to keep track where the script is stopping or failing.

Tried and nothing appears, the buttons simply doesn't work... The print should appear on the console or i have to use a kind of LUA software for testing?
 
Post the script then!

Jeezus.... Doesnt even ask nicely... I Assumed everyone made it for themselves haha here it is... I havnt used it in awhile so not 100% its still working.


Code:
-- CONFIG --
local deathGroupId = 4 -- Add your death ID from your revive script here
local cost = 80 -- Add the spell mana cost here
local vocs = {2, 6} -- Add the vocation numbers you want to be able to use the spell.
local cooldown = 30 -- Add your cooldown in seconds.
-- END CONFIG --


-- CORE CODE --
function onSay(player, words, param)
  local target = Creature(param)
  
  if not target then
  player:sendCancelMessage("A player with this name cannot be found.")
  return false
  end

  if isInArray(vocs, player:getVocation():getId()) then
     if player:getStorageValue(987654) >= os.time() then
       player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You are still drained from your last revive!")
       return false
     end
       if player:getMana() < cost then
         player:sendCancelMessage("You dont have enough mana.")
         return false
       else
         if target:getGroup():getId() == deathGroupId then
           target:applyDeathAttributes(false)
           target:removeCondition(CONDITION_OUTFIT)
           target:addHealth(target:getMaxHealth())
           target:addMana(target:getMaxMana())
           player:addMana(-cost)
           player:setStorageValue(987654, os.time() + cooldown)
           return true
         end
       end
     else
       player:sendCancelMessage("Only Druids can cast this spell.")
       return false
     end
   end

EDIT: Updated spell.
 
Last edited:
Tried and nothing appears, the buttons simply doesn't work... The print should appear on the console or i have to use a kind of LUA software for testing?
The print should appear on the console window, is really weird tho, are you sure that you registered the script on the creaturescripts.xml file?
 
The print should appear on the console window, is really weird tho, are you sure that you registered the script on the creaturescripts.xml file?
He might have anotehr modal window registered or somthing
 
You see Test Knight (Level 15). He is a knight.

This is what i see when the player "dies" as god character when the player dies...
Shouldn't it say something like "He is a death player" ? Maybe there's my problem, the groupID isn't changing.

Heres my lines:

Code:
<group id="4" name="death player" flags="13194139558159" access="0" maxdepotitems="0" maxvipentries="0" />

and

Code:
local deathStorage = 51898
local deathGroupId = 4
local deathItemRevive = 2160
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!
 
He might have anotehr modal window registered or somthing
Code:
    player:registerEvent("tp_pad")
    player:registerEvent("tp_pad_register")
    player:registerEvent("modalAD")
    player:registerEvent("modalMD")

I'm using those, tp_pad and tp_pad_register for teleport system and modalAD/modalMD for addons and mounts item...
 
No, I didn't added any onLook script so the description should remain the same.

Check if you have this:
1.- creaturescripts/creaturescripts.xml
Add:
Code:
<event type="preparedeath" name="modalDeath" script="modaldeath.lua"/>
<event type="modalwindow" name="deathMW" script="modaldeath.lua"/>
<event type="login" name="loginDeath" script="modaldeath.lua"/>
 
The print should appear on the console window, is really weird tho, are you sure that you registered the script on the creaturescripts.xml file?

Creaturescripts.xml:
Code:
<!-- Revive System -->
    <event type="preparedeath" name="modalDeath" script="custom/modaldeath.lua"/>
    <event type="modalwindow" name="deathMW" script="custom/modaldeath.lua"/>
    <event type="login" name="loginDeath" script="custom/modaldeath.lua"/>
        <!-- Revive System END -->

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 = 49898
local deathGroupId = 4
local deathItemRevive = 2160
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

login.lua:

Code:
function onLogin(player)
   
    --if getPlayerAccess(cid) > 3 then
      --doPlayerSendCancel(cid, "$@$Administrador")
      --doPlayerSendCancel(cid, " ")
    --end
   
    -- Free bless config
    freeBless = {
        level = 200,
        blesses = {1, 2, 3, 4, 5}
    }
    -- Free Bless config END

    local loginStr = "Welcome to " .. configManager.getString(configKeys.SERVER_NAME) .. "!"
    if player:getLastLoginSaved() <= 0 then
        loginStr = loginStr .. " Please choose your outfit."
        player:sendOutfitWindow()
    else
        if loginStr ~= "" then
            player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
        end

        loginStr = string.format("Your last visit was on %s.", os.date("%a %b %d %X %Y", player:getLastLoginSaved()))
    end
    player:sendTextMessage(MESSAGE_STATUS_DEFAULT, loginStr)
   
    -- Free bless system
    if player:getLevel() <= freeBless.level then
        for i=1,#freeBless.blesses do
            player:addBlessing(freeBless.blesses[i])
            player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "You received the free blessings available untill level 200.")
        end
    end
    -- Free bless system END

    -- Stamina
    nextUseStaminaTime[player.uid] = 0

    -- Promotion
    local vocation = player:getVocation()
    local promotion = vocation:getPromotion()
    if player:isPremium() then
        local value = player:getStorageValue(STORAGEVALUE_PROMOTION)
        if not promotion and value ~= 1 then
            player:setStorageValue(STORAGEVALUE_PROMOTION, 1)
        elseif value == 1 then
            player:setVocation(promotion)
        end
    elseif not promotion then
        player:setVocation(vocation:getDemotion())
    end

    -- Events
    player:registerEvent("PlayerDeath")
    player:registerEvent("DropLoot")
    --Custom
    player:registerEvent("modalDeath")
    player:registerEvent("deathMW")
    player:registerEvent("loginDeath")
    player:registerEvent("tp_pad")
    player:registerEvent("tp_pad_register")
    player:registerEvent("modalAD")
    player:registerEvent("modalMD")
    return true
end

and groups.xml:

Code:
<?xml version="1.0" encoding="UTF-8"?>
<groups>
    <group id="1" name="player" flags="0" access="0" maxdepotitems="0" maxvipentries="0" />
    <group id="2" name="gamemaster" flags="137438953471" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="3" name="god" flags="272730398714" access="1" maxdepotitems="0" maxvipentries="200" />
    <group id="4" name="death player" flags="13194139558159" access="0" maxdepotitems="0" maxvipentries="0" />
</groups>
 
Back
Top