T
Tibia Demon
Guest
i try to complete this script alone for days but i fail. i will write full script and explain all parts here and in tags too
if someone can help complete or remake for better one
full script
here i check if no global storage player learn first spell. if global storage then go next
here i check if no global storage player learn second spell. if global storage then go next
here i check if no global storage player learn third spell. if global storage then go next
here i check if no global storage player learn forth spell. if global storage then continue quest.
so this 4 checks all check. if not player has 4 storages [any of 4 spell storage] then it teach player next spell depend on [server global storage] and clean. and repeat for other teams and players. all 4 check work maybe there better way for write it cuz i add many [and].
next part.
here i check if players in quest room other cant go in. player only come to this part if he finished check up so he got 1 of 4 spells up
here i check if 4 player in right pos and no 1 joined quest today then go
here i check if items in pos remove all items and continue quest.
if no items in pos np continue. its removed before or server restart.
if all up done player continue quest to here and have 1 hour for quest
all up work like i explain 100% i cant continue this here
i need to add check if player in pos has storage and if not dont go quest this storage in settings table with pos
and this storages too
i need to add check if player in pos has spell and if not dont go quest this spell in settings table with pos
i need when player join if monster in remove monster
i need when player kick after 1h if time pass remove all items if there in pos.
and create 1 item in pos (956, 923, 7) with action id 5013
this big script idk if someone have time to help but helping with 1 part is very good too.
sorry if i explain anything bad. i can explain any part again just ask.
if someone can help complete or remake for better one
full script
Lua:
-- this config for check if player got spell. next player get next spell for this i use global storage.
local config = {
AddGroundGlobalStorage = PlayerStorageKeys.addgroundglobalstorage, -- 1 player got first spell add global storage. for next player get next spell
RemoveStoneGlobalStorage = PlayerStorageKeys.removestoneglobalstorage, -- 1 player got second spell add global storage. for next player get next spell
AddWallGlobalStorage = PlayerStorageKeys.addwallglobalstorage, -- 1 player got third spell add global storage. for next player get next spell
RemoveWallGlobalStorage = PlayerStorageKeys.removewallglobalstorage, -- 1 player got fourth spell add global storage and clean global storage for other teams
AddGroundPlayerStorage = PlayerStorageKeys.addgroundplayerstorage, -- player storage for check if got spell cant get other spell after global storage clean
RemoveStonePlayerStorage = PlayerStorageKeys.removestoneplayerstorage, -- player storage for check if got spell cant get other spell after global storage clean
AddWallPlayerStorage = PlayerStorageKeys.addwallplayerstorage, -- player storage for check if got spell cant get other spell after global storage clean
RemoveWallPlayerStorage = PlayerStorageKeys.removewallplayerstorage, -- player storage for check if got spell cant get other spell after global storage clean
AddGround = "Grounder", -- first spell
RemoveStone = "Stonebreaker", -- second spell
AddWall = "Builder", -- third spell
RemoveWall = "Destroyer", -- forth spell
ActionID = 5006
}
local settings = {
-- stand players pos
playerPositions = {
Position(1018, 953, 7),
Position(1022, 957, 7),
Position(1018, 961, 7),
Position(1014, 957, 7)
},
-- new players pos after use
newPositions = {
Position(957, 943, 7),
Position(957, 944, 7),
Position(956, 944, 7),
Position(956, 943, 7)
},
HasSpellstorages = {
{hasAddGroundStorage = PlayerStorageKeys.addgroundplayerstorage}, -- player in this pos should have this storage Position(1018, 953, 7),
{hasRemoveStoneStorage = PlayerStorageKeys.removestoneplayerstorage}, -- player in this pos should have this storage Position(1022, 957, 7),
{hasAddWallStorage = PlayerStorageKeys.addwallplayerstorage}, -- player in this pos should have this storage Position(1018, 961, 7),
{hasRemoveWallStorage = PlayerStorageKeys.removewallplayerstorage} -- player in this pos should have this storage Position(1014, 957, 7)
},
spells = {
{AddGround = "Grounder"}, -- player in this pos should have this spell Position(1018, 953, 7),
{RemoveStone = "Stonebreaker"}, -- player in this pos should have this spell Position(1022, 957, 7),
{AddWall = "Builder"}, -- player in this pos should have this spell Position(1018, 961, 7),
{RemoveWall = "Destroyer"} -- player in this pos should have this spell Position(1014, 957, 7)
},
-- need check if not spell > os.time() then dont go quest. this storage for player when use spell
timedstorages = {
{usedAddGroundStorage = PlayerStorageKeys.addgroundtimedstorage}, -- player in this pos should have this storage Position(1018, 953, 7),
{usedRemoveStoneStorage = PlayerStorageKeys.removestonetimedstorage}, -- player in this pos should have this storage Position(1022, 957, 7),
{usedAddWallStorage = PlayerStorageKeys.addwalltimedstorage}, -- player in this pos should have this storage Position(1018, 961, 7),
{usedRemoveWallStorage = PlayerStorageKeys.removewalltimedstorage} -- player in this pos should have this storage Position(1014, 957, 7)
},
-- if item in pos remove. if not item exist in pos. continue script normal
itemstoRemove = {
{position = Position(962, 942, 7), itemid = 1730},
{position = Position(949, 942, 7), itemid = 1730},
{position = Position(949, 926, 7), itemid = 1730},
{position = Position(962, 926, 7), itemid = 1730},
{position = Position(965, 939, 7), itemid = 1543},
{position = Position(947, 939, 7), itemid = 1543},
{position = Position(947, 923, 7), itemid = 1543},
{position = Position(965, 923, 7), itemid = 1543}
},
-- for check if players in room
centrePosition = {Position(975, 1011, 7), 10, 10, 10, 10},
-- kick pos after time
kickPosition = {x = 1000, y = 1000, z = 7},
-- player made quest need wait after restart for i clean this storage onstartup
JoinedQuestStorage = PlayerStorageKeys.joinrebirthqueststorage
}
local rebirthmagictree = Action()
function rebirthmagictree.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if
Game.getStorageValue(config.AddGroundGlobalStorage) ~= 1 and
player:getStorageValue(config.AddGroundPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveStonePlayerStorage) ~= 1 and
player:getStorageValue(config.AddWallPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveWallPlayerStorage) ~= 1
then
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
player:learnSpell(config.AddGround)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "i will add msg.")
player:setStorageValue(config.AddGroundPlayerStorage, 1)
Game.setStorageValue(config.AddGroundGlobalStorage, 1)
if Game.getStorageValue(config.RemoveStoneGlobalStorage) == 1 then
Game.setStorageValue(config.RemoveStoneGlobalStorage, 0)
end
return true
end
if
Game.getStorageValue(config.RemoveStoneGlobalStorage) ~= 1 and
player:getStorageValue(config.AddGroundPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveStonePlayerStorage) ~= 1 and
player:getStorageValue(config.AddWallPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveWallPlayerStorage) ~= 1
then
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
player:learnSpell(config.RemoveStone)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "i will add msg.")
player:setStorageValue(config.RemoveStonePlayerStorage, 1)
Game.setStorageValue(config.RemoveStoneGlobalStorage, 1)
if Game.getStorageValue(config.AddWallGlobalStorage) == 1 then
Game.setStorageValue(config.AddWallGlobalStorage, 0)
end
return true
end
if
Game.getStorageValue(config.AddWallGlobalStorage) ~= 1 and
player:getStorageValue(config.AddGroundPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveStonePlayerStorage) ~= 1 and
player:getStorageValue(config.AddWallPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveWallPlayerStorage) ~= 1
then
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
player:learnSpell(config.AddWall)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "i will add msg.")
player:setStorageValue(config.AddWallPlayerStorage, 1)
Game.setStorageValue(config.AddWallGlobalStorage, 1)
if Game.getStorageValue(config.RemoveWallGlobalStorage) == 1 then
Game.setStorageValue(config.RemoveWallGlobalStorage, 0)
end
return true
end
if
Game.getStorageValue(config.RemoveWallGlobalStorage) ~= 1 and
player:getStorageValue(config.AddGroundPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveStonePlayerStorage) ~= 1 and
player:getStorageValue(config.AddWallPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveWallPlayerStorage) ~= 1
then
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
player:learnSpell(config.RemoveWall)
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "i will add msg.")
player:setStorageValue(config.RemoveWallPlayerStorage, 1)
Game.setStorageValue(config.RemoveWallGlobalStorage, 1)
if Game.getStorageValue(config.AddGroundGlobalStorage) == 1 then
Game.setStorageValue(config.AddGroundGlobalStorage, 0)
end
return true
end
local spectators =
Game.getSpectators(
settings.centrePosition[i][1],
false,
false,
settings.centrePosition[i][2],
settings.centrePosition[i][3],
settings.centrePosition[i][4],
settings.centrePosition[i][5]
)
for i = 1, #spectators do
if spectators[i]:isPlayer() then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "team is inside quest!.")
return true
end
end
local storePlayers, playerTile = {}
for i = 1, #settings.playerPositions do
playerTile = Tile(settings.playerPositions[i]):getTopCreature()
if not playerTile or not playerTile:isPlayer() then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "you need 4 players for quest!.")
return true
end
if playerTile:getStorageValue(PlayerStorageKeys.JoinedQuestStorage) == 1 then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_INFO_DESCR, "1 player tried this quest")
return true
end
storePlayers[#storePlayers + 1] = playerTile
end
local requiredItems, foundItem = {}
for _, requiredItem in ipairs(settings.itemstoRemove) do
foundItem = Tile(requiredItem.position):getItemById(requiredItem.itemid)
requiredItems[#requiredItems + 1] = foundItem
end
for _, itemToRemove in ipairs(requiredItems) do
itemToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
itemToRemove:remove(1)
end
local players
for i = 1, #storePlayers do
players = storePlayers[i]
settings.playerPositions[i]:sendMagicEffect(CONST_ME_TELEPORT)
players:teleportTo(settings.newPositions[i])
settings.newPositions[i]:sendMagicEffect(CONST_ME_HITAREA)
players:setDirection(DIRECTION_NORTH)
players:setStorageValue(PlayerStorageKeys.JoinedQuestStorage, 1)
config.kickPlayersEventId =
addEvent(
function(cid)
local playerToRemove = Player(cid)
if not playerToRemove or not playerToRemove:isPlayer() then
return nil
end
if playerToRemove then
local playerToRemovePosition = playerToRemove:getPosition()
local leftTopCorner = Position(944, 922, 7)
local rightBottomCorner = Position(968, 946, 7)
if playerToRemovePosition:isInRange(leftTopCorner, rightBottomCorner) then
playerToRemove:getPosition():sendMagicEffect(CONST_ME_POFF)
playerToRemove:teleportTo(Position(settings.kickPosition))
playerToRemove:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
end
end,
60 * 60 * 1000,
players:getId()
)
end
return true
end
rebirthmagictree:aid(config.ActionID)
rebirthmagictree:register()
here i check if no global storage player learn first spell. if global storage then go next
Lua:
-- if player dont have any of 4 storage mean he didnt take any spell so continue
-- if server dont have this global storage so no other player of the team took this spell
if
Game.getStorageValue(config.AddGroundGlobalStorage) ~= 1 and
player:getStorageValue(config.AddGroundPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveStonePlayerStorage) ~= 1 and
player:getStorageValue(config.AddWallPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveWallPlayerStorage) ~= 1
then
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
player:learnSpell(config.AddGround) -- here i add first spell
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "i will add msg.")
player:setStorageValue(config.AddGroundPlayerStorage, 1) --i add this so same player not take all 4 spell
Game.setStorageValue(config.AddGroundGlobalStorage, 1) -- i add this so next player of the 4 in quest take next spell not same spell
if Game.getStorageValue(config.RemoveStoneGlobalStorage) == 1 then -- here i clean next global storage so if 1 player of previous team took it. this is another team so can take it too
Game.setStorageValue(config.RemoveStoneGlobalStorage, 0)
end
return true
end
Lua:
-- if player dont have any of 4 storage mean he didnt take any spell so continue
-- if server dont have this global storage so no other player of the team took this spell
if
Game.getStorageValue(config.RemoveStoneGlobalStorage) ~= 1 and
player:getStorageValue(config.AddGroundPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveStonePlayerStorage) ~= 1 and
player:getStorageValue(config.AddWallPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveWallPlayerStorage) ~= 1
then
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
player:learnSpell(config.RemoveStone) -- here i add second spell
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "i will add msg.")
player:setStorageValue(config.RemoveStonePlayerStorage, 1) --i add this so same player not take all 4 spell
Game.setStorageValue(config.RemoveStoneGlobalStorage, 1) -- i add this so next player of the 4 in quest take next spell not same spell
if Game.getStorageValue(config.AddWallGlobalStorage) == 1 then -- here i clean next global storage so if 1 player of previous team took it. this is another team so can take it too
Game.setStorageValue(config.AddWallGlobalStorage, 0)
end
return true
end
Lua:
-- if player dont have any of 4 storage mean he didnt take any spell so continue
-- if server dont have this global storage so no other player of the team took this spell
if
Game.getStorageValue(config.AddWallGlobalStorage) ~= 1 and
player:getStorageValue(config.AddGroundPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveStonePlayerStorage) ~= 1 and
player:getStorageValue(config.AddWallPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveWallPlayerStorage) ~= 1
then
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
player:learnSpell(config.AddWall) -- here i add third spell
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "i will add msg.")
player:setStorageValue(config.AddWallPlayerStorage, 1) --i add this so same player not take all 4 spell
Game.setStorageValue(config.AddWallGlobalStorage, 1)
if Game.getStorageValue(config.RemoveWallGlobalStorage) == 1 then -- here i clean next global storage so if 1 player of previous team took it. this is another team so can take it too
Game.setStorageValue(config.RemoveWallGlobalStorage, 0)
end
return true
end
Lua:
-- if player dont have any of 4 storage mean he didnt take any spell so continue
-- if server dont have this global storage so no other player of the team took this spell
if
Game.getStorageValue(config.RemoveWallGlobalStorage) ~= 1 and
player:getStorageValue(config.AddGroundPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveStonePlayerStorage) ~= 1 and
player:getStorageValue(config.AddWallPlayerStorage) ~= 1 and
player:getStorageValue(config.RemoveWallPlayerStorage) ~= 1
then
player:getPosition():sendMagicEffect(CONST_ME_HITAREA)
toPosition:sendMagicEffect(CONST_ME_TELEPORT)
player:learnSpell(config.RemoveWall) -- here i add forth spell
player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "i will add msg.")
player:setStorageValue(config.RemoveWallPlayerStorage, 1) --i add this so same player not take all 4 spell
Game.setStorageValue(config.RemoveWallGlobalStorage, 1)
if Game.getStorageValue(config.AddGroundGlobalStorage) == 1 then -- here i clean next global storage so if 1 player of previous team took it. next another team so can take it too
Game.setStorageValue(config.AddGroundGlobalStorage, 0)
end
return true
end
next part.
here i check if players in quest room other cant go in. player only come to this part if he finished check up so he got 1 of 4 spells up
Lua:
-- if any players in room from centreposition in settings table then return true
local spectators =
Game.getSpectators(
settings.centrePosition[i][1],
false,
false,
settings.centrePosition[i][2],
settings.centrePosition[i][3],
settings.centrePosition[i][4],
settings.centrePosition[i][5]
)
for i = 1, #spectators do
if spectators[i]:isPlayer() then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "team is inside quest!.")
return true
end
end
Lua:
-- if 1 player has JoinedQuestStorage then he cant go [i clean this in server startup] so he go 1 time every restart
local storePlayers, playerTile = {}
for i = 1, #settings.playerPositions do
playerTile = Tile(settings.playerPositions[i]):getTopCreature()
if not playerTile or not playerTile:isPlayer() then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_STATUS_SMALL, "you need 4 players for quest!.")
return true
end
if playerTile:getStorageValue(PlayerStorageKeys.JoinedQuestStorage) == 1 then
player:getPosition():sendMagicEffect(CONST_ME_POFF)
player:sendTextMessage(MESSAGE_INFO_DESCR, "1 player tried this quest")
return true
end
storePlayers[#storePlayers + 1] = playerTile
end
if no items in pos np continue. its removed before or server restart.
Lua:
-- players cant go only if [items in pos not removed] must remove first
local requiredItems, foundItem = {}
for _, requiredItem in ipairs(settings.itemstoRemove) do
foundItem = Tile(requiredItem.position):getItemById(requiredItem.itemid)
requiredItems[#requiredItems + 1] = foundItem
end
for _, itemToRemove in ipairs(requiredItems) do
itemToRemove:getPosition():sendMagicEffect(CONST_ME_MAGIC_RED)
itemToRemove:remove(1)
end
Lua:
-- here player join quest and have 1 hour before quick
local players
for i = 1, #storePlayers do
players = storePlayers[i]
settings.playerPositions[i]:sendMagicEffect(CONST_ME_TELEPORT)
players:teleportTo(settings.newPositions[i])
settings.newPositions[i]:sendMagicEffect(CONST_ME_HITAREA)
players:setDirection(DIRECTION_NORTH)
players:setStorageValue(PlayerStorageKeys.JoinedQuestStorage, 1)
config.kickPlayersEventId =
addEvent(
function(cid)
local playerToRemove = Player(cid)
if not playerToRemove or not playerToRemove:isPlayer() then
return nil
end
if playerToRemove then
local playerToRemovePosition = playerToRemove:getPosition()
local leftTopCorner = Position(944, 922, 7)
local rightBottomCorner = Position(968, 946, 7)
if playerToRemovePosition:isInRange(leftTopCorner, rightBottomCorner) then
playerToRemove:getPosition():sendMagicEffect(CONST_ME_POFF)
playerToRemove:teleportTo(Position(settings.kickPosition))
playerToRemove:getPosition():sendMagicEffect(CONST_ME_TELEPORT)
end
end
end,
60 * 60 * 1000,
players:getId()
)
return true
end
i need to add check if player in pos has storage and if not dont go quest this storage in settings table with pos
Lua:
HasSpellstorages = {
{hasAddGroundStorage = PlayerStorageKeys.addgroundplayerstorage}, -- player in this pos should have this storage Position(1018, 953, 7),
{hasRemoveStoneStorage = PlayerStorageKeys.removestoneplayerstorage}, -- player in this pos should have this storage Position(1022, 957, 7),
{hasAddWallStorage = PlayerStorageKeys.addwallplayerstorage}, -- player in this pos should have this storage Position(1018, 961, 7),
{hasRemoveWallStorage = PlayerStorageKeys.removewallplayerstorage} -- player in this pos should have this storage Position(1014, 957, 7)
},
Lua:
-- need check if not spell > os.time() then dont go quest. this storage for player when use spell
timedstorages = {
{usedAddGroundStorage = PlayerStorageKeys.addgroundtimedstorage}, -- player in this pos should have this storage Position(1018, 953, 7),
{usedRemoveStoneStorage = PlayerStorageKeys.removestonetimedstorage}, -- player in this pos should have this storage Position(1022, 957, 7),
{usedAddWallStorage = PlayerStorageKeys.addwalltimedstorage}, -- player in this pos should have this storage Position(1018, 961, 7),
{usedRemoveWallStorage = PlayerStorageKeys.removewalltimedstorage} -- player in this pos should have this storage Position(1014, 957, 7)
},
Lua:
spells = {
{AddGround = "Grounder"}, -- player in this pos should have this spell Position(1018, 953, 7),
{RemoveStone = "Stonebreaker"}, -- player in this pos should have this spell Position(1022, 957, 7),
{AddWall = "Builder"}, -- player in this pos should have this spell Position(1018, 961, 7),
{RemoveWall = "Destroyer"} -- player in this pos should have this spell Position(1014, 957, 7)
},
i need when player kick after 1h if time pass remove all items if there in pos.
Lua:
itemstoRemove = {
{position = Position(962, 942, 7), itemid = 1730},
{position = Position(949, 942, 7), itemid = 1730},
{position = Position(949, 926, 7), itemid = 1730},
{position = Position(962, 926, 7), itemid = 1730},
{position = Position(965, 939, 7), itemid = 1543},
{position = Position(947, 939, 7), itemid = 1543},
{position = Position(947, 923, 7), itemid = 1543},
{position = Position(965, 923, 7), itemid = 1543}
},
this big script idk if someone have time to help but helping with 1 part is very good too.
sorry if i explain anything bad. i can explain any part again just ask.