View Full Version : [562][RS2HD] Using timers
scootersam
October 2nd, 2010, 13:15
well ima show you hwo to use normal timers, you can use these for any thing but if you want my opinion dont use for minigames use gamengine timers for that
ok so
lets start goto src>com>rs2hd>model>player.java
and add this at the top
/*Timers*/
public int timer = -1;
now this means that your timer is called timer and its on -1 seconds so not started..
so no
search for 600ms
and you will see something like this i belive
if (takingitem > 0) {
takingitem--;
}
if (potDelay > 0) {
potDelay--;
}
if (MiasmicDelay > 0) {
MiasmicDelay--;
AttackSpeed = 2;
}
if (MiasmicDelay == 0) {
MiasmicDelay--;
AttackSpeed = 1;
}
now under that last "}"
add this for your timer
if (pctimer > 0) {
timer--;
} else if (timer == 0) {
timer = -1;
}
where you see
else if (timer == 0) {
after that bit add what you want for the timer to do when it reaches 0 and there you got your timer, i used this one a while ago
if (pctimer > 0) {
pctimer--;
} else if (pctimer == 0) {
getActionSender().sendMessage("The boat takes you into game!");
getActionSender().sendCloseInterface();
getActionSender().sendRemoveOverlay();
pctimer = -1;
teleport(Location.location(2657, 2612, 0));
getActionSender().sendMessage("You will get max 2 minutes in game..");
getActionSender().sendMessage("After the game is finished you will get 2 pc points!");//pcingame
pcingame = 120;
}
it works pretty well tbh
now for your timer to start when you click an object or something
just type
player.timer = ##;
ok the ## stands for your time these timers are also done in seconds not miliseconds
well thanks and i hope i helped
~sam
Stacx
October 2nd, 2010, 13:24
Don't teach people to use process please.
scootersam
October 2nd, 2010, 13:41
why whats up with that?
Relapse
October 2nd, 2010, 13:57
Don't teach people to use process please.
Ffs get over yourself, i'd say over half of the people just want the content to be right and don't care how its programmed. If it bothers you enough to post then post your way of doing it.
@Scootersam, not bad if; but at the beginning do you have to set the timer to -1? I thought it would be negative one by default?
public int timer = -1;
scootersam
October 2nd, 2010, 14:01
idk tbh i usualy set at -1 :S
Relapse
October 2nd, 2010, 14:11
What do you have to import to be able to use a timer, or is it standard in java.lang?
scootersam
October 2nd, 2010, 14:12
i dont think you gota import any thing tbh :S
Relapse
October 2nd, 2010, 14:13
ok thanks
Stacx
October 2nd, 2010, 15:25
Ffs get over yourself, i'd say over half of the people just want the content to be right and don't care how its programmed. If it bothers you enough to post then post your way of doing it.
@Scootersam, not bad if; but at the beginning do you have to set the timer to -1? I thought it would be negative one by default?
public int timer = -1;
That's called half-assing stuff bro, also, 0 is by default.
Relapse
October 2nd, 2010, 16:22
That's called half-assing stuff bro, also, 0 is by default.
Ok, well half-assed servers get wayy more players than not "half-assed". Just take battlescape for example, and compare it to hyperion. Sometimes people need to consider the fact that while having a good core that can hold 2000 players is great, players want content and that is what many good programmers lack, because they spend too much time updating/redoing the core.
Emily
October 2nd, 2010, 21:56
Didn't i already post a teaching or something on using timers?
Emperor
October 2nd, 2010, 22:07
I'm going to try to put this in a calm, non-aggressive way..
Why the fuck would anyone use timers?
Use the fucking Java Timertask.
Or atleast that eventmanager shit.
[I'm]_[Not]_[Caelum]
October 2nd, 2010, 22:08
EOnly the registered members can see the link.
Trey
October 2nd, 2010, 22:11
I'm going to try to put this in a calm, non-aggressive way..
Why the fuck would anyone use timers?
Use the fucking Java Timertask.
Or atleast that eventmanager shit.
Event managers sucks. Use Executors and ExecutorServices, they exist for a reason.
Emperor
October 2nd, 2010, 22:11
Event managers sucks. Use Executors and ExecutorServices, they exist for a reason.
Why not the timer task in the API?
And; I dislike the eventmanager, which is why I called it shit.
Trey
October 2nd, 2010, 22:19
Why not the Java timer task?
And; I dislike the eventmanager, which is why I called it shit.
The ExecutorService design provided is much more robust than Timer and TimerTask. Timer runs everything on the same thread, so a time consuming TimerTask will hog the Timer's thread. Also, if any exceptions are thrown by a TimerTask the entire Timer will crash. ExecutorServices and ScheduledExecutorServices allow you to very specifically implement how tasks are executed, and even grab results from and monitor submitted tasks with Callables and Futures. Plus there are a lot of ExecutorServices supplied by the API if you check the Executors class, including different variations of thread pools and single-thread executors.
In my opinion, anything you can do with Timer you can do better with ExecutorServices. The only real reason I can think of for using Timer and TimerTask is simply backwards compatibility, since ExecutorServices weren't introduced until java 5.
Emperor
October 2nd, 2010, 22:21
The ExecutorService design provided is much more robust than Timer and TimerTask. Timer runs everything on the same thread, so a time consuming TimerTask will hog the Timer's thread. Also, if any exceptions are thrown by a TimerTask the entire Timer will crash. ExecutorServices and ScheduledExecutorServices allow you to very specifically implement how tasks are executed. Plus there are a lot of ExecutorServices supplied by the API if you check the Executors class, including different variations of thread pools and single-thread executors.
In my opinion, anything you can do with Timer you can do better with ExecutorServices. The only real reason I can think of for using Timer and TimerTask is simply backwards compatibility, since ExecutorServices weren't introduced until java 5.
Very well, I'm going to find some more information about it, never used it before.
Trey
October 2nd, 2010, 22:22
Very well, I'm going to find some more information about it, never used it before.
Good idea, because you're missing out, lul.
scootersam
October 2nd, 2010, 22:35
well idc i only know how to do timers 2 ways atm ones in gameengine,java an the other is this way so unless you willin got teach me the others ill hapily say ok yeah yours is better...
David
October 3rd, 2010, 11:21
Not bad, although there are better ways for this ;)
Niator
October 3rd, 2010, 12:10
Didn't i already post a teaching or something on using timers?
Yep, but your was a bit harder to understand. This was just the ting O needed. Thanks sam (:
scootersam
October 3rd, 2010, 12:18
no prob glad i helped (:
Emily
October 7th, 2010, 20:23
Pc timer should be declared in gameengine, since its a global timer, declaring it on the player file takes up un needed space, and is the incorrect timer for a minigame.
David
October 7th, 2010, 20:27
This is a timer for private use (One player only) and Emily's tut is about global use (For a single player AND groups)
scootersam
October 7th, 2010, 20:31
ikr i didnt know that before i dnow lol
Stacx
October 8th, 2010, 13:31
Ok, well half-assed servers get wayy more players than not "half-assed". Just take battlescape for example, and compare it to hyperion. Sometimes people need to consider the fact that while having a good core that can hold 2000 players is great, players want content and that is what many good programmers lack, because they spend too much time updating/redoing the core.
LOLOLOLOL Battlescape is not "half-assed" neither is hyperion.
David
October 8th, 2010, 16:11
LOLOLOLOL Battlescape is not "half-assed" neither is hyperion.
He didn't said that hyperon is half-assed, he just said you need to compare it. Although Battlescape is half-assed. 97% of the servers is half-asses.
apache ah64
October 12th, 2010, 17:17
really nice was already lookingg for that :)
Jon
October 12th, 2010, 17:20
He didn't said that hyperon is half-assed, he just said you need to compare it. Although Battlescape is half-asses. 97% of the servers is half-asses.
Half-Asses? Wtf is that =/.
And it's more like 99% 100 good coders in rsps is like 1% ;P
David
October 13th, 2010, 17:56
True, true. And I mend Half-AsseD, it's just a typo....
Mystic Flow
October 17th, 2010, 16:02
To all of the idiots on this thread, the process doesn't effect server stability in any way
hoodlink
December 27th, 2011, 13:57
thnx for this now i can add timers for my agility as it teleports then does emote atm ;)
Arix
December 27th, 2011, 14:38
Ffs get over yourself, i'd say over half of the people just want the content to be right and don't care how its programmed. If it bothers you enough to post then post your way of doing it.
@Scootersam, not bad if; but at the beginning do you have to set the timer to -1? I thought it would be negative one by default?
public int timer = -1;
I think if you declare it like this
public int timer;
The default value would be 0.
Powered by vBulletin® Version 4.1.9 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.