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

block damage if have x amount of storage

mmheo

New Member
Joined
Sep 14, 2017
Messages
157
Reaction score
1
i need script for block damage by storage

if player have x storage value 1 block 1% from all damage

if player have x storage value 2 block 2% from all damage

Etc

if player have storage value 100 block 100% from damage

2 : premium npc for token 1 token = one premium day
2 tokens = 2 premium day
Etc

3: npc give me storage for money its work one time only

tfs 0.4
 
Last edited:
Solution
You can try this, I haven't tested it, theoretically it should work but it's really not a smart way of doing it, I don't like using addEvent this often:
In this case, your stackoverflow protection would be triggered after receiving damaged, then removed after 0.1 seconds allowing for another attack to be blocked after 0.1 seconds, but if you receive more instances of damage during this 0.1 second period, they will not be blocked. But it's not safe at all cuz it can still happen that 2 creatures are attacking you at once, one attack will be blocked, the second will be received within these 0.1 seconds, and stack overflow will happen. My 0.3.6 engine catches it and limits the overflow to avoid crash, but you will still get a ton of errors...
Make a statschange type creaturescript and try something like this, I think it should work:

Lua:
function onStatsChange(cid, attacker, type, combat, value)
    if type == STATSCHANGE_HEALTHLOSS then
        if value > 0 then
            local reduce_by_percent = getPlayerStorageValue(cid, SOME_STORAGE) * 0.01
            value = value - (value * reduce_by_percent)
        end
    end
    return true
end
 
Make a statschange type creaturescript and try something like this, I think it should work:

Lua:
function onStatsChange(cid, attacker, type, combat, value)
    if type == STATSCHANGE_HEALTHLOSS then
        if value > 0 then
            local reduce_by_percent = getPlayerStorageValue(cid, SOME_STORAGE) * 0.01
            value = value - (value * reduce_by_percent)
        end
    end
    return true
end
here no work i give myself storage value 100 and monster can hit me i need 1 value = 1% block damage
 
here no work i give myself storage value 100 and monster can hit me i need 1 value = 1% block damage

Nevermind bro, that's not gonna work, I read into how this works and there's kinda no effective way to do it through LUA. I tried cancelling out the original damage later and creating a new instance of damage with manipulated value via doTargetCombatHealth but onStatsChange triggers itself again in that case, resulting in a swarm of damage instances. For your request to be done, you're best off editing it in sources, but that's out of my domain of comfort so I'm afraid I can't help with this, sorry.
 
Nevermind bro, that's not gonna work, I read into how this works and there's kinda no effective way to do it through LUA. I tried cancelling out the original damage later and creating a new instance of damage with manipulated value via doTargetCombatHealth but onStatsChange triggers itself again in that case, resulting in a swarm of damage instances. For your request to be done, you're best off editing it in sources, but that's out of my domain of comfort so I'm afraid I can't help with this, sorry.
:S at first i think this is easy script anyway thx so much you helped me enough today
 
it can be done through lua, it's just trickier because you're using 0.4
try this
Lua:
local storage = 815500 -- make sure stack overflow doesn't happen, don't change this
local modifier = 77001 -- storage key for damage reduction

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and getPlayerStorageValue(attacker, config.storage) == 1 then
        if getPlayerStorageValue(cid, storage) == -1 then
            doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
            local modifierValue = getPlayerStorageValue(cid, modifier)
            modifierValue = (modifierValue == -1) and 0 or modifierValue
            local damage = value - (value * (modifierValue / 100))
            if type == STATSCHANGE_HEALTHLOSS then
                doTargetCombatHealth(attacker, cid, combat, -damage, -damage, 255)
            else
                doTargetCombatMana(attacker, cid, -damage, -damage, 255)
            end
            return false
        else
            doPlayerSetStorageValue(cid, storage, -1)
        end
    end
    return true
end
 
it can be done through lua, it's just trickier because you're using 0.4
try this
Lua:
local storage = 815500 -- make sure stack overflow doesn't happen, don't change this
local modifier = 77001 -- storage key for damage reduction

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and getPlayerStorageValue(attacker, config.storage) == 1 then
        if getPlayerStorageValue(cid, storage) == -1 then
            doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
            local modifierValue = getPlayerStorageValue(cid, modifier)
            modifierValue = (modifierValue == -1) and 0 or modifierValue
            local damage = value - (value * (modifierValue / 100))
            if type == STATSCHANGE_HEALTHLOSS then
                doTargetCombatHealth(attacker, cid, combat, -damage, -damage, 255)
            else
                doTargetCombatMana(attacker, cid, -damage, -damage, 255)
            end
            return false
        else
            doPlayerSetStorageValue(cid, storage, -1)
        end
    end
    return true
end

how this work?? i use this storage 45003 if have 45003 value 1 block 1% from damage
where i must change storage for 45003 local storage or local modifier
 
how this work?? i use this storage 45003 if have 45003 value 1 block 1% from damage
where i must change storage for 45003 local storage or local modifier

You should change the modifier table to this

Lua:
local modifier = 45003 -- storage key for damage reduction

Edit:
The first line should be untouched as stated in the comment
 
What if you try this script
Lua:
local storage = 815500 -- make sure stack overflow doesn't happen, don't change this
local modifier = 45003 -- storage key for damage reduction

function onStatsChange(cid, attacker, type, combat, value)
        if getPlayerStorageValue(cid, storage) == -1 then
            doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
            local modifierValue = getPlayerStorageValue(cid, modifier)
            modifierValue = (modifierValue == -1) and 0 or modifierValue
            local damage = value - (value * (modifierValue / 100))
            if type == STATSCHANGE_HEALTHLOSS then
                doTargetCombatHealth(attacker, cid, combat, -damage, -damage, 255)
            else
                doTargetCombatMana(attacker, cid, -damage, -damage, 255)
            end
            return false
        else
            doPlayerSetStorageValue(cid, storage, -1)
        end
    return true
end
 
it can be done through lua, it's just trickier because you're using 0.4
try this
Lua:
local storage = 815500 -- make sure stack overflow doesn't happen, don't change this
local modifier = 77001 -- storage key for damage reduction

function onStatsChange(cid, attacker, type, combat, value)
    if isPlayer(attacker) and getPlayerStorageValue(attacker, config.storage) == 1 then
        if getPlayerStorageValue(cid, storage) == -1 then
            doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
            local modifierValue = getPlayerStorageValue(cid, modifier)
            modifierValue = (modifierValue == -1) and 0 or modifierValue
            local damage = value - (value * (modifierValue / 100))
            if type == STATSCHANGE_HEALTHLOSS then
                doTargetCombatHealth(attacker, cid, combat, -damage, -damage, 255)
            else
                doTargetCombatMana(attacker, cid, -damage, -damage, 255)
            end
            return false
        else
            doPlayerSetStorageValue(cid, storage, -1)
        end
    end
    return true
end

Yeah this is what I tried pretty much but it didn't work out so well, but this doesn't look like it's gonna do the trick either, in my case because I used a timed protecting for stackoverflow, but that's messed up, and in your case because it only triggers for 50% of the hits and reset the storage on the other 50%. So in both cases, it can happen that the creature still receives damage between 2 instances of this triggering, as demonstrated below using this script:

You can see I'm still taking damage even though my 77001 storage is at 100. Sometimes it blocks it, sometimes not, which does not suffice for these purposes.
ZkAdj1U.gif





If you read the script, you will see there are some conditions that monsters will never meet, namely the first condition which requires the attacker to be a Player and to have config.storage (?) set to 1 for this script to trigger.
If you delete this condition, the script will work, but it will work how you see in this gif.

It's best done in sources, all you can manage in Lua must go through sketchy creaturescripts.
 
Yeah this is what I tried pretty much but it didn't work out so well, but this doesn't look like it's gonna do the trick either, in my case because I used a timed protecting for stackoverflow, but that's messed up, and in your case because it only triggers for 50% of the hits and reset the storage on the other 50%. So in both cases, it can happen that the creature still receives damage between 2 instances of this triggering, as demonstrated below using this script:

You can see I'm still taking damage even though my 77001 storage is at 100. Sometimes it blocks it, sometimes not, which does not suffice for these purposes.
ZkAdj1U.gif






If you read the script, you will see there are some conditions that monsters will never meet, namely the first condition which requires the attacker to be a Player and to have config.storage (?) set to 1 for this script to trigger.
If you delete this condition, the script will work, but it will work how you see in this gif.

It's best done in sources, all you can manage in Lua must go through sketchy creaturescripts.
yea i understood now this script work like dodge system this mean first hit to add storage value 1 second hit to reduced * storage value
 
You can try this, I haven't tested it, theoretically it should work but it's really not a smart way of doing it, I don't like using addEvent this often:
In this case, your stackoverflow protection would be triggered after receiving damaged, then removed after 0.1 seconds allowing for another attack to be blocked after 0.1 seconds, but if you receive more instances of damage during this 0.1 second period, they will not be blocked. But it's not safe at all cuz it can still happen that 2 creatures are attacking you at once, one attack will be blocked, the second will be received within these 0.1 seconds, and stack overflow will happen. My 0.3.6 engine catches it and limits the overflow to avoid crash, but you will still get a ton of errors in the console.

Lua:
local storage = 815500 -- make sure stack overflow doesn't happen, don't change this
local modifier = 77001 -- storage key for damage reduction
local dmg_receive_limit = 100 -- miliseconds between which these blocks are not triggering

function onStatsChange(cid, attacker, type, combat, value)
        if getPlayerStorageValue(cid, storage) == -1 then
            doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
            local modifierValue = getPlayerStorageValue(cid, modifier)
            modifierValue = (modifierValue == -1) and 0 or modifierValue
            local damage = value - (value * (modifierValue / 100))
            if type == STATSCHANGE_HEALTHLOSS then
                doTargetCombatHealth(attacker, cid, combat, -damage, -damage, 255)
            else
                doTargetCombatMana(attacker, cid, -damage, -damage, 255)
            end
            addEvent(function()
                if isCreature(cid) then
                    doPlayerSetStorageValue(cid, storage, -1)
                end
            end,dmg_receive_limit)
            return false
        end
    return true
end
 
Solution
You can try this, I haven't tested it, theoretically it should work but it's really not a smart way of doing it, I don't like using addEvent this often:
In this case, your stackoverflow protection would be triggered after receiving damaged, then removed after 0.1 seconds allowing for another attack to be blocked after 0.1 seconds, but if you receive more instances of damage during this 0.1 second period, they will not be blocked. But it's not safe at all cuz it can still happen that 2 creatures are attacking you at once, one attack will be blocked, the second will be received within these 0.1 seconds, and stack overflow will happen. My 0.3.6 engine catches it and limits the overflow to avoid crash, but you will still get a ton of errors in the console.

Lua:
local storage = 815500 -- make sure stack overflow doesn't happen, don't change this
local modifier = 77001 -- storage key for damage reduction
local dmg_receive_limit = 100 -- miliseconds between which these blocks are not triggering

function onStatsChange(cid, attacker, type, combat, value)
        if getPlayerStorageValue(cid, storage) == -1 then
            doPlayerSetStorageValue(cid, storage, 1) -- set storage value before the creature takes another hit to avoid overflow
            local modifierValue = getPlayerStorageValue(cid, modifier)
            modifierValue = (modifierValue == -1) and 0 or modifierValue
            local damage = value - (value * (modifierValue / 100))
            if type == STATSCHANGE_HEALTHLOSS then
                doTargetCombatHealth(attacker, cid, combat, -damage, -damage, 255)
            else
                doTargetCombatMana(attacker, cid, -damage, -damage, 255)
            end
            addEvent(function()
                if isCreature(cid) then
                    doPlayerSetStorageValue(cid, storage, -1)
                end
            end,dmg_receive_limit)
            return false
        end
    return true
end
work fine
you add time to reduced damage every 1 sec reduced right ??

