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

[2067] Can't sync a property on a CPlayer between client & server

Discussion in 'Archive' started by Eluded, Feb 2, 2017.

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

    Eluded Haxor Official Server Admin

    Messages:
    132
    Category: KAG Client and KAG Server
    Operating system: Windows
    Build number: 2067
    Description: It seems impossible to sync properties set on a CPlayer object between the server and clients. What I expect to happen is: set a property on a CPlayer object server-side, sync it, the property is the same on the client.

    What actually happens is: set a property on a CPlayer object server-side, sync it, the property is some default value (like 0 or the empty string) on the client.
    Steps to reproduce: Here is example code to reproduce (set the server gamemode to TDM and run it as a script attached to the TDM gamemode.cfg)
    Code:
    void onTick(CRules@ this) {
        CPlayer@ player = getPlayerByUsername("Eluded");
        if (player !is null) {
            if (getNet().isServer()) {
                player.set_u8("test", 7);
                player.Sync("test", true);
            }
            printf("player test property: " + player.get_u8("test"));
        }
    }
    

    The output on the server looks like: "player test property: 7"
    The output on the client looks like: "player test property: 0"
    Although initially the client outputs some stuff about bad snapshots:
    Error receiving property - object does not exist yet - (PACKET_SNAPSHOT_ONCE_PROPERTY_CREATE) propid 1000007
    Properties not found (PACKET_SNAPSHOT_ONCE_PROPERTY_CREATE) id 1000007
    Bad snapshot; skipping 10894b fail 16 (last packet 52 once 72 debug RULES)
    Object with ID 48 has bad delta (2)
    RecdDeltas: last netobj id 49, cache -1
    Bad delta!
    Bad snapshot; skipping 0b fail 18 (last packet 50 once 72 debug RULES)

    Screenshots/Videos:

    Kazaco: See Mak's solution.
     
    TFlippy and makmoud98 like this.
  2. Furai

    Furai THD Team THD Team Administrator

    Messages:
    3,124
    I don't know if it's a bug because I have not enough knowledge about KAG. Might be that you're just doing something wrong in your scripts.
     
  3. Eluded

    Eluded Haxor Official Server Admin

    Messages:
    132
    Yes this is very possible. Maybe it's just wrong to try and put properties on players like this. But if so perhaps that should be documented somewhere.
     
  4. makmoud98

    makmoud98 You are already DEAD Forum Moderator Staff Alumni Tester

    Messages:
    586
    yea its been finicky for a long time, what you want to do instead is something like this
    Code:
    void onTick(CRules@ this) {
        if (getNet().isServer()) {
            this.set_u8("Eluded_test", 7);
            this.Sync("Eluded_test", true);
        }
        printf("player test property: " + this.get_u8("Eluded_test"));
    }
    
     
  5. Geti

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

    Messages:
    3,730
    Yeah player lifetimes are... strange, and I don't think MM quite thought through how they'd work with sync and friends. I've considered just removing properties entirely from players more than once.

    As such, as mak says you're better off putting them in rules and doing a lookup by username - or, if you dont need it to persist across them disconnecting/rejoining in the same game, network ID should be the same everywhere too.

    If only that player needs that property there's also SyncToPlayer, which is used in vanilla for stuff like respawn time.
     
Thread Status:
Not open for further replies.