• Vote in May Mapping Competition to select a winner!
  • 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!

Lua Resistance CreatureEvent Problem

alvaro007

New Member
Joined
Jun 15, 2012
Messages
35
Best answers
0
Reaction score
2
Hi, i have a problem, i have done a resistance elemental script that seem work correctly but i have a problem, when other player attack you and you have low hp, the player who attack u dont get killing you, you are with 1 hp and no never die, this is my script help me pls:

Lua:
local TimStr = 398931

  local element = {
  -- [Tipo de daño] = {porcentaje de daño},
    [COMBAT_PHYSICALDAMAGE] = 40, -- Físico.

    [COMBAT_ICEDAMAGE] = 10, -- Mágico.
    [COMBAT_FIREDAMAGE] = 90, -- Mágico.
    [COMBAT_EARTHDAMAGE] = 10, -- Mágico.
    [COMBAT_ENERGYDAMAGE] = 90, -- Mágico.

    [COMBAT_HOLYDAMAGE] = 10, -- ¿Mágico?
    [COMBAT_DEATHDAMAGE] = 10, -- ¿Mágico?
  }

function onStatsChange(cid, attacker, type, combat, value)

      local v = element[combat]

        if isPlayer(cid) and getPlayerStorageValue(cid, TimStr+1) ~= 1 and v and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then

          local newValue = (value * v) / 100
            setPlayerStorageValue(cid, TimStr+1, 1)
            doTargetCombatHealth(attacker, cid, combat, math.floor(newValue - value), math.floor(newValue - value), CONST_ME_NONE)
            setPlayerStorageValue(cid, TimStr+1, -1)

          return
        end
    end

  return true
end
Sorry for my english and thank you
 
Last edited:

Xikini

I whore myself out for likes
Joined
Nov 17, 2010
Messages
4,213
Best answers
185
Reaction score
2,271
as-is, I doubt your script even loads into the game, since you have an extra return and end currently in the script.

Untitled.png

Beyond that, what you want to do to fix your issue is to confirm whether or not the damage they are about to take is going to kill them or not, then simply let it pass normally instead of attempting to reduce the damage and send it through again.

(This is because "value" can only ever be the remaining hp of the person.)
This is easy to check, by hitting a person with a higher damage then their remaining hp value, and printing the value inside of onStatsChange

A side note, is that increasing and reducing the storage value like you are currently doing it doesn't do anything.
When you trigger the 'doTargetCombatHealth' it doesn't actually damage the person until this script is finished already.

Initial damage -> reduce damage -> storage set to 1 -> storage set to 0 -> script end
doTargetCombatHealth damage -> ?? repeat the reduce damage infinitely?

beyond that..

Because of the other issue.. you have a new issue of someone being 90% resistant to magic.. so even if they are hit with 8 billion damage the maximum they will be hit is their current hp value..

Anyway..you can figure that issue out on your own..

To fix your current issue of them not dying.. simply check "value" against the target's current remaining hp... then return true the damage instea dof mitigatinga portion of it.
 
OP
A

alvaro007

New Member
Joined
Jun 15, 2012
Messages
35
Best answers
0
Reaction score
2
mmm something like that:

Lua:
local TimStr = 415897

local element = {
   -- [Tipo de daño] = {porcentaje de daño},
     [COMBAT_PHYSICALDAMAGE] = 40, -- Físico.

     [COMBAT_ICEDAMAGE] = 10, -- Mágico.
     [COMBAT_FIREDAMAGE] = 10, -- Mágico.
     [COMBAT_EARTHDAMAGE] = 10, -- Mágico.
     [COMBAT_ENERGYDAMAGE] = 10, -- Mágico.

     [COMBAT_HOLYDAMAGE] = 10, -- ¿Mágico?
     [COMBAT_DEATHDAMAGE] = 10, -- ¿Mágico?
}

function onStatsChange(cid, attacker, type, combat, value)

     local v = element[combat]

       if isPlayer(cid) and getPlayerStorageValue(cid, TimStr+1) ~= 1 and v and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then
        if (getCreatureHealth(cid) - value) > 0 then

         local newValue = (value * v) / 100
           setPlayerStorageValue(cid, TimStr+1, 1)
           doTargetCombatHealth(attacker, cid, combat, math.floor(newValue - value), math.floor(newValue - value), CONST_ME_NONE)
           setPlayerStorageValue(cid, TimStr+1, -1)

         return
       end
   end

return true
end
 
Last edited:
OP
A

alvaro007

