New PVP Bounty System

I’m working on a PVP Script that will work to give, money, tokens, etc etc. Currently what I have right now works, but I have one little issue with it.

void OnPVPKill(Player* killer, Player* killed)override
{
SQLTransaction trans = CharacterDatabase.BeginTransaction();
QueryResult charResult = CharacterDatabase.PQuery(“SELECT reward FROM bounty_rewards WHERE guid=%u”, (int64)killed->GetGUID());
int64 rewardt = 0;
if (charResult)
{
Field* charFields = charResult->Fetch();
int64 reward = charFields[0].GetUInt32();
QueryResult typeresult = CharacterDatabase.PQuery(“SELECT reward_type FROM bounty_rewards WHERE guid =%u”, (int64)killed->GetGUID());
Field* typefield = typeresult->Fetch();
int64 type = typefield[0].GetUInt32();
std::ostringstream ss;
if(type == 0 ) {
killer->ModifyMoney(rewardGOLD);
ss << "|cffFF0000[Bounty System]|r ““Bounty of “<<reward<<” Gold has been claimed by " << killed->GetName() <<””;
}
//if(type = 1) { killer->ModifyHonor(reward
HONOR);}
if(type == 2) {
uint32 rewardg = reward;
killer->AddItem(LOYALTY_POINT, rewardg);
ss << "|cffFF0000[Bounty System]|r ““Bounty on “<getLevel()<<” of “<<reward<<” “<<TOKEN_NAME<<” has been claimed by " << killed->GetName() <<””;
}
sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
CharacterDatabase.PExecute(“DELETE FROM bounty_rewards WHERE guid = %u”, (int64)killed->GetGUID());
}
}So up top you can see that in the token reward system I’ve tried returning the level for debugging reasons. I don’t want anyone to be able to claim I want it to be fair, but killed->getLevel() returns ? in the chat, so I’m not sure how I can return the level. Hell. Not even sure how to continue after I get the level at this point.

uint32 killedlevel = killed->getLevel();

uint32 killerlevel = killer->getLevel();

uint32 difference = killerlevel - killedlevel;

if(difference <= 9) {

//Run my Script Up top

}

else {

//Actually Reverse and take from the killer if they’re camping lowbies.

}Once again. That’s just a rough draft, but I can’t even try it if killed->getLevel() returns ?

Posted this while browsing the wrong section if someone could move it please.

CharacterDatabase.PExecute(“DELETE FROM bounty_rewards WHERE guid = %u”, (int64)killed->GetGUID());You shouldnt do this. Dont use %u and GetGUID() together since %u is not for 64 bit balues and the guid is 64 bit. Use %u and GetGUID().GetCounter()
use it in all the queries.

The issue with printing level is because the level is uint8 which is unsigned char. When using a stringstream to concatenate it, it will be converted into a character. For example if the level would be 100, then the character would be \100 which is ‘d’ character.
You could try casting the level into uint32 when concatenating it to the string so it will show as a number.

http://pastebin.com/BB0N0mfZ

Well. Thought it would work alright, but got a SQL syntax when the kill went through, Trying to narrow it down now, it’s essentially the same query I had though…

btw, are you using 3.3.5 or 6.x?

3.3.5, Sorry. On a side note, I have it working, I wanted to add the detriment to keep campers away, but I’ve ran into a little issue with the deterrence.

uint32 killerlevel = killer->getLevel();
uint32 killedlevel = killed->getLevel();
uint32 difference = killerlevel - killedlevel;
if(difference < 8 ) {
//Run Bounty Retrieval Script }
else {

    std::ostringstream ss;
    ss << "|cffFF0000[Bounty System]|r "<<killer->GetName()<<" Has Killed a Player "<<difference<<" levels lower than them! A Bounty of "<<difference*10<<" has been placed!";
    sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());    
    CharacterDatabase.PExecute("INSERT INTO bounty_rewards(guid,reward,reward_type) VALUES(%u, %d, 0)", (int64)killer->GetGUID(), difference*10);

}

Which works great when a higher level kills a lower!

No say a lower level kills a higher level the end result is the lower level is getting a ridiculous bounty placed.

[ATTACH]1492._xfImport[/ATTACH]

Dont use unsigned for the types and use abs for the calculation:

int32 killerlevel = killer->getLevel();
int32 killedlevel = killed->getLevel();
int32 difference = std::abs(killerlevel - killedlevel);
if(difference < 8 ) {uint32 = unsigned 32 bit int.
int32 = signed 32 bit int.

PS. I still strongly recommend not to use %u with 64 bit value.

So I’ve ran some updates and I’m not sure what I’m doing wrong. I’m almost done with the script, but not quite

if(killerlevel > killedlevel) {
QueryResult bountyResult = CharacterDatabase.PQuery(“SELECT reward FROM bounty_rewards WHERE guid=%u”, killed->GetGUID().GetCounter());
if(!bountyResult)
CharacterDatabase.PExecute(“INSERT INTO bounty_rewards(guid,reward,reward_type) VALUES(%u, %d, 0)”, killer->GetGUID().GetCounter(), difference10);
ss << "|cffFF0000[Bounty System]|r “<GetName()<<” Has Killed a Player “<<difference<<” levels lower than them! A Bounty of "<<difference
10<<" has been placed!";
sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
return;

		Field* bountyFields = bountyResult->Fetch();
		int64 activebounty = bountyFields[0].GetUInt32();
		ss << "|cffFF0000[Bounty System]|r "<<killer->GetName()<<" Has Killed a Player "<<difference<<" levels lower than them! Bounty has increased to "<<activebounty+difference*10<<"";
		sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());	
		CharacterDatabase.PExecute("UPDATE bounty_rewards SET reward =+ %d WHERE guid = %u",activebounty+difference,killer->GetGUID().GetCounter());	
		}For The script to work correctly I want the second database execute to execute if a result is returned, but instead it simply adds a new line with the guid. I'm looking more for an update to the bounty rewards table if there's already a bounty in place. Do you see anything wrong with the way I'm running it here?

Post full code.
For example we can not know if difference is a 64 bit value or 32 bit value which could make the queries go wrong.

[CODE]if (killerlevel > killedlevel) {
QueryResult bountyResult = CharacterDatabase.PQuery(“SELECT reward FROM bounty_rewards WHERE guid = %u”, killed->GetGUID().GetCounter());
// notice how this IF case only affects the DB execution and not the prints.
if (!bountyResult)
CharacterDatabase.PExecute(“INSERT INTO bounty_rewards(guid, reward, reward_type) VALUES(%u, %d, 0)”, killer->GetGUID().GetCounter(), difference10);
ss << "|cffFF0000[Bounty System]|r " << killer->GetName() << " Has Killed a Player " << difference << " levels lower than them! A Bounty of " << (difference
10) << " has been placed!";
sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
return; // code ends here

// below this never executed

Field* bountyFields = bountyResult->Fetch();
int64 activebounty = bountyFields[0].GetUInt32();
ss << "|cffFF0000[Bounty System]|r " << killer->GetName() << " Has Killed a Player " << difference << " levels lower than them! Bounty has increased to " << (activebounty+difference*10);
sWorld->SendServerMessage(SERVER_MSG_STRING, ss.str().c_str());
CharacterDatabase.PExecute("UPDATE bounty_rewards SET reward =+ %d WHERE guid = %u", activebounty+difference, killer->GetGUID().GetCounter());

}[/CODE]

Alright, Sorry. :). I’ll have to redo what I had. Directory I was in was wrong…

sudo chown -R morgan *while inside / on a unix system. Tsk tsk on me.