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

Need help with script.

shioon

New Member
Joined
Feb 10, 2024
Messages
11
Reaction score
1
Hi

I got problem with script: I want to use function OnStepIn to gain skill tries and exp while reducing health.

my movement.xml for used script:


<movement type="StepIn" actionid="9801" event="script" value="gravity_machine.lua"/>

gravity_machine.lua :
Lua:
function onStepIn(cid, item, pos)
    local set = getPlayerStorageValue(cid,98991)
    local lvl = getPlayerLevel(cid)
    local addExp2 = math.random(set * 2, set * 3)
    local hp2 = math.random(0.5, 1.5)
    local addExp = math.random(set, set * 1.5)
    local hp = math.random(2.5, 5.5)
    local addExp0 = math.random(set * 0.8, set)
    local hp0 = math.random(4.5, 6.5)
  
    if isPlayer(cid) == TRUE then
        if lvl < 50 and set > 0 then
        doPlayerAddExp(cid, set)

        elseif 50 <= lvl <= 500 and set < lvl then
        doPlayerAddExp(cid, addExp)
        doPlayerRemoveMaxHpProcent(cid, hp0)
        doPlayerAddSkillTry(cid, 4, 2)

        elseif 50 <= lvl <= 500 and set == lvl then
        doPlayerAddExp(cid, addExp)
        doPlayerRemoveMaxHpProcent(cid, hp)
        doPlayerAddSkillTry(cid, 4, 2)

        elseif lvl > 500 and set < lvl then
        doPlayerAddExp(cid, addExp2)
        doPlayerRemoveMaxHpProcent(cid, hp)
        doPlayerAddSkillTry(cid, 4, 2)
 
        elseif lvl > 500 and set == lvl then
        doPlayerAddExp(cid, addExp2)
        doPlayerRemoveMaxHpProcent(cid, hp2)
        doPlayerAddSkillTry(cid, 4, 3)

        else
        doPlayerSendCancel(cid, "Set Machine to a level lower than " .. (lvl + 1) .. ".")
        end
    end
end

GetPlayerStorageValue is set by talking with npc, I have checked this value, it is fine but stepping in do nothing. Also I checked item id's and it's fine, itemid is 102 and actiond is 9801. Any advice?
 
Last edited:
Solution
try! not yet tested
Lua:
function onStepIn(cid, item, pos)
    print("Player with cid " .. cid .. " stepped in at position (" .. pos.x .. ", " .. pos.y .. ", " .. pos.z .. ")")

    if not isPlayer(cid) then
        return
    end

    local set = getPlayerStorageValue(cid, 98991)
    if set == nil or set < 0 then
        doPlayerSendCancel(cid, "Invalid storage value. Please set the machine correctly.")
        return
    end

    local lvl = getPlayerLevel(cid)
    local addExp2 = math.random(set * 2, set * 3)
    local hp2 = math.random(50, 150) / 10
    local addExp = math.random(set, set * 1.5)
    local hp = math.random(25, 55) / 10
    local addExp0 = math.random(set * 0.8, set)
    local hp0 = math.random(45, 65) / 10

    if lvl...
Quick help😂


Lua:
function onStepIn(cid, item, pos)
    local set = getPlayerStorageValue(cid, 98991)
    local lvl = getPlayerLevel(cid)
    local addExp2 = math.random(set * 2, set * 3)
    local hp2 = math.random(getPlayerMaxHealth(cid) / 15 * 100 + 1, getPlayerMaxHealth(cid) / 15 + 30)
    local addExp = math.random(set, set * 1.5)
    local hp = math.random(getPlayerMaxHealth(cid) / 20 * 100 + 1, getPlayerMaxHealth(cid) / 20 + 30)
    local addExp0 = math.random(set, set * 0.8)
    local hp0 = math.random(getPlayerMaxHealth(cid) / 25 * 100 + 1, getPlayerMaxHealth(cid) / 25 + 30)

    if isPlayer(cid) == TRUE then
        if lvl < 50 and set > 0 then
            doPlayerAddExp(cid, set)
        elseif 50 <= lvl <= 500 and set < lvl then
            doPlayerAddExp(cid, addExp)
            doPlayerRemoveMaxHpProcent(cid, hp)
            doPlayerAddSkillTry(cid, 4, 2)
        elseif 50 <= lvl <= 500 and set == lvl then
            doPlayerAddExp(cid, addExp)
            doPlayerRemoveMaxHpProcent(cid, hp)
            doPlayerAddSkillTry(cid, 4, 2)
        elseif lvl > 500 and set < lvl then
            doPlayerAddExp(cid, addExp2)
            doPlayerRemoveMaxHpProcent(cid, hp)
            doPlayerAddSkillTry(cid, 4, 2)
        elseif lvl > 500 and set == lvl then
            doPlayerAddExp(cid, addExp2)
            doPlayerRemoveMaxHpProcent(cid, hp2)
            doPlayerAddSkillTry(cid, 4, 3)
        else
            doPlayerSendCancel(cid, "Set Machine to a level lower than " .. (lvl + 1) .. ".")
        end
    end
