• 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!
  • 2026 staff recruitment is open! Check it out and consider applying!

Guild war system

Elgenady

Veteran OT User
Joined
Aug 5, 2011
Messages
1,683
Solutions
36
Reaction score
388
i got tired i tried everything but nothing want work
i have full complaining war system but still give me this error doguildaddenemy idk what imust do :S
anyone can help me?
im use tfs 0.4 r3884
OPTIONAL_FLAGS="-D__WAR_SYSTEM__" done
-D__WAR_SYSTEM__ done
mysql done everything but idk where error :S
 
i did everything
luascript.cpp
Code:
#ifdef __WAR_SYSTEM__

    //doGuildAddEnemy(guild, enemy, war, type)
    lua_register(m_luaState, "doGuildAddEnemy", LuaInterface::luaDoGuildAddEnemy);

    //doGuildRemoveEnemy(guild, enemy)
    lua_register(m_luaState, "doGuildRemoveEnemy", LuaInterface::luaDoGuildRemoveEnemy);
#endif





#ifdef __WAR_SYSTEM__

int32_t LuaInterface::luaDoGuildAddEnemy(lua_State* L)
{
    //doGuildAddEnemy(guild, enemy, war, type)
    War_t war;
    war.type = (WarType_t)popNumber(L);
    war.war = popNumber(L);

    uint32_t enemy = popNumber(L), guild = popNumber(L), count = 0;
    for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
    {
        if(it->second->isRemoved() || it->second->getGuildId() != guild)
            continue;

        ++count;
        it->second->addEnemy(enemy, war);
        g_game.updateCreatureEmblem(it->second);
    }

    lua_pushnumber(L, count);
    return 1;
}

int32_t LuaInterface::luaDoGuildRemoveEnemy(lua_State* L)
{
    //doGuildRemoveEnemy(guild, enemy)
    uint32_t enemy = popNumber(L), guild = popNumber(L), count = 0;
    for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
    {
        if(it->second->isRemoved() || it->second->getGuildId() != guild)
            continue;

        ++count;
        it->second->removeEnemy(enemy);
        g_game.updateCreatureEmblem(it->second);
    }

    lua_pushnumber(L, count);
    return 1;
}
#endif

configure.ac
Code:
# add own flags in here
OPTIONAL_FLAGS="-D__WAR_SYSTEM__"

and add -D__WAR_SYSTEM__ in parameters ....
now when say /war accept,guildname crash my server why???
before when say /war accept,guildname give me error " doguildaddeenemy <a nil value> ...
why now crash server i search everywhere how to compline with guild war i work in this 3 days ago and can't solve i will be thx if somone helped me.
im use tfs 0.4
 
i don't stop bump here because i never open my server without this :S "Help please"

configure.ac

OPTIONAL_FLAGS=""
to
OPTIONAL_FLAGS="-D__WAR_SYSTEM__"

ioguild.cpp
channel->talk("", SPEAK_CHANNEL_RA, s.str());
to
channel->talk("", SPEAK_CHANNEL_W, s.str());

