PlayerVariables -> EnterWorld

Support for the latest build of L2J Server, get help here with installations, upgrades, problems.
Do not post bugs reports here, use viewforum.php?f=77 instead.
There is no support for other server builds than the official provided by l2jserver.com
Forum rules
READ NOW: L2j Forums Rules of Conduct
Post Reply
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

PlayerVariables -> EnterWorld

Post by KGB1st »

I learned how to work with PlayerVariables and want to ask you about Enterword and L2PcInstance.

I've some variable on client. The variable is stored in the database when a customer leaves the game. But when player enters the game again I'll have to make some changes on the client which are based on data character_variables... And here my question, where I must do it, or how? Is it will be as new method in l2pcinstance or what?

This's one part of code. I've many changes, and many will be in future. For example on: val "experience". I need disable exp for char when it enters the game, and now I think how to do this better.

Code: Select all

// Example part of code, already done

				if (param.equals("experience"))
				{
					try
					{
						boolean exp_isenabled = activeChar.getVariables().getBoolean("experience", false);
						String s_state = "";
						
						if (!exp_isenabled)
						{
							activeChar.addListener(new FunctionEventListener(activeChar, EventType.ON_PLAYABLE_EXP_CHANGED, (OnPlayableExpChanged event) -> onExperienceReceived(event.getActiveChar(), event.getNewExp() - event.getOldExp()), this));
							activeChar.getVariables().set("experience", true);
							s_state = "выключено";
						}
					
						else if (exp_isenabled)
						{
							activeChar.removeListenerIf(EventType.ON_PLAYABLE_EXP_CHANGED, listener -> listener.getOwner() == this);
							activeChar.getVariables().set("experience", false);
							s_state = "включено";
						}
						activeChar.sendMessage("Получение опыта: "+s_state+".");
						SendReadyHTML(activeChar, htmltext);
						return false;
					}
					
					catch (Exception e)
					{
						SendDenideAccess(activeChar, "Возникла ошибка при обработке: experience");
						_log.info("**** VIP Manager **** < " + activeChar + " > got error in experience");
						return false;
					}
				}
Why I say about L2pcinstance.. because I need write this code once, but use it twice: 1st when char enters the game and 2nd when it chage val through handler.
Last edited by KGB1st on Wed Jul 27, 2016 2:23 pm, edited 2 times in total.
User avatar
Zephyr
L2j Veteran
L2j Veteran
Posts: 331
Joined: Wed Sep 19, 2012 10:44 pm
Location: Argentina

Re: PlayerVariables -> EnterWorld

Post by Zephyr »

You don't need change the core to handle the onEnterWorld event. You just need create a script for that.

https://gist.github.com/luksdlt92/0f08e ... 87cd7076b2

Remember add the script inside scripts.cfg to enable it!

For more examples, check dist/game/data/scripts :)
User avatar
KGB1st
Posts: 230
Joined: Sat Jul 26, 2014 5:58 pm

Re: PlayerVariables -> EnterWorld

Post by KGB1st »

It's great method, thx.
Is I must to reload the server when using this method?
User avatar
Zephyr
L2j Veteran
L2j Veteran
Posts: 331
Joined: Wed Sep 19, 2012 10:44 pm
Location: Argentina

Re: PlayerVariables -> EnterWorld

Post by Zephyr »

KGB1st wrote:It's great method, thx.
Is I must to reload the server when using this method?
I don't know what you mean with reload the server, but i'm not sure if there is a way to reload the scripts on runtime, so yes.
Post Reply