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

RevScripts Exercise Dummy 8.60

Pifafa

New Member
Joined
Nov 9, 2010
Messages
47
Reaction score
4
hello everyone I use this Exercise Dummy script on my little server, but I suddenly found that some players were reaching a destroyed 300 skill mark. Seeing this was to see what the error was and how it was done. So, when using a buff magic and my exercise weapon, the skill goes crazy, it simply goes up by 1% or even 1 skill per hit on the dummy, someone would you know how to block the use of buff spells when using training weapons?
follow the script if you can make a correction because I couldn't.

~~PT-BR~~

olá para todos eu uso esse script para Dummy de Exercício no meu pequeno servidor, mas descobri subitamente que alguns jogadores estavam chegando a uma marca destruída de 300 habilidades. Visto isso foi ver qual era o erro e como era feito .. Pois então, ao usar uma magia de buff e mais minha arma de exercícios o skill fica louco, simplesmente sobe de 1% ou até mesmo 1 skill por hit no dummy, alguém saberia como por pra bloquerar uso de magias de buff ao usa as armas de treino?
segue o script caso tenha como fazer uma correção pois eu não consegui.





Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ETHEREALSPEAR)
 
function onUseWeapon(cid, var)
    local skill = getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, getPlayerSkillLevel(cid, SKILL_DISTANCE))
    local target = getCreatureTarget(cid)
    local crit = math.random(1, 100)
    
    if getCreatureName(target) == "Exercise Dummy" then
        if getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 0 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 19 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.7), false) -- 70%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 70%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.5), false) -- 50%
                doSendAnimatedText(getPlayerPosition(cid),"+ 50%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 20 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 29 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.5), false) -- 60%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 50%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.3), false) -- 40%
                doSendAnimatedText(getPlayerPosition(cid),"+ 30%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 30 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 39 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.4), false) -- 50%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 40%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.2), false) -- 30%
                doSendAnimatedText(getPlayerPosition(cid),"+ 20%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 40 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 49 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.3), false) -- 50%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 30%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.15), false) -- 25%
                doSendAnimatedText(getPlayerPosition(cid),"+ 15%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 50 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 59 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.1), false) -- 40%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 10%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.05), false) -- 20%
                doSendAnimatedText(getPlayerPosition(cid),"+ 5%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 60 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 69 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.03), false) -- 30%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 3%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.015), false) -- 15%
                doSendAnimatedText(getPlayerPosition(cid),"+ 1.5%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 70 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 79 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.02), false) -- 20%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 2%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.01), false) -- 10%
                doSendAnimatedText(getPlayerPosition(cid),"+ 1%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
        
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 80 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 89 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.01), false) -- 10%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 1%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.005), false) -- 5%
                doSendAnimatedText(getPlayerPosition(cid),"+ 0.5%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
        
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 90 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 99 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.005), false) -- 3%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 0.5%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.0025), false) -- 1.5%
                doSendAnimatedText(getPlayerPosition(cid),"+ 0.25%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 100 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 109 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.0025), false) -- 1.4%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 0.25%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.0015), false) -- 0.7%
                doSendAnimatedText(getPlayerPosition(cid),"+ 0.15%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 110 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 119 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.001), false) -- 0.6%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 0.1%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.0005), false) -- 0.3%
                doSendAnimatedText(getPlayerPosition(cid),"+ 0.05%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 120 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 129 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.0005), false) -- 0.5%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 0.05%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.00025), false) -- 0.25%
                doSendAnimatedText(getPlayerPosition(cid),"+ 0.025%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
            
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 130 then
            if crit <= 5 then
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.0003), false) -- 0.25%
                doSendAnimatedText(getPlayerPosition(cid),"CRIT+ 0.03%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            else
                doPlayerAddSkillTry(cid, SKILL_DISTANCE, math.ceil(skill*0.00015), false) -- 0.15%
                doSendAnimatedText(getPlayerPosition(cid),"+ 0.015%", TEXTCOLOR_RED)
                doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
                return doCombat(cid, combat, var)
            end
        end
    else
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Você só pode usar o exercise weapon no 'Exercise Dummy'.")
    end
end
 
Before I can even examine your code for logic problems... I must eliminate prima fascia problems. 😧

The DRY Principle: Benefits and Costs with Examples (https://thevaluable.dev/dry-principle-cost-benefit-example/)

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ETHEREALSPEAR)

function onUseWeapon(cid, var)
    local skill = getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, getPlayerSkillLevel(cid, SKILL_DISTANCE))
    local target = getCreatureTarget(cid)
    local crit = math.random(1, 100)

    local function copyPasteYourWayToGiantFuckingCode(amount, message)
        doPlayerAddSkillTry(cid, SKILL_DISTANCE, amount, false)
        doSendAnimatedText(getPlayerPosition(cid), message, TEXTCOLOR_RED)
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        return doCombat(cid, combat, var)
    end

    if getCreatureName(target) == "Exercise Dummy" then
        if getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 0 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 19 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.7), "CRIT+ 70%") -- 70%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.5), "+ 50%") -- 50%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 20 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 29 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.5), "CRIT+ 50%") -- 60%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.3), "+ 30%") -- 40%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 30 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 39 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.4), "CRIT+ 40%") -- 50%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.2), "+ 20%") -- 30%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 40 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 49 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.3), "CRIT+ 30%") -- 50%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.15), "+ 15%") -- 25%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 50 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 59 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.1), "CRIT+ 10%") -- 40%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.05), "+ 5%") -- 20%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 60 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 69 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.03), "CRIT+ 3%") -- 30%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.015), "+ 1.5%") -- 15%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 70 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 79 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.02), "CRIT+ 2%") -- 20%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.01), "+ 1%") -- 10%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 80 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 89 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.01), "CRIT+ 1%") -- 10%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.005), "+ 0.5%") -- 5%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 90 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 99 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.005), "CRIT+ 0.5%") -- 3%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.0025), "+ 0.25%") -- 1.5%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 100 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 109 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.0025), "CRIT+ 0.25%") -- 1.4%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.0015), "+ 0.15%") -- 0.7%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 110 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 119 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.001), "CRIT+ 0.1%") -- 0.6%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.0005), "+ 0.05%") -- 0.3%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 120 and getPlayerSkillLevel(cid, SKILL_DISTANCE) <= 129 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.0005), "CRIT+ 0.05%") -- 0.5%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.00025), "+ 0.025%") -- 0.25%
            end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 130 then
            if crit <= 5 then
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.0003), "CRIT+ 0.03%") -- 0.25%
            else
                return copyPasteYourWayToGiantFuckingCode(math.ceil(skill*0.00015), "+ 0.015%") -- 0.15%
            end
        end
    else
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Você só pode usar o exercise weapon no 'Exercise Dummy'.")
    end
