[COLOR="#808080"]
// By slp13at420 of EmuDevs.com
std::string DB_COLUMN = "reward_count"; // this is the name of the element in auth.account you added to store this value.
void StoreCredit(uint32 id, uint32 count);
{
LoginDatabase.PExecute("UPDATE account SET `%s` = '%u' WHERE `id` = '%u';", DB_COLUMN.c_str(), count, id);
};
class KillCreatureCredit : public CreatureScript
{
public: KillCreatureCredit() : CreatureScript("KillCreatureCredit"){ }
struct KillCreatureCredit_AI : public ScriptedAI
{
void JustDied(Unit* unit)
{
if (unit->ToPlayer())
{
StoreCredit(player->GetSession()->GetAccountId(), 2);
}
}
}
CreatureAI* GetAI(Creature* creature)const override
{
return new KillCreatureCredit_AI(creature);
}
};
void AddSC_KillCreatureRewarder()
{
new KillCreatureCredit;
}[/COLOR]
void OnCreatureKill
CharacterDatabase.Pquery
Look for this keywords. Should be help. If not, check this video:
https://www.youtube.com/watch?v=31wdIpdxoxc&list=PLu6yRPZ4Ec3ZMtFLO6mtPI8fuZ3CLq10B&index=23
[COLOR="#808080"]
// By slp13at420 of EmuDevs.com
#include "AccountMgr.h"
#include "chat.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "WorldSession.h"
std::string DB_COLUMN = "reward_count"; // this is the name of the element in auth.account you added to store this value. use default '0' so it wont need another block for OnAccountCreation.
std::unordered_map<uint32, uint32>CKR;
void StoreCredit(uint32 id, uint32 count)
{
LoginDatabase.PExecute("UPDATE account SET `%s` = '%u' WHERE `id` = '%u';", DB_COLUMN.c_str(), count, id);
};
class KillCreatureCredit_Account_Events : public AccountScript
{
public: KillCreatureCredit_Account_Events() : AccountScript("KillCreatureCredit_Account_Events"){ };
virtual void OnAccountLogout(uint32 accountId)
{
WorldDatabase.PExecute("REPLACE INTO account SET `%s`='%u';", DB_COLUMN.c_str(), CKR[accountId]);
CKR.erase(accountId);
};
virtual void OnAccountLogin(uint32 accountId)
{
if (accountId > 0)
{
QueryResult CKRPlayerQery = LoginDatabase.PQuery("SELECT `%s` FROM `account` WHERE `id` = '%u';", DB_COLUMN.c_str(), accountId);
if (CKRPlayerQery)
{
do
{
Field* fields = CKRPlayerQery->Fetch();
uint32 Reward_Count = fields[0].GetUInt32();
CKR[accountId] = Reward_Count;
} while (CKRPlayerQery->NextRow());
}
}
};
};
class KillCreatureCredit : public PlayerScript
{
public: KillCreatureCredit() : PlayerScript("KillCreatureCredit"){ }
virtual void OnCreatureKill(Player* player, Creature* killed)
{
ChatHandler(player->GetSession()).PSendSysMessage("You earned x rewards.");
StoreCredit(player->GetSession()->GetAccountId(), 2);
};
};
void AddSC_KillCreatureRewarder()
{
new KillCreatureCredit_Account_Events;
new KillCreatureCredit;
}
[/COLOR]
[COLOR="#808080"]
// By slp13at420 of EmuDevs.com
#include "AccountMgr.h"
#include "chat.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "WorldSession.h"
uint32 reward_value = 2;
std::string DB_COLUMN = "reward_count"; // this is the name of the element in auth.account you added to store this value. use default '0' so it wont need another block for OnAccountCreation.
std::unordered_map<uint32, uint32>CKR;
class KillCreatureCredit : public PlayerScript
{
public: KillCreatureCredit() : PlayerScript("KillCreatureCredit"){ }
virtual void OnLogout(Player* player)
{
uint32 accountId = player->GetSession()->GetAccountId();
LoginDatabase.PExecute("UPDATE `account` SET `%s` = '%u' WHERE `id` = '%u';", DB_COLUMN.c_str(), CKR[accountId], accountId);
CKR.erase(accountId);
};
virtual void OnLogin(Player* player, bool /*firstLogin*/)
{
uint32 accountId = player->GetSession()->GetAccountId();
QueryResult CKRPlayerQery = LoginDatabase.PQuery("SELECT `%s` FROM `account` WHERE `id` = '%u';", DB_COLUMN.c_str(), accountId);
if (CKRPlayerQery)
{
do
{
Field* fields = CKRPlayerQery->Fetch();
uint32 Reward_Count = fields[0].GetUInt32();
CKR[accountId] = Reward_Count;
} while (CKRPlayerQery->NextRow());
}
};
void OnCreatureKill(Player* player, Creature* killed) override
{
uint32 accountId = player->GetSession()->GetAccountId();
CKR[accountId] = CKR[accountId] + reward_value;
ChatHandler(player->GetSession()).PSendSysMessage("You earned %u rewards for a total of %u points.", reward_value, CKR[accountId]);
};
};
void AddSC_KillCreatureRewarder()
{
new KillCreatureCredit;
}
[/COLOR]
void OnCreatureKill
CharacterDatabase.Pquery
Look for this keywords. Should be help. If not, check this video:
https://www.youtube.com/watch?v=31wd...Lq10B&index=23
Yes and thx again for your help.
[COLOR="#808080"]
// By slp13at420 of EmuDevs.com
#include "AccountMgr.h"
#include "chat.h"
#include "Player.h"
#include "ScriptMgr.h"
#include "WorldSession.h"
uint32 reward_value = 2;
std::string DB_COLUMN = "reward_count"; // this is the name of the element in auth.account you added to store this value. use default '0' so it wont need another block for OnAccountCreation.
std::unordered_map<uint32, uint32>CKR;
std::array<uint32, 255> CreatureList = { 3100, 3127, 600004, 49999, 600003}; // this is where you add each creature entry id. should work for up to 255 unique id's uint8.
class KillCreatureCredit : public PlayerScript
{
public: KillCreatureCredit() : PlayerScript("KillCreatureCredit"){ }
virtual void OnLogout(Player* player)
{
uint32 accountId = player->GetSession()->GetAccountId();
LoginDatabase.PExecute("UPDATE `account` SET `%s` = '%u' WHERE `id` = '%u';", DB_COLUMN.c_str(), CKR[accountId], accountId);
CKR.erase(accountId);
};
virtual void OnLogin(Player* player, bool /*firstLogin*/)
{
uint32 accountId = player->GetSession()->GetAccountId();
QueryResult CKRPlayerQery = LoginDatabase.PQuery("SELECT `%s` FROM `account` WHERE `id` = '%u';", DB_COLUMN.c_str(), accountId);
if (CKRPlayerQery)
{
do
{
Field* fields = CKRPlayerQery->Fetch();
uint32 Reward_Count = fields[0].GetUInt32();
CKR[accountId] = Reward_Count;
} while (CKRPlayerQery->NextRow());
}
};
virtual void OnCreatureKill(Player* player, Creature* creature)
{
uint32 accountId = player->GetSession()->GetAccountId();
uint32 creatureId = creature->GetEntry();
for (auto i = CreatureList.begin(); i <= CreatureList.end(); ++i)
{
if (creatureId == *i)
{
CKR[accountId] = CKR[accountId] + reward_value;
ChatHandler(player->GetSession()).PSendSysMessage("You earned %u rewards for a total of %u points.", reward_value, CKR[accountId]);
break;
}
}
};
};
void AddSC_KillCreatureRewarder()
{
new KillCreatureCredit;
}
[/COLOR]
yeaa.. I do see that sometimes when im surfin forums looking for examples. These guyz here run a clean ship :thumbupguy:Im not a flattery person but i cant believe that you guys help other with such a pleasure.If i requested that script on other forums i get a late response,they request moneygives you shitty scripts or they tell you to learn c++.I know there's good forums but some of them....
Edit:So this is the only way to work, i mean you cant just ignore the ids in c++ so you only put the script name in creature_templates?
Ok, i will try thx alot.