Code:
#ifdef __WAR_SYSTEM__
void IOGuild::checkWars()
{
    Database* db = Database::getInstance();
    DBResult* result;
    DBQuery query;
    query << "SELECT `id`, `guild_id`, `enemy_id` FROM `guild_wars` WHERE `status` IN (1,4) AND `end` > 0 AND `end` < " << time(NULL);
    if(!(result = db->storeQuery(query.str())))
        return;
    War_t tmp;
    do
    {
        tmp.war = result->getDataInt("id");
        tmp.ids[WAR_GUILD] = result->getDataInt("guild_id");
        tmp.ids[WAR_ENEMY] = result->getDataInt("enemy_id");
        finishWar(tmp, false);
    }
    while(result->next());
    result->free();
}
bool IOGuild::updateWar(War_t& war)
{
    Database* db = Database::getInstance();
    DBResult* result;
    DBQuery query;
    query << "SELECT `g`.`name` AS `guild_name`, `e`.`name` AS `enemy_name`, `w`.* FROM `guild_wars` w INNER JOIN `guilds` g ON `w`.`guild_id` = `g`.`id` INNER JOIN `guilds` e ON `w`.`enemy_id` = `e`.`id` WHERE `w`.`id` = " << war.war;
    if(!(result = db->storeQuery(query.str())))
        return false;
    war.ids[WAR_GUILD] = result->getDataInt("guild_id");
    war.ids[WAR_ENEMY] = result->getDataInt("enemy_id");
    war.names[WAR_GUILD] = result->getDataString("guild_name");
    war.names[WAR_ENEMY] = result->getDataString("enemy_name");
    war.frags[WAR_GUILD] = result->getDataInt("guild_kills");
    war.frags[WAR_ENEMY] = result->getDataInt("enemy_kills");
    war.frags[war.type]++;
    war.limit = result->getDataInt("frags");
    war.payment = result->getDataInt("payment");
    result->free();
    if(war.frags[WAR_GUILD] >= war.limit || war.frags[WAR_ENEMY] >= war.limit)
    {
        Scheduler::getInstance().addEvent(createSchedulerTask(3000,
            boost::bind(&IOGuild::finishWar, this, war, true)));
        return true;
    }
    query.str("");
    query << "UPDATE `guild_wars` SET `guild_kills` = " << war.frags[WAR_GUILD] << ", `enemy_kills` = " << war.frags[WAR_ENEMY] << " WHERE `id` = " << war.war;
    return db->query(query.str());
}
void IOGuild::finishWar(War_t war, bool finished)
{
    Database* db = Database::getInstance();
    DBQuery query;
    if(finished)
    {
        query << "UPDATE `guilds` SET `balance` = `balance` + " << (war.payment * 2) << " WHERE `id` = " << war.ids[war.type];
        if(!db->query(query.str()))
            return;
        query.str("");
    }
    query << "UPDATE `guild_wars` SET ";
    if(finished)
        query << "`guild_kills` = " << war.frags[WAR_GUILD] << ", `enemy_kills` = " << war.frags[WAR_ENEMY] << ",";
    query << "`end` = " << time(NULL) << ", `status` = 5 WHERE `id` = " << war.war;
    if(!db->query(query.str()))
        return;
    for(AutoList<Player>::iterator it = Player::autoList.begin(); it != Player::autoList.end(); ++it)
    {
        if(it->second->isRemoved())
            continue;
        bool update = false;
        if(it->second->getGuildId() == war.ids[WAR_GUILD])
        {
            it->second->removeEnemy(war.ids[WAR_ENEMY]);
            update = true;
        }
        else if(it->second->getGuildId() == war.ids[WAR_ENEMY])
        {
            it->second->removeEnemy(war.ids[WAR_GUILD]);
            update = true;
        }
        if(update)
            g_game.updateCreatureEmblem(it->second);
    }
    if(finished)
    {
        std::stringstream s;
        s << war.names[war.type] << " has just won the war against " << war.names[war.type == WAR_GUILD] << ".";
        g_game.broadcastMessage(s.str().c_str(), MSG_EVENT_ADVANCE);
    }
}
void IOGuild::frag(Player* player, uint64_t deathId, const DeathList& list, bool score)
{
    War_t war;
    std::stringstream s;
    for(DeathList::const_iterator it = list.begin(); it != list.end(); )
    {
        if(score)
        {
            if(it->isLast())
                war = it->getWar();
        }
        else if(!war.war)
            war = it->getWar();
        Creature* creature = it->getKillerCreature();
        if(it != list.begin())
        {
            ++it;
            if(it == list.end())
                s << " and ";
            else
                s << ", ";
        }
        else
            ++it;
        s << creature->getName();
    }
    std::string killers = s.str();
    s.str("");
    ChatChannel* channel = NULL;
    if((channel = g_chat.getChannel(player, CHANNEL_GUILD)))
    {
        s << "Guild member " << player->getName() << " was killed by " << killers << ".";
        if(score)
            s << " The new score is " << war.frags[war.type == WAR_GUILD] << ":"
                << war.frags[war.type] << " frags (limit " << war.limit << ").";
        channel->talk("", SPEAK_CHANNEL_W, s.str());
    }
    s.str("");
    if((channel = g_chat.getChannel(list[0].getKillerCreature()->getPlayer(), CHANNEL_GUILD)))
    {
        s << "Opponent " << player->getName() << " was killed by " << killers << ".";
        if(score)
            s << " The new score is " << war.frags[war.type] << ":"
                << war.frags[war.type == WAR_GUILD] << " frags (limit " << war.limit << ").";
        channel->talk("", SPEAK_CHANNEL_W, s.str());
    }
    Database* db = Database::getInstance();
    DBQuery query;
    query << "INSERT INTO `guild_kills` (`guild_id`, `war_id`, `death_id`) VALUES ("
        << war.ids[war.type] << ", " << war.war << ", " << deathId << ");";
    db->query(query.str());
}
#endif

