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

Really need help with this one

insebbe123

New Member
Joined
Mar 31, 2012
Messages
44
Reaction score
2
hello, i got a major problem, tried to make a blocking system that makes u have a 5-10% chance to 100% block a physical damage and it only works for knights it works but the thing is that i can't use healing runes or spells, i doesn't grant any healing but if i heal the block shows, im really bad at scripting sorry
Lua:
function onStatsChange(cid, attacker, type, combat, value)
    local chance = 25
    if isKnight(cid) == true then
        else
    end
    if isPlayer(cid) or isCreature(attacker) then -- in case you register monsters later
        if type == STATSCHANGE_HEALTHLOSS and value > 10000 then
        if combat == COMBAT_PHYSICALDAMAGE then --add the upper condition here if you want them
            end
        end
    end
            if math.random(100) <= chance then
                doSendAnimatedText(getPlayerPosition(cid),"BLOCK!", TEXTCOLOR_GREY)
                return false
            end
        end
 
You have two empty blocks that do checks (vocation, combat type) but they don't do anything (you close them instantly)

I recommend starting with this Programming in Lua : 4.3.1 (https://www.lua.org/pil/4.3.1.html)

Use a text editor different than windows notepad and fix your tabbing in this code and you will notice these things.

Can't fix your code because I'm on a phone.
 
Try this one, (I don't have a TFS0.3.4, so I don't know if it really works or not).
Lua:
function onStatsChange(cid, attacker, type, combat, value)
    local chance = 25
    if combat == COMBAT_HEALING then
        return true
    end
    if not isPlayer(cid) then
        return true
    end
    if not isKnight(cid) then
        return true
    end
    if type == STATSCHANGE_HEALTHLOSS and value > 10000 then
        if combat == COMBAT_PHYSICALDAMAGE then
            if math.random(100) <= chance then
                doSendAnimatedText(getPlayerPosition(cid),"BLOCK!", TEXTCOLOR_GREY)
                return false
            end   
        end
    end
end
 
I don't have 0.3.6 either, but this one looks like something that would work.

If that won't work, check "value" parameter
I don't remember if damage was passed to function as number or -number
 
Try this one, (I don't have a TFS0.3.4, so I don't know if it really works or not).
Lua:
function onStatsChange(cid, attacker, type, combat, value)
    local chance = 25
    if combat == COMBAT_HEALING then
        return true
    end
    if not isPlayer(cid) then
        return true
    end
    if not isKnight(cid) then
        return true
    end
    if type == STATSCHANGE_HEALTHLOSS and value > 10000 then
        if combat == COMBAT_PHYSICALDAMAGE then
            if math.random(100) <= chance then
                doSendAnimatedText(getPlayerPosition(cid),"BLOCK!", TEXTCOLOR_GREY)
                return false
            end  
        end
    end
end
i tried this code but it doesn't seem to work if i doesn't have "else return false" the monsters wont do any damage at all, but i only take damage by physical damage not of arrow's, burst arrows, fire field, monster spells etc, please help
Lua:
function onStatsChange(cid, attacker, type, combat, value)
    local chance = 25
    if combat == COMBAT_HEALING then
        return true
    end
    if not isPlayer(cid) then
        return true
    end
    if not isKnight(cid) then
        return true
    end
    if type == STATSCHANGE_HEALTHLOSS and value > 10000 then
        if combat == COMBAT_PHYSICALDAMAGE then
            if math.random(100) <= chance then
                doSendAnimatedText(getPlayerPosition(cid),"BLOCK!", TEXTCOLOR_GREY)
                return false
            else
                return true
            end   
        end
    end
end
 
if everything else has to return true, how about stacking the conditions?

Lua:
function onStatsChange(cid, attacker, type, combat, value)
    local chance = 25
    if isPlayer(cid) and combat ~= COMBAT_HEALING then
        if isKnight(cid) then
            if type == STATSCHANGE_HEALTHLOSS and value > 10000 then
                if combat == COMBAT_PHYSICALDAMAGE then
                    if math.random(100) <= chance then
                        doSendAnimatedText(getPlayerPosition(cid),"BLOCK!", TEXTCOLOR_GREY)
                        return false
                    end  
                end
            end
        end
    end

    return true
end
 
if everything else has to return true, how about stacking the conditions?

Lua:
function onStatsChange(cid, attacker, type, combat, value)
    local chance = 25
    if isPlayer(cid) and combat ~= COMBAT_HEALING then
        if isKnight(cid) then
            if type == STATSCHANGE_HEALTHLOSS and value > 10000 then
                if combat == COMBAT_PHYSICALDAMAGE then
                    if math.random(100) <= chance then
                        doSendAnimatedText(getPlayerPosition(cid),"BLOCK!", TEXTCOLOR_GREY)
                        return false
                    end 
                end
            end
        end
    end

    return true
end
doesn't seems to work, i get melee attacks but the spells do no damage, and walking if fire does no damage aswell :/
 
does everything work fine when you disable the script?

if yes, try replacing return values (true with false and vice versa)
 
@zbizu Previous script should 100% work.
Try restarting your server after you've implemented it to make sure it's properly updated.
i always turns of the server before a save a script then saves it and runs it but some how, it works with that script even doe it didn't before wtf, im so lost, thank you guys anyways
 
Back
Top