end
 
under
Lua:
function onStepIn(cid, item, pos)
make a print that make sure server see that tile you wanna to step its registered properly
like idk
Lua:
print("Its working!")
 
try! not yet tested
Lua:
function onStepIn(cid, item, pos)
    print("Player with cid " .. cid .. " stepped in at position (" .. pos.x .. ", " .. pos.y .. ", " .. pos.z .. ")")

    if not isPlayer(cid) then
        return
    end

    local set = getPlayerStorageValue(cid, 98991)
    if set == nil or set < 0 then
        doPlayerSendCancel(cid, "Invalid storage value. Please set the machine correctly.")
        return
    end

    local lvl = getPlayerLevel(cid)
    local addExp2 = math.random(set * 2, set * 3)
    local hp2 = math.random(50, 150) / 10
    local addExp = math.random(set, set * 1.5)
    local hp = math.random(25, 55) / 10
    local addExp0 = math.random(set * 0.8, set)
    local hp0 = math.random(45, 65) / 10

    if lvl < 50 and set > 0 then
        doPlayerAddExp(cid, set)
    elseif lvl >= 50 and lvl <= 500 then
        if set < lvl then
            doPlayerAddExp(cid, addExp)
            doPlayerRemoveMaxHpProcent(cid, hp0)
            doPlayerAddSkillTry(cid, 4, 2)
        elseif set == lvl then
            doPlayerAddExp(cid, addExp)
            doPlayerRemoveMaxHpProcent(cid, hp)
            doPlayerAddSkillTry(cid, 4, 2)
        end
    elseif lvl > 500 then
        if set < lvl then
            doPlayerAddExp(cid, addExp2)
            doPlayerRemoveMaxHpProcent(cid, hp)
            doPlayerAddSkillTry(cid, 4, 2)
        elseif set == lvl then
            doPlayerAddExp(cid, addExp2)
            doPlayerRemoveMaxHpProcent(cid, hp2)
            doPlayerAddSkillTry(cid, 4, 3)
        end
    else
        doPlayerSendCancel(cid, "Set Machine to a level lower than " .. (lvl + 1) .. ".")
    end
end
Post automatically merged:

or

Lua:
local config = {
    storageValue = 98991,
    skillTries = {
        lowLevel = 2,
        highLevel = 3
    },
    healthPercentage = {
        low = {min = 45, max = 65},
        medium = {min = 25, max = 55},
        high = {min = 50, max = 150}
    },
    experienceMultiplier = {
        low = {min = 0.8, max = 1},
        medium = {min = 1, max = 1.5},
        high = {min = 2, max = 3}
    },
    levelRanges = {
        {min = 1, max = 49, expMultiplier = 'low'},
        {min = 50, max = 500, expMultiplier = 'medium', healthPercentage = 'medium'},
        {min = 501, max = nil, expMultiplier = 'high', healthPercentage = 'high'}
    }
}

function doPlayerRemoveHealthPercentage(cid, percent)
    local maxHealth = getCreatureMaxHealth(cid)
    local healthToRemove = math.floor(maxHealth * (percent / 100))
    doCreatureAddHealth(cid, -healthToRemove)
end

function onStepIn(cid, item, pos)
    if not isPlayer(cid) then
        return true
    end

    local set = getPlayerStorageValue(cid, config.storageValue)
    if set < 0 then
        doPlayerSendCancel(cid, "You need to set the machine first.")
        return true
    end

    local lvl = getPlayerLevel(cid)
    local levelRange = nil

    for _, range in ipairs(config.levelRanges) do
        if (range.max == nil and lvl >= range.min) or (lvl >= range.min and lvl <= range.max) then
            levelRange = range
            break
        end
    end

    if not levelRange then
        doPlayerSendCancel(cid, "Your level does not match any configured level range.")
        return true
    end

    local expMultiplier = config.experienceMultiplier[levelRange.expMultiplier]
    local healthPercentageConfig = config.healthPercentage[levelRange.healthPercentage]
    local addExp = math.random(set * expMultiplier.min, set * expMultiplier.max)
    local hpPercent = math.random(healthPercentageConfig.min, healthPercentageConfig.max) / 10

    if set < lvl or (set == lvl and lvl > 500) then
        doPlayerAddExp(cid, addExp)
        doPlayerRemoveHealthPercentage(cid, hpPercent)
        doPlayerAddSkillTry(cid, SKILL_FIST, (lvl > 500 and config.skillTries.highLevel) or config.skillTries.lowLevel)
    elseif set == lvl then
        doPlayerAddExp(cid, set)
    else
        doPlayerSendCancel(cid, "Set Machine to a level lower than " .. (lvl + 1) .. ".")
    end

    return true
