这是第一堂课:
package Chatter;
public class Timer
{
private long period;
private long start;
private long CurrentTime = System.currentTimeMillis();
public Timer(long period)
{
this.period = period;
start = System.currentTimeMillis();
}
public long getElapsed()
{
return System.currentTimeMillis() - start;
}
public long getRemaining()
{
return period - getElapsed();
}
public boolean isRunning()
{
return getElapsed() <= period;
}
public long TimetoExcucte(int Seconds){
return CurrentTime + (Seconds * 1000);
}
public boolean Reached(int Seconds){
return System.currentTimeMillis() > TimetoExcucte(Seconds);
keyboard.typeString("Test", true);
}
public void reset()
{
start = System.currentTimeMillis();
}
public void stop()
{
period = 0;
}
public static String format(long milliSeconds)
{
long secs = milliSeconds / 1000L;
return String.format("%02d:%02d:%02d", new Object[] {
Long.valueOf(secs / 3600L), Long.valueOf((secs % 3600L) / 60L), Long.valueOf(secs % 60L)
});
}
}
这是第二堂课:
package Chatter;
import java.util.List;
import Chatter.Timer;
import org.osbot.rs07.api.ui.Message;
import org.osbot.rs07.script.Script;
import org.osbot.rs07.script.ScriptManifest;
@ScriptManifest(name="Chatter", author="Chatter", version=1, info="Chatter", logo="")
public class Chatter extends Script{
private static long Lastime = 0;
private Dialogue Dialogue;
boolean said;
int Index;
Timer runTimer;
public void onStart() throws InterruptedException {
runTimer = new Timer(0);
}
public int onLoop() throws InterruptedException {
if(runTimer.Reached(5)){
keyboard.typeString("Hoi", true);
}else{
log("Waiting");
}
return 500;
}
private void Respond() throws InterruptedException {
//Message sending method
if(said == true){
sleep(random(2000,4500));
Dialogue = new Dialogue();
List<String> RespondSpeach = Dialogue.getNumberList1();
keyboard.typeString(RespondSpeach.get(Index) , true);
said = false;
}
}
public void onMessage(Message m) throws InterruptedException {
//Message recieveing method
if(m.getUsername().equalsIgnoreCase(""))
Dialogue = new Dialogue();
List<String> ReceivedSpeach = Dialogue.getNumberList();
for (String word : ReceivedSpeach){
if (m.getMessage().contains(word)){
Index = ReceivedSpeach.indexOf(word);
said = true;
}
}
}
}
所以第一个类是计时器,它的名称生成一个计时器,我想做的是让脚本每隔5秒执行一次动作
此脚本在Osbot http://osbot.org/上运行,我想要执行的操作是让脚本每5秒写一次Test
,但脚本会不断发送垃圾邮件Test
我如何每5秒做一次布尔工作而不是垃圾邮件?
答案 0 :(得分:0)
在Reached函数中的返回调用之后调用Keyboard.typeString,这意味着它永远不会被调用。尝试将它移动到正确的位置。
编辑误解。