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

guild members online in look.

seleo

Active Member
Joined
Jun 6, 2012
Messages
498
Reaction score
33
Location
Egypt
Hello
im using TFS 0.3.6 tibia 8.60 so the source dont have the function to check the guild members online when you look a player.
can anyone please send me a creature script that show how many guild members online in look.
just like real tibia.
 
`search function` :)
http://otland.net/threads/function-getguildmembers-online-offline.171518/

also:
Code:
function onLook(cid, thing, position, lookDistance)
if isPlayer(thing.uid) then
    if getPlayerGuildId(thing.uid) > 0 then
        doPlayerSetSpecialDescription(thing.uid, ". Guild Members [" .. getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. "|" .. getGuildMembers(getPlayerGuildId(thing.uid)) .. "].")
    end
end
return true
end

Not tested but should work.
 
`search function` :)
http://otland.net/threads/function-getguildmembers-online-offline.171518/

also:
Code:
function onLook(cid, thing, position, lookDistance)
if isPlayer(thing.uid) then
    if getPlayerGuildId(thing.uid) > 0 then
        doPlayerSetSpecialDescription(thing.uid, ". Guild Members [" .. getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. "|" .. getGuildMembers(getPlayerGuildId(thing.uid)) .. "].")
    end
end
return true
end

Not tested but should work.
not working :(
Code:
function getGuildMembersOnline(GuildId)
local players = {}
for _, pid in pairs(getPlayersOnline()) do
if getPlayerGuildId(pid) == tonumber(GuildId) then
table.insert(players, pid)
end
end
return #players > 0 and players or false
end

function getGuildMembers(GuildId)
local players,query = {},db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " .. GuildId .. ");")
if (query:getID() ~= -1) then
repeat
table.insert(players,query:getDataString("name"))
until not query:next()
query:free()
end
return #players > 0 and players or false
end

function onLook(cid, thing, position, lookDistance)
if isPlayer(thing.uid) then
  if getPlayerGuildId(thing.uid) > 0 then
  doPlayerSetSpecialDescription(thing.uid, ". Guild Members [" .. getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. "|" .. getGuildMembers(getPlayerGuildId(thing.uid)) .. "].")
  end
end
return true
end

1zlam90.jpg
 
Try this one:

Code:
function getGuildMembersOnline(GuildId)
local players = {}
for _, pid in pairs(getPlayersOnline()) do
if getPlayerGuildId(pid) == tonumber(GuildId) then
table.insert(players, pid)
end
end
return #players > 0 and #players or 0
end

function getGuildMembers(GuildId)
local players,query = {},db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " .. GuildId .. ");")
if (query:getID() ~= -1) then
repeat
table.insert(players,query:getDataString("name"))
until not query:next()
query:free()
end
return #players > 0 and #players or 0
end
 
Try this one:

Code:
function getGuildMembersOnline(GuildId)
local players = {}
for _, pid in pairs(getPlayersOnline()) do
if getPlayerGuildId(pid) == tonumber(GuildId) then
table.insert(players, pid)
end
end
return #players > 0 and #players or 0
end

function getGuildMembers(GuildId)
local players,query = {},db.getResult("SELECT `name` FROM `players` WHERE `rank_id` IN (SELECT `id` FROM `guild_ranks` WHERE `guild_id` = " .. GuildId .. ");")
if (query:getID() ~= -1) then
repeat
table.insert(players,query:getDataString("name"))
until not query:next()
query:free()
end
return #players > 0 and #players or 0
end



thanks
its working now but isnt there any other function to add online players after the guild rank like real tibia
Code:
18:02 You see Angel (Level 188). She is an elder druid. She is Member of the The Angels (Angel rogues:)), which has 49 members, and 24 of them online.
 
So, it will be hard to do same [or if someone have time to edit source].
But, you can do something like this:
Code:
21:21 You see yourself. You are an elite knight. Guild has 1 members, and 1 of them online. You are Leader of the test 3.



