Jump to content

Recommended Posts

Posted

Hello gyes, since it requested, i will try to make this guide about some methods and creating methods explanations.

 

This time, we will talk about set and is methods.You know..., maybe all of you know these methods , you have seen it at hero status,noble status :

setHero(true,false)  ,   setNoble(true,false)  , isHero()  ,  isNoble().

I will explain you exactly how these methods are working, so that you can create easy your own .

 

In my guide i will use the name MaxCheatersMember.So, there will be two methods, right?

The one is   setMaxCheatersMember(true,false)  and the other isMaxCheatersMember() .

 

Creating the methods....

First of all, lets create the method isMaxCheatersMember() .  I will make it via steps.

1)We go at L2PcInstance.java class and we create a boolean named like we want i will use this:

private boolean _maxcheater;

 

2)For make it easy and more readable, find this line: public boolean isNoble() , above this create a method :

public boolean isMaxCheatersMember()

{

}

 

3)We have a empty method,named isMaxCheatersMember,right? Inside this method just add this line:

return _maxcheater; . So the method will have the body return _maxcheater; .

The isMaxCheatersMember() method is ready, now we will create the method seMaxCheatersMember(true or false).

 

4)Above of the line: public boolean isMaxCheatersMember() or under the whole method we create a new method named setMaxCheatersMember(boolean value)

{

}

 [in the value you can put everything ,even x,y,z

 

5)Now we have again a empty method xD , inside this method now we put this line:

_maxcheater = value; (where value the name of your boolean)

 

Now we have the both methods we need: isMaxCheatersMember() and setMaxCheatersMember(boolean value)

 

 

How they work.....?Explanation?

I will explain it again in some simple steps:

 

1)First of all we create a private boolean named _maxcheater;. A boolean can have only 2 values ,

it can be true or false .

Ok , but why private?

We set it as private because the only class that checks this value is the class L2PcInstance, only this class checks this boolean , only.

 

2)the whole method:

public boolean isMaxCheatersMember()

{

  return _maxcheater;

}

just returns the value of _maxcheater; So if _maxcheater boolean is true , the method

isMaxCheatersMember() will return true, if false the method will return false; You catch it , o yea!!

By default it is false, as we created the boolean _maxcheater as false in the beggining.But for changing it,for changing the boolean, so for changing the value of method isMaxCheatersMember() to return true if we want, or false, look at the step 3.

Why the method is public?

Because , we want to use this method and in another classes, not only in L2PcInstance for example maybe we want to go at Enterworld class and we need to add this method there!

 

3)Here's come the creation of method:

public void setMaxCheatersMember(boolean value)

{

 _maxcheater = value;

}

What the hell is it?Ok, this method first of all needs a parameter,a parameter in our example is the: boolean value .Then it reads this boolean , so it will read if it is true or false.Then it takes the value of the boolean, and it set's it at _maxcheater boolean.For example if value=true then _maxcheater = true ; if False, the opposite. It's easy i think to understand it.

Why public and why void and not boolean?

Not private for the same reason as method isMaxCheatersMember().

Ok, now lets explain why void and not boolean.If we had boolean we should return something, for example return _aboolean; But we don't want this method to return something, we want this method to DO something.We we want a method to do something, we put void.

 

That was how these simple methods work, i think that for newbies it is usefull and they can understand it.

 

Puting methods into methods...

Ok, i will continue with these 2 methods. isMaxCheatersMember() and setMaxCheatersMember(true,false) .

Now , players can't get this method to true, its false by default....for example now i will explain you how to "check" if the players has some conditions to take the isMaxCheatersMember() status(i mean to be true).

 

In my example, one player will become isMaxCheatersMember() if he has 50000 pvp.How can we do it?We can do it and without put methods into methods, but by doing this it's better, i think it looks more advanced.

So what we want our method to return or do something? Think about it, we need to DO, so we create a void method.

Let's create it, i will explain you what i did then.

 

public void checkForMxcStatus(L2PcInstance activeChar)

{

 if (activeChar.getPvpKills() >= 50000 && !(activeChar.isMaxCheatersMember()))

 {

   activeChar.setMaxCheatersMember(true);

 }

 else if (activeChar.getPvpKills() < 50000)

 {

   activeChar.setMaxCheatersMember(false);

 }

}

 

What we did?

1)We created a public (you know now why public) method as void named checkForMxcStatus with 1 parameter which is an l2pcinstance object, the well known to all of you activeChar.

2)First of all we check if the activeChar has 50000 pvp and if he is'nt MaxCheatersMember() (! means not).

3)If the player has these conditions, we set him isGamingParadiseMember() with the setMaxCheatersMember() method that we created before.

4)then we use the else if to check if the player's pvps ar lower than 50000 , if it is we set him isMaxCheatersMember false, again with the method setMaxCheatersMember().

 

Yes that can be done with a better way, that was an example.If you are a newbie, the best you can do is practice to methods, they are very very very very usefull to continue your carreer.I hope i helped gyes, for now i need some masause at my fingers.

 

 

PS: the is and get is example, but all are used to use these methods to be more understandable, you catch me :D

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...