1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Guest, PO has ceased our separate tiering and adopted Smogon tiers for SM. More information and updates here.

    Dismiss Notice

Script suggestions

Discussion in 'Simulator Suggestions' started by Astruvis, May 27, 2010.

Thread Status:
Not open for further replies.
  1. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Current requests:

    sys.inBattle(id);
    Checks if the user is in a battle.
    sys.changeTier(id,new);
    Changes the users tier to the new one specified.
    sys.changeAway(id,new);
    Changes away status.
    sys.endBattle(id);
    Terminates a battle.
    sys.sendHTML(tar,html);
    Same as send message but without the auto html and html escape.
    sys.sendAllHTML(html);
    Same as send all but without the auto html and html escape.
    sys.getColor(id)
    Finds out someone's usercolor.

    Events

    [before/after]ChangeTier(id,old,new);
    When the user selects a tier from the dropdown list.
    [before/after]WatchBattle(id,old,new);
    Before someone tries to watch a battle.
     
    Last edited: Jul 2, 2010
  2. Jules

    Jules i make you MANGRY

    Joined:
    Apr 23, 2010
    Messages:
    243
    Likes Received:
    1
    what is the point if you can't see the contents?

    you can already block a user from pming another by ignoring that person

    why need boolean parameter?

    a return method would be much more valuable.

    i like everything else.
     
  3. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    For something like this:
    Code (text):
    1. beforePM: function(src, tar) {
    2.     if (sys.auth(src) < 1 && sys.getVal('muted' + sys.ip(src)) == 1 && sys.auth(tar) < 1) {
    3.         sys.stopEvent();
    4.         sys.sendMessage(src, "~~Server~~: You are muted.");
    5.         return; }
    6.     }
     
  4. Jules

    Jules i make you MANGRY

    Joined:
    Apr 23, 2010
    Messages:
    243
    Likes Received:
    1
    uh, okay..
     
  5. Steve

    Steve Active Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    491
    Likes Received:
    45
    Wondering how this would be possible. Sure, the server can shut down, but how is a closed program gonna start itself?
     
  6. Akusu

    Akusu Guest

    That's easy. The last thing you do after the shutdown process (just before the process kills itself) is launch a new process with the new instance of the server.
     
  7. Steve

    Steve Active Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    491
    Likes Received:
    45
    Ah alright.
     
  8. Erebos

    Erebos Banned

    Joined:
    May 6, 2010
    Messages:
    743
    Likes Received:
    0
    just wondering if this would go better under "scripts"...
     
  9. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    Well this is suggesting adding functions to the already available ones for use in scripting. Perhaps there could be a subforum for scripting suggestions though as I don't think many really understand the use of them unless they have experience in it.

    Anyway, I agree with all suggestions except I think there should still be a before and after for all of the events. Also, I'd like a before/afterReceiveMessage event so you have the ability to ignore sendall without having to do a sendmessage to all loop and having to ignore that ( and perhaps also to ignore certain sendmessages).
     
    Last edited: May 27, 2010
  10. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    Done some of them (will see in the change log), will probably do the rest later.
     
  11. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Here is something I thought of:

    sys.mac(tar);

    The mac address of the user is returned.
     
  12. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    That - isn't - even - stored - server - side. But Maybe with the new system.
     
  13. Akusu

    Akusu Guest

    I forgot to mention this, but I would like something that will "blind" someone so they can't see the chat. It would be used in my password-protected server script.
     
  14. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Thats already do-able and very easy.
     
  15. Akusu

    Akusu Guest

    In an ugly manner. That's the sort of thing that should be a server function similar to kick or mute.
     
  16. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    So what would happen if you tried to send messages into the main server chat in this mode? Would they be sent to every user or not? Would you even get to view them?
     
  17. Akusu

    Akusu Guest

    I think blind would basically be mute + blind. It's just so you have control over who can see the chat even if they get into the chat.
     
  18. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    I hope we can get some things...

    First:

    sys.inBattle(id);

    sys.changeAway(id);

    sys.endBattle(id,result);
    Ends the battle ID is in, result 0 will cause a tie, result 1 will cause a loss(for id), and result 2 will cause a win.

    sys.saveFileValue(fname,vname,value);

    String, number, or array for value, sting for vname.

    sys.readFileValue(fname,vname)

    Returns the value, undefined if it does not exist(not '').

    sys.deleteFileValue(fname,vname);
    This deletes the value.

    withusers(expression(i) == true) {
    statement(i); }

    Works like this, for each user, it checks if what is inside the ( ) is true, i referring to the user in question, then executes anything inside the { }, where i also refers to the user.

    beforeTierChange(src,oldtier,newtier)
    (and after version)
    Event for tier control.

    sys.changeTier(src,newtier)

    Tier control, again.

    2 last ones are desperately needed.
     
    Last edited: Jun 8, 2010
  19. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Quoted for relevance.
     
  20. Jules

    Jules i make you MANGRY

    Joined:
    Apr 23, 2010
    Messages:
    243
    Likes Received:
    1
    printLine
    print
    printF
    "String HTML Wrapper Methods"

    ;(
     
  21. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    I don't believe it's possible to alter syntax of javascript. You could try:

    withUsers = function(func1, func2) {
    var cnt = sys.numPlayers();
    var user = 0;
    while(user < cnt)
    {
    if (sys.loggedIn(user) == true) {
    if(func1(user)) { func2(user); }
    } else {
    cnt += 1;
    }
    user += 1;
    }
    }

    And then call it like:
    withUsers( function(user) { return expression(user) == true; }, function(user) { doSomething(user); } );

    You could collapse two functions so that if becomes
    withUsers( function(user) { if(expression(user) == true) { doSomething(user); }});
     
    Last edited: Jun 16, 2010
  22. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    Yeah, when I was thinking of making my own scripting language, strangely enough, I was thinking of doing something like that.

    And yeah, the solution of lamperit is the right one in Javascript: give it one function to testthe statement, and one function to apply the statement on the user.
     
  23. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Wasn't I the one who originally posted that code? Although its been changed a bit, and sys.numPlayers is glitched.

    Though, coyotte can edit the syntax of javascript, it just wont be javascript anymore.

    Edit: Updated first post.
     
    Last edited: Jun 18, 2010
  24. Lamperi

    Lamperi I see what you did there

    Joined:
    Apr 25, 2010
    Messages:
    2,647
    Likes Received:
    11
    I copied the user looping part from your code.

    Pokemon-Online's Javascript-engine uses QScriptEngine, and that is why syntax cannot be altered easily.
     
  25. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    I updated the first post with a couple of ideas.
     
  26. Lutra

    Lutra All Gen Battler/Scripter

    Joined:
    Apr 25, 2010
    Messages:
    509
    Likes Received:
    188
    PO Trainer Name:
    Lutra
    You don't need a sendhtml function. The html methods just need to be implemented.
     
  27. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    I think it should be separate.
     
  28. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Updated first post, coyotte do you ever plan to add any of those? <.<
     
  29. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    My answer is and will always stay the same.
     
  30. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    sys.battling() added

    sys.getVal(file, key, value), sys.removeVal(file, key), sys.getVal(file, key) added

    sys.changeTier(id, tier) added

    beforeChangeTier(src, oldTier, newTier) and afterChangeTier(src, oldTier, newTier) added

    sys.shutDown() added (closes the server after triggering the serverShutDown() event)

    sys.numPlayers() fixed to show only online players.

    Will be there next update, but already in the source. Need to be double-checked.
     
  31. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    sys.hasLegalTeamForTier(id, tier)

    sys.memoryDump() : gives the state of memory in a string (would be useful for me in order to gather memory data usage, to be able to opt things)

    Same remarks as before.
     
  32. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    O.o

    Thank you. xD
    (still want the html though, for ex links)

    Will there be a way to query the SQL database though, or at least an option to use the old one?
     
  33. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    I'll provide sys.maxAuth(ip) and sys.aliases(ip). I'll do SQL some other time.
     
  34. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    can you do sys.authOf('name') and sys.ipOf('name')? I think if you add that along with the first 2 it would be usable. Otherwise ill just keep the old server. >.<

    Still want to be able to send html though, although its less important.
     
  35. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    Well as i said even saving vals to file or in the registry with infos on players (like everytime they log on) is far better than querying the members.txt file each time, in terms of performance, in all cases and especially for bigger servers, so there's really no benefit in keeping the old servern even if those functions are not added.

    You can even launch a script on the members.txt file when switching over, to save all the content you want in vals.

    -- Even so, i'll add sys.dbAuth(name), sys.dbIp(name), and sys.dbLastOn(name), as they seem relevant and are easily doable.
     
  36. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Coyotte, here is a simple suggestion, make the new SQL players database loaded into ram, and let us read it freely using a function, that would cut down on lag and give us the functions we need.

    PS: Add sys.sendHtml, sys.sendAllHtml, and sys.ecapeHtml please. xP
     
    Last edited: Jul 7, 2010
  37. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    No.

    The whole point of the SQL database was to not have everything in RAM. Read the topics in Developer's Den. Moreover with all the functions added you can do whatever you want and you could with the older system, with far greater speed and no lag induced. If you really think the current system will introduce more lag, learn general programming common sense, like knowing the difference in speed between Javascript and C++, like reading the topics in Developer's Den about the database management -- and seeing almost everything is threaded and cached to opt perfs --, like not parsing the members.txt file every time you use /info on a user, like not making http webcalls everytime a player logs in, and all that in javascript.

    With html functions i'd have to break compatibility and do it a way that won't force the server to check and escape automatically html on every message, and for SQL functions it's not trivial at all, and I don't have the envy to do that at the moment. (Yes, I'm coding what i am feeling like doing or deem important...)

    Sorry if that sounded harsh but your absurd comment with no knowledge on the subject and previous assumptions made me realize you really need to know that you don't know everything.
     
    Last edited: Jul 7, 2010
  38. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    I never noticed any lag before though. I didn't say I knew much about C++ either, I script, not program. For me my only lag factor has been the netspeed by my isp. I have never been above 1% cpu on my server except when I acci infinity looped a few times.

    Though, not having it in ram is going to slow it down for me, you can't tell me that it can read faster from the hardrive than from ram, that's impossible(unless you have a godlike hard drive). Don't lecture me on a swap file either, I know what that is.
     
    Last edited: Jul 7, 2010
  39. coyotte508

    coyotte508 Well-Known Member Administrator Server Owner Administrator Server Owner

    Joined:
    Apr 21, 2010
    Messages:
    6,363
    Likes Received:
    167
    SQL engines only read from hard drive when the server starts (for SQLite, which is a lib attached to the program) or when the computer starts (all other SQL engines, which are server processes running in background), and then store everything in their RAM except if it exceeds a certain limit (like, i don't know, 2/3 of the RAM?), in which case they load only the most probable to read data, still keeping indexes to access other data fastly and always caching the most used or recently used data. Plus the current db system on the server caches a lot (10 000 last users requested) in order to go further.

    That's why i made my previous post. You don't know how the system works, and are making false assumptions and false claims.

    --Edit: Moreover, all access to the SQL database in common situations (all player events) is asynchronous, which reduces lag to 0. That means, even if the sql database was fully relying on hard drive -- which is not, it's in RAM -- it would still cause no lag at all for the server. You can read about SQL systems in general or topics in the developer's den (there's two).
     
    Last edited: Jul 7, 2010
  40. Astruvis

    Astruvis Banned

    Joined:
    May 14, 2010
    Messages:
    217
    Likes Received:
    0
    Ok, w/e, but could you make it so we can get the database in whatever form it is in as a string?
     
Thread Status:
Not open for further replies.