Code:
function onLook(cid, thing, position, lookDistance)
if isPlayer(thing.uid) then
    if getPlayerGuildId(thing.uid) > 0 then
        doPlayerSetSpecialDescription(thing.uid, ". Guild has " .. getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online")
    end
end
return true
end
 
what should i put in creaturescripts.xml?
<event type="look" name="guildmembers" event="script" value="look.lua"/>
i have this and it doesnt work. no errors
 
So, it will be hard to do same [or if someone have time to edit source].
But, you can do something like this:
Code:
21:21 You see yourself. You are an elite knight. Guild has 1 members, and 1 of them online. You are Leader of the test 3.



Code:
function onLook(cid, thing, position, lookDistance)
if isPlayer(thing.uid) then
    if getPlayerGuildId(thing.uid) > 0 then
        doPlayerSetSpecialDescription(thing.uid, ". Guild has " .. getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online")
    end
end
return true
end

thanks for your help.
but do you have any idea how i can do that with source edits ?
 
what should i put in creaturescripts.xml?
<event type="look" name="guildmembers" event="script" value="look.lua"/>
i have this and it doesnt work. no errors


You have to register the event in your login.lua file
Code:
registerCreatureEvent(cid, "guildmembers")
 
Nope, cpp sucks.
Maybe in player.cpp ?

yes, its in player.cpp
this is how its look like


Code:
if (guild) {
     GuildRank* rank = guild->getRankByLevel(guildLevel);

     if (rank) {
       if (lookDistance == -1) {
         s << " You are ";
       } else if (sex == PLAYERSEX_FEMALE) {
         s << " She is ";
       } else {
         s << " He is ";
       }

       s << rank->name << " of the " << guild->getName();

       if (!guildNick.empty()) {
         s << " (" << guildNick << ')';
       }

       size_t memberCount = guild->getMemberCount();

       if (memberCount == 1) {
         s << ", which has 1 member, " << guild->getMembersOnline().size() << " of them online.";
       } else {
         s << ", which has " << memberCount << " members, " << guild->getMembersOnline().size() << " of them online.";
       }
     }
   }

the problem is
Code:
guild->getMembersOnline
guild->getMemberCount
is routed to guild.h file
and that file is not exist in my source :D
 
yes, its in player.cpp
this is how its look like


Code:
if (guild) {
     GuildRank* rank = guild->getRankByLevel(guildLevel);

     if (rank) {
       if (lookDistance == -1) {
         s << " You are ";
       } else if (sex == PLAYERSEX_FEMALE) {
         s << " She is ";
       } else {
         s << " He is ";
       }

       s << rank->name << " of the " << guild->getName();

       if (!guildNick.empty()) {
         s << " (" << guildNick << ')';
       }

       size_t memberCount = guild->getMemberCount();

       if (memberCount == 1) {
         s << ", which has 1 member, " << guild->getMembersOnline().size() << " of them online.";
       } else {
         s << ", which has " << memberCount << " members, " << guild->getMembersOnline().size() << " of them online.";
       }
     }
   }

the problem is
Code:
guild->getMembersOnline
guild->getMemberCount
is routed to guild.h file
and that file is not exist in my source :D


I've tried here, and not work too
Code:
player.cpp: In member function ‘virtual std::__cxx11::string Player::getDescription(int32_t) const’:
player.cpp:256:36: error: base operand of ‘->’ is not a pointer
  size_t memberCount = guildId->getMemberCount();
  ^
player.cpp:259:50: error: base operand of ‘->’ is not a pointer
  s << ", which has 1 member, " << guildId->getMembersOnline().size() <<
  ^
player.cpp:261:71: error: base operand of ‘->’ is not a pointer
  s << ", which has " << memberCount << " members, " << guildId->getMember
  ^
Makefile:546: recipe for target 'player.o' failed
make[1]: *** [player.o] Error 1

Code:
  if(guildId)
   {
     if(lookDistance == -1)
       s << " You are ";
     else
       s << " " << (sex % 2 ? "He" : "She") << " is ";

     s << (rankName.empty() ? "a member" : rankName)<< " of the " << guildName;
     if(!guildNick.empty())
       s << " (" << guildNick << ")";

  size_t memberCount = guildId->getMemberCount();

  if (memberCount == 1) {
  s << ", which has 1 member, " << guildId->getMembersOnline().size() << " of them online.";
  } else {
  s << ", which has " << memberCount << " members, " << guildId->getMembersOnline().size() << " of them online.";
  }

     s << ".";
   }
 
I tried in LUA and not work too

Code:
<event type="look" name="guildmembersonlook" event="script" value="guild_members_online.lua"/>

Code:
registerCreatureEvent(cid, "guildmembersonlook")

Code:
function onLook(cid, thing, position, lookDistance)
if isPlayer(thing.uid) then
  if getPlayerGuildId(thing.uid) > 0 then
  doPlayerSetSpecialDescription(thing.uid, ". Guild has " .. getGuildMembers(getPlayerGuildId(thing.uid)) .. " members, and " .. getGuildMembersOnline(getPlayerGuildId(thing.uid)) .. " of them online")
  end
end
return true
end

Error
Code:
[23:45:35.141] [Error - CreatureScript Interface]
[23:45:35.141] data/creaturescripts/scripts/guild_members_online.lua:onLook
[23:45:35.141] Description:
[23:45:35.141] ...ata/creaturescripts/scripts/guild_members_online.lua:4: attempt to concatenate a table value
[23:45:35.141] stack traceback:
[23:45:35.141]    ...ata/creaturescripts/scripts/guild_members_online.lua:4: in function <...ata/creaturescripts/scripts/guild_members_online.lua:1>

[23:45:35.342] [Error - CreatureScript Interface]
[23:45:35.342] data/creaturescripts/scripts/guild_members_online.lua:onLook
[23:45:35.342] Description:
[23:45:35.342] ...ata/creaturescripts/scripts/guild_members_online.lua:4: attempt to concatenate a table value
[23:45:35.342] stack traceback:
[23:45:35.342]    ...ata/creaturescripts/scripts/guild_members_online.lua:4: in function <...ata/creaturescripts/scripts/guild_members_online.lua:1>

[23:45:35.542] [Error - CreatureScript Interface]
[23:45:35.542] data/creaturescripts/scripts/guild_members_online.lua:onLook
[23:45:35.542] Description:
[23:45:35.542] ...ata/creaturescripts/scripts/guild_members_online.lua:4: attempt to concatenate a table value
[23:45:35.542] stack traceback:
[23:45:35.542]    ...ata/creaturescripts/scripts/guild_members_online.lua:4: in function <...ata/creaturescripts/scripts/guild_members_online.lua:1>

[23:45:37.488] [Error - CreatureScript Interface]
[23:45:37.488] data/creaturescripts/scripts/guild_members_online.lua:onLook
[23:45:37.488] Description:
[23:45:37.488] ...ata/creaturescripts/scripts/guild_members_online.lua:4: attempt to concatenate a table value
[23:45:37.488] stack traceback:
[23:45:37.488]    ...ata/creaturescripts/scripts/guild_members_online.lua:4: in function <...ata/creaturescripts/scripts/guild_members_online.lua:1>

[23:45:39.187] [Error - CreatureScript Interface]
[23:45:39.187] data/creaturescripts/scripts/guild_members_online.lua:onLook
[23:45:39.187] Description:
[23:45:39.187] ...ata/creaturescripts/scripts/guild_members_online.lua:4: attempt to concatenate a table value
[23:45:39.187] stack traceback:
[23:45:39.187]    ...ata/creaturescripts/scripts/guild_members_online.lua:4: in function <...ata/creaturescripts/scripts/guild_members_online.lua:1>

[23:45:39.980] [Error - CreatureScript Interface]
[23:45:39.980] data/creaturescripts/scripts/guild_members_online.lua:onLook
[23:45:39.980] Description:
[23:45:39.980] ...ata/creaturescripts/scripts/guild_members_online.lua:4: attempt to concatenate a table value
[23:45:39.980] stack traceback:
[23:45:39.981]    ...ata/creaturescripts/scripts/guild_members_online.lua:4: in function <...ata/creaturescripts/scripts/guild_members_online.lua:1>

[23:45:40.280] [Error - CreatureScript Interface]
[23:45:40.280] data/creaturescripts/scripts/guild_members_online.lua:onLook
[23:45:40.280] Description:
[23:45:40.280] ...ata/creaturescripts/scripts/guild_members_online.lua:4: attempt to concatenate a table value
[23:45:40.280] stack traceback:
[23:45:40.280]    ...ata/creaturescripts/scripts/guild_members_online.lua:4: in function <...ata/creaturescripts/scripts/guild_members_online.lua:1>
 
you only need the onlook afaik

I look inside my source in creatureevent.cpp
And have onlook
Code:
std::string CreatureEvent::getScriptEventName() const
{
   switch(m_type)
   {
     case CREATURE_EVENT_LOGIN:
       return "onLogin";
     case CREATURE_EVENT_LOGOUT:
       return "onLogout";
     case CREATURE_EVENT_CHANNEL_JOIN:
       return "onJoinChannel";
     case CREATURE_EVENT_CHANNEL_LEAVE:
       return "onLeaveChannel";
     case CREATURE_EVENT_THINK:
       return "onThink";
     case CREATURE_EVENT_ADVANCE:
       return "onAdvance";
     case CREATURE_EVENT_LOOK:
       return "onLook";
     case CREATURE_EVENT_DIRECTION:
       return "onDirection";
     case CREATURE_EVENT_OUTFIT:
       return "onOutfit";
     case CREATURE_EVENT_MAIL_SEND:
       return "onSendMail";
     case CREATURE_EVENT_MAIL_RECEIVE:
       return "onReceiveMail";
     case CREATURE_EVENT_TRADE_REQUEST:
       return "onTradeRequest";
     case CREATURE_EVENT_TRADE_ACCEPT:
       return "onTradeAccept";
     case CREATURE_EVENT_TEXTEDIT:
       return "onTextEdit";
     case CREATURE_EVENT_REPORTBUG:
       return "onReportBug";
     case CREATURE_EVENT_STATSCHANGE:
       return "onStatsChange";
     case CREATURE_EVENT_COMBAT_AREA:
       return "onAreaCombat";
     case CREATURE_EVENT_PUSH:
       return "onPush";
     case CREATURE_EVENT_TARGET:
       return "onTarget";
     case CREATURE_EVENT_FOLLOW:
       return "onFollow";
     case CREATURE_EVENT_COMBAT:
       return "onCombat";
     case CREATURE_EVENT_ATTACK:
       return "onAttack";
     case CREATURE_EVENT_CAST:
       return "onCast";
     case CREATURE_EVENT_KILL:
       return "onKill";
     case CREATURE_EVENT_DEATH:
       return "onDeath";
     case CREATURE_EVENT_PREPAREDEATH:
       return "onPrepareDeath";
     case CREATURE_EVENT_MOVEITEM:
       return "onMoveItem";
     case CREATURE_EVENT_NONE:
     default:
       break;
   }

   return "";
}

Code:
uint32_t CreatureEvent::executeLook(Player* player, Thing* thing, const Position& position, int16_t stackpos, int32_t lookDistance)
{
   //onLook(cid, thing, position, lookDistance)
 
Back
Top