• 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++ I need help (I'm doing something wrong but I don't know what)

Kownikuzyt

Member
Joined
Feb 11, 2020
Messages
170
Solutions
1
Reaction score
8
Hello, I'm trying to add "Loot Channel System".
C++ - Loot Channel System (https://otland.net/threads/loot-channel-system.254816/)

I am using the TFS 1.1 engine.

My problem after adding to code:
  • No "Loot" window opened when logging into the game.
  • The "server Log" still shows "Loot" (I wish it wouldn't show).
  • The "Loot" window does not show anything (after killing a monster, it does not show loot).



Code: data/chatchannels/chatchannels.xml



XML:
<?xml version="1.0" encoding="UTF-8"?>
<channels>
    <!--<channel id="2" name="Tutor" script="tutor.lua" />-->
    <channel id="3" name="World Chat" public="1" script="worldchat.lua" />
    <!--<channel id="4" name="English Chat" public="1" script="englishchat.lua" />-->
    <!--<channel id="5" name="Advertising" public="1" script="advertising.lua" />-->
    <!--<channel id="6" name="Advertising-Rookgaard" public="1" script="advertising-rook.lua" />-->
    <channel id="7" name="Help" public="1" script="help.lua" />
    <!--<channel id="8" name="Gamemaster" script="gamemaster.lua" />-->
    <channel id="9" name="Loot" public="1" script="loot.lua" />
</channels>



Code: data/chatchannels/scripts/loot.lua



Lua:
function onSpeak(player, type, message)
    return false
end



Code: src/const.h



#define CHANNEL_PARTY 0x01
#define CHANNEL_LOOT 0x09



Code: src/monsters.cpp



if (owner) {
std:: ostringstream ss;
ss << "Loot of " << nameDescription << ": " << corpse->getContentDescription();

if (owner->getParty()) {
owner->getParty()->broadcastPartyLoot(ss.str());
} else {
owner->sendTextMessage(MESSAGE_LOOT, ss.str());
}
owner->sendChannelMessage("", ss.str(), TALKTYPE_CHANNEL_Y, CHANNEL_LOOT);
}
} else {
std:: ostringstream ss;
ss << "Loot of " << nameDescription << ": nothing (due to low stamina)";

if (owner->getParty()) {
owner->getParty()->broadcastPartyLoot(ss.str());
} else {
owner->sendTextMessage(MESSAGE_LOOT, ss.str());
}
owner->sendChannelMessage("", ss.str(), TALKTYPE_CHANNEL_Y, CHANNEL_LOOT);
}

corpse->startDecaying();
}



Code: src/party.cpp



void Party::broadcastPartyLoot(const std::string& loot)
{
leader->sendTextMessage(MESSAGE_LOOT, loot);

for (Player* member : memberList) {
member->sendTextMessage(MESSAGE_LOOT, loot);
member->sendChannelMessage("", loot, TALKTYPE_CHANNEL_Y, CHANNEL_LOOT);
}
}



Should I just replace:
owner->sendTextMessage(MESSAGE_LOOT, ss.str());
on
owner->sendChannelMessage("", ss.str(), TALKTYPE_CHANNEL_Y, CHANNEL_LOOT);

member->sendTextMessage(MESSAGE_LOOT, loot);
on
member->sendChannelMessage("", loot, TALKTYPE_CHANNEL_Y, CHANNEL_LOOT);
 
Solution
Verify if you have pasted well the codes. Here, check

sources/party.cpp
git repo reference
line #325
Code:
void Party::broadcastPartyLoot(const std::string& loot)
{
    //leader->sendTextMessage(MESSAGE_INFO_DESCR, loot);
    leader->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);

    for (Player* member : memberList) {
        //member->sendTextMessage(MESSAGE_INFO_DESCR, loot);
        member->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
    }
}

