[DONE] Landro Longshot

Finaly i finished this script. Code is rubbish, but that how i know c++

/*

  • Copyright © 2008-2013 TrinityCore http://www.trinitycore.org/
  • Copyright © 2012-2013 FreedomCore http://freedomcore.ru/
  • This program is free software; you can redistribute it and/or modify it
  • under the terms of the GNU General Public License as published by the
  • Free Software Foundation; either version 2 of the License, or (at your
  • option) any later version.
  • This program is distributed in the hope that it will be useful, but WITHOUT
  • ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  • FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  • more details.
  • You should have received a copy of the GNU General Public License along
  • with this program. If not, see http://www.gnu.org/licenses/.
    */

/* ScriptData
SDName: Landro Longshot
SD%Complete: 100
SDComment: Blizzlike implementation of NPC Landro Longshot
SDCategory: Custom
EndScriptData */

#include “ScriptMgr.h”
#include “ScriptedCreature.h”
#include “ScriptedGossip.h”
#include “Player.h”
#include “ScriptPCH.h”

#include

enum eEnums
{
SPELL_POLYMORPH = 12826,

SAY_NOT_INTERESTED      = 0,
SAY_WRONG               = 1,
SAY_CORRECT             = 2

};

#define GOSSIP_ITEM_1 “I want to redeem item”
#define GOSSIP_ITEM_2 “I’m not interested”

class landro_longshot : public CreatureScript
{
public:

    landro_longshot()
        : CreatureScript("landro_longshot")
    {
    }

    bool OnGossipHello(Player* player, Creature* creature)
    {
        player->ADD_GOSSIP_ITEM_EXTENDED(0, GOSSIP_ITEM_1, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+1, "", 0, true);
        player->ADD_GOSSIP_ITEM(GOSSIP_ICON_CHAT, GOSSIP_ITEM_2, GOSSIP_SENDER_MAIN, GOSSIP_ACTION_INFO_DEF+2);

        player->PlayerTalkClass->SendGossipMenu(907, creature->GetGUID());

        return true;
    }

    bool OnGossipSelect(Player* player, Creature* creature, uint32 /*sender*/, uint32 action)
    {
        player->PlayerTalkClass->ClearMenus();
        if (action == GOSSIP_ACTION_INFO_DEF+2)
        {
            creature->AI()->Talk(SAY_NOT_INTERESTED);
            player->CLOSE_GOSSIP_MENU();
        }

        return true;
    }

    bool OnGossipSelectCode(Player* player, Creature* creature, uint32 sender, uint32 action, char const* code)
    {
        player->PlayerTalkClass->ClearMenus();
        if (sender == GOSSIP_SENDER_MAIN)
        {
            switch (action)
            {
				case GOSSIP_ACTION_INFO_DEF+1:
				uint32 codeUINT = (uint32)atol(code);
				if(!codeUINT)
					return false; // send error about invalid value inserted
				QueryResult result = WorldDatabase.PQuery("SELECT code FROM landro_redeem_codes WHERE code = %u AND USED = 0", codeUINT);
				if (!result)
				{
					//Read comment in enum
					creature->AI()->Talk(SAY_WRONG);
					creature->CastSpell(player, SPELL_POLYMORPH, true);
					sLog->outInfo(LOG_FILTER_SERVER_LOADING, "Player '%u' entered wrong redeem code! Entered code is: %u",player->GetName(), codeUINT);
				}
                else
                {
                    creature->AI()->Talk(SAY_CORRECT);
					int i = 0;
                    QueryResult itemresult = WorldDatabase.PQuery("SELECT item FROM landro_redeem_codes WHERE code = %u AND USED = 0", codeUINT);
					if (itemresult)
						{
							do
								{
									Field *fields = itemresult->Fetch();
									int id = fields[0].GetInt32();
									player->AddItem(id,1);
									WorldDatabase.PQuery("Update landro_redeem_codes SET USED = 1 WHERE code = %u", codeUINT);
								}
							while (result->NextRow());
						}
					return i;
				}
                player->CLOSE_GOSSIP_MENU();

                return true;
            }
        }

        return false;
    }

};

