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

NPC don't sell if you don't have capacity

skic

Member
Joined
Aug 15, 2020
Messages
58
Reaction score
13
Hello guys, I'm using TFS 1.2 and when I buy something from NPC he won't sell me unless I don't have enough capacity. I want to make him throw stuff under me if I don't have the capacity.

Here's the part of the script that check's if I have cap or not:
Lua:
local a, b = doNpcSellItem(cid, shop_itemid[cid], shop_amount[cid], shop_subtype[cid], false, false, 1988)
            if(a < shop_amount[cid]) then
                local msgId = MESSAGE_NEEDMORESPACE
                if(a == 0) then
                    msgId = MESSAGE_NEEDSPACE
                end

                local msg = module.npcHandler:getMessage(msgId)
                msg = module.npcHandler:parseMessage(msg, parseInfo)
                module.npcHandler:say(msg, cid)
                if(a > 0) then
                    Player(cid):removeMoney(a * shop_cost[cid])
                    if shop_itemid[cid] == ITEM_PARCEL then
                        doNpcSellItem(cid, ITEM_LABEL, shop_amount[cid], shop_subtype[cid], true, false, 1988)
                    end
                    return true
                end
                return false
            else
                local msg = module.npcHandler:getMessage(MESSAGE_ONBUY)
                msg = module.npcHandler:parseMessage(msg, parseInfo)
                module.npcHandler:say(msg, cid)
                Player(cid):removeMoney(cost)
                if shop_itemid[cid] == ITEM_PARCEL then
                    doNpcSellItem(cid, ITEM_LABEL, shop_amount[cid], shop_subtype[cid], true, false, 1988)
                end
                return true
            end

What do I need to change here?
 
use the lib from latest tfs and it should work like that:
Ye I fixed it, just had to change:
Lua:
local a, b = doNpcSellItem(cid, shop_itemid[cid], shop_amount[cid], shop_subtype[cid], false, false, 1988)

To:
Code:
local a, b = doNpcSellItem(cid, shop_itemid[cid], shop_amount[cid], shop_subtype[cid], true, false, 1988)

Thanks for the answer anyway :)
Post automatically merged:

@Evil Puncker Hey, any idea how to fix so that I can shoot runes with target crosshair on invisible monsters like warlock? I don't know which file I should look for that?
 
Last edited:
Hey, any idea how to fix so that I can shoot runes with target crosshair on invisible monsters like warlock? I don't know which file I should look for that?
 
Same thing with this script, I think problem is with my spells.cpp.

Here's the code where it is checking:
Lua:
ReturnValue RuneSpell::canExecuteAction(const Player* player, const Position& toPos)
{
    if (player->hasFlag(PlayerFlag_CannotUseSpells)) {
        return RETURNVALUE_CANNOTUSETHISOBJECT;
    }

    ReturnValue ret = Action::canExecuteAction(player, toPos);
    if (ret != RETURNVALUE_NOERROR) {
        return ret;
    }

    if (toPos.x == 0xFFFF) {
        if (needTarget) {
            return RETURNVALUE_CANONLYUSETHISRUNEONCREATURES;
        } else if (!selfTarget) {
            return RETURNVALUE_NOTENOUGHROOM;
        }
    }

    return RETURNVALUE_NOERROR;
}

Code:
bool Spell::playerRuneSpellCheck(Player* player, const Position& toPos)
{
    if (!playerSpellCheck(player)) {
        return false;
    }

    if (toPos.x == 0xFFFF) {
        return true;
    }

    const Position& playerPos = player->getPosition();
    if (playerPos.z > toPos.z) {
        player->sendCancelMessage(RETURNVALUE_FIRSTGOUPSTAIRS);
        g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
        return false;
    } else if (playerPos.z < toPos.z) {
        player->sendCancelMessage(RETURNVALUE_FIRSTGODOWNSTAIRS);
        g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
        return false;
    }

    Tile* tile = g_game.map.getTile(toPos);
    if (!tile) {
        player->sendCancelMessage(RETURNVALUE_NOTPOSSIBLE);
        g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
        return false;
    }

    if (range != -1 && !g_game.canThrowObjectTo(playerPos, toPos, true, range, range)) {
        player->sendCancelMessage(RETURNVALUE_DESTINATIONOUTOFREACH);
        g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
        return false;
    }

    ReturnValue ret = Combat::canDoCombat(player, tile, aggressive);
    if (ret != RETURNVALUE_NOERROR) {
        player->sendCancelMessage(ret);
        g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
        return false;
    }

    const Creature* topVisibleCreature = tile->getBottomVisibleCreature(player);
    if (blockingCreature && topVisibleCreature) {
        player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM);
        g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
        return false;
    } else if (blockingSolid && tile->hasFlag(TILESTATE_BLOCKSOLID)) {
        player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM);
        g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
        return false;
    }

    if (needTarget && !topVisibleCreature) {
        player->sendCancelMessage(RETURNVALUE_CANONLYUSETHISRUNEONCREATURES);
        g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
        return false;
    }

    if (aggressive && needTarget && topVisibleCreature && player->hasSecureMode()) {
        const Player* targetPlayer = topVisibleCreature->getPlayer();
        if (targetPlayer && targetPlayer != player && player->getSkullClient(targetPlayer) == SKULL_NONE && !Combat::isInPvpZone(player, targetPlayer)) {
            player->sendCancelMessage(RETURNVALUE_TURNSECUREMODETOATTACKUNMARKEDPLAYERS);
            g_game.addMagicEffect(player->getPosition(), CONST_ME_POFF);
            return false;
        }
    }
    return true;
}

Look at RETURNVALUE_CANONLYUSETHISRUNEONCREATURES
Post automatically merged:


Nevermind I fixed it, I forgot to save file after changing needTarget.. so dumb..
Thank you for the help :)
 
Last edited:
Back
Top