there are some bugs but they will be fixed soon.
add this to player.java
Code:
public static void RandomEventTeleportPlayer(final Player player, final int x, final int y, final int z) {
player.setNextAnimation(new Animation(2140));
player.setNextForceTalk(new ForceTalk("ARGHHHHHHHHH!"));
player.getControllerManager().startControler("RandomEvent");
player.setInfiniteStopDelay();
player.stopAll();
WorldTasksManager.schedule(new WorldTask() {
@Override
public void run() {
player.resetStopDelay();
player.setNextWorldTile(new WorldTile(x, y, z));
}
}, 1);
}
public void randomevent(final Player p) {
EventManager.getSingleton().addEvent(new Event() {//sec this works???
public void execute(EventContainer c) {
int r3 = 0;
r3 = Utils.random(2);
if (r3 == 0) {
RandomEventTeleportPlayer(p, 2602, 4775, 0);
} else if (r3 == 1) {
RandomEventTeleportPlayer(p, 1952, 4764, 0);
getDialogueManager().startDialogue("QuizMaster",
2477);
}
}
}, 1800000);
}
;
add this to your welcome method in player.java
now add this these dialogues in your dialogue folder
QuizMaster.java
Code:
package com.rs.game.player.dialogues;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.player.content.Magic;
import com.rs.game.player.Player;
import com.rs.game.WorldTile;
/**
* Handles QuizMaster Game.
*
* @author Demon Dylan
*
*/
public class QuizMaster extends Dialogue {
private int npcId;
private int wrong = 0;
@Override
public void start() {
npcId = (Integer) parameters[0];
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Hello, and Welcome to the game show!" }, IS_NPC, npcId, 9827);
}
@Override
public void run(int interfaceId, int componentId) {
if (stage == -1) {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"The rules are simple answer all 5 questions correct",
"and you win a prize, answer 3 wrong you lose" }, IS_NPC, npcId, 9827);
stage = 1;
} else if (stage == 1) {
sendDialogue(SEND_2_OPTIONS, "What Level do you need to weild Dragon", "Definantly 40!",
"Defiantly 60!");
stage = 2;
} else if (stage == 2) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 3;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 3;
}
} else if (stage == 3) {
sendDialogue(SEND_2_OPTIONS, "Which of the following is flame resistant", "Anti-Dragonfire Shield!",
"Rune Beserker Shield!");
stage = 4;
} else if (stage == 4) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 5;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 5;
}
} else if (stage == 5) {
sendDialogue(SEND_2_OPTIONS, "Which of the following restores more health", "Salmon!",
"Shrimp!");
stage = 6;
} else if (stage == 6) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 7;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 7;
}
} else if (stage == 7) {
if (wrong == 3) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"3 Wrong You have Lost!" }, IS_NPC, npcId, 9827);
stage = 13;
} else {
sendDialogue(SEND_2_OPTIONS, "What attack level is required to weild a godsword", "85!",
"75!");
stage = 8;
}
} else if (stage == 8) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 9;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 9;
}
} else if (stage == 9) {
if (wrong == 3) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"3 Wrong You have Lost!" }, IS_NPC, npcId, 9827);
stage = 13;
} else {
sendDialogue(SEND_2_OPTIONS, "Who is the owner of pwnerzscape", "demon darren!",
"demon dylan!");
stage = 10;
}
} else if (stage == 10) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 11;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 11;
}
} else if (stage == 11) {
if (wrong == 3) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"3 Wrong You have Lost!" }, IS_NPC, npcId, 9827);
stage = 13;
} else {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"You win please accept this reward and come back soon!",
"Thanks for playing" }, IS_NPC, npcId, 9827);
stage = 12;
}
} else if (stage == 12) {
winner();
} else if (stage == 13) {
loser();
}
}
public void loser() {
Magic.sendNormalTeleportSpell(player, 0, 0, new WorldTile(2562, 5739, 0));
wrong = 0;
}
public void winner() {
Magic.sendNormalTeleportSpell(player, 0, 0, new WorldTile(2562, 5739, 0));
wrong = 0;
player.getInventory().addItem(6199, 1);
}
private void teleportPlayer(int x, int y, int z) {
player.setNextWorldTile(new WorldTile(x, y, z));
player.stopAll();
}
@Override
public void finish() {
}
}
FreakyForester.java
Code:
package com.rs.game.player.dialogues;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.player.content.Magic;
import com.rs.game.player.Player;
import com.rs.game.WorldTile;
public class FreakyForester extends Dialogue {
private int npcId;
@Override
public void start() {
npcId = (Integer) parameters[0];
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Welcome to my forester event," }, IS_NPC, npcId, 9827);
}
@Override
public void run(int interfaceId, int componentId) {
if (stage == -1) {
if (player.gotreward == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "You may exit through the portal" },
IS_NPC, npcId, 9827);
stage = 3;
} else {
sendDialogue(SEND_2_OPTIONS, "What would you like to say?", "I found pheasant meat.",
"What am i doing here?");
stage = 1;
}
} else if (stage == 1) {
if (componentId == 1) {
if (player.getInventory().containsItem(6178, 1)) {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "You brought me my meat.", "Please accept this reward.." },
IS_NPC, npcId, 9827);
player.getInventory().deleteItem(6178, 1);
player.getInventory().addItem(6199, 1);
player.gotreward = 1;
stage = 2;
} else {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "You do not have a pheasant meat.", "kill a pheasant to get some." },
IS_NPC, npcId, 9827);
stage = 3;
}
} else if (componentId == 2) {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "Hi i need some raw pheasant meat", "Bring it to me and I will release you." },
IS_NPC, npcId, 9827);
stage = 3;
}
} else if (stage == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "You may exit through the portal" },
IS_NPC, npcId, 9827);
stage = 3;
} else if (stage == 3) {
end();
}
}
private void teleportPlayer(int x, int y, int z) {
player.setNextWorldTile(new WorldTile(x, y, z));
player.stopAll();
}
@Override
public void finish() {
}
}
open dialogue handler add these and change the numbers 55 and 56 to your next numbers
Code:
Class<Dialogue> value55 = (Class<Dialogue>) Class.forName(FreakyForester.class.getCanonicalName());
handledDialogues.put("FreakyForester", value55);
Class<Dialogue> value56 = (Class<Dialogue>) Class.forName(QuizMaster.class.getCanonicalName());
handledDialogues.put("QuizMaster", value56);
ok now open controler folder and add RandomEvent.java put this in it
Code:
package com.rs.game.player.controlers;
import com.rs.game.Animation;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.player.content.Magic;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
/**
* Handles Random Event Controler
*
* @author Demon Dylan
*
*/
public class RandomEvent extends Controler {
@Override
public void start() {
//todo
}
@Override
public boolean sendDeath() {
player.addStopDelay(7);
player.stopAll();
WorldTasksManager.schedule(new WorldTask() {
int loop;
@Override
public void run() {
if (loop == 0) {
player.setNextAnimation(new Animation(836));
} else if (loop == 1) {
player.getPackets().sendGameMessage(
"Oh dear, you have died.");
} else if (loop == 3) {
player.reset();
player.setNextWorldTile(new WorldTile(2602, 4775, 0));
player.setNextAnimation(new Animation(-1));
stop();
}
loop++;
}
}, 0, 1);
return false;
}
@Override
public boolean login() {
player.getPackets().sendGameMessage("Your logged into a random event.");
return false;
}
@Override
public boolean logout() {
return false;
}
@Override
public boolean processMagicTeleport(WorldTile toTile) {
player.getPackets().sendGameMessage("You can't teleport in this area!");
return false;
}
@Override
public boolean processItemTeleport(WorldTile toTile) {
player.getPackets().sendGameMessage("You can't teleport in this area!");
return false;
}
@Override
public boolean processObjectClick1(WorldObject object) {
if (object.getId() == 15645)
return true;
return false;
}
}
open controlerhandler.java and add this to it replace the numbers 30 with yours
Code:
Class<Controler> value30 = (Class<Controler>) Class.forName(RandomEvent.class.getCanonicalName());
handledControlers.put("RandomEvent", value30);
open npchandler.java add this
Code:
if (npc.getId() == 100) {
player.getDialogueManager().startDialogue("FreakyForester",
npc.getId());
}
open objecthandler.java add this
Code:
} else if (id == 15645) {
Magic.pushLeverTeleport(player, new WorldTile(3616, 3365, 0));
player.getControlerManager().getControler().removeControler();
// WorldTasksManager.removeTask();
player.gotreward = 0;
add this to player.java also
Code:
public int gotreward = 0;
EDIT if you don't have events yet add a folder called event in location of src\com\rs
so now it should look like src\com\rs\event
add the following files into it
CycleEvent.java
Code:
package com.rs.event;
/**
* What the event must implement
*
* @author Stuart <RogueX>
*
*/
public abstract class CycleEvent {
/**
* Code which should be ran when the event is executed
*
* @param container
*/
public abstract void execute(CycleEventContainer container);
/**
* Code which should be ran when the event stops
*/
public abstract void stop();
}
CycleEventContainer.java
Code:
package com.rs.event;
/**
* The wrapper for our event
*
* @author Stuart <RogueX>
* @author Null++
*
*/
public class CycleEventContainer {
/**
* Event owner
*/
private Object owner;
/**
* Is the event running or not
*/
private boolean isRunning;
/**
* The amount of cycles per event execution
*/
private int tick;
/**
* The actual event
*/
private CycleEvent event;
/**
* The current amount of cycles passed
*/
private int cyclesPassed;
/**
* The event ID
*/
private int eventID;
/**
* Sets the event containers details
*
* @param owner
* , the owner of the event
* @param event
* , the actual event to run
* @param tick
* , the cycles between execution of the event
*/
public CycleEventContainer(int id, Object owner, CycleEvent event, int tick) {
this.eventID = id;
this.owner = owner;
this.event = event;
this.isRunning = true;
this.cyclesPassed = 0;
this.tick = tick;
}
/**
* Execute the contents of the event
*/
public void execute() {
event.execute(this);
}
/**
* Stop the event from running
*/
public void stop() {
isRunning = false;
event.stop();
}
/**
* Does the event need to be ran?
*
* @return true yes false no
*/
public boolean needsExecution() {
if (!this.isRunning()) {
return false;
}
if (++this.cyclesPassed >= this.tick) {
this.cyclesPassed = 0;
return true;
}
return false;
}
/**
* Returns the owner of the event
*
* @return
*/
public Object getOwner() {
return owner;
}
/**
* Is the event running?
*
* @return true yes false no
*/
public boolean isRunning() {
return isRunning;
}
/**
* Returns the event id
*
* @return id
*/
public int getID() {
return eventID;
}
/**
* Set the amount of cycles between the execution
*
* @param tick
*/
public void setTick(int tick) {
this.tick = tick;
}
}
CycleEventHandler.java
Code:
package com.rs.event;
import java.util.ArrayList;
import java.util.List;
/**
* Handles all of our cycle based events
*
* @author Stuart <RogueX>
* @author Null++
*
*/
public class CycleEventHandler {
/**
* The instance of this class
*/
private static CycleEventHandler instance;
/**
* Returns the instance of this class
*
* @return
*/
public static CycleEventHandler getSingleton() {
if (instance == null) {
instance = new CycleEventHandler();
}
return instance;
}
/**
* Holds all of our events currently being ran
*/
private List<CycleEventContainer> events;
/**
* Creates a new instance of this class
*/
public CycleEventHandler() {
this.events = new ArrayList<CycleEventContainer>();
}
/**
* Add an event to the list
*
* @param id
* @param owner
* @param event
* @param cycles
*/
public void addEvent(int id, Object owner, CycleEvent event, int cycles) {
this.events.add(new CycleEventContainer(id, owner, event, cycles));
}
/**
* Add an event to the list
*
* @param owner
* @param event
* @param cycles
*/
public void addEvent(Object owner, CycleEvent event, int cycles) {
this.events.add(new CycleEventContainer(-1, owner, event, cycles));
}
/**
* Execute and remove events
*/
public void process() {
List<CycleEventContainer> eventsCopy = new ArrayList<CycleEventContainer>(events);
List<CycleEventContainer> remove = new ArrayList<CycleEventContainer>();
for (CycleEventContainer c : eventsCopy) {
if (c != null) {
if (c.needsExecution())
c.execute();
if (!c.isRunning()) {
remove.add(c);
}
}
}
for (CycleEventContainer c : remove) {
events.remove(c);
}
}
/**
* Returns the amount of events currently running
*
* @return amount
*/
public int getEventsCount() {
return this.events.size();
}
/**
* Stops all events for a specific owner and id
*
* @param owner
*/
public void stopEvents(Object owner) {
for (CycleEventContainer c : events) {
if(c.getOwner() == owner) {
c.stop();
}
}
}
/**
* Stops all events for a specific owner and id
*
* @param owner
* @param id
*/
public void stopEvents(Object owner, int id) {
for (CycleEventContainer c : events) {
if(c.getOwner() == owner && id == c.getID()) {
c.stop();
}
}
}
/**
* Stops all events for a specific owner and id
*
* @param id
*/
public void stopEvents(int id) {
for (CycleEventContainer c : events) {
if(id == c.getID()) {
c.stop();
}
}
}
}
Event.java
Code:
package com.rs.event;
/**
* A simple interface for an event.
*
* @author Graham
*
*/
public interface Event {
/**
* Called when the event is executed.
*
* @param container
* The event container, so the event can dynamically change the
* tick time etc.
*/
public void execute(EventContainer container);
}
EventContainer.java
Code:
package com.rs.event;
import com.rs.game.World;
import com.rs.game.player.Player;
/**
* Holds extra data for an event (for example the tick time etc).
*
* @author Graham
*
*/
public class EventContainer {
/**
* The actual event.
*/
private Event event;
/**
* A flag which specifies if the event is running;
*/
private boolean isRunning;
/**
* When this event was last run.
*/
private long lastRun;
/**
* The tick time in milliseconds.
*/
private int tick;
/**
* The event container.
*
* @param evt
* @param tick
*/
protected EventContainer(Event evt, int tick) {
this.tick = tick;
this.event = evt;
this.isRunning = true;
this.lastRun = System.currentTimeMillis();
// can be changed to 0 if you want events to run straight away
}
public void sendPlayersOnline(Player player, int interfaceId, int line) {
player.getPackets().sendIComponentText(interfaceId, line,
" Players: " + World.getPlayers().size() + "");
}
/**
* Executes the event!
*/
public void execute() {
this.lastRun = System.currentTimeMillis();
this.event.execute(this);
}
/**
* Gets the last run time.
*
* @return
*/
public long getLastRun() {
return this.lastRun;
}
/**
* Returns the tick time.
*
* @return
*/
public int getTick() {
return this.tick;
}
/**
* Returns the is running flag.
*
* @return
*/
public boolean isRunning() {
return this.isRunning;
}
/**
* Stops this event.
*/
public void stop() {
this.isRunning = false;
}
}
EventManager.java
Code:
package com.rs.event;
import com.rs.game.World;
import com.rs.game.player.Player;
import java.util.ArrayList;
import java.util.List;
/**
* Manages events which will be run in the future. Has its own thread since some
* events may need to be ran faster than the cycle time in the main thread.
*
* @author Graham
*
*/
public class EventManager implements Runnable {
/**
* A reference to the singleton;
*/
private static EventManager singleton = null;
/**
* The waitFor variable is multiplied by this before the call to wait() is
* made. We do this because other events may be executed after waitFor is
* set (and take time). We may need to modify this depending on event count?
* Some proper tests need to be done.
*/
private static final double WAIT_FOR_FACTOR = 0.5;
/**
* Gets the event manager singleton. If there is no singleton, the singleton
* is created.
*
* @return The event manager singleton.
*/
public void sendPlayersOnline(Player player, int interfaceId, int line) {
player.getPackets().sendIComponentText(interfaceId, line,
" Players: " + World.getPlayers().size() + "");
}
public static EventManager getSingleton() {
if (singleton == null) {
singleton = new EventManager();
singleton.thread = new Thread(singleton);
singleton.thread.start();
}
return singleton;
}
/**
* Initialises the event manager (if it needs to be).
*/
public static void initialize() {
getSingleton();
}
/**
* A list of events that are being executed.
*/
private List<EventContainer> events;
/**
* The event manager thread. So we can interrupt it and end it nicely on
* shutdown.
*/
private Thread thread;
/**
* Initialise the event manager.
*/
private EventManager() {
events = new ArrayList<EventContainer>();
}
/**
* Adds an event.
*
* @param event
* The event to add.
* @param tick
* The tick time.
*/
public synchronized void addEvent(Event event, int tick) {
events.add(new EventContainer(event, tick));
notify();
}
@Override
/*
* Processes events. Works kinda like newer versions of cron.
*/
public synchronized void run() {
long waitFor = -1;
List<EventContainer> remove = new ArrayList<EventContainer>();
while (true) {
// reset wait time
waitFor = -1;
// process all events
for (EventContainer container : events) {
if (container.isRunning()) {
if ((System.currentTimeMillis() - container.getLastRun()) >= container
.getTick()) {
try {
container.execute();
} catch (Exception e){e.printStackTrace();}
}
if (container.getTick() < waitFor || waitFor == -1) {
waitFor = container.getTick();
}
} else {
// add to remove list
remove.add(container);
}
}
// remove events that have completed
for (EventContainer container : remove) {
events.remove(container);
}
remove.clear();
// no events running
try {
if (waitFor == -1) {
wait(); // wait with no timeout
} else {
// an event is running, wait for that time or until a new
// event is added
int decimalWaitFor = (int) (Math.ceil(waitFor
* WAIT_FOR_FACTOR));
wait(decimalWaitFor);
}
} catch (InterruptedException e) {
break; // stop running
}
}
}
/**
* Shuts the event manager down.
*/
public void shutdown() {
this.thread.interrupt();
}
}
Update
add this to player.java
Code:
public int tX;
public int tY;
public int tH;
public boolean saved;
public void saveLoc(int x, int y, int h) {
this.tX = x;
this.tY = y;
this.tH = h;
}
Replace or add these to player.java
Code:
public static void RandomEventTeleportPlayer(final Player player, final int x, final int y, final int z) {
player.setNextAnimation(new Animation(2140));
player.setNextForceTalk(new ForceTalk("ARGHHHHHHHHH!"));
player.getControllerManager().startControler("RandomEvent");
player.setInfiniteStopDelay();
player.stopAll();
WorldTasksManager.schedule(new WorldTask() {
@Override
public void run() {
player.resetStopDelay();
player.setNextWorldTile(new WorldTile(x, y, z));
}
}, 1);
}
public static void QuizEventTeleportPlayer(final Player player, final int x, final int y, final int z) {
player.setNextAnimation(new Animation(2140));
player.setNextForceTalk(new ForceTalk("ARGHHHHHHHHH!"));
player.getControllerManager().startControler("QuizEvent");
player.setInfiniteStopDelay();
player.stopAll();
WorldTasksManager.schedule(new WorldTask() {
@Override
public void run() {
player.resetStopDelay();
player.setNextWorldTile(new WorldTile(x, y, z));
}
}, 1);
}
public void randomevent(final Player p) {
EventManager.getSingleton().addEvent(new Event() {//sec this works???
public void execute(EventContainer c) {
if (getControlerManager().getControler() instanceof CorpBeastControler
|| getControlerManager().getControler() instanceof PestControler
|| getControlerManager().getControler() instanceof ZGDControler
|| getControlerManager().getControler() instanceof GodWars
|| getControlerManager().getControler() instanceof DTControler
|| getControlerManager().getControler() instanceof Duelarena
|| getControlerManager().getControler() instanceof CastleWarsPlaying
|| getControlerManager().getControler() instanceof CastleWarsWaiting
|| getControlerManager().getControler() instanceof TowersPkControler) {
return;
}
int r3 = 0;
r3 = Utils.random(2);
if (r3 == 0) {
saveLoc(getX(), getY(), getPlane());
RandomEventTeleportPlayer(p, 2602, 4775, 0);
} else if (r3 == 1) {
saveLoc(getX(), getY(), getPlane());
QuizEventTeleportPlayer(p, 1952, 4764, 0);
getDialogueManager().startDialogue("QuizMaster", 2477);
}
}
}, 1800000);
}
;
replace randomevent.java
Code:
package com.rs.game.player.controlers;
import com.rs.game.Animation;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.player.content.Magic;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
/**
* Handles Random Event Controler
*
* @author Demon Dylan
*
*/
public class RandomEvent extends Controler {
@Override
public void start() {
//todo
}
@Override
public boolean sendDeath() {
player.addStopDelay(7);
player.stopAll();
WorldTasksManager.schedule(new WorldTask() {
int loop;
@Override
public void run() {
if (loop == 0) {
player.setNextAnimation(new Animation(836));
} else if (loop == 1) {
player.getPackets().sendGameMessage(
"Oh dear, you have died.");
} else if (loop == 3) {
player.reset();
player.setNextWorldTile(new WorldTile(2602, 4775, 0));
player.setNextAnimation(new Animation(-1));
stop();
}
loop++;
}
}, 0, 1);
return false;
}
@Override
public boolean login() {
player.getPackets().sendGameMessage("Your logged into a random event.");
return false;
}
@Override
public boolean logout() {
return false;
}
@Override
public boolean processMagicTeleport(WorldTile toTile) {
player.getPackets().sendGameMessage("You can't teleport in this area!");
return false;
}
@Override
public boolean processItemTeleport(WorldTile toTile) {
player.getPackets().sendGameMessage("You can't teleport in this area!");
return false;
}
@Override
public boolean processObjectClick1(WorldObject object) {
if (object.getId() == 15645)
return true;
return false;
}
}
replace QuizEvent.java or add it
Code:
package com.rs.game.player.controlers;
import com.rs.game.Animation;
import com.rs.game.WorldObject;
import com.rs.game.WorldTile;
import com.rs.game.player.content.Magic;
import com.rs.game.tasks.WorldTask;
import com.rs.game.tasks.WorldTasksManager;
/**
* Handles Random Event Controler
*
* @author Demon Dylan
*
*/
public class QuizEvent extends Controler {
@Override
public void start() {
//todo
}
@Override
public boolean sendDeath() {
player.addStopDelay(7);
player.stopAll();
WorldTasksManager.schedule(new WorldTask() {
int loop;
@Override
public void run() {
if (loop == 0) {
player.setNextAnimation(new Animation(836));
} else if (loop == 1) {
player.getPackets().sendGameMessage(
"Oh dear, you have died.");
} else if (loop == 3) {
player.reset();
player.setNextWorldTile(new WorldTile(2602, 4775, 0));
player.setNextAnimation(new Animation(-1));
stop();
}
loop++;
}
}, 0, 1);
return false;
}
@Override
public boolean login() {
player.getDialogueManager().startDialogue("QuizMaster", 2477);
return false;
}
@Override
public boolean logout() {
return false;
}
@Override
public boolean processMagicTeleport(WorldTile toTile) {
player.getPackets().sendGameMessage("You can't teleport in this area!");
return false;
}
@Override
public boolean processItemTeleport(WorldTile toTile) {
player.getPackets().sendGameMessage("You can't teleport in this area!");
return false;
}
@Override
public boolean processObjectClick1(WorldObject object) {
if (object.getId() == 15645)
return true;
return false;
}
}
Replace QuizMaster.java
Code:
package com.rs.game.player.dialogues;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.player.content.Magic;
import com.rs.game.player.Player;
import com.rs.game.WorldTile;
/**
* Handles QuizMaster Game.
*
* @author Demon Dylan
*
*/
public class QuizMaster extends Dialogue {
private int npcId;
private int wrong = 0;
@Override
public void start() {
npcId = (Integer) parameters[0];
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Hello, and Welcome to the game show!" }, IS_NPC, npcId, 9827);
}
@Override
public void run(int interfaceId, int componentId) {
if (stage == -1) {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"The rules are simple answer all 5 questions correct",
"and you win a prize, answer 3 wrong you lose" }, IS_NPC, npcId, 9827);
stage = 1;
} else if (stage == 1) {
sendDialogue(SEND_2_OPTIONS, "What Level do you need to weild Dragon", "Definantly 40!",
"Defiantly 60!");
stage = 2;
} else if (stage == 2) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 3;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 3;
}
} else if (stage == 3) {
sendDialogue(SEND_2_OPTIONS, "Which of the following is flame resistant", "Anti-Dragonfire Shield!",
"Rune Beserker Shield!");
stage = 4;
} else if (stage == 4) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 5;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 5;
}
} else if (stage == 5) {
sendDialogue(SEND_2_OPTIONS, "Which of the following restores more health", "Salmon!",
"Shrimp!");
stage = 6;
} else if (stage == 6) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 7;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 7;
}
} else if (stage == 7) {
if (wrong == 3) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"3 Wrong You have Lost!" }, IS_NPC, npcId, 9827);
stage = 13;
} else {
sendDialogue(SEND_2_OPTIONS, "What attack level is required to weild a godsword", "85!",
"75!");
stage = 8;
}
} else if (stage == 8) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 9;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 9;
}
} else if (stage == 9) {
if (wrong == 3) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"3 Wrong You have Lost!" }, IS_NPC, npcId, 9827);
stage = 13;
} else {
sendDialogue(SEND_2_OPTIONS, "Who is the owner of pwnerzscape", "demon darren!",
"demon dylan!");
stage = 10;
}
} else if (stage == 10) {
if (componentId == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Incorrect!" }, IS_NPC, npcId, 9827);
wrong++;
stage = 11;
} else if (componentId == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Correct!" }, IS_NPC, npcId, 9827);
stage = 11;
}
} else if (stage == 11) {
if (wrong == 3) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"3 Wrong You have Lost!" }, IS_NPC, npcId, 9827);
stage = 13;
} else {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"You win please accept this reward and come back soon!",
"Thanks for playing" }, IS_NPC, npcId, 9827);
stage = 12;
}
} else if (stage == 12) {
winner();
} else if (stage == 13) {
loser();
}
}
public void loser() {
player.getControlerManager().getControler().removeControler();
teleportPlayer(player.tX, player.tY, player.tH);
wrong = 0;
}
public void winner() {
player.getControlerManager().getControler().removeControler();
teleportPlayer(player.tX, player.tY, player.tH);
wrong = 0;
player.getInventory().addItem(6199, 1);
}
private void teleportPlayer(int x, int y, int z) {
Magic.sendNormalTeleportSpell(player, 0, 0.0D, new WorldTile(x, y, z),
new int[0]);
player.stopAll();
}
@Override
public void finish() {
}
}
Replace FreakyForester.java
Code:
package com.rs.game.player.dialogues;
import com.rs.cache.loaders.NPCDefinitions;
import com.rs.game.player.content.Magic;
import com.rs.game.player.Player;
import com.rs.game.WorldTile;
public class FreakyForester extends Dialogue {
private int npcId;
@Override
public void start() {
npcId = (Integer) parameters[0];
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name,
"Welcome to my forester event," }, IS_NPC, npcId, 9827);
}
@Override
public void run(int interfaceId, int componentId) {
if (stage == -1) {
if (player.gotreward == 1) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "You may exit through the portal" },
IS_NPC, npcId, 9827);
stage = 3;
} else {
sendDialogue(SEND_2_OPTIONS, "What would you like to say?", "I found pheasant meat.",
"What am i doing here?");
stage = 1;
}
} else if (stage == 1) {
if (componentId == 1) {
if (player.getInventory().containsItem(6178, 1)) {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "You brought me my meat.", "Please accept this reward.." },
IS_NPC, npcId, 9827);
player.getInventory().deleteItem(6178, 1);
player.getInventory().addItem(6199, 1);
player.gotreward = 1;
stage = 2;
} else {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "You do not have a pheasant meat.", "kill a pheasant to get some." },
IS_NPC, npcId, 9827);
stage = 3;
}
} else if (componentId == 2) {
sendEntityDialogue(SEND_2_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "Hi i need some raw pheasant meat", "Bring it to me and I will release you." },
IS_NPC, npcId, 9827);
stage = 3;
}
} else if (stage == 2) {
sendEntityDialogue(SEND_1_TEXT_CHAT,
new String[] { NPCDefinitions.getNPCDefinitions(npcId).name, "You may exit through the portal" },
IS_NPC, npcId, 9827);
stage = 3;
} else if (stage == 3) {
end();
}
}
private void teleportPlayer(int x, int y, int z) {
player.setNextWorldTile(new WorldTile(x, y, z));
player.stopAll();
}
@Override
public void finish() {
}
}
open objecthandler and replace the object id with this
Code:
} else if (id == 15645) {
player.getControlerManager().getControler().removeControler();
teleportPlayer(player, player.tX, player.tY, player.tH);
// WorldTasksManager.removeTask();
player.gotreward = 0;
add this method to objecthandler if you do not have it
Code:
public static void teleportPlayer(Player player, int x, int y, int z) {
player.setNextWorldTile(new WorldTile(x, y, z));
player.stopAll();
}
post any errors il be glad to fix.
credits all to me
oh yea and graham for event system