what about second script :D premium npc and other npc


you must be staff here :D
 
Last edited:
work fine
you add time to reduced damage every 1 sec reduced right ??

what about second script :D premium npc and other npc


you must be staff here :D

The rule is that you can only get reduced damage when your storage is set to -1. When you get hit, damage is reduced and your storage is set to 1 for 0.1 seconds, then it is set back to -1 so you can get your resistance again.
If there was no delay at all, this script would infinitely trigger itself, causing problems, so a mimimal delay must exist. I set it to 100 miliseconds, but you can further reduce this if you wanna test around.

However, within this current 0.1 second window of opportunity, it is possible for you to receive more than one instance of damage, and this infinite loop will happen, posing a huge stability problem.
Best case scenario, your engine will catch the stack overflow and prevent it from crashing the server, but you will still receive full damage during this time even if you have 100% resistance.
Worst case scenario, server will crash.

I advise you not to use this script at all, but at least we got to some conclusion. If you must use it, use it sparingly, don't make this into some system that every player will use at all times, that's just asking for trouble.
You can try to reduce this delay from 0.1 seconds to 0.01 seconds, it may prove more safe, but at the same time, using addEvents at such short intervals can also be a stability risk.

About your other request, I suggest you make another thread about it, so that when it's answered, other people who are looking for similar stuff can easily find the thread using search.
 
The rule is that you can only get reduced damage when your storage is set to -1. When you get hit, damage is reduced and your storage is set to 1 for 0.1 seconds, then it is set back to -1 so you can get your resistance again.
If there was no delay at all, this script would infinitely trigger itself, causing problems, so a mimimal delay must exist. I set it to 100 miliseconds, but you can further reduce this if you wanna test around.

However, within this current 0.1 second window of opportunity, it is possible for you to receive more than one instance of damage, and this infinite loop will happen, posing a huge stability problem.
Best case scenario, your engine will catch the stack overflow and prevent it from crashing the server, but you will still receive full damage during this time even if you have 100% resistance.
Worst case scenario, server will crash.

I advise you not to use this script at all, but at least we got to some conclusion. If you must use it, use it sparingly, don't make this into some system that every player will use at all times, that's just asking for trouble.
You can try to reduce this delay from 0.1 seconds to 0.01 seconds, it may prove more safe, but at the same time, using addEvents at such short intervals can also be a stability risk.

About your other request, I suggest you make another thread about it, so that when it's answered, other people who are looking for similar stuff can easily find the thread using search.
so this script not safe ???!! or what

about other thread look here
npc for premium days
 
so this script not safe ???!! or what

about other thread look here
npc for premium days

You should always try to understand what the script does when someone posts it, otherwise you will forever be asking on otland for solutions to problems. I've been repeating since the start that it's not safe, best way to do it would be in sources, not lua.
 
You should always try to understand what the script does when someone posts it, otherwise you will forever be asking on otland for solutions to problems. I've been repeating since the start that it's not safe, best way to do it would be in sources, not lua.
yes you right about it {{You should always try to understand what the script does when someone posts it}} i'm new and i try to learn to be like you be sure my english is my big problem :S i will delete this system nvm because i don't know anything in source cods :S !!
if you can help me in other scripts will be nice
 
yes you right about it {{You should always try to understand what the script does when someone posts it}} i'm new and i try to learn to be like you be sure my english is my big problem :S i will delete this system nvm because i don't know anything in source cods :S !!
if you can help me in other scripts will be nice

It's good to see you are of that mindset, the language barrier will not stop you since code is an universal language for all of us :) I'll have a look later unless someone helps out in the meantime, i'm a bit busy right now.
 
It's good to see you are of that mindset, the language barrier will not stop you since code is an universal language for all of us :) I'll have a look later unless someone helps out in the meantime, i'm a bit busy right now.
i try to learn English to be nice in conversation with other people and to understand all scripts cod.... take your time i try to make npc sell storage now im very close to done it .... really you helped me a lot today thanks for everything

anyone can help me to make it in source?
 
Back
Top