Making your own timers(and can't log out in certain areas)
This started out as not being able to log out in a certain area, and after a bit I realised that I forgot the super easy way to do it rofl, so instead I guess this is more of a guideline to making your own timers.
**IF YOU ARE NOT EXPERIENCED PLEASE MAKE A COPY OF YOUR Client.java BEFORE STARTING!!! I don't want to be held responsible for any damage that you may cause to your server if you mess up and can't fix it, although this is very easy to do!**
Ok well I was coding around with jiber earlier and he really inspired me to just experiment around with coding, something I havn't done much. So I started messing around with things in hopes of getting something I could incorporate into a minigame. This is the first tut i've ever posted having to do with servers and i'm still learning so if this is of no use to you please ignore it, or guide me in the right direction if there was an easier way to do this lol; :p
You could probably use this as a base to mess around and make yourself unable to do things and etc in certain areas.
Purpose: Making it so you can't log out within set coordinates.
Difficulty: 1
Assumed Knowledge: Knows how to add new zones.Copy, paste, and search if you just want to add it. Ability to understand if you want to learn lol.
Server Base: Should be capable on all servers.
Classes Modified: Client.java
Procedure
Step 1: First you are going to need a set area to make perform this on. Open up your client.java and search for
Hopefully you will know how to add new zones, as this was in the assumed knowledge. If you dont, search around or study the code. It's not too hard. Once you add in your new zone with the coords, we're going to need to make it so that the server knows what to do when you're in that location.
Step 2: Go back to the top of your client and search for
You should see something like this-
Code:
checkwildy2();
if(nonWild())
{
outStream.createFrame(208); //
outStream.writeWordBigEndian_dup(197);
sendQuest("@[email protected]", 199);
} else {
outStream.createFrame(208); //
outStream.writeWordBigEndian_dup(197);
sendQuest("@[email protected] Zone", 199);
}
What this does is checks were you are and performs the said actions. So if you're in the nonWild zone, it will display an image and the word "Safe". Were it says "else" means that if you are not in the nonWild zone, then it will display what's said there. Now you're going to need to add your zone into this. Make sure the end result looks like this.
Code:
checkwildy2();
if(nonWild())
{
outStream.createFrame(208); //
outStream.writeWordBigEndian_dup(197);
sendQuest("@[email protected]", 199);
} else {
outStream.createFrame(208); //
outStream.writeWordBigEndian_dup(197);
sendQuest("@[email protected] Zone", 199);
}
if(yourzone())
{
outStream.createFrame(208); //
outStream.writeWordBigEndian_dup(197);
sendQuest("@[email protected] Zone", 199);
} else {
checkwildy2();
}
}
What this does is if you're in the nonWild zone, it will display the Safe image. If you're not in the nonWild zone it will display the Pk Zone image. Also, if you're in your zone you made earlier it will display the words you put there, and if you aren't in your zone it will check to see wether or not you're in the nonWild zone or not. That might be kind of confusing, make sure you compile after this and you might want to make sure it displays these words in-game.
Step 3: Now we're going to need to make it so that you can't log out while in the zones that you choose. Search for
Code:
public int LogoutDelay = 0;
and you should see some things around it like
Code:
public int rangePotTimer = 0;
public boolean rangePot = true;
public int magePotTimer = 0;
public boolean magePot = true;
public int LogoutDelay = 0;
public int EntangleDelay = 0;
public int PkingDelay = 0;
public int LoopAttDelay = 0;
Above the public int LogoutDelay=0; add this
Code:
public int CantLog = 0;
This little bit of info isn't needed, but i'd read it if you want to learn. Search for
Code:
if(LogoutDelay > 0)
and you should see a lot of other codes that look similar to eachother.
Code:
if(LogoutDelay > 0)
LogoutDelay -= 1;
What this does is make it so if the LogoutDelay is greater than zero, it decreases by 1. We're not going to add in our "CantLog" here because we don't want the number to be increasing or decreasing.
Step 4: Now we need to add this in so that by using it properly, you can't log out. Search for
Code:
case 9154: //Log out
This is, obviously, your log out case. Yours will probably look like this
Code:
case 9154: //Log out
if (LogoutDelay >= 1)
{
sendMessage("You have to wait 15 seconds out of being in combat to logout.");
}
else
{
logout();
savefile = true;
}
break;
Note that your's doesnt have to be 100% the same. What this is saying is if your logout delay is greater than or equal to 1 when you try to log out, it will just send the message saying you have to wait 15 seconds. If your logout delay is less than one than it will log out and save your file. We want to add in our code here so you can only log out if it is equal to zero. So right above
add this
Now you will only be able to log out if the CantLog is equal to zero.
Step 5: Now, the last step, we need to make it so you actually can't log out while in the specified zones. Search for
Code:
checkwildy2();
if(nonWild())
{
again and you will see where we were at earlier.Now listen up carefully.
Wherever you want to be able to log out normally (ruling the CantLog out as a factor) you need to add in
so you can still log out without that playing a role. Remember, we said that you can log out in our log out case if this is equal to 0. In the zones that you DO NOT want to be able to log out in, add in
Now you will not be able to log out in this zone no matter what. You wont be able to because you can only use the logout case if this is equal to 0. This will never go up or down from 1 because we didn't choose to change it at all earlier on were I explained. My final code looks like this
Code:
public int WildyLevel = 0;
public int leftwild = 0;
public boolean InWildrange = false;
public void WriteWildyLevel()
{
checkwildy2();
if(nonWild())
{
CantLog = 0;
outStream.createFrame(208); //
outStream.writeWordBigEndian_dup(197);
sendQuest("@[email protected]", 199);
} else {
CantLog = 0;
outStream.createFrame(208); //
outStream.writeWordBigEndian_dup(197);
sendQuest("@[email protected] Zone", 199);
}
if(funpk())
{
CantLog = 1;
outStream.createFrame(208); //
outStream.writeWordBigEndian_dup(197);
sendQuest("@[email protected] PK", 199);
} else {
checkwildy2();
}
}
Now compile and run, make sure you can't log out in the zone you added it into but in the other ones. Hope it works for you, took a while to type out this entire tutorial >.< so if atleast ONE person finds it useful to their server or served as a learning experience then i've reached my goal.
Credits: Aftee
I just ran a few more tests with this and you CAN use it for alot of things. I set up a test int that decreases normally as other ints by 1. I then set up an object case so when you clicked on it, that test int was set to 100 and you were teleported into a specified zone. When that int hit 0 the zone was instructed to teleport you somewhere else, and it worked o.o