void AddSC_landro_longshot()
{
new landro_longshot();
}

Just create landro_longshot.cpp in Custom scripts folder and dont forget to place values in script loader

http://youtu.be/pvlPlV3Or5s

landro_longshot.sql

landro_longshot_en.sql

Wont it be good idea to change the text to English in sql file ? as not every one here know Russian

I’ve updated fist post with english sql

Good job /emoticons/default_smile.png

Now we need an English video. /emoticons/default_wink.png

from the rus video that he post here… its pretty work… its only text…

Anybody here can help me?

[ 36%] Built target authserver
[ 36%] Building CXX object src/server/scripts/CMakeFiles/scripts.dir/Custom/landro_longshot.cpp.o
/root/cisty/TrinityCore/src/server/scripts/Custom/landro_longshot.cpp: In member function ‘virtual bool landro_longshot::OnGossipSelectCode(Player*, Creature*, uint32, uint32, const char*)’:
/root/cisty/TrinityCore/src/server/scripts/Custom/landro_longshot.cpp:94: warning: cannot pass objects of non-POD type ‘const struct std::basic_string<char, std::char_traits, std::allocator >’ through ‘…’; call will abort at runtime

Core: 4.3.4

Revision: ce742dc7a075

You should use %s for a const char* instead of %u.

Thanks for the answer but I do not understand exactly what to do. Could you write me already covered? Thank you very much

Search and replace: %u with %s

Hmmm…

I edited it but still error occurs.

Anyone here can help? /emoticons/default_ohmy.png/emoticons/default_sad.png

[ 36%] Building CXX object src/server/scripts/CMakeFiles/scripts.dir/Custom/landro_longshot.cpp.o
/root/cisty/TrinityCore/src/server/scripts/Custom/landro_longshot.cpp: In member function 'virtual bool landro_longshot::OnGossipSelectCode(Player*, Creature*, uint32, uint32, const char*)':
/root/cisty/TrinityCore/src/server/scripts/Custom/landro_longshot.cpp:94: warning: cannot pass objects of non-POD type 'const struct std::basic_string<char, std::char_traits<char>, std::allocator<char> >' through '...'; call will abort at runtime

Warning != error.

Find: “sLog->outInfo(LOG_FILTER_SERVER_LOADING, “Player ‘%u’ entered wrong redeem code! Entered code is: %u”,player->GetName(), codeUINT);”

Replace: “sLog->outInfo(LOG_FILTER_SERVER_LOADING, “Player ‘%s’ entered wrong redeem code! Entered code is: %u”,player->GetName().c_str(), codeUINT);”

Only reason it’s a warning and not an error is, that it fails on run-time and call - not on compilation.

Thanks Ascathor. /emoticons/default_tongue.png

Thanks buddy, it works! /emoticons/default_smile.png

What the actual fuck? This is only the case for very few warnings…

I didn’t generallize it, did I ? I was saying it for that particular one oO

Dat Monday morning. Sorry. /emoticons/default_tongue.png

nub /emoticons/default_tongue.png

Hello, i have some error in compilation. Someone can help me please? /emoticons/default_smile.png

[ 50%] Building CXX object src/server/scripts/CMakeFiles/scripts.dir/Custom/landro_longshot.cpp.o
/home/wowko/kompilace/TrinityCore/src/server/scripts/Custom/landro_longshot.cpp: In member function ‘virtual bool landro_longshot::OnGossipSelectCode(Player*, Creature*, uint32, uint32, const char*)’:
/home/wowko/kompilace/TrinityCore/src/server/scripts/Custom/landro_longshot.cpp:94: error: ‘class Log’ has no member named ‘outInfo’
compilation terminated due to -Wfatal-errors.
make[2]: *** [src/server/scripts/CMakeFiles/scripts.dir/Custom/landro_longshot.cpp.o] Error 1
make[1]: *** [src/server/scripts/CMakeFiles/scripts.dir/all] Error 2
make: *** [all] Error 2
root@cataclysm:/home/wowko/kompilace/TrinityCore/cmake#

Anybody doesnt know how to fix it? /emoticons/default_sad.png
Core: 4.3.4

Revision: 4d80611a1095