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

C++ problem

  • Thread starter Thread starter Emky
  • Start date Start date
Currently this is how it is:
player1 on top, player2 below, player1 uses UH = player1 gets healed
player1 on top, player2 below, player2 uses UH = player2 gets healed

so both gets healed no matter what currently, but it should be that only the top player gets healed(player1) regardless of who uses the UH.
acko uh trap: youtu.be/uRIDuixN88w?t=19m1s

Code:
void Combat::CombatFunc(Creature* caster, const Position& pos,
    const AreaCombat* area, const CombatParams& params, COMBATFUNC func, void* data)
{
    std::list<Tile*> tileList;

    if (caster){
        getCombatArea(caster->getPosition(), pos, area, tileList);
    }
    else{
        getCombatArea(pos, pos, area, tileList);
    }

    SpectatorVec list;
    uint32_t maxX = 0;
    uint32_t maxY = 0;
    uint32_t diff;

    //calculate the max viewable range
    for (std::list<Tile*>::iterator it = tileList.begin(); it != tileList.end(); ++it){
        diff = std::abs((*it)->getPosition().x - pos.x);
        if (diff > maxX){
            maxX = diff;
        }

        diff = std::abs((*it)->getPosition().y - pos.y);
        if (diff > maxY){
            maxY = diff;
        }
    }

    g_game.getSpectators(list, pos, false, true, maxX + Map::maxViewportX, maxX + Map::maxViewportX,
        maxY + Map::maxViewportY, maxY + Map::maxViewportY);

    for (std::list<Tile*>::iterator it = tileList.begin(); it != tileList.end(); ++it){
        Tile* iter_tile = *it;
        bool bContinue = true;

        if (canDoCombat(caster, iter_tile, params.isAggressive) == RET_NOERROR){
            if (iter_tile->getCreatures()){
                for (CreatureVector::iterator cit = iter_tile->getCreatures()->begin(),
                    cend = iter_tile->getCreatures()->end();
                    bContinue && cit != cend; ++cit)
                {
                    if (params.targetCasterOrTopMost){
                        if (caster && caster->getTile() == iter_tile){
                            if (*cit == caster){
                                bContinue = false;
                            }
                        }
                        else if (*cit == iter_tile->getTopCreature()){
                            bContinue = false;
                        }

                        if (bContinue){
                            continue;
                        }
                    }

                    if (!params.isAggressive || (caster != *cit && Combat::canDoCombat(caster, *cit) == RET_NOERROR)){
                        func(caster, *cit, params, data);

                        if (params.targetCallback){
                            params.targetCallback->onTargetCombat(caster, *cit);
                        }

                        if (func == CombatDispelFunc || func == CombatConditionFunc){
                            onCreatureDoCombat(caster, *cit, params.isAggressive);
                        }
                    }
                }
            }

            combatTileEffects(list, caster, iter_tile, params);
        }
    }

    postCombatEffects(caster, pos, params);
}

I'm using OThire Dist, if anyone know how to fix this. I would much appreciate it!, i already tested with avesta and it was wrong aswell.

Try commenting those lines:
Code:
                        if (caster && caster->getTile() == iter_tile){
                            if (*cit == caster){
                                bContinue = false;
                            }
                        }

And remove that else after it
 
I am not sure if it is variant.pos or just variant..
Code:
local combat = Combat()
combat:setParameter(COMBAT_PARAM_TYPE, COMBAT_HEALING)
combat:setParameter(COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
combat:setParameter(COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
combat:setParameter(COMBAT_PARAM_TARGETCASTERORTOPMOST, true)
combat:setParameter(COMBAT_PARAM_AGGRESSIVE, false)

function onGetFormulaValues(player, level, maglevel)
    local min = (level / 5) + (maglevel * 7.3) + 42
    local max = (level / 5) + (maglevel * 12.4) + 90
    return min, max
end

combat:setCallback(CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")

function onCastSpell(creature, variant, isHotkey)
    local selfPosition = creature:getPosition()
    return combat:execute(creature, variant == selfPosition and selfPosition or variant)
end
 
nope not working, not even any error. Are you sure this can be solved with lua? :eek:

also i tried to rewrite it without any success, this might be wrong tho not sure..
Code:
function onCastSpell(cid, var)
    local selfPosition = getPlayerPos(cid)
    if var == selfPosition and selfPosition or var then
        return doCombat(cid, combat, var)
    end
end
 
Code:
function onCastSpell(cid, var)
    local pos = getPlayerPos(cid)
    var = var == pos and pos or var
    return doCombat(cid, combat, var)
end

Edit: If it doesn't work
Code:
print( unpack(var) )
 
The stack of players are reversed. You need to find a way to execute use on the player at the very bottom (even though he entered last of all players a stack)
 
Well i'm gonna need help with that since i'm not so good with this. I would appreciate if anyone took their time to look into this issue for me
 
Still nothing, if anyone have any other solutions let me know
You could learn lua :)
Well i'm gonna need help with that since i'm not so good with this. I would appreciate if anyone took their time to look into this issue for me
You need a basic foundation in the language to have general idea of what your looking at, I am just trying to help, its nice to learn by example but at some point you have to learn the language :)
 
You could learn lua :)

You need a basic foundation in the language to have general idea of what your looking at, I am just trying to help, its nice to learn by example but at some point you have to learn the language :)

I guess its not a lua problem, i have fixed that via source on TFS 0.4
Might be a different engine but the cpp Code here looks similar to TFS code.
 
try this:
Code:
local combat = createCombatObject()
setCombatParam(combat, COMBAT_PARAM_TYPE, COMBAT_HEALING)
setCombatParam(combat, COMBAT_PARAM_EFFECT, CONST_ME_MAGIC_BLUE)
setCombatParam(combat, COMBAT_PARAM_TARGETCASTERORTOPMOST, 1) 
setCombatParam(combat, COMBAT_PARAM_AGGRESSIVE, 0)
setCombatParam(combat, COMBAT_PARAM_DISPEL, CONDITION_PARALYZE)
--setCombatFormula(combat, COMBAT_FORMULA_LEVELMAGIC, 2.5, -30, 2.5, 0)
function onGetFormulaValues(cid, level, maglevel)
    min = (level * 2 + maglevel * 3) * 2.5
    max = (level * 2 + maglevel * 3) * 2.5
   
    if min < 250 then
        min = 250
    end

    return min, max
end
setCombatCallback(combat, CALLBACK_PARAM_LEVELMAGICVALUE, "onGetFormulaValues")
function onCastSpell(cid, var)
    local healed = variantToNumber(var)
    if(healed == 0) then
        local pos = variantToPosition(var)
        healed = getTopCreature(pos).uid or getTopCreature(pos)
    end
    return doCombat(cid, combat, numberToVariant( healed ))
end
 
-- Ignore this line | This is the original UHTrap, the top player CANNOT heal. --

Edit: Ops, my mistake, it just seems like the top player gets under the stack... I'm reading a c++ book and trying to reverse the damn vector.

It seems like the ingame vectoring is a little weird, since the owner of the stack (1st player to go down) keeps up on the stack, instead of going down.

The problem is probably just inverting the vector.

Wondering if std::reverse would do something here.
 
Last edited:
Back
Top