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

TFS 0.X Exercise Dummie to 8.6

samandriel

Active Member
Joined
Oct 19, 2016
Messages
242
Solutions
1
Reaction score
46
I was thinking about add the new train mode in my 8.6 project...
It it would be nice in almost every project 8.6 :)

I made this base:
Code:
<action actionid="7998" script="train_weapon.lua" />

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerItemCount(cid, 8980) < 1 then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "You need a Exercise Weapon to train in a Exercise Dummie.")
        return true
    end
    doSendMagicEffect(toPosition, 2)
    doPlayerAddSkillTry(cid, SKILL_FIST, 1)
    doPlayerRemoveItem(cid, 8980, 1)
    return true
end


It's working, but need some changes that idk how to do and need some help

1- Add charges to item 8980, something who show when player look the item (in description for example)
2- Change the if getPlayerItemCount(cid, 8980) < 1 then to that charges and remove charges until charge 1 and remove the item
3- Player click one time and still training until player move out, no need to click 1000 times if have 1000 charges
 
I was thinking about add the new train mode in my 8.6 project...
It it would be nice in almost every project 8.6 :)

I made this base:
Code:
<action actionid="7998" script="train_weapon.lua" />

Code:
function onUse(cid, item, fromPosition, itemEx, toPosition)
    if getPlayerItemCount(cid, 8980) < 1 then
        doSendMagicEffect(getCreaturePosition(cid), CONST_ME_POFF)
        doPlayerSendCancel(cid, "You need a Exercise Weapon to train in a Exercise Dummie.")
        return true
    end
    doSendMagicEffect(toPosition, 2)
    doPlayerAddSkillTry(cid, SKILL_FIST, 1)
    doPlayerRemoveItem(cid, 8980, 1)
    return true
end


It's working, but need some changes that idk how to do and need some help

1- Add charges to item 8980, something who show when player look the item (in description for example)
2- Change the if getPlayerItemCount(cid, 8980) < 1 then to that charges and remove charges until charge 1 and remove the item
3- Player click one time and still training until player move out, no need to click 1000 times if have 1000 charges
Not tested
Lua:
local requiredItem = {
    [8980] = {
        storage = 123456,
        removeAmount = 1,
        effect = 2,
        skill = SKILL_FIST,
        tries = 1,
        poof = CONST_ME_POFF,
        message = "Your Exercise Weapon is already in use.",
    }
}

local state, eventId = {}, {}

test = function(cid, pos, t)
    if not next(eventId[cid]) then
        return
    end
    -- if the player does not exist (they logged out) or their position has changed since they used the item
    if not Player(cid) or pos ~= getCreaturePosition(cid) then
        -- reset everything
        if next(eventId[cid]) then
            for _, eid in pairs(eventId[cid]) do
                stopEvent(eid)
            end
        end
        eventId[cid] = nil
        state[cid].key = false
    -- is the return value of getting the storage greater than or equal to the remove amount
    -- and is the stored position the same as the player's current position
    elseif t.value >= t.removeAmount and pos == getCreaturePosition(cid) then
        doSendMagicEffect(pos, t.effect)
        doPlayerAddSkillTry(cid, t.skill, t.tries)
        setPlayerStorageValue(cid, t.storage, (t.value - t.removeAmount))
        if getPlayerStorageValue(cid, t.storage) <= 0 then
            -- remove the item and reset the state
            doPlayerRemoveItem(cid, t.itemid, 1)
            state[cid].key = false
        end
    end       
end

