Jump to content
Sign in to follow this  
AXEL777

Rewriting bits of your code modifications

Recommended Posts

I have emerged the next kind of a question. The situation is:

There is a modification to the Steam workshop, script kotori is this part of the code:

modded class DayZPlayerImplement extends DayZPlayer
{
	// тут куча коду
	void traderServerLog(string message)
	{
		TraderMessage.ServerLog("[TRADER] Player: (" + this.GetIdentity().GetName() + ") " + this.GetIdentity().GetId() + " " + message);
	}
	// тут куча коду
}

on the server side via -FilePatching I make my script in the same section of the game scripts (not as a modification, a simple script). Write the following code:

modded class DayZPlayerImplement extends DayZPlayer
{
	override void traderServerLog(string message)
	{
		super.traderServerLog(message);

		private PlayerIdentity p_Identity = this.GetIdentity();
		if (p_Identity)
		{
			string name_player = p_Identity.GetName();
			string UID_player = p_Identity.GetPlainId();
			vector pos_object = this.GetPosition();	
			private string message_log = name_player + "(steam64id=" + UID_player + ",pos=" + pos_object.ToString() + ") " + message;
			Print(message_log);
		}
	}
	
}

I get an error when starting the server, they say on the 3rd line of my script in the error line, supposedly I'm trying to update the function, and it is not defined.

Tell me how to correctly rewrite such a Modded code of the native class of the game from your modification with the preservation of the original call of the modification?

Share this post


Link to post
Share on other sites

You're trying to override a method which doesn't need to be overridden because it doesn't exist in the inherited class DayZPlayer. If you remove the override keyword, the error will go away.

Edited by IMT

Share this post


Link to post
Share on other sites
1 hour ago, IMT said:

You're trying to override a method which doesn't need to be overridden because it doesn't exist in the inherited class DayZPlayer. If you remove the override keyword, the error will go away. 

Yes, but there is another error, a string

super.traderServerLog(message);

is undefined for use

But how is correct will use this?

Share this post


Link to post
Share on other sites
Just now, AXEL777 said:

Yes, but there is another error, a string


super.traderServerLog(message);

is undefined for use

But how is correct will use this?

That's because there is no method in DayZPlayer called traderServerLog, I assume. So you need to remove that line as well.

Here, try this, I belive this is what you're trying to achieve:

modded class DayZPlayerImplement extends DayZPlayer
{
	void traderServerLog(string message)
	{
		TraderMessage.ServerLog("[TRADER] Player: (" + this.GetIdentity().GetName() + ") " + this.GetIdentity().GetId() + " " + message);

		private PlayerIdentity p_Identity = this.GetIdentity();
		if (p_Identity)
		{
			string name_player = p_Identity.GetName();
			string UID_player = p_Identity.GetPlainId();
			vector pos_object = this.GetPosition();	
			private string message_log = name_player + "(steam64id=" + UID_player + ",pos=" + pos_object.ToString() + ") " + message;
			Print(message_log);
		}
	}
	
}

 

Share this post


Link to post
Share on other sites
17 hours ago, IMT said:

That's because there is no method in DayZPlayer called traderServerLog, I assume. So you need to remove that line as well.

Here, try this, I belive this is what you're trying to achieve: 


modded class DayZPlayerImplement extends DayZPlayer
{
	void traderServerLog(string message)
	{
		TraderMessage.ServerLog("[TRADER] Player: (" + this.GetIdentity().GetName() + ") " + this.GetIdentity().GetId() + " " + message);

		private PlayerIdentity p_Identity = this.GetIdentity();
		if (p_Identity)
		{
			string name_player = p_Identity.GetName();
			string UID_player = p_Identity.GetPlainId();
			vector pos_object = this.GetPosition();	
			private string message_log = name_player + "(steam64id=" + UID_player + ",pos=" + pos_object.ToString() + ") " + message;
			Print(message_log);
		}
	}
	
}

 

Yes, but if the author of the modifications will change the function of it is to have a fully copy? There is no way to call her own code without his constant perekopirovannye to yourself?

Share this post


Link to post
Share on other sites
9 minutes ago, AXEL777 said:

Yes, but if the author of the modifications will change the function of it is to have a fully copy? There is no way to call her own code without his constant perekopirovannye to yourself?

To be honest I have no idea how dependencies are managed with DayZ modding and how you can override them. Somebody else might be able to help you on that part.

Share this post


Link to post
Share on other sites
19 hours ago, IMT said:

That's because there is no method in DayZPlayer called traderServerLog, I assume. So you need to remove that line as well.

Here, try this, I belive this is what you're trying to achieve:


