Thread: AddNPC Command+Saving. Simple But useful.

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 AddNPC Command+Saving. Simple But useful. 
    Registered Member
    BamBam's Avatar
    Join Date
    Jan 2007
    Posts
    270
    Thanks given
    24
    Thanks received
    8
    Rep Power
    153
    Well, I got tired of simply adding npcs into the npcspawn.cfg manually and since I use one of these
    for my MySql based server. I figured I'd make one for the standard .cfg file which most of these 508
    server's use. Hope it helps someone. Mission is to save developers time.


    First add this:

    Code:
    	/**
    	* Handles spawning a new npc in-game and
    	* also add's it to your npcspawn.cfg
    	* @author     BamBam <[email protected]>
    	* @version     %1%
    	* @param NpcID the NpcId of the npc that is added.
    	*/
    	public void addNpc(int NpcID) {
    	
    			BufferedWriter bw = null;
    			
    			try {
    			
    				bw = new BufferedWriter(new FileWriter("./data/npcs/npcspawn.cfg", true));
    				
    				bw.write("spawn = " +NpcID+ "\t" +absX+ "\t" +absY +"\t0\t0\t0\t0\t0\tNpc "+NpcID+" was added in-game by BamBam. Runekeep.com");
    				
    				frames.sendMessage(this, "NPC was added to npcspawn.cfg.");
    				
    				bw.newLine();
    				
    				bw.flush();
    				
    			} 
    					
    			catch (Exception e) 
    					
    			{
    				e.printStackTrace();
    						
    			}
    		
    		}
    Then go add this

    Code:
    	/**
    	* Command for spawning a new npc in-game and
    	* adding it to your npcspawn.cfg
    	* @author     BamBam <[email protected]>
    	* @version     %1%
    	*/
    		if (cmd[0].equals("addnpc")) {
    		
    			try {
    			
    				int NpcID = Integer.parseInt(cmd[1]);
    			
    					Server.engine.newNPC(Integer.parseInt(cmd[1]), p.absX, p.absY, p.heightLevel, p.absX, p.absY, p.absX, p.absY, false, 0);
    					
    					p.addNpc(NpcID);
    					
    				} 
    			
    				catch (Exception e) 
    				
    				{ 
    				
    					p.frames.sendMessage(p, "Usage: addnpc NpcID"); 
    			
    				}	
    			
    			}

    To use, you must type ::addnpc npcid in-game.
    (e.g ::addnpc 14 would add a druid in-game and save it into the npcspawn.cfg.)

    If its useful to you, a simple Thank You is all I'm looking for. =)

    Enjoy.

    BamBam - RK

    Runekeep®
    Reply With Quote  
     

  2. #2  
    Registered Member
    wreckless's Avatar
    Join Date
    Dec 2008
    Posts
    727
    Thanks given
    82
    Thanks received
    78
    Rep Power
    294
    What file is the 1st part of the code added in?
    Reply With Quote  
     

  3. #3  
    Registered Member
    BamBam's Avatar
    Join Date
    Jan 2007
    Posts
    270
    Thanks given
    24
    Thanks received
    8
    Rep Power
    153
    Quote Originally Posted by r i s k View Post
    What file is the 1st part of the code added in?
    Well, you can put it in any file you like with little changes. Also remember, this is a snippet and not a tutorial. =)

    Runekeep®
    Reply With Quote  
     

  4. #4  
    Registered Member
    X Mercy X's Avatar
    Join Date
    May 2009
    Age
    28
    Posts
    1,336
    Thanks given
    3
    Thanks received
    41
    Rep Power
    301
    kind of a longer version of serenity/laxika's 1 for SDS but meh gj

    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  5. #5  
    Registered Member
    BamBam's Avatar
    Join Date
    Jan 2007
    Posts
    270
    Thanks given
    24
    Thanks received
    8
    Rep Power
    153
    Oh, I didn't know one of these were released. but, Thank you. Nice sig by the way, pretty funny. =)

    Runekeep®
    Reply With Quote  
     

  6. #6  
    Renown Programmer

    Nikki's Avatar
    Join Date
    Aug 2008
    Posts
    3,993
    Thanks given
    553
    Thanks received
    1,077
    Rep Power
    5000
    Nice but i suggest checking conventions.
    No need for new lines and spaces in lines
    Code:
    	/**
    	* Handles spawning a new npc in-game and
    	* also add's it to your npcspawn.cfg
    	* @author     BamBam <[email protected]>
    	* @version     %1%
    	* @param NpcID the NpcId of the npc that is added.
    	*/
    	public void addNpc(int NpcID) {
    			BufferedWriter bw = null;
    			try {
    				bw = new BufferedWriter(new FileWriter("./data/npcs/npcspawn.cfg", true));
    				bw.write("spawn = " +NpcID+ "\t" +absX+ "\t" +absY +"\t0\t0\t0\t0\t0\tNpc "+NpcID+" was added in-game by BamBam. ");
    				frames.sendMessage(this, "NPC was added to npcspawn.cfg.");
    				bw.newLine();
    				bw.flush();
    			} catch (Exception e) {
    				e.printStackTrace();
    			}
    		}
    Also. remove your site from the code.

    I use a MySQL version something like this, adding the npc i want, also adding the player coord offset for the size of the npc if you want it, then editable later in the mysql.
    Way cleaner than CFG file loading
    Please don't add/pm me asking for RSPS help!

    Links:
    - [Only registered and activated users can see links. ]
    - [Only registered and activated users can see links. ]

    Reply With Quote  
     

  7. #7  
    Registered Member
    BamBam's Avatar
    Join Date
    Jan 2007
    Posts
    270
    Thanks given
    24
    Thanks received
    8
    Rep Power
    153
    Well, I do know conventions. However, everyone has there own way of doing things, I find it easier to read using my style. but, thank you for your opinion. It's much appreciated.

    Also. I am the author. The web address is the source distributor. Removing it, is like stealing the code itself. I would like it to stay in there as to people know the original group that created it. You wouldn't go to sourceforge.net and copy their code and remove everything that is related to their author or work group, would you? This is what open source is all about. Groups, Communities, Dedication. Work as a team. Win as a individual. =)

    Runekeep®
    Reply With Quote  
     

  8. #8  
    Renown Programmer

    Nikki's Avatar
    Join Date
    Aug 2008
    Posts
    3,993
    Thanks given
    553
    Thanks received
    1,077
    Rep Power
    5000
    Quote Originally Posted by BamBam View Post
    Well, I do know conventions. However, everyone has there own way of doing things, I find it easier to read using my style. but, thank you for your opinion. It's much appreciated.
    I'm not saying you don't know conventions, but that looks too spaced out for me.
    I'm used to huge screens with lots of code and i can easily read it regularly
    Please don't add/pm me asking for RSPS help!

    Links:
    - [Only registered and activated users can see links. ]
    - [Only registered and activated users can see links. ]

    Reply With Quote  
     

  9. Thankful user:


  10. #9  
    The internet's reject
    Andy's Avatar
    Join Date
    Jun 2007
    Age
    31
    Posts
    4,376
    Thanks given
    148
    Thanks received
    1,522
    Rep Power
    3133
    This is nicely done, very simply. Better ways to do it imo; simply setting up a mapper would do the trick nice job overall though.
    Reply With Quote  
     

  11. #10  
    Registered Member «I 1 H1t K0˛»'s Avatar
    Join Date
    Nov 2008
    Posts
    408
    Thanks given
    11
    Thanks received
    6
    Rep Power
    55
    Nice, Thank you.
    If you think you're good at quickscoping in Black ops, add GT: TrYxH4Rd QSer on Xbox360.
    Reply With Quote  
     

Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

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


User Tag List

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •