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

Lua Xikini's Free Scripting Service TFS 1.3

Status
Not open for further replies.

Xikini

I whore myself out for likes
Senator
Premium User
Joined
Nov 17, 2010
Messages
6,756
Solutions
578
Reaction score
5,305
Please request
actions / creatureevents / globalevents / npcs / movements / talkactions

Do not request
spells / weapons / monsters / source editing / database queries

My goal of this thread is to learn TFS 1.3 scripting.

------------------------------------
Support

If you have an issue with one of my scripts, I will attempt to help you, but not in this thread.
Make a thread in the support board.
Ensure to follow all rules of the support board.
Without all neccesary information it's impossible to help you.

------------------------------------
I will only be scripting for TFS 1.3

Not TFS 1.1 / 1.2
Not OTServBR / OTX
and certainly not TFS 0.4

When requesting a script, don't ask for "this script I saw on super popular OT".

I don't care where the idea came from.
I don't want to see a video of the script in action.

I'm here to learn how to script better.
Just describe what the script is supposed to do, and I'll try to make it.

Any script that I make in response to a request from this thread will be shared publically, here, in this thread.

I'm not going to make anything in private, so post your request in this thread only.
Please, for the love of god, don't pm me asking to make a script.
I will actually add you to my ignore list if you do that.
--------------

Anyways!

Thanks for coming by and checking the thread out.
If you think there is a better way to script something, feel free to let me know.
I'm here to learn.

Cheers,

Xikini

----

Completed Scripts

DPS Dummy -> using RevScripts
!playerinfo character name -> using RevScripts
Positional Text talkaction -> using RevScripts
||--> Updated version that can use text & effects
Vocational Item Bonus's -> using RevScripts
||--> Updated version with easier config.
Simple damge buff potion -> using Revscripts
Kill monster in specific area, remove stone for x seconds -> using RevScripts
Training Room Teleporter -> using RevScripts
Lever that removes/adds/transforms objects or ground tiles -> using RevScripts
Loot from monster goes into single backpack, no matter how much loot there is.
Extra loot in monsters, based on chance and tier list -> using RevScripts
||--> Updated version that allows specific monsters to have their own loot table
Random Item chest that disappears after use, and respawns after x time -> using RevScripts
Multiple players required to open passageway.
Monster Arena Lever (x amount of waves, complete all waves, teleport appears) -> using RevScripts
Daily Boosted Creatures (experience & loot chance of items)
||--> Updated main file of boosted creatures, so that it triggers at midnight, instead of when the server starts up.
Reward Chest - Extremely simple. -> using Revscripts
Simple Npc that can sell an item, via text.

----

Extremely useful libs that I use quite often.

data/lib/core/player.lua
Give player items by table

data/lib/core/container.lua
getContainerFreeSlots

----

To-Do List

Shalaby - Player death counter. (Movement and talkaction)
Shalaby - Npc kill monster task, with item reward.
Shalaby - Boss respawn after x time.

-------

Last spot I've read messages
 
Last edited:
Xikini, do you work in Othire 1.0 maybe? why did you choose tfs btw? i love you, you have helped me ever since i started in this community so i owe you a blowjob
 
@Nokturno Your "Random Item chest that disappears after use, and respawns after x time" script is finished.

I was semi-absent for awhile soo... sorry if you no longer need this.

Random Item chest that disappears after use, and respawns after x time.gif

data\scripts\ disappearingLootChest.lua
Lua:
--[[

Install this
https://otland.net/threads/tfs-1-x-give-player-items-by-table.260702/#post-2643954

]]--