New Member
Joined
Jun 15, 2012
Messages
35
Best answers
0
Reaction score
2
Now work, but the problem is that the last hit dont reduce the true damage of value and i dont know how fix that, i have trying fix it but when i reduce the last hit, the player dont die again :(
 

Xikini

I whore myself out for likes
Joined
Nov 17, 2010
Messages
4,213
Best answers
185
Reaction score
2,271
Now work, but the problem is that the last hit dont reduce the true damage of value and i dont know how fix that, i have trying fix it but when i reduce the last hit, the player dont die again :(
Only way to reduce the true value of damage is to reduce it before the attack hits the creature.
(inside the attack calculation itself.)

Or do a source edit.

Otherwise, work with what you got.
 
OP
A

alvaro007

New Member
Joined
Jun 15, 2012
Messages
35
Best answers
0
Reaction score
2
I did that:

Lua:
local TimStr = 415897

local element = {
   -- [Tipo de daño] = {porcentaje de daño},
     [COMBAT_PHYSICALDAMAGE] = 40, -- Físico.

     [COMBAT_ICEDAMAGE] = 10, -- Mágico.
     [COMBAT_FIREDAMAGE] = 10, -- Mágico.
     [COMBAT_EARTHDAMAGE] = 10, -- Mágico.
     [COMBAT_ENERGYDAMAGE] = 10, -- Mágico.

     [COMBAT_HOLYDAMAGE] = 10, -- ¿Mágico?
     [COMBAT_DEATHDAMAGE] = 10, -- ¿Mágico?
}

function onStatsChange(cid, attacker, type, combat, value)

     local v = element[combat]

    if isPlayer(cid) and getPlayerStorageValue(cid, TimStr+1) ~= 1 and v and (type == STATSCHANGE_HEALTHLOSS or type == STATSCHANGE_MANALOSS) then

     local newValue = (value * v) / 100
         if (getCreatureHealth(cid) + (newValue-value) > 0) then

           setPlayerStorageValue(cid, TimStr+1, 1)
           doTargetCombatHealth(attacker, cid, combat, math.floor(newValue - value), math.floor(newValue - value), CONST_ME_NONE)
           setPlayerStorageValue(cid, TimStr+1, -1)

         return
       end
   end

return true
end
Should work but again the player dont die, and first i check the reduction value with health of player and then if is false i return the true damage but dont work, i dont know why :(
 

Perun

nems.online
Joined
May 1, 2009
Messages
308
Best answers
6
Reaction score
127
change
return
to
return true

return means if you return true on statschange or not, if u're not returning true it will not stats change
 
OP
A

alvaro007

New Member
Joined
Jun 15, 2012
Messages
35
Best answers
0
Reaction score
2
Its not a good idea, if u put a return true where is return u are return the true value and the reduction value, both of values and then ur player doing more damage
 

heba

Advanced OT User
Joined
Aug 5, 2011
Messages
1,428
Best answers
15
Reaction score
199
try this
u need source edit because if u used lua and got 50+ player online will lag your server
 
OP
A

alvaro007

New Member
Joined
Jun 15, 2012
Messages
35
Best answers
0
Reaction score
2
The problem to did that on source is that if i want to use this script to create a spell, i couldnt because i would need a creaturescript with a storage id to connect with a spell script.
 

heba

Advanced OT User
Joined
Aug 5, 2011
Messages
1,428
Best answers
15
Reaction score
199
The problem to did that on source is that if i want to use this script to create a spell, i couldnt because i would need a creaturescript with a storage id to connect with a spell script.
look to my idea for u
lets say this spell block fire damage for 5 sec
this part in source
Lua:
     // fire protection
          if(target && target->getPlayer())
           {
            std::string value;
            target->getPlayer()->getStorage(173397, value);
            tmp = (int32_t)(atoi(value.c_str()));
            if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
            damage = (int64_t)std::floor (damage - damage * tmp /100);
            addAnimatedText("FIRE PROTECT", targetPos, hitColor, buffer);
            else if(tmp > 0 && combatType == COMBAT_FIREDAMAGE)
                 damage = 0;

        }
how to make spell block 10% from fire damage
like this one
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_RED)
setCombatParam(combat, COMBAT_PARAM_DISTANCEEFFECT, CONST_ANI_DEATH)



local function Back(cid)
    if(isPlayer(cid)) then
    doCreatureSetStorage(cid, 173397, 0)
    doCreatureSetStorage(cid, 173392, 0)
    doSendMagicEffect(getCreaturePosition(cid),77)
    end
    return true
end

function onCastSpell(cid, var)
if exhaustion.check(cid, 23900) == false then
exhaustion.set(cid, 23900, 15)
doCreatureSetStorage(cid, 173392, 1) -- for check when player login
     doCreatureSetStorage(cid, 173397, 10)
     addEvent(doSendEffectes, 5000, cid)
     addEvent(Back,5000,cid)  
     doCombat(cid, combat, var)
     else
doPlayerSendCancel(cid,"You will be able to cast this spell again in " ..exhaustion.get(cid, 23900).." seconds.")
     end
     return true
end
and add in login ( this because if player logout or die )
if getPlayerStorageValue(cid, 173392) >= 1 then
doCreatureSetStorage(cid, 173397, 0)
doCreatureSetStorage(cid, 173392, 0)
end
 
OP
A

alvaro007

New Member
Joined
Jun 15, 2012
Messages
35
Best answers
0
Reaction score
2
I did and no work, I use the spell and nothing happen and this part why:

Lua:
addEvent(doSendEffectes, 5000, cid)
Dont exist on script this function "doSendEffectes"
 
Last edited:

heba

Advanced OT User
Joined
Aug 5, 2011
Messages
1,428
Best answers
15
Reaction score
199
I did and no work, I use the spell and nothing happen and this part why:

Lua:
addEvent(doSendEffectes, 5000, cid)
Dont exist on script this function "doSendEffectes"
remove it
Lua:
addEvent(doSendEffectes, 5000, cid)
 
Top