Colors
♥
- Joined
- Mar 22, 2013
- Messages
- 812
- Solutions
- 4
- Reaction score
- 271
ONLY tested vs monsters.
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:
2.- creaturescripts/scripts/yourlogin.lua
I don't really know how your register event is structured, so just register these events:
3.- creaturescripts/scripts/modaldeath.lua
XML:
1.- xml/groups.xml
This is the weird part, you have to add a new group with the following:
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
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" />
Note2: Sorry about the text messages
Last edited: