Thread: Dialogue System(Easy usage)

Page 1 of 5 123 ... LastLast
Results 1 to 10 of 47
  1. #1 Dialogue System(Easy usage) 
    Registered Member

    Join Date
    Feb 2007
    Posts
    1,005
    Thanks given
    2
    Thanks received
    17
    Rep Power
    93
    Make a new class to model folder called DialogueQueue
    Code:
    package com.rs2hd.model;
    
    import java.util.LinkedList;
    import java.util.Queue;
    import com.rs2hd.definitionhandling.DefinitionHandler;
    
    public class DialogueQueue {
    	/**
    	*	Whos dialogues are we dealing with?
    	*/
    	private Player player;
    	/**
    	*	Array where all dialogues are stored.
    	*/
    	private Queue<Dialogue> dialogueQueue;
    
    	public DialogueQueue(Player player) {
    		this.player = player;
    		this.dialogueQueue = new LinkedList<Dialogue>();
    	}
    	
    	public void add(Dialogue d) {
    		dialogueQueue.add(d);
    		display(dialogueQueue.remove());
    	}
    	
    	public void add(Dialogue[] d) {
    		for(int i = 0; i < d.length; i++) {
    			dialogueQueue.add(d[i]);
    		}
    		display(dialogueQueue.poll());
    	}
    	
    	public Dialogue getNext() {
    		Dialogue next = dialogueQueue.poll();
    		if(next == null) {
    			return null;
    		}
    		display(next);
    		return next;
    	}
    	
    	public void display(Dialogue d) {
    		if(d.getNpcId() > -1) {
    			String npcName = DefinitionHandler.getNPCDef(d.getNpcId()).getName() == null ? "Unknown" : DefinitionHandler.getNPCDef(d.getNpcId()).getName();
    			player.getActionSender().sendNpcHead(d.getNpcId(), 241, 2);
    			player.getActionSender().sendString(npcName, 241, 3);
    		} else {
    			player.getActionSender().sendString(player.getUsername(), 241, 3);
    			player.getActionSender().sendPlayerHead(241, 2);
    		}
    		player.getActionSender().sendChatboxInterface(241);
    		player.getActionSender().animateInterface(9847, 241, 2);
    		player.getActionSender().sendString(d.getText(), 241, 4);
    	}
    }
    And a class called Dialogue

    Code:
    package com.rs2hd.model;
    
    public class Dialogue {
    
    	private Player owner;
    	private String text;
    	private int npcId;
    	
    	public Dialogue(Player p, String str, int npcId) {
    		this.owner = p;
    		this.text = str;
    		this.npcId = npcId;
    	}
    	
    	public String getText() {
    		return text;
    	}
    	
    	public int getNpcId() {
    		return npcId;
    	}
    	
    	public Player getOwner() {
    		return owner;
    	}
    }
    Add this to player class:
    Code:
    	/**
    	*	Dialogues
    	*/
    	private DialogueQueue dialogueQueue;
    	/**
    	 * Handles player dialogues.
    	 */
    	public DialogueQueue getDialogueQueue() {
    		return dialogueQueue;
    	}
    Declare this where you set constructors:
    Code:
    dialogueQueue = new DialogueQueue(this);
    Add this to where you handle buttons for interfaces/chatboxinterfaces
    Code:
    			case 241:
    				if(button == 5) {
    					player.getActionSender().sendCloseChatboxInterface();
    					player.getDialogueQueue().getNext();
    				}
    				break;
    Have fun.

    Usage:
    Code:
    		player.getDialogueQueue().add(new Dialogue[]{
    		new Dialogue(player, "Hello!",  -1),
    		new Dialogue(player, "Hi!", affectedNpc.getId()),
    		new Dialogue(player, "How's it going?", -1),
    		new Dialogue(player, "I'm fine thank you.",	affectedNpc.getId())});
    or single dialogue:
    Code:
    
    		player.getDialogueQueue().add(new Dialogue(player, "Hello!",  -1));
    -Removed

    Advertising is not allowed.
    Reply With Quote  
     

  2. #2  
    But python...

    Join Date
    Jun 2009
    Posts
    0
    Thanks given
    262
    Thanks received
    379
    Rep Power
    0
    Good job mate going to test it out now.
    Would it work if i change the imports to codeusa?
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Sep 2010
    Age
    26
    Posts
    860
    Thanks given
    303
    Thanks received
    203
    Rep Power
    0
    Why are you creating a new queue? Just use a Queue class in the java framework

    Why is the "dialogueQueue" instance a transient variable? There's nothing to be serialized.

    LOL, A new Dialogue instance for every line, Damn talking about memory waste rofl
    Reply With Quote  
     

  4. Thankful user:


  5. #4  
    Registered Member

    Join Date
    Feb 2007
    Posts
    1,005
    Thanks given
    2
    Thanks received
    17
    Rep Power
    93
    Quote Originally Posted by Encour' View Post
    Why are you creating a new queue? Just use a Queue class in the java framework

    Why is the "dialogueQueue" instance a transient variable? There's nothing to be serialized.

    LOL, A new Dialogue instance for every line, Damn talking about memory waste rofl
    It's transient because RS2HD saves every variable that's not transient, dialogues do NOT need saving.

    Of course I create a new dialogue for each dialogue, without making new it would make no sense, memory waste? ..just no.

    Why be such a troll? It seems that your ego makes you think you're far better than anybody else.

    You should be happy that somebody actually does 503+ anymore and actually releases something usefull. Go rage on some other thread.
    -Removed

    Advertising is not allowed.
    Reply With Quote  
     

  6. Thankful user:


  7. #5  
    Registered Member

    Join Date
    Feb 2007
    Posts
    1,005
    Thanks given
    2
    Thanks received
    17
    Rep Power
    93
    Quote Originally Posted by Third Demension View Post
    Good job mate going to test it out now.
    Would it work if i change the imports to codeusa?
    Yes it will work.
    -Removed

    Advertising is not allowed.
    Reply With Quote  
     

  8. #6  
    Extreme Donator


    Join Date
    Jul 2009
    Age
    24
    Posts
    4,350
    Thanks given
    824
    Thanks received
    1,237
    Rep Power
    1789
    Quote Originally Posted by Encour' View Post
    Why are you creating a new queue? Just use a Queue class in the java framework

    Why is the "dialogueQueue" instance a transient variable? There's nothing to be serialized.

    LOL, A new Dialogue instance for every line, Damn talking about memory waste rofl
    dont get so full of urself, anyways nice job

    You can find my [Only registered and activated users can see links. ], for what I'm currently working on.
    Reply With Quote  
     

  9. #7  
    Banned

    Join Date
    Sep 2010
    Age
    26
    Posts
    860
    Thanks given
    303
    Thanks received
    203
    Rep Power
    0
    Quote Originally Posted by nemesis View Post
    Of course I create a new dialogue for each dialogue, without making new it would make no sense, memory waste? ..just no.
    Probably never heard of the static keyword.

    Quote Originally Posted by Sir Tom View Post
    dont get so full of urself, anyways nice job
    You shouldn't talk because you don't know shit. You demand respect, Yet you don't want to learn either how a framework should be written mr netty's a waste of threads.
    Reply With Quote  
     

  10. #8  
    Registered Member

    Join Date
    Feb 2007
    Posts
    1,005
    Thanks given
    2
    Thanks received
    17
    Rep Power
    93
    Quote Originally Posted by Encour' View Post
    Probably never heard of the static keyword.



    You shouldn't talk because you don't know shit. You demand respect, Yet you don't want to learn either how a framework should be written mr netty's a waste of threads.
    I don't see it as memory waste, as they are removed when displayed, but what ever.
    -Removed

    Advertising is not allowed.
    Reply With Quote  
     

  11. #9  
    Registered Member Sir BeatDown's Avatar
    Join Date
    Nov 2009
    Age
    27
    Posts
    403
    Thanks given
    25
    Thanks received
    5
    Rep Power
    67
    Pretty nice. Wont use because I have my own dialog system and I'm using pali base.

    9/10


    Quote Originally Posted by GloryScape View Post
    Then code it yourself fucker
    Reply With Quote  
     

  12. #10  
    Registered Member

    Join Date
    Feb 2007
    Posts
    1,005
    Thanks given
    2
    Thanks received
    17
    Rep Power
    93
    Quote Originally Posted by pivotgamer84 View Post
    Pretty nice. Wont use because I have my own dialog system and I'm using pali base.

    9/10
    This can be easily converted ,plus I highly recommend to switch from the if statement shit to this, since when you start making quests, this will come in handy.
    -Removed

    Advertising is not allowed.
    Reply With Quote  
     

Page 1 of 5 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. NPC Dialogue the Easy Way
    By Full Metalst in forum Tutorials
    Replies: 12
    Last Post: 11-10-2010, 01:56 PM
  2. Dialogue System
    By Profesor Oak in forum Snippets
    Replies: 2
    Last Post: 03-11-2010, 02:49 AM
  3. Adding a Easy-To-Use Dialogue (NPC/Player) System
    By LesterKnome in forum Tutorials
    Replies: 7
    Last Post: 08-05-2009, 09:12 PM
  4. Best Dialogue System{3x better than yours}
    By wizzyt21 in forum Tutorials
    Replies: 14
    Last Post: 11-28-2008, 12:41 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •