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

Action [TFS 1.X] Cursed Chests

oen432

Legendary OT User
Joined
Oct 3, 2014
Messages
1,900
Solutions
55
Reaction score
2,121
Location
Poland
GitHub
Oen44
Cursed Chests
Cursed Chests are a new treasure type chests that are spawned randomly on the map. They can't be just opened like any other, first, player will have to defend against waves of powerful monsters. After surviving and killing every spawned monster, chest will open with rewards inside.​


Installation

  1. Open data/actions/actions.xml.
  2. Add
    XML:
    <action actionid="9000" script="custom/cursed_chest.lua" />
  3. Open data/creaturescripts/creaturescripts.xml.
  4. Add
    XML:
    <event type="death" name="CursedChestsDeath" script="cursed_chests.lua" />
  5. Open data/globalevents/globalevents.xml.
  6. Add (300000 = 5 minutes, spawn new chest every 5 minutes)
    XML:
    <globalevent name="CursedChestSpawner" interval="300000" script="cursed_chest_spawner.lua"/>
  7. Open data/events/events.xml.
  8. Enable onMoveItem, set enabled="1" here
    XML:
    <event class="Player" method="onMoveItem" enabled="1" />
  9. Open data/events/scripts/player.lua.
  10. Find function Player:onMoveItem and add as first line in that function
    Lua:
    if item:getActionId() == CURSED_CHESTS_AID then return false end
  11. Open data/globalevents/scripts/startup.lua.
  12. At the end of the function onStartup (before last end) add this CursedChestsLoad().
  13. Open data/lib/core/position.lua.
  14. Add if you don't have this function
    Lua:
    function Position.sendAnimatedText(self, message)
        local specs = Game.getSpectators(self, false, true, 9, 9, 8, 8)
        if #specs > 0 then
            for i = 1, #specs do
                local player = specs[i]
                player:say(message, TALKTYPE_MONSTER_SAY, false, player, self)
            end
        end
    end
  15. Download cursed_chests.rar from attachment at the bottom of this post.
  16. Copy cursed_chest.lua to data/actions/scripts/custom/cursed_chest.lua.
  17. Copy cursed_chests.lua to data/creaturescripts/scripts/cursed_chests.lua.
  18. Copy cursed_chest_spawner.lua to data/globalevents/scripts/cursed_chest_spawner.lua.
Configuration
Basic chests configuration - data/actions/scripts/custom/cursed_chest.lua.
Here you can set chance to spawn given tier and text to be shown on spawned chest.
Change item to ids of your chests if you want different chest look for each tier.
Lua:
CURSED_CHESTS_TIERS = {
    {
        tier = CURSED_CHESTS_TIER_COMMON,
        chance = 70,
        text = "Common Cursed Chest",
        item = 1750
    },
    {
        tier = CURSED_CHESTS_TIER_RARE,
        chance = 50,
        text = "Rare Cursed Chest",
        item = 1750
    },
    {
        tier = CURSED_CHESTS_TIER_EPIC,
        chance = 30,
        text = "Epic Cursed Chest",
        item = 1750
    },
    {
        tier = CURSED_CHESTS_TIER_LEGENDARY,
        chance = 10,
        text = "Legendary Cursed Chest",
        item = 1750
    }
}
Rewards and waves are now configured separately for each tier. Example chest inside. Hope you get it.
CURSED_CHESTS_SKULL_DEFAULT - skull type to set to wave monsters.
CURSED_CHESTS_SKULL_BOSS - skull type to set to boss monster.

CURSED_CHESTS_CONFIG - here you can add, remove and adjust chests.
[1], [2] - these are Chests IDs, make sure they are unique to each other.
message - text to show when player activates the chest.

rewards - list of items that can be added to the chest after every monster dies.
chance - value in % indicates chance for that item to be added. If set to 100, then will be added only ONCE
item - ID of the item
amount - how many items to add
random - set to true if you want to randomize amount of that item (from 1 to amount set)

waves - list of monsters that are randomly chosen to spawn
"Monster Name" - name of the monster to spawn

boss - optional if you want to spawn Boss at the end
name - name of the monster to be Boss.
fightDuration - in seconds, if this time passes and boss is alive, chest and boss will be removed from the map, player failed.
message - text to show on the player when boss is about to be spawned

Chests spawn configuration - data/globalevents/scripts/cursed_chest_spawner.lua.
CURSED_CHESTS_AID - action id set to the chest, change if already in use, change in actions.xml too.
CURSED_CHESTS_SPAWNS - list of centers of the spawn area where chests can appear.
[1] - Spawn ID, make sure they are unique to each other.
pos - Center of the spawn area.
size - Size of the spawn area.
chests - list of Chests IDs that can be spawned in that area, eg. { 1, 2, 6, 10 }.
Changelog
[1.1.1] - 2019-03-28
  • Fixed spawning monsters and chests in PZ
[1.1.0] - 2019-03-27
  • Rewritten basic functionality
  • Chest and monsters won't spawn in PZ anymore
  • Removed level requirements to open chest
  • Added chest tiers
  • Changed monster spawning, amount of monsters depends on a wave number and tier of the chest
  • Monsters are spawned randomly from a list
  • If player is not in a party and activates the chest, only he is able to open that chest
  • If player is in a party and activates the chest, only he and party members are able to open that chest
  • If chest is not emptied and 5 minutes passes, it is removed from the map
  • Added poff effect when chest is removed
  • New configuration fields
[1.0.2] - 2019-03-21
  • New wave - Boss - starts after all waves are cleared (optional)
  • Added skulls to spawned monster (white for default, black for boss), to show which monster is from the chest
  • New configuration fields
[1.0.1] - 2019-03-20
  • Removed unnecessary code
[1.0.0] - 2019-03-20
  • Release version
 

Attachments

  • cursed_chests-1_1_1.rar
    4.4 KB · Views: 334 · VirusTotal
Last edited by a moderator:
Nice, some thoughts:
That position:compare isnt needed, pos1 == pos2 is enough, tfs has built-in compare for that
sendAnimatedText is only supported by otc, so warn people before adding that, it will crash any cipsoft client above 9.x.
 
Nice, some thoughts:
That position:compare isnt needed, pos1 == pos2 is enough, tfs has built-in compare for that
sendAnimatedText is only supported by otc, so warn people before adding that, it will crash any cipsoft client above 9.x.
Weird, I'm sure that it didn't work for me before, oh well, will change.
sendAnimatedText is not what you think it is. That is completely different function.
 
Weird, I'm sure that it didn't work for me before, oh well, will change.
sendAnimatedText is not what you think it is. That is completely different function.
Oh I see, it only sends orange message, rename it then, its confusing.
 
Oh I see, it only sends orange message, rename it then, its confusing.
Is it? Not sure. This is the only way to show text like that and it's made as a replacement, that's why I left the name. For me, any different name would be more confusing. Especially if you know what sendAnimatedText was.
 
I have not tested it yet, but its missing this function:

isBadTile(tile)
 
Oh! It was at the bottom, totally missed it there! Well done! Learned a few things with that script. Thanks for your contribution, really appreciate it.
 
Update! New version attached to first post. Posted new video to show most recent version (1.0.2).

[1.0.2] - 2019-03-21
  • New wave - Boss - starts after all waves are cleared (optional)
  • Added skulls to spawned monsters (white for default, black for boss), to show which monster is from the chest
  • New configuration fields
 
Last edited:
How do I add more chests to make a Tier Chests (Other Sprites)?
Like This:
35599
 
Oh, it's a good idea! I'll like a lot config with Spawn Chance and tier, lvl requirement for me it's a useless
 
Oh, it's a good idea! I'll like a lot config with Spawn Chance and tier, lvl requirement for me it's a useless
Well then, that should do it.