mysql
Code:
CREATE TABLE IF NOT EXISTS `guild_wars` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `guild_id` INT NOT NULL,
  `enemy_id` INT NOT NULL,
  `begin` BIGINT NOT NULL DEFAULT '0',
  `end` BIGINT NOT NULL DEFAULT '0',
  `frags` INT UNSIGNED NOT NULL DEFAULT '0',
  `payment` BIGINT UNSIGNED NOT NULL DEFAULT '0',
  `guild_kills` INT UNSIGNED NOT NULL DEFAULT '0',
  `enemy_kills` INT UNSIGNED NOT NULL DEFAULT '0',
  `status` TINYINT(1) UNSIGNED NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`),
  KEY `status` (`status`),
  KEY `guild_id` (`guild_id`),
  KEY `enemy_id` (`enemy_id`)
) ENGINE=InnoDB;
ALTER TABLE `guild_wars`
  ADD CONSTRAINT `guild_wars_ibfk_1` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `guild_wars_ibfk_2` FOREIGN KEY (`enemy_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE;
ALTER TABLE `guilds` ADD `balance` BIGINT UNSIGNED NOT NULL AFTER `motd`;
CREATE TABLE IF NOT EXISTS `guild_kills` (
  `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  `guild_id` INT NOT NULL,
  `war_id` INT NOT NULL,
  `death_id` INT NOT NULL
) ENGINE = InnoDB;
ALTER TABLE `guild_kills`
  ADD CONSTRAINT `guild_kills_ibfk_1` FOREIGN KEY (`war_id`) REFERENCES `guild_wars` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `guild_kills_ibfk_2` FOREIGN KEY (`death_id`) REFERENCES `player_deaths` (`id`) ON DELETE CASCADE,
  ADD CONSTRAINT `guild_kills_ibfk_3` FOREIGN KEY (`guild_id`) REFERENCES `guilds` (`id`) ON DELETE CASCADE;
ALTER TABLE `killers` ADD `war` INT NOT NULL DEFAULT 0;

and in start.lua
Code:
db.executeQuery("DELETE FROM `guild_wars` WHERE `status` = 0 AND `begin` < " .. (os.time() - 2 * 86400) .. ";")
db.executeQuery("UPDATE `guild_wars` SET `status` = 5, `end` = " .. os.time() .. " WHERE `status` = 1 AND `end` > 0 AND `end` < " .. os.time() .. ";")

lib 101-war.lua
WAR_GUILD = 0
WAR_ENEMY = 1

and war talkaction and complin with -D__WAR_SYSTEM__


and server crash when say /war accept,guildname what i missing to make this script work ? @Limos


 
Last edited:
I have no idea if this has anything to do but ok:
in lib/000-constant
down of this part:

SHIELD_NONE = 0
SHIELD_WHITEYELLOW = 1
SHIELD_WHITEBLUE = 2
SHIELD_BLUE = 3
SHIELD_YELLOW = 4
SHIELD_BLUE_SHAREDEXP = 5
SHIELD_YELLOW_SHAREDEXP = 6
SHIELD_BLUE_NOSHAREDEXP_BLINK = 7
SHIELD_YELLOW_NOSHAREDEXP_BLINK = 8
SHIELD_BLUE_NOSHAREDEXP = 9
SHIELD_YELLOW_NOSHAREDEXP = 10
SHIELD_LAST = SHIELD_YELLOW_NOSHAREDEXP

is this, about the emblems (shields):

EMBLEM_NONE = 0
EMBLEM_GREEN = 1
EMBLEM_RED = 2
EMBLEM_BLUE = 3

add to lib/000-constant and you can see if that solves your problem
 
now i fixe more things.. now when say /war accept,guildname ..
08:55 Yes has invited Meee to war till 100 frags.
08:55 Meee has accepted Yes invitation to war.....
i look my enemy with red shield and my guild mates with a green shield, but when I logout with any of the guild members and login again the shield has gone, it dissapeared. and if i killed player from enemy guild server crash :S ...you can help me in this ... im free not premium :S @Limos @
Evil Puncker
 
Last edited:
I have the same problem, when I logout the shields dissapear, can you tell how u did to fix it?
 
bohahahhahahahah 7 days work solveeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeed :D remove this post

Heba, please, can you post your solution?

@EDIT: The "Solved" tag can be add if you want on Thread Tools >> Edit Title (Top and right)
 

Similar threads

Replies
8
Views
3K
Back
Top