--[[
 __  __     _      _        _               _    
 \ \/ /    (_)    | |__    (_)    _ _      (_)   
  >  <     | |    | / /    | |   | ' \     | |   
 /_/\_\   _|_|_   |_\_\   _|_|_  |_||_|   _|_|_  
_|"""""|_|"""""|_|"""""|_|"""""|_|"""""|_|"""""| 
"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-'"`-0-0-' 

]]--

local rewardsTable = {
    [45000] = {
        containerId = 10522, -- itemid of bag/backpack that holds items
        chestReturnTime = 10, -- in seconds.
        magicEffect = CONST_ME_TELEPORT,
        {2173, 5, 5, 2500}, 
        {2160, 1, 5, 10000}  --{itemid, amount_min, amount_max, chance/10000}
    },
    [45001] = {
        containerId = 1988,
        chestReturnTime = 5, -- 5 * 60 would be 5 minutes
        magicEffect = CONST_ME_TELEPORT,
        {2173, 5, 5, 2500},
        {2152, 1, 5, 10000}
    },
    [45002] = {
        containerId = 1987,
        chestReturnTime = 2,
        magicEffect = CONST_ME_TELEPORT,
        {2148, 1, 5, 10000},
        {2148, 1, 5, 10000},
        {2173, 5, 5, 2500},  -- 25% chance
        {2148, 1, 5, 10000}, -- 100% chance
        {2148, 1, 5, 10000}
    },
}

local function lootChestDeAndReappear(position, chestId, actionId, effect, timer)
    position:sendMagicEffect(effect)
    if timer > 0 then
        -- remove chest
        Tile(position):getItemById(chestId):remove()
        addEvent(lootChestDeAndReappear, timer, position, chestId, actionId, effect, 0)
    else
        -- reAdd chest with actionid
        local chest = Game.createItem(chestId, 1, position)
        chest:setActionId(actionId)
    end
end

local disappearingLootChest = Action()

function disappearingLootChest.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    -- confirm index exists
    local actionId = item:getActionId()
    local index = rewardsTable[actionId]
    if not index then
        print("LUA error: ActionId not in table." .. item:getActionId())
        return true
    end
    
    -- check chances and create rewardItems table
    local rewardItems = {}
    local amount = 0
    for i = 1, #index do
        if math.random(10000) <= index[i][4] then
            amount = math.random(index[i][2], index[i][3])
            table.insert(rewardItems, {index[i][1], amount})
        end
    end

    -- give rewardItems if any exist
    if #rewardItems > 0 then
        player:giveItems(rewardItems, index.containerId and index.containerId > 0 and index.containerId or 1987)
    end
    
    -- remove and reAdd the chest
    lootChestDeAndReappear(toPosition, item:getId(), actionId, index.magicEffect, index.chestReturnTime * 1000)
    return true
end

for actionid, _ in pairs(rewardsTable) do
    disappearingLootChest:aid(actionid) -- adds all actionid's from rewardsTable
end
disappearingLootChest:register()
 
@Shalaby your "Multiple players required to open passageway. (stand 3 tiles)" script is finished.

It isn't limited to 3 tiles however.
You can use 1, 2, 3, 4, 5, 6, 7, 8, 9+ tiles, if you add them to the table.

I was semi-absent for awhile soo... sorry if you no longer need this.

Multiple players required to open passageway. (stand 3 tiles).gif

data\scripts\ stepTilesRemoveObject.lua
Lua:
--[[

.------..------..------..------..------..------.
|X.--. ||I.--. ||K.--. ||I.--. ||N.--. ||I.--. |
| :/\: || (\/) || :/\: || (\/) || :(): || (\/) |
| (__) || :\/: || :\/: || :\/: || ()() || :\/: |
| '--'X|| '--'I|| '--'K|| '--'I|| '--'N|| '--'I|
`------'`------'`------'`------'`------'`------'

]]--

local config = {
    [45000] = {
        object = {
            position = Position(250, 242, 7),
            itemId = 1514,
            removeTimer = 4 -- seconds
        },
        tilePositions = {
            Position(248, 245, 7),
            Position(250, 245, 7),
            Position(252, 245, 7)
        }
    },
    [45001] = {
        object = {
            position = Position(1000, 1000, 7),
            itemId = 1111,
            removeTimer = 4
        },
        tilePositions = {
            Position(1000, 1000, 7),
            Position(1000, 1000, 7),
            Position(1000, 1000, 7)
        }
    }
}

local function removeAndReAddObject(position, objectId, timer)
    position:sendMagicEffect(CONST_ME_POFF)
    if timer > 0 then
        Tile(position):getItemById(objectId):remove()
        addEvent(removeAndReAddObject, timer, position, objectId, 0)
    else
        Game.createItem(objectId, 1, position)
    end
end

local stepTilesRemoveObject = MoveEvent()
stepTilesRemoveObject:type("stepin")

function stepTilesRemoveObject.onStepIn(player, item, position, fromPosition)

    -- confirm is player
    if not player:isPlayer() then
        return true
    end
    
    -- confirm index
    local actionId = item:getActionId()
    local index = config[actionId]
    if not index then
        print("LUA error: ActionId not in table." .. actionId)
        return true
    end
    
    -- confirm that object exists
    if Tile(index.object.position):getItemCountById(index.object.itemId) == 0 then
        position:sendMagicEffect(CONST_ME_POFF)
        return true
    end
    
    -- confirm if all tiles are occupied
    local positionAmount = #index.tilePositions
    local playerCount = 0
    for i = 1, positionAmount do
        local creature = Tile(index.tilePositions[i]):getTopCreature()
        if not creature or not creature:isPlayer() then
            index.tilePositions[i]:sendMagicEffect(CONST_ME_MAGIC_RED)
        else
            index.tilePositions[i]:sendMagicEffect(CONST_ME_MAGIC_GREEN)
            playerCount = playerCount + 1
        end            
    end
    
    -- remove and reAdd stone
    if playerCount == positionAmount then
        removeAndReAddObject(index.object.position, index.object.itemId, index.object.removeTimer * 1000)
    end    
    return true
end

for actionid, _ in pairs(config) do
    stepTilesRemoveObject:aid(actionid) -- adds all actionid's from config
end
stepTilesRemoveObject:register()
 
@Shalaby your "Multiple players required to open passageway. (stand 3 tiles)" script is finished.

It isn't limited to 3 tiles however.
You can use 1, 2, 3, 4, 5, 6, 7, 8, 9+ tiles, if you add them to the table.

I was semi-absent for awhile soo... sorry if you no longer need this.

View attachment 54322

data\scripts\ stepTilesRemoveObject.lua
Lua:
--[[

.------..------..------..------..------..------.
|X.--. ||I.--. ||K.--. ||I.--. ||N.--. ||I.--. |
| :/\: || (\/) || :/\: || (\/) || :(): || (\/) |
| (__) || :\/: || :\/: || :\/: || ()() || :\/: |
| '--'X|| '--'I|| '--'K|| '--'I|| '--'N|| '--'I|
`------'`------'`------'`------'`------'`------'

]]--

local config = {
    [45000] = {
        object = {
            position = Position(250, 242, 7),
            itemId = 1514,
            removeTimer = 4 -- seconds
        },
        tilePositions = {
            Position(248, 245, 7),
            Position(250, 245, 7),
            Position(252, 245, 7)
        }
    },
    [45001] = {
        object = {
            position = Position(1000, 1000, 7),
            itemId = 1111,
            removeTimer = 4
        },
        tilePositions = {
            Position(1000, 1000, 7),
            Position(1000, 1000, 7),
            Position(1000, 1000, 7)
        }
    }
}

local function removeAndReAddObject(position, objectId, timer)
    position:sendMagicEffect(CONST_ME_POFF)
    if timer > 0 then
        Tile(position):getItemById(objectId):remove()
        addEvent(removeAndReAddObject, timer, position, objectId, 0)
    else
        Game.createItem(objectId, 1, position)
    end
end

local stepTilesRemoveObject = MoveEvent()
stepTilesRemoveObject:type("stepin")

function stepTilesRemoveObject.onStepIn(player, item, position, fromPosition)

    -- confirm is player
    if not player:isPlayer() then
        return true
    end
   
    -- confirm index
    local actionId = item:getActionId()
    local index = config[actionId]
    if not index then
        print("LUA error: ActionId not in table." .. actionId)
        return true
    end
   
    -- confirm that object exists
    if Tile(index.object.position):getItemCountById(index.object.itemId) == 0 then
        position:sendMagicEffect(CONST_ME_POFF)
        return true
    end
   
    -- confirm if all tiles are occupied
    local positionAmount = #index.tilePositions
    local playerCount = 0
    for i = 1, positionAmount do
        local creature = Tile(index.tilePositions[i]):getTopCreature()
        if not creature or not creature:isPlayer() then
            index.tilePositions[i]:sendMagicEffect(CONST_ME_MAGIC_RED)
        else
            index.tilePositions[i]:sendMagicEffect(CONST_ME_MAGIC_GREEN)
            playerCount = playerCount + 1
        end           
    end
   
    -- remove and reAdd stone
    if playerCount == positionAmount then
        removeAndReAddObject(index.object.position, index.object.itemId, index.object.removeTimer * 1000)
    end   
    return true
end

for actionid, _ in pairs(config) do
    stepTilesRemoveObject:aid(actionid) -- adds all actionid's from config
end
stepTilesRemoveObject:register()
This is all movements script right? Because dont have revscript so i gonna convert it
 
[SCRIPT 1]
Create a system that allow players to buy land and build their own house in the land.
Players can also desconstruct anything they already done in the house and receive the materials back.
Only the player that own that land can build and desconstruct.
Also only allow similar walls and doors to be build. For example, if player build stone wall, he can't put wood wall side by side of a stone wall, just to keep the houses in the server looking normal.








[SCRIPT 2]
Post automatically merged:

How about that same script, but instead of removing it, adding floor?

and Done. :)
Note: don't trap your players. 😋

View attachment 49241


Put this into any monster you want the script to activate for.
XML:
<script>
    <event name="onDeath_open_passageway" />
</script>

data\scripts\ onDeath_open_passageway.lua
Lua:
local config = {
    positionCheck = {north_west = Position(99, 99, 7), south_east = Position(101, 101, 7)},
    item = {Position(103, 100, 7), 1285}, -- {item_position, itemid}
    timer = 20, -- timer is how long until the 'stone' aka: item, is replaced.
    discoveryText = "A passageway has opened nearby!\nQuickly, get inside!"
}

local toggle = 0
local function changePassageway()
    local item = Tile(config.item[1]):getItemById(config.item[2])
    if item then
        item:remove()
        return true
    end
    config.item[1]:sendMagicEffect(CONST_ME_BIGPLANTS)
    Game.createItem(config.item[2], 1, config.item[1])
    toggle = 0
end

local creatureevent = CreatureEvent("onDeath_open_passageway")

function creatureevent.onDeath(creature, corpse, killer, mostDamageKiller, lastHitUnjustified, mostDamageUnjustified)
    if toggle == 1 then
        return true
    end
    local deathPosition = creature:getPosition()
    if not deathPosition:isInRange(config.positionCheck.north_west, config.positionCheck.south_east) then
        return true
    end
    toggle = 1
    config.item[1]:sendMagicEffect(CONST_ME_POFF)
    changePassageway()
    addEvent(changePassageway, config.timer * 1000)
    creature:say(config.discoveryText, TALKTYPE_MONSTER_SAY, false, nil, deathPosition)  
    return true
end

creatureevent:register()
The script will work the same way I guess, but its for a pirate boat. When you kill 50 pirates (any type of pirate), will appear a floor (bridge) that will conect the boats. The bridge will be active until the boss die. (the boss is in the small boat).

View attachment 54448

View attachment 54447
 
Last edited:
hello, I would need a spell that, when used on an opponent, takes him to certain positions on the map and returns with him in five seconds, thank you ^^
 
Hi , if u are still taking request then i would like to request one:
- Creating npc next to player
-To create npc you need item X and item Y (ids) together in your bp
-Npc can give X Money or Y Experience(can only choose one)
-After giving what you chose npc dissapears
-Only player who create npc can talk to him
-After you get reward the item dissapear from bp.
-Cant use item to create npc if he is already created by me, items become inactive during the time he is created.

Thanks in advance.
 
hey man, nice thread :)
If you're still taking requests I would like something like this:
A "bury treasure" system
Would be like this:
The player use a shovel (or any item of your election) and you can make a hole in any ground (grass, desert, snow etc.) could be a custom "hole" item, and you can hide items inside like a depot, then after a X time the hole will decay to the gound that was before and the char can back later and take the buried stuff, it means, all the grounds of the server could be a potential depot or a place to hide things (lootbags, weapons, gp, etc) without need to go to the dp
It is possible?
 
Last edited:
Hello, I would like a script made in movements.
The player can only pass through the floor if it has storage X

Thanks
Lua:
local storage = 45001

function onStepIn(creature, item, position, fromPosition)
    if not creature:isPlayer() then
        return true
    end
    if creature:getStorageValue(storage) == -1 then
        player:teleportTo(fromPosition)
        creature:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Sorry, you cannot pass.")
        return true
    end
    return true
end
 
Thanks for the last script. @Xikini

Create a damage formula for each vocation. My general idea is that sorcerers have more damage than druids.

My script (default):
Lua:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_DEATHDAMAGE)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MORTAREA)
combat:setParameter(COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_SUDDENDEATH)

function onGetFormulaValues(player, level, magicLevel)
    local min = (level / 5) + (magicLevel * 4.3) + 32
    local max = (level / 5) + (magicLevel * 7.4) + 48
    return -min, -max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    return combat:execute(creature, variant)
end
 
Status
Not open for further replies.
Back
Top