Purpose: To eliminate the need for process timers in skills
Difficulty: 1
Assumed Knowledge: Basic Java skills
Classes Modified: Client.java, Event.java
Tested On(if it applies): Devolution
Say goodbye to process timers for your skills. You can now use Graham's Event Manager for almost any skill which requires a timer!
In the past you would have to have variables to prevent massers from reaching the event call, because once they did there was no turning back.
The solution I found was to assign an auth code to clicks on Packet 98 (The 'Walk On' packet), and then when the event was called, have it check the auth code and make sure the player hasn't moved or clicked an object since then.
NOTE: To fully implement this with some skills you will need to call an auth refresh on teleports, item dropping, action button clicking, etc.
Further explanation:
Originally Posted by
Zaga
Lets say you use an event to decide when a player will get an ore while mining. If they send multiple requests to mine then all of those events will be called around the same time giving them fast ores.
This is just an easy way to prevent massing without having to setup a whole bunch of variables like "isMining = true;"
It will only call the last event, while all the ones before that will be ignored since they don't have the latest auth.
How to implement it:
1
Code:
public int clickauth;
2
This generates the auth code itself. It generates a number between 1 and 1 billion.
Code:
case 98: // walk on command
Random r = new Random();
clickauth = r.nextInt(1000000000);
3
In event.java
Add this:
Code:
public Event(int tick, int auth) {
this.authcode = auth;
this.tick = tick;
this.lastRun = System.currentTimeMillis();
}
Under
Code:
public Event(int tick) {
this.tick = tick;
this.lastRun = System.currentTimeMillis();
}
Also make sure you declare this in event.java as well.
Code:
public int authcode;
And you're done.
Now to use it do something like this...
Code:
server.registerEvent(new Event([TIMEHERE], clickauth) {
public void execute() {
if (clickauth == this.authcode){
[Whatever you want to happen once the event is called...]
}
server.deregisterEvent(this);
}
});
The blue is setting the auth code int in event.java.
The green is your current auth code.
And the red is simply comparing the auth code int in the event.java to your current one. If they match then the event is called as normal.
Credits:
Graham for supplying the Event Manager
Zaga for implementing the Auth System