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

Windows KAG Syncing server and client

Discussion in 'Server Help' started by mehwaffle10, May 8, 2016.

Tags:
  1. mehwaffle10

    mehwaffle10 Haxor Mapping Moderator Official Server Admin

    Messages:
    19
    Hey guys I'm working on a custom scoreboard for Nova CTF, I'm trying to add kills current life and previous life among other things, and I can't figure out how to sync the server to the client. Using CPlayer.Sync(String, boolean) and CPlayer.SyncToPlayer(String, CPlayer) hasnt got me anywhere, usually it makes the game super buggy when players die. I've put the code to add each variable in DefaultScoreboard.as, which is as follows. The only lines I added were the 2 victim.set_u8(blah blah blah) and killer.set_u8(blajh blah blah), which work and give the correct values when I use console cmds to retrieve them. Any ideas on how to properly sync the client or skip it altogether?
    Code:
    // set kills and deaths
    
    void onBlobDie(CRules@ this, CBlob@ blob)
    {
        if (blob !is null)
        {
            CPlayer@ killer = blob.getPlayerOfRecentDamage();
            CPlayer@ victim = blob.getPlayer();
    
            if (victim !is null)
            {
                victim.setDeaths(victim.getDeaths() + 1);
                // temporary until we have a proper score system
                victim.setScore(100 * (f32(victim.getKills()) / f32(victim.getDeaths() + 1)));
                victim.set_u8("Kills previous life", victim.get_u8("Kills current life"));
                victim.set_u8("Kills current life", 0);
    
                if (killer !is null) //requires victim so that killing trees matters
                {
                    if (killer.getTeamNum() != blob.getTeamNum())
                    {
                        killer.setKills(killer.getKills() + 1);
                        killer.set_u8("Kills current life", killer.get_u8("Kills current life") + 1);
                        // temporary until we have a proper score system
                        killer.setScore(100 * (f32(killer.getKills()) / f32(killer.getDeaths() + 1)));
                    }
                }
            }
        }
    }
    Thanks
    -Waffle
     
  2. Fuzzle

    Fuzzle Grand Grumbler

    Messages:
    297
    tldr Sync()
     
    8x likes this.
  3. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Player props are "kinda fucked" - whenever I've needed something like this I've ended up using the rules properties (and then lookup based on username, like getRules().get_u8("_kills_thislife"+player.getUsername()); or similar. You're going to want to not change stuff on client, use Sync("property_name_here", true); whenever you change the value - the "true" means server to client, don't do the opposite unless you know what you're doing :)
     
    makmoud98 likes this.
  4. Pirate-Rob

    Pirate-Rob Haxor Staff Alumni Tester

    Messages:
    270
    Will this ever get fixed or unlikely?
     
  5. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Not likely but feel free to bug MM about it. I think his position is "shims exist so why bother" though.
     
  6. mehwaffle10

    mehwaffle10 Haxor Mapping Moderator Official Server Admin

    Messages:
    19
    lol thanks ill give it a go, i figured i could do that but i just didnt want to add 20+ variables to the rules cause i figured itd be bad way to do it, but i guess mak wasnt joking about players being fucked O_O
    thanks tho =D
    --- Double Post Merged, May 11, 2016, Original Post Date: May 11, 2016 ---
    Lol while im on the subject of idk how to do things, Nova CTF has custom red barriers, and theyre different based on each map(so we could have them wherever we felt was appropriate for each map), but on occasion a player won't be able to see the redzone and can walk right through it (with arrwos and grapples not working cause the server says no). Forcing them to relog fixes the problem permanently for each player, but it can happen randomly for anyone logging in(two of my friends who are on frequently just had it the other day). Ill put the code down below, but im kind of lost on how to figure out whats wrong(mak helped me with part of it). Any ideas? (its in RedBarrier.as)
    Code:
    // red barrier before match starts
    
    const f32 BARRIER_PERCENT = 0.175f;
    bool barrier_set = false;
    
    bool shouldBarrier(CRules@ this)
    {
        return this.isIntermission() || this.isWarmup() || this.isBarrier();
    }
    void onTick(CRules@ this)
    {
        if (shouldBarrier(this))
        {
            if (!barrier_set)
            {
                barrier_set = true;
                addBarrier(this);
            }
            f32 x1, x2, y1, y2;
            getBarrierPositions(this, x1, x2, y1, y2);
            const f32 middle = x1 + (x2 - x1) * 0.5f;
    
            CBlob@[] blobsInBox;
            if (getMap().getBlobsInBox(Vec2f(x1, y1), Vec2f(x2, y2), @blobsInBox))
            {
                for (uint i = 0; i < blobsInBox.length; i++)
                {
                    CBlob @b = blobsInBox[i];
                    if (b.getTeamNum() < 100 || b.hasTag("no barrier pass"))
                    {
                        Vec2f pos = b.getPosition();
    
                        f32 f = b.getMass() * 2.0f;
    
                        if (pos.x < middle)
                        {
                            b.AddForce(Vec2f(-f, -f * 0.1f));
                        }
                        else
                        {
                            b.AddForce(Vec2f(f, -f * 0.1f));
                        }
                    }
                }
            }
        }
        else
        {
            if (barrier_set)
            {
                removeBarrier(this);
                barrier_set = false;
            }
        }
    }
    
    void Reset(CRules@ this)
    {
        barrier_set = false;
        this.set_string("map name", getMap().getMapName());
        this.Sync("map name", true);
    }
    
    void onRestart(CRules@ this)
    {
        Reset(this);
    }
    
    void onInit(CRules@ this)
    {
        Reset(this);
    }
    
    void onRender(CRules@ this)
    {
        if (shouldBarrier(this))
        {
            f32 x1, x2, y1, y2;
            getBarrierPositions(this, x1, x2, y1, y2);
            GUI::DrawRectangle(getDriver().getScreenPosFromWorldPos(Vec2f(x1, y1)), getDriver().getScreenPosFromWorldPos(Vec2f(x2, y2)), SColor(100, 235, 0, 0));
        }
    }
    void getBarrierPositions(CRules@ this, f32 &out x1, f32 &out x2, f32 &out y1, f32 &out y2)
    {
        CMap@ map = getMap();
        f32 percent = BARRIER_PERCENT;
        string name = this.get_string("map name");
        if(name == "Maps/Nova/BoulderLake.png")
        {
            percent = .095f;
        }
        if(name == "Maps/Nova/CerberosRift.png")
        {
            percent =.15f;
        }
        if(name == "Maps/Nova/HearthPlains.png")
        {
            percent =.14f;
        }
        if(name == "Maps/Nova/KingArthursPonds.png")
        {
            percent =.125f;
        }
        if(name == "Maps/Nova/IslandCoast.png")
        {
            percent =.14f;
        }
        if(name == "Maps/Nova/NewTortuga.png")
        {
            percent =.09f;
        }
        if(name == "Maps/Nova/EjMap.png")
        {
            percent =.07f;
        }
        if(name == "Maps/Nova/ShaftCanyon.png")
        {
            percent =.16f;
        }
        if(name == "Maps/Nova/ProvingGrounds.png")
        {
            percent =.125f;
        }
        const f32 mapWidth = map.tilemapwidth * map.tilesize;
        const f32 mapMiddle = mapWidth * 0.5f;
        f32 barrierWidth = percent * mapWidth;
        x1 = mapMiddle - barrierWidth;
        x2 = mapMiddle + barrierWidth;
        y2 = map.tilemapheight * map.tilesize;
        y1 = -y2;
        y2 *= 2.0f;
    }
    
    /
    * Adding the barrier sector to the map
    */
    
    void addBarrier(CRules@ this)
    {
        CMap@ map = getMap();
        f32 x1, x2, y1, y2;
        getBarrierPositions(this, x1, x2, y1, y2);
    
        Vec2f ul(x1, y1);
        Vec2f lr(x2, y2);
    
        if (map.getSectorAtPosition((ul + lr) * 0.5, "barrier") is null)
            map.server_AddSector(Vec2f(x1, y1), Vec2f(x2, y2), "barrier");
    }
    
    /
    * Removing the barrier sector from the map
    */
    
    void removeBarrier(CRules@ this)
    {
        CMap@ map = getMap();
    
        f32 x1, x2, y1, y2;
        getBarrierPositions(this, x1, x2, y1, y2);
    
        Vec2f ul(x1, y1);
        Vec2f lr(x2, y2);
    
        map.RemoveSectorsAtPosition((ul + lr) * 0.5 , "barrier");
    }
     
  7. Geti

    Geti Please avoid PMing me (poke a mod instead) THD Team Administrator Global Moderator

    Messages:
    3,730
    Don't have time to debug your code but it'd be important to find out if they have anything in their console about the script having an error; to debug it might also help to have the script print out the current map name every minute or so (so you can see if the name never got there or what). You may also want to check the player position serverside and re-sync it in that case, or rather than relying on sync(), use commands and send them whenever you've got a new player plus at the start of the next match.

    This kind of thing happens in vanilla as well, could be that there's issues with regions syncing or all sorts of things, I've never got time to really sit down with it and figure it out :/ In vanilla the red zone stays though.
     
  8. mehwaffle10

    mehwaffle10 Haxor Mapping Moderator Official Server Admin

    Messages:
    19
    any idea why as a server owner i cant use any admin controls but while any of my admins/ superadmins can? even when i set myself to a superadmin?
    --- Double Post Merged, Sep 15, 2016, Original Post Date: May 15, 2016 ---
    Anyone?