1. Replace cursed_chest_spawner.lua in data/globalevents/scripts
2. Open actions.xml and create 4 lines
XML:
<action itemid="1" script="custom/cursed_chest.lua" />
<action itemid="2" script="custom/cursed_chest.lua" />
<action itemid="3" script="custom/cursed_chest.lua" />
<action itemid="4" script="custom/cursed_chest.lua" />
Change itemid to ids of your chests.

3. Replace cursed_chest.lua in data/actions/scripts

Here you can set chance to spawn given rarity and text to be shown on spawned chest.
Change item to ids of your chests, just like in actions.xml.
Lua:
CURSED_CHESTS_TIERS = {
    {
        tier = CURSED_CHESTS_TIER_COMMON,
        chance = 70,
        text = "Common Cursed Chest",
        item = 1
    },
    {
        tier = CURSED_CHESTS_TIER_RARE,
        chance = 50,
        text = "Rare Cursed Chest",
        item = 2
    },
    {
        tier = CURSED_CHESTS_TIER_EPIC,
        chance = 30,
        text = "Epic Cursed Chest",
        item = 3
    },
    {
        tier = CURSED_CHESTS_TIER_LEGENDARY,
        chance = 10,
        text = "Legendary Cursed Chest",
        item = 4
    }
}
Rewards and waves are now configured separately for each tier. Example chest inside. Hope you get it.

Let me know if something is broken, didn't test it 🤣
Cheers!
 

Attachments

  • cursed_chest.lua
    14.1 KB · Views: 17 · VirusTotal
  • cursed_chest_spawner.lua
    1.7 KB · Views: 17 · VirusTotal
This number is for what?
Lua:
CURSED_CHESTS_TIER_COMMON = 1
CURSED_CHESTS_TIER_RARE = 2
CURSED_CHESTS_TIER_EPIC = 3
CURSED_CHESTS_TIER_LEGENDARY = 4
 
Ignore them.
Oh, ok, if i want add more Tier, I do like this?


Lua:
CURSED_CHESTS_TIER_COMMON = 1
CURSED_CHESTS_TIER_RARE = 2
CURSED_CHESTS_TIER_EPIC = 3
CURSED_CHESTS_TIER_LEGENDARY = 4
CURSED_CHESTS_TIER_NEW = 5
 
Oh, ok, if i want add more Tier, I do like this?


Lua:
CURSED_CHESTS_TIER_COMMON = 1
CURSED_CHESTS_TIER_RARE = 2
CURSED_CHESTS_TIER_EPIC = 3
CURSED_CHESTS_TIER_LEGENDARY = 4
CURSED_CHESTS_TIER_NEW = 5
Yeah, then add to CURSED_CHESTS_TIERS, don't forget about item ids in action.xml. That's all.
 
Thx a lot, nice script

Lua:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/cursed_chest_spawner.lua:onThink
data/globalevents/scripts/cursed_chest_spawner.lua:33: attempt to get length of global 'CURSED_CHESTS_TIERS' (a nil value)
stack traceback:
        [C]: in function '__len'
        data/globalevents/scripts/cursed_chest_spawner.lua:33: in function <data/globalevents/scripts/cursed_chest_spawner.lua:11>
[Error - GlobalEvents::think] Failed to execute event: CursedChestSpawner
Error when Chest will spawn
 
Lua:
Lua Script Error: [GlobalEvent Interface]
data/globalevents/scripts/cursed_chest_spawner.lua:onThink
data/globalevents/scripts/cursed_chest_spawner.lua:33: attempt to get length of global 'CURSED_CHESTS_TIERS' (a nil value)
stack traceback:
        [C]: in function '__len'
        data/globalevents/scripts/cursed_chest_spawner.lua:33: in function <data/globalevents/scripts/cursed_chest_spawner.lua:11>
[Error - GlobalEvents::think] Failed to execute event: CursedChestSpawner
Error when Chest will spawn
And cursed_chest.lua is loaded properly?
Works for me, just tested. Forgot about one thing tho, shouldn't cause errors just no text on a chest.
Open cursed_chest.lua in actions and change CURSED_CHESTS_ITEM_ID to data.rarity.item in ShowEffects
 
Back
Top