end
Post automatically merged:

Round 2, reverse order to eliminate 2 checks!

I'm doing this step by step, so maybe you can see what's going on!

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ETHEREALSPEAR)

function onUseWeapon(cid, var)
    local skill = getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, getPlayerSkillLevel(cid, SKILL_DISTANCE))
    local target = getCreatureTarget(cid)
    local roll = math.random(1, 100)
    local crit = roll <= 5 
    
    local function combatFlourish(amount, message)
        doPlayerAddSkillTry(cid, SKILL_DISTANCE, amount, false)
        doSendAnimatedText(getPlayerPosition(cid), message, TEXTCOLOR_RED)
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        return doCombat(cid, combat, var)
    end
    
    if getCreatureName(target) == "Exercise Dummy" then
            if getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 130 then
            if crit then return combatFlourish(math.ceil(skill * 0.0003), "CRIT+ 0.03%") --[[ 0.25% ]]
                    else return combatFlourish(math.ceil(skill * 0.00015), "+ 0.015%") --[[ 0.15% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 120 then
            if crit then return combatFlourish(math.ceil(skill * 0.0005), "CRIT+ 0.05%") --[[ 0.5% ]]
                    else return combatFlourish(math.ceil(skill * 0.00025), "+ 0.025%") --[[ 0.25% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 110 then
            if crit then return combatFlourish(math.ceil(skill * 0.001), "CRIT+ 0.1%") --[[ 0.6% ]]
                    else return combatFlourish(math.ceil(skill * 0.0005), "+ 0.05%") --[[ 0.3% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 100 then
            if crit then return combatFlourish(math.ceil(skill * 0.0025), "CRIT+ 0.25%") --[[ 1.4% ]]
                    else return combatFlourish(math.ceil(skill * 0.0015), "+ 0.15%") --[[ 0.7% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 90  then
            if crit then return combatFlourish(math.ceil(skill * 0.005), "CRIT+ 0.5%") --[[ 3% ]]
                    else return combatFlourish(math.ceil(skill * 0.0025), "+ 0.25%") --[[ 1.5% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 80  then
            if crit then return combatFlourish(math.ceil(skill * 0.01), "CRIT+ 1%") --[[ 10% ]]
                    else return combatFlourish(math.ceil(skill * 0.005), "+ 0.5%") --[[ 5% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 70  then
            if crit then return combatFlourish(math.ceil(skill * 0.02), "CRIT+ 2%") --[[ 20% ]]
                    else return combatFlourish(math.ceil(skill * 0.01), "+ 1%") --[[ 10% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 60  then
            if crit then return combatFlourish(math.ceil(skill * 0.03), "CRIT+ 3%") --[[ 30% ]]
                    else return combatFlourish(math.ceil(skill * 0.015), "+ 1.5%") --[[ 15% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 50  then
            if crit then return combatFlourish(math.ceil(skill * 0.1), "CRIT+ 10%") --[[ 40% ]]
                    else return combatFlourish(math.ceil(skill * 0.05), "+ 5%") --[[ 20% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 40  then
            if crit then return combatFlourish(math.ceil(skill * 0.3), "CRIT+ 30%") --[[ 50% ]]
                    else return combatFlourish(math.ceil(skill * 0.15), "+ 15%") --[[ 25% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 30  then
            if crit then return combatFlourish(math.ceil(skill * 0.4), "CRIT+ 40%") --[[ 50% ]]
                    else return combatFlourish(math.ceil(skill * 0.2), "+ 20%") --[[ 30% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 20  then
            if crit then return combatFlourish(math.ceil(skill * 0.5), "CRIT+ 50%") --[[ 60% ]]
                    else return combatFlourish(math.ceil(skill * 0.3), "+ 30%") --[[ 40% ]]end
        elseif getPlayerSkillLevel(cid, SKILL_DISTANCE) >= 0   then
            if crit then return combatFlourish(math.ceil(skill * 0.7), "CRIT+ 70%") --[[ 70% ]]
                    else return combatFlourish(math.ceil(skill * 0.5), "+ 50%") --[[ 50% ]]end
        end
    else
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Você só pode usar o exercise weapon no 'Exercise Dummy'.")
    end
end

This whole chunk is eliminated!
1587338539621.png
Post automatically merged:

Round 3!

This process is called refactoring. You have no idea how much time I'm spent on doing such things both professionally and as a hobby.

Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ETHEREALSPEAR)

function onUseWeapon(cid, var)
    local skill = getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, getPlayerSkillLevel(cid, SKILL_DISTANCE))
    local target = getCreatureTarget(cid)
    local roll = math.random(1, 100)
    local crit = roll <= 5
    
    local function combatFlourish(amount, message)
        doPlayerAddSkillTry(cid, SKILL_DISTANCE, amount, false)
        doSendAnimatedText(getPlayerPosition(cid), message, TEXTCOLOR_RED)
        doSendMagicEffect(getThingPos(cid), CONST_ME_MAGIC_BLUE)
        return doCombat(cid, combat, var)
    end
    
    if getCreatureName(target) == "Exercise Dummy" then
        local skillLevel = getPlayerSkillLevel(cid, SKILL_DISTANCE)
        local skillXP, onom = 0, "" -- Onomatopoeia!

            if skillLevel >= 130 then
            if crit then skillXP = math.ceil(skill * 0.0003); onom = "CRIT+ 0.03%") --[[ 0.25% ]]
                    else skillXP = math.ceil(skill * 0.00015); onom = "+ 0.015%") --[[ 0.15% ]]end
        elseif skillLevel >= 120 then
            if crit then skillXP = math.ceil(skill * 0.0005); onom = "CRIT+ 0.05%") --[[ 0.5% ]]
                    else skillXP = math.ceil(skill * 0.00025); onom = "+ 0.025%") --[[ 0.25% ]]end
        elseif skillLevel >= 110 then
            if crit then skillXP = math.ceil(skill * 0.001); onom = "CRIT+ 0.1%") --[[ 0.6% ]]
                    else skillXP = math.ceil(skill * 0.0005); onom = "+ 0.05%") --[[ 0.3% ]]end
        elseif skillLevel >= 100 then
            if crit then skillXP = math.ceil(skill * 0.0025); onom = "CRIT+ 0.25%") --[[ 1.4% ]]
                    else skillXP = math.ceil(skill * 0.0015); onom = "+ 0.15%") --[[ 0.7% ]]end
        elseif skillLevel >= 90  then
            if crit then skillXP = math.ceil(skill * 0.005); onom = "CRIT+ 0.5%") --[[ 3% ]]
                    else skillXP = math.ceil(skill * 0.0025); onom = "+ 0.25%") --[[ 1.5% ]]end
        elseif skillLevel >= 80  then
            if crit then skillXP = math.ceil(skill * 0.01); onom = "CRIT+ 1%") --[[ 10% ]]
                    else skillXP = math.ceil(skill * 0.005); onom = "+ 0.5%") --[[ 5% ]]end
        elseif skillLevel >= 70  then
            if crit then skillXP = math.ceil(skill * 0.02); onom = "CRIT+ 2%") --[[ 20% ]]
                    else skillXP = math.ceil(skill * 0.01); onom = "+ 1%") --[[ 10% ]]end
        elseif skillLevel >= 60  then
            if crit then skillXP = math.ceil(skill * 0.03); onom = "CRIT+ 3%") --[[ 30% ]]
                    else skillXP = math.ceil(skill * 0.015); onom = "+ 1.5%") --[[ 15% ]]end
        elseif skillLevel >= 50  then
            if crit then skillXP = math.ceil(skill * 0.1); onom = "CRIT+ 10%") --[[ 40% ]]
                    else skillXP = math.ceil(skill * 0.05); onom = "+ 5%") --[[ 20% ]]end
        elseif skillLevel >= 40  then
            if crit then skillXP = math.ceil(skill * 0.3); onom = "CRIT+ 30%") --[[ 50% ]]
                    else skillXP = math.ceil(skill * 0.15); onom = "+ 15%") --[[ 25% ]]end
        elseif skillLevel >= 30  then
            if crit then skillXP = math.ceil(skill * 0.4); onom = "CRIT+ 40%") --[[ 50% ]]
                    else skillXP = math.ceil(skill * 0.2); onom = "+ 20%") --[[ 30% ]]end
        elseif skillLevel >= 20  then
            if crit then skillXP = math.ceil(skill * 0.5); onom = "CRIT+ 50%") --[[ 60% ]]
                    else skillXP = math.ceil(skill * 0.3); onom = "+ 30%") --[[ 40% ]]end
        elseif skillLevel >= 0   then
            if crit then skillXP = math.ceil(skill * 0.7); onom = "CRIT+ 70%") --[[ 70% ]]
                    else skillXP = math.ceil(skill * 0.5); onom = "+ 50%") --[[ 50% ]]end
        end
        return combatFlourish(skillXP, onom)
    else
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Você só pode usar o exercise weapon no 'Exercise Dummy'.")
    end
