• 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++ addBestiaryKill

alcapone

Member
Joined
Jan 13, 2021
Messages
246
Reaction score
19
I would like to put an option to put bestiary 3x

Lua:
void IOBestiary::addBestiaryKill(Player* player, MonsterType* mtype, uint32_t amount /*= 1*/)
{
    uint16_t raceid = mtype->info.raceid;
    if (raceid == 0 || !player || !mtype) {
        return;
    }
    uint32_t curCount = player->getBestiaryKillCount(raceid);
    std::ostringstream ss;

    player->addBestiaryKillCount(raceid, amount);

    if (curCount == 0) {
        player->sendBestiaryEntryChanged(raceid);
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        return;
    }

    curCount += amount;

    if ((curCount == mtype->info.bestiaryFirstUnlock) || (curCount == mtype->info.bestiarySecondUnlock)) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        player->sendBestiaryEntryChanged(raceid);
    } else if (curCount == mtype->info.bestiaryToUnlock) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        addCharmPoints(player, mtype->info.bestiaryCharmsPoints);
        player->sendBestiaryEntryChanged(raceid);
    }

    std::list<MonsterType*> trackerList = player->getBestiaryTrackerList();
    for (MonsterType* mType : trackerList) {
        if (raceid == mType->info.raceid) {
            player->refreshBestiaryTracker(trackerList);
        }
    }
}
 
Solution
E
change:

C++:
player->addBestiaryKillCount(raceid, amount);

to:

C++:
player->addBestiaryKillCount(raceid, amount * 3);

recompile.
enjoy.
it worked in parts when it closes the right amount the player sometimes wins the points and when it passes the kill number the player doesn't get the points
 
The problem is say for example you have 48 kills and the bestiary unlock is 50, when it adds 3 points the total points is now 51.

This line is checking if the current count is exactly 50, and 51 does not equal 50, and that's why its sometimes working because if you had 47 points and added 3, you would receive the charm points
C++:
if ((curCount == mtype->info.bestiaryFirstUnlock) || (curCount == mtype->info.bestiarySecondUnlock)) {

You cant simply change the line to this either:
C++:
if ((curCount > mtype->info.bestiaryFirstUnlock) || (curCount > mtype->info.bestiarySecondUnlock)) {
This would then execute the code for every kill if you're over the unlock limit

....

A solution would be to check within the range. This isn't pretty and there probably is a much better solution.

Change this:
C++:
if ((curCount == mtype->info.bestiaryFirstUnlock) || (curCount == mtype->info.bestiarySecondUnlock)) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        player->sendBestiaryEntryChanged(raceid);
    } else if (curCount == mtype->info.bestiaryToUnlock) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        addCharmPoints(player, mtype->info.bestiaryCharmsPoints);
        player->sendBestiaryEntryChanged(raceid);
    }

for this:
C++:
if ((curCount >= mtype->info.bestiaryFirstUnlock && curCount < mtype->info.bestiaryFirstUnlock + 3) || (curCount >= mtype->info.bestiarySecondUnlock && curCount < mtype->info.bestiarySecondUnlock + 3)) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        player->sendBestiaryEntryChanged(raceid);
    } else if (curCount >= mtype->info.bestiaryToUnlock && curCount < mtype->info.bestiaryToUnlock + 3) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        addCharmPoints(player, mtype->info.bestiaryCharmsPoints);
        player->sendBestiaryEntryChanged(raceid);
    }
 
The problem is say for example you have 48 kills and the bestiary unlock is 50, when it adds 3 points the total points is now 51.

This line is checking if the current count is exactly 50, and 51 does not equal 50, and that's why its sometimes working because if you had 47 points and added 3, you would receive the charm points
C++:
if ((curCount == mtype->info.bestiaryFirstUnlock) || (curCount == mtype->info.bestiarySecondUnlock)) {

You cant simply change the line to this either:
C++:
if ((curCount > mtype->info.bestiaryFirstUnlock) || (curCount > mtype->info.bestiarySecondUnlock)) {
This would then execute the code for every kill if you're over the unlock limit

....

A solution would be to check within the range. This isn't pretty and there probably is a much better solution.

Change this:
C++:
if ((curCount == mtype->info.bestiaryFirstUnlock) || (curCount == mtype->info.bestiarySecondUnlock)) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        player->sendBestiaryEntryChanged(raceid);
    } else if (curCount == mtype->info.bestiaryToUnlock) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        addCharmPoints(player, mtype->info.bestiaryCharmsPoints);
        player->sendBestiaryEntryChanged(raceid);
    }

for this:
C++:
if ((curCount >= mtype->info.bestiaryFirstUnlock && curCount < mtype->info.bestiaryFirstUnlock + 3) || (curCount >= mtype->info.bestiarySecondUnlock && curCount < mtype->info.bestiarySecondUnlock + 3)) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        player->sendBestiaryEntryChanged(raceid);
    } else if (curCount >= mtype->info.bestiaryToUnlock && curCount < mtype->info.bestiaryToUnlock + 3) {
        ss << "You unlocked details for the creature '" << mtype->name << "'";
        player->sendTextMessage(MESSAGE_STATUS, ss.str());
        addCharmPoints(player, mtype->info.bestiaryCharmsPoints);
        player->sendBestiaryEntryChanged(raceid);
    }
it worked, thanks everyone now i need only understand a problem players who are in pt is doubling the points 3x gets 6x for pt players

local bestiaryOnKill = CreatureEvent("BestiaryOnKill")
function bestiaryOnKill.onKill(player, creature, lastHit)

if not player:isPlayer() or not creature:isMonster() or creature:hasBeenSummoned() or creature:isPlayer() then
return true
end

for cid, damage in pairs(creature:getDamageMap()) do
local participant = Player(cid)
if participant and participant:isPlayer() then
participant:addBestiaryKill(creature:getName())
end
end

return true
end
bestiaryOnKill:register()

will it be something in the lua script?
 
use onDeath instead of onKill:
 
data/scripts/creaturescripts/others/bestiary_kill.lua

You must change from:
Lua:
participant:addBestiaryKill(creature:getName())

For:
Lua:
participant:addBestiaryKill(creature:getName(), 3)

OP has already changed the sources so he only needs to call the original LUA. If he didn't change the sources he would still get the issue where the charm points aren't being added.
 
use onDeath instead of onKill:
and @Boy67

thanks works the changes in src


changing the kill to 'onDeath' no longer works when I make the change it doesn't count the kill
 
Back
Top