Page 1 of 1

PlayerVariables -> EnterWorld

Posted: Fri Jul 22, 2016 2:40 pm
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.

Re: PlayerVariables -> EnterWorld

Posted: Sat Jul 23, 2016 2:30 am
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 :)

Re: PlayerVariables -> EnterWorld

Posted: Sat Jul 23, 2016 4:42 am
by KGB1st
It's great method, thx.
Is I must to reload the server when using this method?

Re: PlayerVariables -> EnterWorld

Posted: Sat Jul 23, 2016 7:00 pm
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.