function isActive(cid)
    if not state[cid] then
        state[cid] = {key = false}
    end
    return state[cid].key
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    -- default values
    local x, pos, message, effect = requiredItem[item.itemid], getCreaturePosition(cid), "Sorry, not possible.", CONST_ME_POFF
    if x and isActive(cid) then
        effect = x.poof
        message = x.message
    elseif x and not isActive(cid) then
        x.count = getPlayerItemCount(cid, item.itemid)
        x.value = getPlayerStorageValue(cid, x.storage)
        x.itemid = item.itemid
        state[cid].key = true
        if x.count >= 1 and x.value >= x.removeAmount then
            eventId[cid] = {}
            for i = x.value, 1, -1 do
                -- save the event id's so we can stop them later if the player moves
                eventId[cid][i] = addEvent(test, i * 1000, cid, pos, x)
            end
        end
        return true
    else
        message = "You need an Exercise Weapon to train with an Exercise Dummie."
    end
    doSendMagicEffect(pos, effect)
    doPlayerSendCancel(cid, message)
    return true
end

Edit: Made a 1.3 version of this and applied some of the corrections. I still don't know if it will work for 8.6
 
Last edited:
Not tested
Lua:
local requiredItem = {
    [8980] = {
        storage = 123456,
        removeAmount = 1,
        effect = 2,
        skill = SKILL_FIST,
        tries = 1,
        poof = CONST_ME_POFF,
        message = "Your Exercise Weapon is already in use.",
    }
}

local state, eventId = {}, {}

test = function(cid, pos, t)
    if not next(eventId[cid]) then
        return
    end
    -- if the player does not exist (they logged out) or their position has changed since they used the item
    if not Player(cid) or pos ~= getCreaturePosition(cid) then
        -- reset everything
        if next(eventId[cid]) then
            for _, eid in pairs(eventId[cid]) do
                stopEvent(eid)
            end
        end
        eventId[cid] = nil
        state[cid].key = false
    -- is the return value of getting the storage greater than or equal to the remove amount
    -- and is the stored position the same as the player's current position
    elseif t.value >= t.removeAmount and pos == getCreaturePosition(cid) then
        doSendMagicEffect(pos, t.effect)
        doPlayerAddSkillTry(cid, t.skill, t.tries)
        setPlayerStorageValue(cid, t.storage, (t.value - t.removeAmount))
        if getPlayerStorageValue(cid, t.storage) <= 0 then
            -- remove the item and reset the state
            doPlayerRemoveItem(cid, t.itemid, 1)
            state[cid].key = false
        end
    end      
end

function isActive(cid)
    if not state[cid] then
        state[cid] = {key = false}
    end
    return state[cid].key
end

function onUse(cid, item, fromPosition, itemEx, toPosition)
    -- default values
    local x, pos, message, effect = requiredItem[item.itemid], getCreaturePosition(cid), "Sorry, not possible.", CONST_ME_POFF
    if x and isActive(cid) then
        effect = x.poof
        message = x.message
    elseif x and not isActive(cid) then
        x.count = getPlayerItemCount(cid, item.itemid)
        x.value = getPlayerStorageValue(cid, x.storage)
        x.itemid = item.itemid
        state[cid].key = true
        if x.count >= 1 and x.value >= x.removeAmount then
            eventId[cid] = {}
            for i = x.value, 1, -1 do
                -- save the event id's so we can stop them later if the player moves
                eventId[cid][i] = addEvent(test, i * 1000, cid, pos, x)
            end
        end
        return true
    else
        message = "You need an Exercise Weapon to train with an Exercise Dummie."
    end
    doSendMagicEffect(pos, effect)
    doPlayerSendCancel(cid, message)
    return true
end

Edit: Made a 1.3 version of this and applied some of the corrections. I still don't know if it will work for 8.6

It's always stuck on You need an Exercise Weapon to train with an Exercise Dummie.
Even if i have the sword
 
did u find why its showing "You need an exercise...
No it works fine but i am not at my computer to show you any code. And also since it's written for 1.3 then it wouldn't be compatible. I understand that there is modern code for 8.6 servers you should really consider abandoning the older version and join the rest of us. You will also find more support for your project.
 
rlly?

i'm using this amazing 0.4 source pack

It still reciving updates, almost ots 8.6 are 0.4
Would be nice have this train method in 8.6's servers :(
 
It's always showing the message = "You need an Exercise Weapon to train with an Exercise Dummie."
Anybody could help to fix?
 
Back
Top