[ACS] Retrieving the value of map scope variables in a CLIENTSIDE script

Discuss all aspects related to modding Zandronum here.
Post Reply
User avatar
buu342
 
Posts: 58
Joined: Tue Nov 08, 2016 11:23 pm
Location: Earth

[ACS] Retrieving the value of map scope variables in a CLIENTSIDE script

#1

Post by buu342 » Fri Mar 22, 2019 12:45 am

Hello.

I am currently designing a HUD + GUI system for my multiplayer wad, and everything works in singleplayer flawlessly. However, when I tested the game in a multiplayer server, I found that the menu GUI could lead to the game freezing up entirely because of the amount of stuff it's trying to draw. As a result, my plan was to convert the GUI and HUD over to CLIENTSIDE scripts, but I've hit a major roadblock, which is that all of these are reliant on the values of some map scope variables.

These variables don't change very often, so if the HUD is lagging behind by a few milliseconds it's not a major ordeal, but as it is right now, it assumes all the map variables I'm trying to call have a value of 0. Stuff like PlayerIsLoggedIn() is completely ignored as well. So my question is, what would be the best way to retrieve data from the server on a CLIENTSIDE script? I'm aware that to do the opposite, I have to use RequestPuke(). But I'm not interested in changing the value of map scope variables clientside, I want to just retrieve them.

Suggestions?
Remember that you are unique, just like everyone else.

User avatar
Fused
Contributor
Posts: 663
Joined: Sat Nov 09, 2013 9:47 am
Location: Netherlands
Contact:

[ACS] Re: Retrieving the value of map scope variables in a CLIENTSIDE script

#2

Post by Fused » Fri Mar 22, 2019 10:47 am

You can send serverside variables to clients. You can do it in a single call because server->client affects all clients unless you check their PlayerId and match it with the activator.
Alternatively one very easy way to do this is the way the ACSutils library does it, where it spawns dummy objects and set their speed to the value you want to transfer. This is synced and available to clients. I don't think it works with anything other than integers, but considering that's what you need, that should work aswell. These dummy objects are invisible and only used for this syncing.
If you plan on doing a manual transfer through script puking, you can try packing your integers to a single vlaue, if they're small enough. ACSutils also provides tools for that, and it's very easy if you udnerstand the logic behind it.

It is a good idea to clientside as much as possible, even if it means synching everything of it. Try and reduce as much traffic as possible by doing manual synching and clientsiding scripts, and it will open up many possibilities.
My mods
Image Image

My socials
Image Image

User avatar
buu342
 
Posts: 58
Joined: Tue Nov 08, 2016 11:23 pm
Location: Earth

[ACS] Re: Retrieving the value of map scope variables in a CLIENTSIDE script

#3

Post by buu342 » Fri Mar 22, 2019 2:05 pm

Fused wrote:
Fri Mar 22, 2019 10:47 am
You can send serverside variables to clients. You can do it in a single call because server->client affects all clients unless you check their PlayerId and match it with the activator.
Alternatively one very easy way to do this is the way the ACSutils library does it, where it spawns dummy objects and set their speed to the value you want to transfer. This is synced and available to clients. I don't think it works with anything other than integers, but considering that's what you need, that should work aswell. These dummy objects are invisible and only used for this syncing.
If you plan on doing a manual transfer through script puking, you can try packing your integers to a single vlaue, if they're small enough. ACSutils also provides tools for that, and it's very easy if you udnerstand the logic behind it.

It is a good idea to clientside as much as possible, even if it means synching everything of it. Try and reduce as much traffic as possible by doing manual synching and clientsiding scripts, and it will open up many possibilities.
Currently, the way I'm doing to check if a player has their menu open is by giving/taking an item to the player, this seems to work as well in comparison to having to spawn a dummy object for each variable. But am I really just limited to using ints? I really need strings to work with this as well... Is there literally no other way to synchronize map variables without having to create a shit ton of items and user cvars/stringcvars?

Edit:
It seems UserCVars are broken? Because this script works fine with server CVars. Am I doing this wrong? Puke script 1 and the CLIENTSIDE HUDMessage will show 0, but on the center of the screen it prints a completely different value serverside.

CVARINFO:

Code: Select all

user noarchive int test_sync_int = 0;
ACS:

Code: Select all

int test_int;

Script 1 (void) NET
{
    ACS_ExecuteAlways(2, 0);
}

Script 2 (void) CLIENTSIDE
{
    if (ConsolePlayerNumber() != PlayerNumber())
        terminate;

    SetActivator(0); // Also doesn't work with -1

    SetFont("BIGFONT");
    while (1)
    {
        HudMessage(d:GetUserCVar(0, "test_sync_int"); HUDMSG_PLAIN, 1, CR_WHITE, 0.5, 0.1, 1);
        delay(1);
    }
}

Script 3 ENTER
{
    test_int = 0;
    ACS_ExecuteAlways(4, 0);
}

Script 4 (void)
{
    test_int++;
    bool ret = SetUserCVar(0, "test_sync_int", test_int);
    print(d:ret, s:" ", d:GetUserCVar(0, "test_sync_int"));
    delay(1);
    restart;
}
Remember that you are unique, just like everyone else.

User avatar
buu342
 
Posts: 58
Joined: Tue Nov 08, 2016 11:23 pm
Location: Earth

[ACS] Re: Retrieving the value of map scope variables in a CLIENTSIDE script

#4

Post by buu342 » Sun Mar 24, 2019 1:15 am

I've actually figured out a crazy solution. Instead of using UserCVars (which are broken on CLIENTSIDE scripts, along with UserVariables...) I have instead packed all of the data into a single string and sent them to all clients in a CVar.

Image

On the center, is what the server sees, where each line represents the value for that specific player variable (line 1 for player 1, line 2 for player 2).
On the top, is what the client sees in his clientside script. The left window is player 2, right window is player 1.

Sadly, since I can't pass arrays into function arguments, I gotta make a string packing function for each global array, but an unpack function works as all it needs to do is return a string.
Remember that you are unique, just like everyone else.

User avatar
buu342
 
Posts: 58
Joined: Tue Nov 08, 2016 11:23 pm
Location: Earth

[ACS] Re: Retrieving the value of map scope variables in a CLIENTSIDE script

#5

Post by buu342 » Sat Mar 30, 2019 9:40 pm

This sort of this works half assedly. Sometimes it doesn't really work at all. I could really use a solid alternative.
Remember that you are unique, just like everyone else.

Post Reply