end
 
Last edited:
Solution
If the storage doesn't exist, and it's -1, "set" variable will now be a negative number.... "set" will always be less than "lvl" and then you are calling addExp with a negative number.

Check the storage value exists first. Return early if it doesn't exist.
 
try! not yet tested
Lua:
function onStepIn(cid, item, pos)
    print("Player with cid " .. cid .. " stepped in at position (" .. pos.x .. ", " .. pos.y .. ", " .. pos.z .. ")")

    if not isPlayer(cid) then
        return
    end

    local set = getPlayerStorageValue(cid, 98991)
    if set == nil or set < 0 then
        doPlayerSendCancel(cid, "Invalid storage value. Please set the machine correctly.")
        return
    end

    local lvl = getPlayerLevel(cid)
    local addExp2 = math.random(set * 2, set * 3)
    local hp2 = math.random(50, 150) / 10
    local addExp = math.random(set, set * 1.5)
    local hp = math.random(25, 55) / 10
    local addExp0 = math.random(set * 0.8, set)
    local hp0 = math.random(45, 65) / 10

    if lvl < 50 and set > 0 then
        doPlayerAddExp(cid, set)
    elseif lvl >= 50 and lvl <= 500 then
        if set < lvl then
            doPlayerAddExp(cid, addExp)
            doPlayerRemoveMaxHpProcent(cid, hp0)
            doPlayerAddSkillTry(cid, 4, 2)
        elseif set == lvl then
            doPlayerAddExp(cid, addExp)
            doPlayerRemoveMaxHpProcent(cid, hp)
            doPlayerAddSkillTry(cid, 4, 2)
        end
    elseif lvl > 500 then
        if set < lvl then
            doPlayerAddExp(cid, addExp2)
            doPlayerRemoveMaxHpProcent(cid, hp)
            doPlayerAddSkillTry(cid, 4, 2)
        elseif set == lvl then
            doPlayerAddExp(cid, addExp2)
            doPlayerRemoveMaxHpProcent(cid, hp2)
            doPlayerAddSkillTry(cid, 4, 3)
        end
    else
        doPlayerSendCancel(cid, "Set Machine to a level lower than " .. (lvl + 1) .. ".")
    end
end
Post automatically merged:

or

Lua:
local config = {
    storageValue = 98991,
    skillTries = {
        lowLevel = 2,
        highLevel = 3
    },
    healthPercentage = {
        low = {min = 45, max = 65},
        medium = {min = 25, max = 55},
        high = {min = 50, max = 150}
    },
    experienceMultiplier = {
        low = {min = 0.8, max = 1},
        medium = {min = 1, max = 1.5},
        high = {min = 2, max = 3}
    },
    levelRanges = {
        {min = 1, max = 49, expMultiplier = 'low'},
        {min = 50, max = 500, expMultiplier = 'medium', healthPercentage = 'medium'},
        {min = 501, max = nil, expMultiplier = 'high', healthPercentage = 'high'}
    }
}

function doPlayerRemoveHealthPercentage(cid, percent)
    local maxHealth = getCreatureMaxHealth(cid)
    local healthToRemove = math.floor(maxHealth * (percent / 100))
    doCreatureAddHealth(cid, -healthToRemove)
end

function onStepIn(cid, item, pos)
    if not isPlayer(cid) then
        return true
    end

    local set = getPlayerStorageValue(cid, config.storageValue)
    if set < 0 then
        doPlayerSendCancel(cid, "You need to set the machine first.")
        return true
    end

    local lvl = getPlayerLevel(cid)
    local levelRange = nil

    for _, range in ipairs(config.levelRanges) do
        if (range.max == nil and lvl >= range.min) or (lvl >= range.min and lvl <= range.max) then
            levelRange = range
            break
        end
    end

    if not levelRange then
        doPlayerSendCancel(cid, "Your level does not match any configured level range.")
        return true
    end

    local expMultiplier = config.experienceMultiplier[levelRange.expMultiplier]
    local healthPercentageConfig = config.healthPercentage[levelRange.healthPercentage]
    local addExp = math.random(set * expMultiplier.min, set * expMultiplier.max)
    local hpPercent = math.random(healthPercentageConfig.min, healthPercentageConfig.max) / 10

    if set < lvl or (set == lvl and lvl > 500) then
        doPlayerAddExp(cid, addExp)
        doPlayerRemoveHealthPercentage(cid, hpPercent)
        doPlayerAddSkillTry(cid, SKILL_FIST, (lvl > 500 and config.skillTries.highLevel) or config.skillTries.lowLevel)
    elseif set == lvl then
        doPlayerAddExp(cid, set)
    else
        doPlayerSendCancel(cid, "Set Machine to a level lower than " .. (lvl + 1) .. ".")
    end

    return true
end
I tried first one and IT WORKS ! THANKS MATE.
 

Similar threads

Back
Top