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

Feature onStatsChange for TFS 1.0

What features does it have onChangeHealth can't provide?

example reflect:
Code:
  local shoottypes = {
     [COMBAT_NONE] = {CONST_ANI_SNOWBALL, CONST_ME_DRAWBLOOD},
     [COMBAT_PHYSICALDAMAGE] = {CONST_ANI_LARGEROCK, CONST_ME_DRAWBLOOD},
     [COMBAT_ENERGYDAMAGE] = {CONST_ANI_ENERGY, CONST_ME_ENERGYHIT},
     [COMBAT_EARTHDAMAGE] = {CONST_ANI_EARTH, CONST_ME_POISONAREA},
     [COMBAT_FIREDAMAGE] = {CONST_ANI_FIRE, CONST_ME_TELEPORT},
     [COMBAT_UNDEFINEDDAMAGE] = {CONST_ANI_LARGEROCK, CONST_ME_DRAWBLOOD},
     [COMBAT_LIFEDRAIN] = {CONST_ANI_INFERNALBOLT, CONST_ME_MAGIC_RED},
     [COMBAT_MANADRAIN] = {CONST_ANI_POWERBOLT, CONST_ME_TELEPORT},
     [COMBAT_HEALING] = {CONST_ANI_LARGEROCK, CONST_ME_DRAWBLOOD},
     [COMBAT_DROWNDAMAGE] = {CONST_ANI_ENERGYBALL, CONST_ME_LOSEENERGY},
     [COMBAT_ICEDAMAGE] = {CONST_ANI_ICE, CONST_ME_ICEATTACK},
     [COMBAT_HOLYDAMAGE] = {CONST_ANI_HOLY, CONST_ME_HOLYDAMAGE},
     [COMBAT_DEATHDAMAGE] = {CONST_ANI_DEATH, CONST_ME_MORTAREA}
   }
   
   
   function onChangeHealth(cid, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
     if attacker ~= cid then
       if math.random(1, 100) <= 7 then
         reflect_dmg = -primaryDamage
         reflect_type = primaryType
         if primaryType == COMBAT_HEALING then
           reflect_dmg = primaryDamage
           reflect_type = COMBAT_PHYSICALDAMAGE
         end
         local t = Monster(cid):getTargetList()
         if #t > 0 then
           doSendDistanceShoot(getThingPos(cid), t[math.random(1, #t)]:getPosition(), shoottypes[reflect_type][1])
           doTargetCombatHealth(cid, t[math.random(1, #t)], reflect_type, reflect_dmg * 0.5, reflect_dmg * 1.5, shoottypes[reflect_type][2])
         end
       end
     end
     return true
   end
 
If you return false, the server continues doing the action so it does not matter if you return true or false. onStatsChange just stops the action if you return false and won't change player hp/mana.
 
Nice release,
could you also make oncombat, look etc?
onLook is already in TFS 1.0. Check folder events/. I have already onCombat working but just in beta testing. I'll post it when I'll be 100% sure it works.
 
If you return false, the server continues doing the action so it does not matter if you return true or false. onStatsChange just stops the action if you return false and won't change player hp/mana.
That is already fixed :p
 
I still can not and I need a lot!

I saw you have to alter sourcer in 3 archive, which is creatureevent.cpp / creatureevent.h / game.cpp

If I import the 3 changes you make to me? Please?
 
It seems some parameters at game.cpp where changed on newer tfs 1.0, so this has to be updated.
 
Not work, example:

Code:
function onChangeHealth(cid, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if isPlayer(cid) and isPlayer(attacker) then
        if getPlayerStorageValue(cid, battlefield.team_1.storage) == getPlayerStorageValue(attacker, battlefield.team_1.storage) then
            doPlayerSendCancel(attacker, "You may not attack your team mates.")
            return false
        end
      
       elseif getPlayerStorageValue(cid, battlefield.team_2.storage) == getPlayerStorageValue(attacker, battlefield.team_2.storage)  then
           doPlayerSendCancel(attacker, "You may not attack your team mates.")
           return false
       end
    end
  
    return true
end

I tested with storage1(cid) == 1 and storage1(attacker) == 1 then ..
I tested with storage1(cid) ~= -1 and storage1(attacker) ~= -1 then ...

NOT WORK, PLEASE, HELP ME
 
Not work, example:

Code:
function onChangeHealth(cid, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType)
    if isPlayer(cid) and isPlayer(attacker) then
        if getPlayerStorageValue(cid, battlefield.team_1.storage) == getPlayerStorageValue(attacker, battlefield.team_1.storage) then
            doPlayerSendCancel(attacker, "You may not attack your team mates.")
            return false
        end
     
       elseif getPlayerStorageValue(cid, battlefield.team_2.storage) == getPlayerStorageValue(attacker, battlefield.team_2.storage)  then
           doPlayerSendCancel(attacker, "You may not attack your team mates.")
           return false
       end
    end
 
    return true
end

I tested with storage1(cid) == 1 and storage1(attacker) == 1 then ..
I tested with storage1(cid) ~= -1 and storage1(attacker) ~= -1 then ...

NOT WORK, PLEASE, HELP ME

Mind making your own support thread? That's offtopic
 
try this:
Code:
function onChangeHealth(creature, attacker, primaryDamage, primaryType, secondaryDamage, secondaryType, origin)
  if creature:isPlayer() and attacker:isPlayer() then
     local player = Player(creature)
     local attackPlayer = Player(attacker)
  if player:getStorageValue(battlefield.team_1.storage) == attackPlayer:getStorageValue(battlefield.team_1.storage) then
       if primaryDamage ~= COMBAT_HEALING then
         attackerPlayer:sendCancelMessage("You may not attack your team mates.")
         return 0, primaryType, 0, secondaryType
       end
       return primaryDamage, primaryType, secondaryDamage, secondaryType
     elseif player:getStorageValue(battlefield.team_2.storage) == attackPlayer:getStorageValue(battlefield.team_2.storage)  then
  if primaryDamage ~= COMBAT_HEALING then
         attackerPlayer:sendCancelMessage("You may not attack your team mates.")
         return 0, primaryType, 0, secondaryType
       end
       return primaryDamage, primaryType, secondaryDamage, secondaryType
     end
  end
  return primaryDamage, primaryType, secondaryDamage, secondaryType
end
 
Could someone make this for latest version of TFS? It seems onstatschange is better in some ways than onChangeHealth
 
The function is already implemented in TFS 1.1+ as onHealthChange and onManaChange and works perfectly

also the creatureevent onCombat is already implemented in the folder events/ - I think only in TFS 1.2+
 
also the creatureevent onCombat is already implemented in the folder events/ - I think only in TFS 1.2+

Nope it's in 1.1 and actually the use of onStatsChange is beneficial in so many more ways, maybe not this particular version but the one from the older versions includes a little more...
 
Back
Top