1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Hey Guest, is it this your first time on the forums?

    Visit the Beginner's Box

    Introduce yourself, read some of the ins and outs of the community, access to useful links and information.

    Dismiss Notice

KScript - Server Scripting for KAG Classic

Discussion in 'Community Dev Corner' started by master4523, Mar 26, 2013.

Mods: Downburst, Mazey
  1. miniu

    miniu Haxor

    Messages:
    765
    Ok thx
     
  2. Zer0Striker

    Zer0Striker Shipwright

    Messages:
    139
    You can use virtual box though(Virtual box is a program that installs operating systems to your system and lets you use them. Google debian with virtual box for more details.).
     
    miniu likes this.
  3. kaizokuroof

    kaizokuroof Agkubuk|'Kaizokuroof' Cilobakil, Roofpointy Global Moderator Forum Moderator Donator Tester
    1. PumpkinStars - [Pk#] - Inactive

    Messages:
    909
    If I am wanting multiple admins or players, to have this ability, how would one go about editing that in? (I am running this from the linux box that I host the server on)

    I assume it's something to do with the first function declared. Sorry I'm a script nub ;-;

    Code:
    function isAdmin(player)
        {
        return (player.getName().toLowerCase() == 'kaizokuroof' 'mazey' 'someotheradmin' || player.getName().toLowerCase() == 'anadmin');
        }
     
  4. SnIcKeRs

    SnIcKeRs Bison Rider

    Messages:
    148
    How can I run script "kscript_app.js" in "data" folder? Its needed for debugging in Cloud9 IDE my mods code.
    I cant use "cd" or "node data/*app*".

    --------------
    Guys, you can edit your mods and test them together in good online IDE. I created worksplace for it.
    For testing run in terminl ./kscript.sh ,after you can test mods in public server : "Public mods dev server", sv password: publicDev

    But debugging doesn't work for mods now :QQ:

    --------------
    Node.js docs
     
    master4523 likes this.
  5. SnIcKeRs, good stuff.
    When me and master4523 started working on this project, we really hoped that KScript would be used by people like you.
    I never tought that KScript could run on Cloud9, because of the many restrictions. But it seems only creating "listening" sockets have their port numbers restricted, very good stuff indeed.
     
  6. Mazey

    Mazey Haxor Global Moderator Forum Moderator Staff Alumni Donator Official Server Admin

    Messages:
    1,914
    return (player.getName().toLowerCase() == 'kaizukoroof' || player.getName().toLowerCase() == 'mazey' )

    || means or, you can also do it another way, I don't really like this one:
    Code:
    function isAdmin(anAdmin)
    {
    //all my code
    }
    isAdmin(player.getName().toLowerCase() == 'kaizukoroof')
    isAdmin(player.getName().toLowerCase() == 'mazey')
    isAdmin(player.getName().toLowerCase() == 'someone')
    
    
     
    kaizokuroof likes this.
  7. Mazey, try to look into NodeJS Filesystem documentation (Google these exact three words).
    That way you could have admins.txt file or something like that.
    Would be much easier for server admins to add admins.
     
  8. Mazey

    Mazey Haxor Global Moderator Forum Moderator Staff Alumni Donator Official Server Admin

    Messages:
    1,914
    Ye Ardi, I googled it before for uploading server data to my site (as far you can call it a site, http://82.211.8.222/ )
     
  9. FranticIch

    FranticIch Let me be your tank... Donator

    Messages:
    234
    Is there actually a way to check how many players are currently connected, or am I just too stupid to see it?
     
  10. Mazey

    Mazey Haxor Global Moderator Forum Moderator Staff Alumni Donator Official Server Admin

    Messages:
    1,914
    Yes there is, and I have no idea if you are stupid.
     
  11. FranticIch

    FranticIch Let me be your tank... Donator

    Messages:
    234
    Well, could you show me the way? ( I´ll figure out later if I´m stupid or not)
     
  12. Mazey

    Mazey Haxor Global Moderator Forum Moderator Staff Alumni Donator Official Server Admin

    Messages:
    1,914
    PHP:
    var fs = require('fs');
    var 
    PlayingList = ["Players right now:"];
    ks.events.on('newPlayer', function(player)
        {
        
    PlayingList.pushplayer.getName() )
        
    fs.writeFile('CurrentPlayers.txt'PlayingList.join(' '), function (err)
            {
            if (
    err) throw err;
            
    console.log("Added player to the text file")
        });
    ks.events.on('playerLeft', function(player)
        {
        
    PlayingList.splice(PlayingList.indexOfplayer.getName() ),1);
            {
            if (
    err) throw err
            console
    .log('Removed ' player.getName())
            });
        });
    This should create a file named CurrentPlayers.txt with the players in it, and it should remove people when they leave.

    ~Download at kscript.kagdb.com
    ~Set up kscript_config.cfg
    ~Create 'Mods/playernames' and make file 'main.js' with the text above and 'package.cfg' like the on in the map 'Mods/Hellomod'
    ~Run kscript
     
  13. FranticIch

    FranticIch Let me be your tank... Donator

    Messages:
    234
    Ok, but I don´t need a list of all players, i just want the ammount.
    So would it be:
    Code:
    var curPlayers = 0;
     
    ks.events.on('newPlayer', function(player){
    curPlayers ++;
    });
     
    ks.events.on('playerLeft', function(player){
    curPlayers --;
    });
    Or?
    Because if I try to show this ingame, I get "NaN".
    What did I do wrong?
     
  14. master4523

    master4523 Masterful KAG Guard Global Moderator Tester
    1. PumpkinStars - [Pk#] - Inactive

    Messages:
    378
    ks.server.players is an array of Player objects, which contains every connected players.
    It isn't in the documentation yet (my bad) so don't bother looking for it.
    You could use the .length property to find out how many players there are.
    Code:
    ks.server.players.length
     
  15. FranticIch

    FranticIch Let me be your tank... Donator

    Messages:
    234
    Thanks!
     
  16. SnIcKeRs

    SnIcKeRs Bison Rider

    Messages:
    148
    How to use "requirements" or functions from other mod?
     
  17. Mazey

    Mazey Haxor Global Moderator Forum Moderator Staff Alumni Donator Official Server Admin

    Messages:
    1,914
    Can you tell what you want to do?
     
  18. SnIcKeRs

    SnIcKeRs Bison Rider

    Messages:
    148
    I want to make chat commands and functions would be separated.
     
  19. PainGiver

    PainGiver Arsonist

    Messages:
    78
    Got this error, but not sure whats causing it to show up. I am using Debian, and I use ./kscript while the server is running.

    - Added sv_tcpr = 1 to my config
    - Added the rcon password to the kscript config

    Error:
    Code:
    KScript version 9
    KS
    { [Error: connect ECONNREFUSED]
      code: 'ECONNREFUSED',
      errno: 'ECONNREFUSED',
      syscall: 'connect' }
    Socked closed
    Reconnecting in 5 seconds...
    
    edit:

    The server is ran on a paid hoster, which it's possible something is being blocked on the server side to disallow this type of connecting but not to sure what it would be.
     
  20. Mazey

    Mazey Haxor Global Moderator Forum Moderator Staff Alumni Donator Official Server Admin

    Messages:
    1,914
    Are you sure the ip, port and rcon is correct in kscript_config.cfg?
     
Mods: Downburst, Mazey