• This is a read only backup of the old Emudevs forum. If you want to have anything removed, please message me on Discord: KittyKaev

[SOLVED] What am I doing wrong here?

Status
Not open for further replies.

Epicblood

Epic Member
Just started trying to learn C++ for trinity and am trying to make a script that adds an item, and x amount of honor when someone kills another player, and subtracts x amount of gold from the player being killed.

Code:
/*
 *
 *#############   #############   #############   #############   #############   ##              #############   #############   #############
 *##              ##          ##       ##         ##              ##          ##  ##              ##         ##   ##         ##   ##          ##
 *##              ##           ##      ##         ##              ##           ## ##              ##         ##   ##         ##   ##           ##   
 *##              ##          ##       ##         ##              ##          ##  ##              ##         ##   ##         ##   ##            ##
 *#############   #############        ##         ##              #############   ##              ##         ##   ##         ##   ##            ##
 *##              ##                   ##         ##              ##          ##  ##              ##         ##   ##         ##   ##            ##
 *##              ##                   ##         ##              ##           ## ##              ##         ##   ##         ##   ##           ## 
 *##              ##                   ##         ##              ##          ##  ##              ##         ##   ##         ##   ##          ##   
 *#############   ##              #############   #############   #############   #############   #############   #############   #############   
 *
 */

#include "ScriptPCH.h"

enum eNums
{
	Reward_Item = 29434,  //Insert your reward item here, it will be given each time a player kills another player
	Reward_Honor = 1,     //The amount of honor given when an enemy player is killed
	Death_Cost = 10000,  //Insert here how much money is taken whenever a player is killed by another player
};
class pvp_script : public PlayerScript
{
public:
	pvp_script() : PlayerScript("PvP Script"){}

	void OnPVPKill(Player* killer, Player* dead){
		WorldSession * k_session = killer->GetSession();
		WorldSession * d_session = dead->GetSession();
		std::string deadName = dead->GetName();
		std::string killerName = killer->GetName();
		std::string deadMessage = "You were just killed by: ";
		std::string killerMessage = "You just killed: ";
		std::string deadOut = deadMessage += killerName;
		std::string killerOut = killerMessage += deadName;
		killer->AddItem(Reward_Item, 1);
		killer->SetHonorPoints(killer->GetHonorPoints() + Reward_Honor);
		if(dead->GetMoney() >= Death_Cost)
			dead->ModifyMoney(dead->GetMoney() - Death_Cost);

		k_session->SendNotification(killerOut);
		d_session->SendNotification(deadOut);
	}
};

void AddSC_pvp_test_script()
{
	new pvp_script;
}

these are my errors:
1 IntelliSense: no instance of overloaded function "WorldSession::SendNotification" matches the argument list
argument types are: (std::string)
object type is: WorldSession c:\Users\Joris Bolsens\Desktop\Trinity\Build\src\server\scripts\pvp_test.cpp 42 12 scripts

2 IntelliSense: no instance of overloaded function "WorldSession::SendNotification" matches the argument list
argument types are: (std::string)
object type is: WorldSession c:\Users\Joris Bolsens\Desktop\Trinity\Build\src\server\scripts\pvp_test.cpp 43 12 scripts

- - - Updated - - -

Fixed it, thanks to: philippovitch
Code:
ChatHandler(dead->GetSession()).PsendSysMessage("You were killed by: '%u' ", killer->GetName());
          ChatHandler(killer->GetSession()).PsendSysMessage("You just killed: '%u' ", dead->GetName());
 
Last edited:

Jameyboor

Retired Staff
also, just some tips, it is common to use capitals when defining enumerations and you should use a stringstream
Code:
std::ostringstream ss;
if you want to merge several string into one line.. the way it could be used in the above script would be something like this :
Code:
std::ostringstream ss; // create the output stringstream
ss << "You just killed  : " << dead->GetName();
k_session->SendNotification(ss.str().c_str());
/*now to clean the stringstream for the death message  ( you could also use 2 stringstreams, 1 per person ) :*/
ss.str("");
ss.clear();
// next message input 
ss << "You were just killed by : " << killer->GetName();
d_session->SendNotification(ss.str().c_str());
Looks a lot tidier :)
 
Last edited:

Jameyboor

Retired Staff
It seems that this question has been answered, this thread will be closed to prevent unrelated posts.
If you do have a question related to this subject, please make a new thread.
 
Status
Not open for further replies.
Top