• 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 Changes on excersise dummy

ralke

(҂ ͠❛ ෴ ͡❛)ᕤ
Joined
Dec 17, 2011
Messages
1,713
Solutions
31
Reaction score
965
Location
Santiago - Chile
GitHub
ralke23
Twitch
ralke23
Hi again, I use TFS 1.5 downgrade 8.6 and I wonder if someone can modify this script to achieve what I would like to do:
LUA:
local skills = {
    [1234] = {skillid=SKILL_MAGLEVEL,voc=2,range=CONST_ANI_SMALLICE}, -- DRUID
    [5678] = {skillid=SKILL_MAGLEVEL,voc=1,range=CONST_ANI_FIRE} -- SORCERER
}

--local houseDummies = {32143}
local freeDummies = {32142, 32149}
local skillRateDefault = (configManager.getNumber(configKeys.RATE_SKILL)* 1)
local magicRateDefault = (configManager.getNumber(configKeys.RATE_MAGIC)* 1)

local function removeExerciseWeapon(player, exercise)
    exercise:remove(1)
    player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training weapon vanished.")
    stopEvent(training)
    player:setStorageValue(Storage.isTraining,0)
end

local function startTraining(playerId, startPosition, itemid, tilePosition, bonusDummy, dummyId)
    local player = Player(playerId)
    if player ~= nil then
        if Tile(tilePosition):getItemById(dummyId) then
            local playerPosition = player:getPosition()
            if startPosition:getDistance(playerPosition) == 0 and getTilePzInfo(playerPosition) then
                if player:getItemCount(itemid) >= 1 then
                    local exercise = player:getItemById(itemid,true)
                    if exercise:isItem() then
                        if exercise:hasAttribute(ITEM_ATTRIBUTE_CHARGES) then
                            local charges_n = exercise:getAttribute(ITEM_ATTRIBUTE_CHARGES)
                            if charges_n >= 1 then
                                exercise:setAttribute(ITEM_ATTRIBUTE_CHARGES,(charges_n-1))

                                local voc = player:getVocation()

                                if skills[itemid].skillid == SKILL_MAGLEVEL then
                                    local magicRate = getRateFromTable(magicLevelStages, player:getMagicLevel(), magicRateDefault)
                                    if not bonusDummy then
                                        player:addManaSpent(math.ceil(20*magicRate))
                                    else
                                        player:addManaSpent(math.ceil(20*magicRate)*1) -- 10%
                                    end
                                else
                                    local skillRate = getRateFromTable(skillsStages, player:getEffectiveSkillLevel(skills[itemid].skillid), skillRateDefault)
                                    if not bonusDummy then
                                        player:addSkillTries(skills[itemid].skillid, 1*skillRate)
                                    else
                                        player:addSkillTries(skills[itemid].skillid, (1*skillRate)*1) -- 10%
                                    end
                                end
                                    tilePosition:sendMagicEffect(CONST_ME_HITAREA)
                                if skills[itemid].range then
                                    playerPosition:sendDistanceEffect(tilePosition, skills[itemid].range)
                                end
                                if exercise:getAttribute(ITEM_ATTRIBUTE_CHARGES) == 0 then
                                    removeExerciseWeapon(player, exercise)
                                else
                                    local training = addEvent(startTraining, voc:getAttackSpeed(), playerId,startPosition,itemid,tilePosition,bonusDummy,dummyId)
                                    player:setStorageValue(Storage.isTraining,1)
                                end
                            else
                                removeExerciseWeapon(player, exercise)
                            end
                        end
                    end
                end
            else
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training has stopped.")
                stopEvent(training)
                player:setStorageValue(Storage.isTraining,0)
            end
        else
            stopEvent(training)
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training has stopped.")
            player:setStorageValue(Storage.isTraining, 0)
        end
    else
        stopEvent(training)
        if player then
            player:sendTextMessage(MESSAGE_INFO_DESCR, "Your training has stopped.")
            player:setStorageValue(Storage.isTraining,0)
        end
    end
    return true
end

local exerciseTraining = Action()

function exerciseTraining.onUse(player, item, fromPosition, target, toPosition, isHotkey)
    local startPos = player:getPosition()
    if player:getStorageValue(Storage.isTraining) == 1 then
        player:sendTextMessage(MESSAGE_INFO_DESCR, "You are already training.")
        return false
    end
    if target:isItem() then
        if isInArray(houseDummies,target:getId()) then
            if not skills[item.itemid].range and (startPos:getDistance(target:getPosition()) > 1) then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Get closer to the dummy.")
                stopEvent(training)
                return true
            end
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You started training.")
            startTraining(player:getId(),startPos,item.itemid,target:getPosition(), true, target:getId())
        elseif isInArray(freeDummies, target:getId()) then
            if not skills[item.itemid].range and (startPos:getDistance(target:getPosition()) > 1) then
                player:sendTextMessage(MESSAGE_INFO_DESCR, "Get closer to the dummy.")
                stopEvent(training)
                return true
            end
            player:sendTextMessage(MESSAGE_INFO_DESCR, "You started training.")
            startTraining(player:getId(),startPos,item.itemid,target:getPosition(), false, target:getId())
        end
    end
    return true
end

--for id = 32124, 32126 do
--    exerciseTraining:id(id)
--end

for id = 1234, 5678 do
    exerciseTraining:id(id)
    exerciseTraining:allowFarUse(true)
end

--for id = 32384, 32386 do
 --   exerciseTraining:id(id)
--end

--for id = 32387, 32389 do
 --   exerciseTraining:id(id)
  --  exerciseTraining:allowFarUse(true)
--end

exerciseTraining:register()

May I ask for some changes for this code? Here's my request
  • I need it to be triggered onUse, without using any item/weapon
  • Only set dummies, so you can use and start training
  • According to the modifications I did, it should spend 20 mana for each tick, and each tickis is equal to player attack speed
  • Only keep magic level lines, delete everything about SKILL that is not magic.
  • Remove charges part since we're using the dummy, without item
  • Only one player can train per dummy
  • This one idk if will be possible, but stop training if you use a spell
  • Stop training if you perform an action (moving, using potion, etc)
  • Dummy must be id 5787, or 5788 and should only be used on protection zones
Thanks in advance!
 
Back
Top