const.h and monsters.cpp
otland reference
and git reference line #94
Code:
            if (owner->getParty()) {
                owner->getParty()->broadcastPartyLoot(ss.str());
            } else {...
Verify if you have pasted well the codes. Here, check

sources/party.cpp
git repo reference
line #325
Code:
void Party::broadcastPartyLoot(const std::string& loot)
{
    //leader->sendTextMessage(MESSAGE_INFO_DESCR, loot);
    leader->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);

    for (Player* member : memberList) {
        //member->sendTextMessage(MESSAGE_INFO_DESCR, loot);
        member->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
    }
}

const.h and monsters.cpp
otland reference
and git reference line #94
Code:
            if (owner->getParty()) {
                owner->getParty()->broadcastPartyLoot(ss.str());
            } else {
                //owner->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
                owner->sendChannelMessage("", ss.str(), TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
            }
        }

and check const.h
git reference line #487
Code:
static constexpr int32_t CHANNEL_LOOT = 0x06;

also party.cpp line #325
git reference
Code:
void Party::broadcastPartyLoot(const std::string& loot)
{
    //leader->sendTextMessage(MESSAGE_INFO_DESCR, loot);
    leader->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);

    for (Player* member : memberList) {
        //member->sendTextMessage(MESSAGE_INFO_DESCR, loot);
        member->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
    }
}

and monsters.cpp in line #90
git reference
Code:
        if (owner) {
            std::ostringstream ss;
            ss << "Loot of " << nameDescription << ": " << corpse->getContentDescription();

            if (owner->getParty()) {
                owner->getParty()->broadcastPartyLoot(ss.str());
            } else {
                //owner->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
                owner->sendChannelMessage("", ss.str(), TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
            }
        }

Also register chatchannel.xml
Code:
   <channel id="6" name="Loot" script="no speak.lua" />

And no speak.lua
Code:
    function onSpeak(player, type, message)
        return false
    end

Hope this helps
Regards!
 
Solution
Verify if you have pasted well the codes. Here, check

sources/party.cpp
git repo reference
line #325
Code:
void Party::broadcastPartyLoot(const std::string& loot)
{
    //leader->sendTextMessage(MESSAGE_INFO_DESCR, loot);
    leader->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);

    for (Player* member : memberList) {
        //member->sendTextMessage(MESSAGE_INFO_DESCR, loot);
        member->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
    }
}

const.h and monsters.cpp
otland reference
and git reference line #94
Code:
            if (owner->getParty()) {
                owner->getParty()->broadcastPartyLoot(ss.str());
            } else {
                //owner->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
                owner->sendChannelMessage("", ss.str(), TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
            }
        }

and check const.h
git reference line #487
Code:
static constexpr int32_t CHANNEL_LOOT = 0x06;

also party.cpp line #325
git reference
Code:
void Party::broadcastPartyLoot(const std::string& loot)
{
    //leader->sendTextMessage(MESSAGE_INFO_DESCR, loot);
    leader->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);

    for (Player* member : memberList) {
        //member->sendTextMessage(MESSAGE_INFO_DESCR, loot);
        member->sendChannelMessage("", loot, TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
    }
}

and monsters.cpp in line #90
git reference
Code:
        if (owner) {
            std::ostringstream ss;
            ss << "Loot of " << nameDescription << ": " << corpse->getContentDescription();

            if (owner->getParty()) {
                owner->getParty()->broadcastPartyLoot(ss.str());
            } else {
                //owner->sendTextMessage(MESSAGE_INFO_DESCR, ss.str());
                owner->sendChannelMessage("", ss.str(), TALKTYPE_CHANNEL_O, CHANNEL_LOOT);
            }
        }

Also register chatchannel.xml
Code:
   <channel id="6" name="Loot" script="no speak.lua" />

And no speak.lua
Code:
    function onSpeak(player, type, message)
        return false
    end

Hope this helps
Regards!

@ralke

Modified a bit and it works, thank you.
 
Back
Top