• 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

Colors

Joined
Mar 22, 2013
Messages
812
Solutions
4
Reaction score
271
ONLY tested vs monsters.

49c77a6108.png

Left: How other players see you while you are with the modalwindow on.
Right: The dead player got the modalwindow.


Creaturescripts:
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"/>

2.- creaturescripts/scripts/yourlogin.lua
I don't really know how your register event is structured, so just register these events:
Code:
modalDeath
deathMW
loginDeath

3.- creaturescripts/scripts/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 = YOUR STORAGE ID HERE
local deathGroupId = YOUR NEW GROUP ID HERE
local deathItemRevive = YOUR REVIVE ITEM ID HERE
local eldinFunction = true --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

XML:
1.- xml/groups.xml

This is the weird part, you have to add a new group with the following:
Code:
<group id="YOUR ID HERE" name="death player" flags="13194139558159" access="0" maxdepotitems="0" maxvipentries="0" />
Note: the group id needs to be the same as the one declared on the creaturescripts/scripts/modaldeath.lua.

Note2: Sorry about the text messages :p
 
Last edited:
Awesome!

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!
Will use it anyway but it would be Amazing.

Kind Regards,
Eldin.
 
Awesome!

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!
Will use it anyway but it would be Amazing.

Kind Regards,
Eldin.
All my scripts posted here on OTLand are more like POC, but yeah that could be added... Sounds really nice.
 
nice, gj, my question is: how the heck you got that popup window so wide and large?
mines are so freaking small i have to cut my sentences nonstop.
 
Piece Of Cake
Priceless.

nice, gj, my question is: how the heck you got that popup window so wide and large?
mines are so freaking small i have to cut my sentences nonstop.
They are auto-sized by the client I guess, you can leave the inner text to " " (a lot of blank spaces, the forum just let me put one) to make it more wide if your text is short.
 
I found this error when I click : Kill me
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/creaturescripts/scripts/modaldeath.lua:9: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/modaldeath.lua:9: in function <data/creatur
escripts/scripts/modaldeath.lua:8>

Also my backpack/bag dont dropping when i used Kill me. Why?
 
I found this error when I click : Kill me
Code:
Lua Script Error: [Main Interface]
in a timer event called from:
(Unknown scriptfile)
data/creaturescripts/scripts/modaldeath.lua:9: attempt to index a nil value
stack traceback:
        [C]: in function '__index'
        data/creaturescripts/scripts/modaldeath.lua:9: in function <data/creatur
escripts/scripts/modaldeath.lua:8>

Also my backpack/bag dont dropping when i used Kill me. Why?

Change your actual sendCountdown to this one:
Code:
function sendCountdown(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:setGroup(Group(1))
            player:setStorageValue(deathStorage, 1)
            player:setHiddenHealth(false)
            player:allowMovement(true)
            player:addHealth(-player:getHealth())
            return true
        end
        addEvent(sendCountdown, 1000, cid, times - 1)
    end
end

As for the item drop... I have no idea, I just tested it and is working fine o_O

@EDIT: Made some changes/fixes in the code, now it doesn't have a lot of repeated functions like before and added the "eldin feature".
 
Last edited:
Back
Top