modded class DayZPlayerImplement extends DayZPlayer
{
	void traderServerLog(string message)
	{
		TraderMessage.ServerLog("[TRADER] Player: (" + this.GetIdentity().GetName() + ") " + this.GetIdentity().GetId() + " " + message);

		private PlayerIdentity p_Identity = this.GetIdentity();
		if (p_Identity)
		{
			string name_player = p_Identity.GetName();
			string UID_player = p_Identity.GetPlainId();
			vector pos_object = this.GetPosition();	
			private string message_log = name_player + "(steam64id=" + UID_player + ",pos=" + pos_object.ToString() + ") " + message;
			Print(message_log);
		}
	}
	
}

 

tested, don't worked((

Share this post


Link to post
Share on other sites
4 minutes ago, AXEL777 said:

tested, don't worked((

Any errors or what was the result?

Share this post


Link to post
Share on other sites
5 hours ago, IMT said:

Any errors or what was the result?

no, this code

private PlayerIdentity p_Identity = this.GetIdentity();
		if (p_Identity)
		{
			string name_player = p_Identity.GetName();
			string UID_player = p_Identity.GetPlainId();
			vector pos_object = this.GetPosition();	
			private string message_log = name_player + "(steam64id=" + UID_player + ",pos=" + pos_object.ToString() + ") " + message;
			Print(message_log);
		}

don't runned when this function called in server

 

Share this post


Link to post
Share on other sites

You are trying to declare 2 instance variables in a method, which to my knowledge, shouldn't be possible.

Try this:

modded class DayZPlayerImplement extends DayZPlayer
{
	void traderServerLog(string message)
	{
		TraderMessage.ServerLog("[TRADER] Player: (" + this.GetIdentity().GetName() + ") " + this.GetIdentity().GetId() + " " + message);

		PlayerIdentity p_Identity = this.GetIdentity();
		if (p_Identity)
		{
			string name_player = p_Identity.GetName();
			string UID_player = p_Identity.GetPlainId();
			vector pos_object = this.GetPosition();	
			string message_log = name_player + "(steam64id=" + UID_player + ",pos=" + pos_object.ToString() + ") " + message;
			Print(message_log);
		}
	}
	
}

 

Share this post


Link to post
Share on other sites
5 hours ago, IMT said:

You are trying to declare 2 instance variables in a method, which to my knowledge, shouldn't be possible.

Try this:


modded class DayZPlayerImplement extends DayZPlayer
{
	void traderServerLog(string message)
	{
		TraderMessage.ServerLog("[TRADER] Player: (" + this.GetIdentity().GetName() + ") " + this.GetIdentity().GetId() + " " + message);

		PlayerIdentity p_Identity = this.GetIdentity();
		if (p_Identity)
		{
			string name_player = p_Identity.GetName();
			string UID_player = p_Identity.GetPlainId();
			vector pos_object = this.GetPosition();	
			string message_log = name_player + "(steam64id=" + UID_player + ",pos=" + pos_object.ToString() + ") " + message;
			Print(message_log);
		}
	}
	
}

 

f20453272f16t.jpg

b51397f18582t.jpg

don't worked(

Edited by AXEL777

Share this post


Link to post
Share on other sites
21 hours ago, AXEL777 said:

f20453272f16t.jpg

b51397f18582t.jpg

don't worked(

I can see the last line printed the message, so why isn't it working?

Share this post


Link to post
Share on other sites
3 hours ago, IMT said:

I can see the last line printed the message, so why isn't it working? 

because this words don't exist in log server, only a default log server from mod

767c29d969a9t.jpg

 

Share this post


Link to post
Share on other sites
33 minutes ago, AXEL777 said:

because this words don't exist in log server, only a default log server from mod

767c29d969a9t.jpg

 

Seems to me the condition of the if-statement isn't met so it doesn't print out your message.

Edit: I'm not sure what "if (p_Identity)" means in EnScript but I know that in Java that line of code will produce an error unless p_Identity is a boolean. Try "if (p_Identity != null)", that might solve your error.

Edited by IMT

Share this post


Link to post
Share on other sites
1 hour ago, IMT said:

Seems to me the condition of the if-statement isn't met so it doesn't print out your message.

Edit: I'm not sure what "if (p_Identity)" means in EnScript but I know that in Java that line of code will produce an error unless p_Identity is a boolean. Try "if (p_Identity != null)", that might solve your error. 

i am try do this

modded class DayZPlayerImplement extends DayZPlayer
{
	void traderServerLog(string message)
	{
		TraderMessage.ServerLog("[TRADER] Player: (" + this.GetIdentity().GetName() + ") " + this.GetIdentity().GetId() + " " + message);
		Print("[My test log] " + message);
	}
	
}

and test server, but don't search message in logs with '[My test log]'

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
Sign in to follow this  

×