end
Post automatically merged:

Finished.


Lua:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_HITAREA)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_ETHEREALSPEAR)

local skillTryMap = { -- Onomatopoeia!
    ["S130_CRIT"] = { skillXP = math.ceil(skill * 0.0003),  onom = "+ 0.03%"  }, -- [[ 00.25% ]]
    ["S130_NORM"] = { skillXP = math.ceil(skill * 0.00015), onom = "+ 0.015%" }, -- [[ 00.15% ]]
    ["S120_CRIT"] = { skillXP = math.ceil(skill * 0.0005),  onom = "+ 0.05%"  }, -- [[ 00.5% ]]
    ["S120_NORM"] = { skillXP = math.ceil(skill * 0.00025), onom = "+ 0.025%" }, -- [[ 00.25% ]]
    ["S110_CRIT"] = { skillXP = math.ceil(skill * 0.001),   onom = "+ 0.1%"   }, -- [[ 00.6% ]]
    ["S110_NORM"] = { skillXP = math.ceil(skill * 0.0005),  onom = "+ 0.05%"  }, -- [[ 00.3% ]]
    ["S100_CRIT"] = { skillXP = math.ceil(skill * 0.0025),  onom = "+ 0.25%"  }, -- [[ 01.4% ]]
    ["S100_NORM"] = { skillXP = math.ceil(skill * 0.0015),  onom = "+ 0.15%"  }, -- [[ 00.7% ]]
    ["S90_CRIT"]  = { skillXP = math.ceil(skill * 0.005),   onom = "+ 0.5%"   }, -- [[ 03.0% ]]
    ["S90_NORM"]  = { skillXP = math.ceil(skill * 0.0025),  onom = "+ 0.25%"  }, -- [[ 01.5% ]]
    ["S80_CRIT"]  = { skillXP = math.ceil(skill * 0.01),    onom = "+ 1%"     }, -- [[ 10.0% ]]
    ["S80_NORM"]  = { skillXP = math.ceil(skill * 0.005),   onom = "+ 0.5%"   }, -- [[ 05.0% ]]
    ["S70_CRIT"]  = { skillXP = math.ceil(skill * 0.02),    onom = "+ 2%"     }, -- [[ 20.0% ]]
    ["S70_NORM"]  = { skillXP = math.ceil(skill * 0.01),    onom = "+ 1%"     }, -- [[ 10.0% ]]
    ["S60_CRIT"]  = { skillXP = math.ceil(skill * 0.03),    onom = "+ 3%"     }, -- [[ 30.0% ]]
    ["S60_NORM"]  = { skillXP = math.ceil(skill * 0.015),   onom = "+ 1.5%"   }, -- [[ 15.0% ]]
    ["S50_CRIT"]  = { skillXP = math.ceil(skill * 0.1),     onom = "+ 10%"    }, -- [[ 40.0% ]]
    ["S50_NORM"]  = { skillXP = math.ceil(skill * 0.05),    onom = "+ 5%"     }, -- [[ 20.0% ]]
    ["S40_CRIT"]  = { skillXP = math.ceil(skill * 0.3),     onom = "+ 30%"    }, -- [[ 50.0% ]]
    ["S40_NORM"]  = { skillXP = math.ceil(skill * 0.15),    onom = "+ 15%"    }, -- [[ 25.0% ]]
    ["S30_CRIT"]  = { skillXP = math.ceil(skill * 0.4),     onom = "+ 40%"    }, -- [[ 50.0% ]]
    ["S30_NORM"]  = { skillXP = math.ceil(skill * 0.2),     onom = "+ 20%"    }, -- [[ 30.0% ]]
    ["S20_CRIT"]  = { skillXP = math.ceil(skill * 0.5),     onom = "+ 50%"    }, -- [[ 60.0% ]]
    ["S20_NORM"]  = { skillXP = math.ceil(skill * 0.3),     onom = "+ 30%"    }, -- [[ 40.0% ]]
    ["S0_CRIT"]   = { skillXP = math.ceil(skill * 0.7),     onom = "+ 70%"    }, -- [[ 70.0% ]]
    ["S0_NORM"]   = { skillXP = math.ceil(skill * 0.5),     onom = "+ 50%"    }, -- [[ 50.0% ]]
}


function onUseWeapon(cid, var)
    local skillLevel = getPlayerSkillLevel(cid, SKILL_DISTANCE)
    local skill = getPlayerRequiredSkillTries(cid, SKILL_DISTANCE, skillLevel)
    local target = getCreatureTarget(cid)
    local crit = math.random(1, 100) <= 5

    local function combatFlourish(mapped)
        local message = (crit and "CRIT" or "") .. mapped.onom
        doSendMagicEffect(getPlayerPosition(cid), CONST_ME_MAGIC_BLUE)
        doSendAnimatedText(getPlayerPosition(cid), message, TEXTCOLOR_RED)
        doPlayerAddSkillTry(cid, SKILL_DISTANCE, mapped.skillXP, false)
        return doCombat(cid, combat, var)
    end

    local function getMapKey()
        local append = crit and "_CRIT" or "_NORM"
        if (skillLevel <= 19) then return ("S0" .. append) end
        if (skillLevel >= 140) then return ("S130" .. append) end
        return string.format("S%s%s", math.min(130, (math.floor(skillLevel / 10) * 10)), append)
    end

    if getCreatureName(target) == "Exercise Dummy" then
        return combatFlourish(skillTryMap[getMapKey()])
    else
        return doPlayerSendTextMessage(cid, MESSAGE_STATUS_CONSOLE_ORANGE, "Você só pode usar o exercise weapon no 'Exercise Dummy'.")
    end
end
 
Last edited:
Back
Top