• 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
42
Best answers
0
Reaction score
0
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
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,692
Location
Poland
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.
 

lokolokio

Well-Known Member
Joined
Jan 7, 2009
Messages
186
Best answers
11
Reaction score
57
Location
Mexico
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
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,692
Location
Poland
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
 
OP
I

insebbe123

New Member
Joined
Mar 31, 2012
Messages
42
Best answers
0
Reaction score
0
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
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,692
Location
Poland
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
 
OP
I

insebbe123

New Member
Joined
Mar 31, 2012
Messages
42
Best answers
0
Reaction score
0
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 :/
 
OP
I

insebbe123

New Member
Joined
Mar 31, 2012
Messages
42
Best answers
0
Reaction score
0
any console errors?
nope none, i doesn't know how, but it seems like all spell damages return false some how, only melee attacks works even if a spell/attack is physical like an normal arrow from hero seems to return false,
 

zbizu

Legendary OT User
Joined
Nov 22, 2010
Messages
2,718
Best answers
7
Reaction score
1,692
Location
Poland
does everything work fine when you disable the script?

if yes, try replacing return values (true with false and vice versa)
 
OP
I

insebbe123

New Member
Joined
Mar 31, 2012
Messages
42
Best answers
0
Reaction score
0
does everything work fine when you disable the script?

if yes, try replacing return values (true with false and vice versa)
ye i get all attacks then it's disabled, doesn't know whats wrong
 

owned

Excellent OT User
Joined
Nov 9, 2008
Messages
2,001
Best answers
3
Reaction score
527
Location
New York
@zbizu Previous script should 100% work.
Try restarting your server after you've implemented it to make sure it's properly updated.
 
OP
I

insebbe123

New Member
Joined
Mar 31, 2012
Messages
42
Best answers
0
Reaction score
0
@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
 
Top