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

TalkAction Item, player, creature attribute talkaction

WibbenZ

Global Moderator
Staff member
Global Moderator
Joined
Oct 16, 2008
Messages
6,374
Solutions
229
Reaction score
1,503
Location
Sweden
The original script was made by @Darkhaos and can be found here: TalkAction - Command "/attr" in lua-script talkaction, you can add more functions. (https://otland.net/threads/command-attr-in-lua-script-talkaction-you-can-add-more-functions.33438/)

Added the functions I think most users will have a need for, if you need anything else then you can request it here in the thread or via pm to me.

If you find any bugs send me a pm or write it here in the thread.

I have only tested a few of them, but those that I tested worked.
Thanks to @yogiikke who tested the script for me :p

Usage: /attr desc, Hello world

Installation
talkactions.xml
XML:
<talkaction words="/attr" separator=" " script="attributes.lua" />

attributes.lua
Lua:
local itemFunctions = {
    ["actionid"] = { isActive = true, targetFunction = function (item, target) return item:setActionId(target) end },
    ["action"] = { isActive = true, targetFunction = function (item, target) return item:setActionId(target) end },
    ["aid"] = { isActive = true, targetFunction = function (item, target) return item:setActionId(target) end },
    ["description"] = { isActive = true, targetFunction = function (item, target) return item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, target) end },
    ["desc"] = { isActive = true, targetFunction = function (item, target) return item:setAttribute(ITEM_ATTRIBUTE_DESCRIPTION, target) end },
    ["remove"] = { isActive = true, targetFunction = function (item, target) return item:remove() end },
    ["decay"] = { isActive = true, targetFunction = function (item, target) return item:decay() end },
    ["transform"] = { isActive = true, targetFunction = function (item, target) return item:transform(target) end },
    ["clone"] = { isActive = true, targetFunction = function (item, target) return item:clone() end }
}

local creatureFunctions = {
    ["health"] = { isActive = true, targetFunction = function (creature, target) return creature:addHealth(target) end },
    ["mana"] = { isActive = true, targetFunction = function (creature, target) return creature:addMana(target) end },
    ["speed"] = { isActive = true, targetFunction = function (creature, target) return creature:changeSpeed(target) end },
    ["droploot"] = { isActive = true, targetFunction = function (creature, target) return creature:setDropLoot(target) end },
    ["skull"] = { isActive = true, targetFunction = function (creature, target) return creature:setSkull(target) end },
    ["direction"] = { isActive = true, targetFunction = function (creature, target) return creature:setDirection(target) end },
    ["maxHealth"] = { isActive = true, targetFunction = function (creature, target) return creature:setMaxHealth(target) end },
    ["say"] = { isActive = true, targetFunction = function (creature, target) creature:say(target, TALKTYPE_SAY) end }
}

local playerFunctions = {
    ["fyi"] = { isActive = true, targetFunction = function (player, target) return player:popupFYI(target) end },
    ["tutorial"] = { isActive = true, targetFunction = function (player, target) return player:sendTutorial(target) end },
    ["guildnick"] = { isActive = true, targetFunction = function (player, target) return player:setGuildNick(target) end },
    ["group"] = { isActive = true, targetFunction = function (player, target) return player:setGroup(Group(target)) end },
    ["vocation"] = { isActive = true, targetFunction = function (player, target) return player:setVocation(Vocation(target)) end },
    ["stamina"] = { isActive = true, targetFunction = function (player, target) return player:setStamina(target) end },
    ["town"] = { isActive = true, targetFunction = function (player, target) return player:setTown(Town(target)) end },
    ["balance"] = { isActive = true, targetFunction = function (player, target) return player:setBankBalance(target + player:getBankBalance()) end },
    ["save"] = { isActive = true, targetFunction = function (player, target) return target:save() end },
    ["type"] = { isActive = true, targetFunction = function (player, target) return player:setAccountType(target) end },
    ["skullTime"] = { isActive = true, targetFunction = function (player, target) return player:setSkullTime(target) end },
    ["maxMana"] = { isActive = true, targetFunction = function (player, target) return player:setMaxMana(target) end },
    ["addItem"] = { isActive = true, targetFunction = function (player, target) return player:addItem(target, 1) end },
    ["removeItem"] = { isActive = true, targetFunction = function (player, target) return player:removeItem(target, 1) end },
    ["premium"] = { isActive = true, targetFunction = function (player, target) return player:addPremiumDays(target) end }
}

function onSay(player, words, param)
    if not player:getGroup():getAccess() then
        return true
    end

    if player:getAccountType() < ACCOUNT_TYPE_GOD then
        return false
    end

    local split = param:split(",")
    if not split[1] then
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Command param required.")
        return false
    end

    local position = player:getPosition()
    position:getNextPosition(player:getDirection(), 1)

    local itemFunction = itemFunctions[split[1]]
    local creatureFunction = creatureFunctions[split[1]]
    local playerFunction = playerFunctions[split[1]]

    if itemFunction and itemFunction.isActive then
        local targetItem = Tile(position):getTopVisibleThing(player)
        if not targetItem or not targetItem:isItem() then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Item not found.")
            return false
        end

        if itemFunction.targetFunction(targetItem, split[2]) then
            position:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot add that attribute to this item.")
        end
    elseif creatureFunction and creatureFunction.isActive then
        local targetCreature = Tile(position):getTopCreature()
        if not targetCreature or not targetCreature:isCreature() then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Creature not found.")
            return false
        end

        if creatureFunction.targetFunction(targetCreature, split[2]) then
            position:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot add that attribute to this creature.")
        end
    elseif playerFunction and playerFunction.isActive then
        local targetPlayer = Tile(position):getTopCreature()
        if not targetPlayer or not targetPlayer:getPlayer() then
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Player not found.")
            return false
        end

        if playerFunction.targetFunction(targetPlayer, split[2]) then
            position:sendMagicEffect(CONST_ME_MAGIC_GREEN)
        else
            player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "You cannot add that attribute to this player.")
        end
    else
        player:sendTextMessage(MESSAGE_STATUS_CONSOLE_BLUE, "Unknow attribute.")
    end
    return false
end
 
Last edited by a moderator:
Can I request an add of more attributes? like Range, Hit%, Protection, and player level maybe? I added a few myself like setting an item name and so, but I can't seem to be able to add those. Could you help please?
EDIT: I added the Hit% xD I used HITPERCENT instead of HITCHANCE that's why I couldn't haha
 
@WibbenZ can you give me some attributes like , attack

You can't modify the attack value unless you do source edits, this script is for servers that run the default source code.
If a function like that is merged to the main repo I can update the script.
 
You can't modify the attack value unless you do source edits, this script is for servers that run the default source code.
If a function like that is merged to the main repo I can update the script.
if i want edit source can i edit it with stev's program?

after editing the source i have to compile it again?
 
if i want edit source can i edit it with stev's program?

after editing the source i have to compile it again?

"stev's?" = ?
You can use the default windows notepad program to edit the C++ and header files, MSVC or notepad++ etc etc
Any program you can edit text files in.

Yes.
 
"stev's?" = ?
You can use the default windows notepad program to edit the C++ and header files, MSVC or notepad++ etc etc
Any program you can edit text files in.

Yes.
compile means that after editing it with msvc click rebuild option?
 
is it possible that there is "<attribute key = "attackspeed" value = "1000" />" for tfs 1.3?
 
Back
Top