Welcome, guest! Please login or register.

    * Shoutbox

    RefreshHistory
    • ragnoroker: Brand new unique server just released! - Awesome Community - [link]
      October 14, 2019, 11:11:32 AM
    • ragnoroker: Brand new unique server just released! - Awesome Community - [link]
      October 14, 2019, 11:11:28 AM
    • ragnoroker: Brand new unique server just released! - Awesome Community - [link]
      October 14, 2019, 11:11:23 AM
    • marquise:[link]
      October 11, 2019, 12:24:21 PM
    • marquise: hey guys try autoscape.org [link]
      October 11, 2019, 12:19:08 PM
    • Rash: is this site still ded
      October 08, 2019, 07:54:22 PM
    • The Meek: Just Uploaded New Server ~Phusion~
      October 01, 2019, 03:30:31 AM
    • ragnoroker: Pre-EOC New server just dropped today! Come check it out :) - [link]
      September 27, 2019, 08:43:43 PM
    • ragnoroker: Pre-EOC New server just dropped today! Come check it out :) - [link]
      September 27, 2019, 08:43:40 PM
    • ragnoroker: Pre-EOC New server just dropped today! Come check it out :) - [link]
      September 27, 2019, 08:43:33 PM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 26, 2019, 09:02:13 AM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 26, 2019, 08:52:25 AM
    • ragnoroker: Brand new server! Join today - Good Eco/Nice Players - [link]
      September 25, 2019, 08:59:33 AM
    • ragnoroker: Brand new server! Join today - Good Eco/Nice Players - [link]
      September 25, 2019, 08:59:24 AM
    • ragnoroker: Brand new server! Join today - Good Eco/Nice Players - [link]
      September 25, 2019, 08:59:15 AM
    • PavSwag: bopalini
      September 23, 2019, 10:08:02 PM
    • PavSwag: Join autoscape,0rg fun events daily for infernal mystery boxes only server with Infernal Twisted Bow
      September 23, 2019, 03:05:33 PM
    • Frostydapure: Upcoming dmm/open pvp world server, 2006 style (different and fun trus me) [link] join join!
      September 23, 2019, 08:05:52 AM
    • Frostydapure: Upcoming dmm/open pvp world server, 2006 style (different and fun trus me) [link] join join!
      September 23, 2019, 08:05:45 AM
    • PavSwag: try autoscape,0rg today i will personally help you get RICH and well KNOWN - pav
      September 22, 2019, 02:55:32 PM

    Author Topic: command to reset a variable?  (Read 988 times)

    0 Members and 1 Guest are viewing this topic.

    OfflineJadefx

    • First Time Poster
    • *
    • Posts: 4
    • Thanks: +10/-10
      • View Profile
    command to reset a variable?
    « on: May 15, 2016, 02:35:31 PM »
    ok so didn know what quite to call what im trying to do but here it goes

    so each playerfile has a variable, well i added a custom one, and what i want to happen is when i use ::update, it changes said varable to 1,  for all players online and offline before it restarts the server, how would i go about doing that?

    aswell as how can i make the server automaticly do ::update every 24 hours?
    « Last Edit: May 15, 2016, 02:47:25 PM by Jadefx »
    Runescape Gambling

    OfflineRoar337

    • Member
    • ****
    • Posts: 252
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #1 on: May 15, 2016, 03:17:11 PM »
    Java has a couple different file reader and file writer type api's you can use them to access and edit the character file since its in a predictable location and since the files follow a predictable format.

    1. For all players warn, wait 30, disconnect.
    2. File writer edits files.

    ^ No reason to have down time just for this.
    Code: [Select]
    for(int i=0; i < 2147483647; i++) {
    doFacedesk();
    }

    OfflineJadefx

    • First Time Poster
    • *
    • Posts: 4
    • Thanks: +10/-10
      • View Profile
    Re: command to reset a variable?
    « Reply #2 on: May 15, 2016, 03:25:23 PM »
    ok well then i guess all i need is a way to update 1 varable in all character files, thats what im trying to accomplish. but also check if that player is online.

    OfflineRoar337

    • Member
    • ****
    • Posts: 252
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #3 on: May 15, 2016, 05:25:46 PM »
    When you create a file writer you specify the file but there is a way to get every file in the directory as a array also included in java api you can use a for loop to iterate through the array for editing every file and as for checking if the player is online your server likely has a function for this if not here you go:

    This is just example code.
    Code: Java(TM) 2 Platform Standard Edition 5.0
    1. for(Player p : onlinePlayers){
    2. if(p != null){
    3. //Player is online
    4. }
    5. }
    6.  
    Code: [Select]
    for(int i=0; i < 2147483647; i++) {
    doFacedesk();
    }

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #4 on: May 16, 2016, 12:32:32 PM »
    To set the variable, it'd be best that you first looped all online players, and saved each name into a list.

    Then, you would use get the list of files in the character directory:
    Code: Java
    1. File charFolder =newFile("char_path");
    2. File[] characterFiles = charFolder.listFiles();

    And you guessed it, you'd loop through all those, checking that they're not null and they are not in the list of names earlier. If both those conditions are met, you will scan the file (See: Character loading in your server) for the update token, change the value to 1, then write it.
    Stackoverflow | java replace specific string in textfile

    You can also use Apache commons to replace the text:
    Stackoverflow | Find and replace words/lines in a file

    OfflinexXSh0ckXx

    • Member
    • ****
    • Posts: 642
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #5 on: May 26, 2016, 10:47:32 AM »
    To set the variable, it'd be best that you first looped all online players, and saved each name into a list.

    Then, you would use get the list of files in the character directory:
    Code: Java
    1. File charFolder =newFile("char_path");
    2. File[] characterFiles = charFolder.listFiles();

    And you guessed it, you'd loop through all those, checking that they're not null and they are not in the list of names earlier. If both those conditions are met, you will scan the file (See: Character loading in your server) for the update token, change the value to 1, then write it.
    Stackoverflow | java replace specific string in textfile

    You can also use Apache commons to replace the text:
    Stackoverflow | Find and replace words/lines in a file


    Wouldn't these files get overwritten dependent if the player is logging out? Because upon logging out, the current state of the player (which is the one before you modified the files) gets saved, overwriting the data you modified while the player being logged in.
    Drop me a pm.

    They got money for wars, but can't feed the poors. - Tupac Shakur
    Old, but Gold.

    OfflineX-J-K-X

    • Member
    • ****
    • Posts: 1,951
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #6 on: May 26, 2016, 02:44:24 PM »
    Just do it all whilst they're offline and you won't have to worry about whether they're online or not.

    Do it in between an update with a separate application

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #7 on: May 26, 2016, 10:48:59 PM »
    To set the variable, it'd be best that you first looped all online players, and saved each name into a list.

    Then, you would use get the list of files in the character directory:
    Code: Java
    1. File charFolder =newFile("char_path");
    2. File[] characterFiles = charFolder.listFiles();

    And you guessed it, you'd loop through all those, checking that they're not null and they are not in the list of names earlier. If both those conditions are met, you will scan the file (See: Character loading in your server) for the update token, change the value to 1, then write it.
    Stackoverflow | java replace specific string in textfile

    You can also use Apache commons to replace the text:
    Stackoverflow | Find and replace words/lines in a file


    Wouldn't these files get overwritten dependent if the player is logging out? Because upon logging out, the current state of the player (which is the one before you modified the files) gets saved, overwriting the data you modified while the player being logged in.
    Yes, hence why you'd first modify the online accounts, taking note of their names, then modify the offline accounts, and if the filename is one of the online accounts, you'd skip it

    OfflinexXSh0ckXx

    • Member
    • ****
    • Posts: 642
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #8 on: May 27, 2016, 02:41:30 AM »
    To set the variable, it'd be best that you first looped all online players, and saved each name into a list.

    Then, you would use get the list of files in the character directory:
    Code: Java
    1. File charFolder =newFile("char_path");
    2. File[] characterFiles = charFolder.listFiles();

    And you guessed it, you'd loop through all those, checking that they're not null and they are not in the list of names earlier. If both those conditions are met, you will scan the file (See: Character loading in your server) for the update token, change the value to 1, then write it.
    Stackoverflow | java replace specific string in textfile

    You can also use Apache commons to replace the text:
    Stackoverflow | Find and replace words/lines in a file


    Wouldn't these files get overwritten dependent if the player is logging out? Because upon logging out, the current state of the player (which is the one before you modified the files) gets saved, overwriting the data you modified while the player being logged in.
    Yes, hence why you'd first modify the online accounts, taking note of their names, then modify the offline accounts, and if the filename is one of the online accounts, you'd skip it
    and if the filename is one of the online accounts, you'd skip it<
    Oh, I mis-interpretated that. So you list the names of players being online, modify them from that point on, then loop through the account files, check if any of the account names equal a name in the list, skip it, else modify it too.

    I'd use a Set for this procedure, due to it not allowing duplicate elements.
    Drop me a pm.

    They got money for wars, but can't feed the poors. - Tupac Shakur
    Old, but Gold.

    Offlinesk8rdude461

    • MOPARSCAPE WAS HACKED
    • Member
    • ****
    • *
    • Posts: 12,471
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #9 on: May 27, 2016, 01:12:51 PM »
    To set the variable, it'd be best that you first looped all online players, and saved each name into a list.

    Then, you would use get the list of files in the character directory:
    Code: Java
    1. File charFolder =newFile("char_path");
    2. File[] characterFiles = charFolder.listFiles();

    And you guessed it, you'd loop through all those, checking that they're not null and they are not in the list of names earlier. If both those conditions are met, you will scan the file (See: Character loading in your server) for the update token, change the value to 1, then write it.
    Stackoverflow | java replace specific string in textfile

    You can also use Apache commons to replace the text:
    Stackoverflow | Find and replace words/lines in a file


    Wouldn't these files get overwritten dependent if the player is logging out? Because upon logging out, the current state of the player (which is the one before you modified the files) gets saved, overwriting the data you modified while the player being logged in.
    Yes, hence why you'd first modify the online accounts, taking note of their names, then modify the offline accounts, and if the filename is one of the online accounts, you'd skip it
    and if the filename is one of the online accounts, you'd skip it<
    Oh, I mis-interpretated that. So you list the names of players being online, modify them from that point on, then loop through the account files, check if any of the account names equal a name in the list, skip it, else modify it too.

    I'd use a Set for this procedure, due to it not allowing duplicate elements.
    No need for that. ArrayList would work just fine. How would you even get a duplicate? It's not like 2 players are going to have the same username.
    Plus, you're just checking the list if it contains it.
    Code: Java
    1. ArrayList<String> playersModified =new ArrayList<String>();
    2. for(Player p : PlayerHandler.players){
    3.      if(p !=null){
    4.           p.setValue(1);
    5.           playersModified.add(p.playerName);
    6.      }
    7. }
    8. File[] dir =newFile("./characters/").listFiles();
    9. for(File f : dir){
    10.      if(f !=null&&!playersModified.contains(f.getName().substring(0, f.getName().indexOf('.'))){
    11.           // parse the file and set the value and save here.
    12.      }
    13. }

    OfflinexXSh0ckXx

    • Member
    • ****
    • Posts: 642
    • Thanks: +0/-0
      • View Profile
    Re: command to reset a variable?
    « Reply #10 on: May 31, 2016, 02:16:53 AM »
    To set the variable, it'd be best that you first looped all online players, and saved each name into a list.

    Then, you would use get the list of files in the character directory:
    Code: Java
    1. File charFolder =newFile("char_path");
    2. File[] characterFiles = charFolder.listFiles();
    And you guessed it, you'd loop through all those, checking that they're not null and they are not in the list of names earlier. If both those conditions are met, you will scan the file (See: Character loading in your server) for the update token, change the value to 1, then write it.
    Stackoverflow | java replace specific string in textfile

    You can also use Apache commons to replace the text:
    Stackoverflow | Find and replace words/lines in a file


    Wouldn't these files get overwritten dependent if the player is logging out? Because upon logging out, the current state of the player (which is the one before you modified the files) gets saved, overwriting the data you modified while the player being logged in.
    Yes, hence why you'd first modify the online accounts, taking note of their names, then modify the offline accounts, and if the filename is one of the online accounts, you'd skip it
    and if the filename is one of the online accounts, you'd skip it<
    Oh, I mis-interpretated that. So you list the names of players being online, modify them from that point on, then loop through the account files, check if any of the account names equal a name in the list, skip it, else modify it too.

    I'd use a Set for this procedure, due to it not allowing duplicate elements.
    No need for that. ArrayList would work just fine. How would you even get a duplicate? It's not like 2 players are going to have the same username.
    Plus, you're just checking the list if it contains it.
    Code: Java
    1. ArrayList<String> playersModified =new ArrayList<String>();
    2. for(Player p : PlayerHandler.players){
    3.      if(p !=null){
    4.           p.setValue(1);
    5.           playersModified.add(p.playerName);
    6.      }
    7. }
    8. File[] dir =newFile("./characters/").listFiles();
    9. for(File f : dir){
    10.      if(f !=null&&!playersModified.contains(f.getName().substring(0, f.getName().indexOf('.'))){
    11.           // parse the file and set the value and save here.
    12.      }
    13. }
    .... I'm not discussing this out anymore, this gets too stupid anyways.
    Drop me a pm.

    They got money for wars, but can't feed the poors. - Tupac Shakur
    Old, but Gold.

     

    Copyright © 2017 MoparScape. All rights reserved.
    Powered by SMFPacks SEO Pro Mod |
    SimplePortal 2.3.5 © 2008-2012, SimplePortal