How can I modify server commands based on player location

Post here if you need help setting up your server, etc.
Post Reply
Tim-Misny
Posts: 9
Joined: Sun Aug 02, 2015 6:01 pm

How can I modify server commands based on player location

Post by Tim-Misny » Sun Oct 20, 2019 7:01 pm

Hi,

I have never done any server modification or customization / scripting so any help would be appreciated.

The basic task that I want to achieve is to change certain values for individual players based on what they are doing. One example might be when a player is in a tunnel between his own wall and another players wall give him slightly more rubber. On the other hand if he is in a tunnel between two of his own walls, reduce his rubber. Is it possible to do all this without affecting the other players in the server?

What do you think? Would this require recompiling the server and writing my own tunnel detection code? I would be able to do that but I am currently not familiar with the code base (but have no problem learning it).

Any help or thoughts appreciated, thanks!

User avatar
Z-Man
God & Project Admin
Posts: 11220
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne, Jabber: [email protected]
Contact:

Re: How can I modify server commands based on player locatio

Post by Z-Man » Sun Oct 20, 2019 9:05 pm

Modifying rubber individually for each player is not currently possible, at least not in the vanilla source. So you will have to modify the code yourself.

A couple of pointers: We already detect the two situations you speak of in the method gCycleMovement::CalculateAcceleration() (in gCycleMovement.cpp), look for these two variables:

Code: Select all

    bool slingshot  = true;         // flag indicating whether the cycle is between two walls
    bool oneOwnWall = false;        // flag indicating whether one of the walls is your own
they're set in the big code block that follows. I hope the comments say it all.

Instead of modifying the total amount of rubber available (which would be very complicated), you should toy with the member variable gCycleMovement::rubberMalus. It is a proper state variable with a timestep behavior and it affects how much rubber is used. The original intention for it is to make it so that right after a turn, you would use more rubber, so that silly 180s against walls become more expensive or deadly even if rubber is high.
The variable is used in gCycleMovement::TimestepCore():

Code: Select all

    // rubber effectiveness right now
    rubberEffectiveness /= (1 + rubberMalus );
...
            // update rubber usage
            rubber += rubberneeded / rubberEffectiveness;
Yay for unnecessary divisions, I guess. But what this means is that the meaningful range for rubberMalus is (-1,infinity). At 0, it does nothing (that's also the default value), at -0.5, it makes rubber get used only half as much (thus worth twice as much), at 1, it makes rubber get used twice as much.

You should be able to set rubberMalus in gCycleMovement::CalculateAcceleration() and just ignore the other code trying to manipulate it. But if you want to make sure, set CYCLE_RUBBER_MALUS_TIME to 0, that disables any time evolution, and leave CYCLE_RUBBER_MALUS_TURN at its default of 0.

Best thing about rubberMalus, it gets synced to the clients and they know about that effect, so players should not feel unduly surprised if their rubber runs out sooner than expected. Though, it is synced in this way:

Code: Select all

    compressZeroOne.Write( m, 1/( 1 + rubberMalus ) );
That means values lower than 0 are clamped to 0. So it's probably best if keep rubberBalus positive.

Tim-Misny
Posts: 9
Joined: Sun Aug 02, 2015 6:01 pm

Re: How can I modify server commands based on player locatio

Post by Tim-Misny » Sun Oct 20, 2019 11:27 pm

Hmm thank you for the quick and interesting answer! I will have to play around with those values and see how I like them.

I suspected that changing individual settings may not have been possible. You gave me the idea, however, that it could instead be possible to target the player, not by changing the amount of rubber they have, but by continually increasing their rubber level until it rises above a specified value. Would this be possible? This would effectively simulate the same response, although maybe looks a little clunkier from the clients perspective.

tim

User avatar
Z-Man
God & Project Admin
Posts: 11220
Joined: Sun Jan 23, 2005 6:01 pm
Location: Cologne, Jabber: [email protected]
Contact:

Re: How can I modify server commands based on player locatio

Post by Z-Man » Mon Oct 21, 2019 8:55 pm

Yeah, just modifying gCycleMovement::rubber on the spot is also possible. For consistency, you have to do it in one of two ways.
If you want continuous changes, you need to apply them in one of the Timestep() family of functions, it's not too important for your purposes which one (TimestepCore is the one called with the finest granularity). There, you always have to multiply your desired rate of change with the timestep (usually called ts here), so

Code: Select all

rubber += ts * rate_of_change;
Or, if you want sudden changes, you apply them on state changes. So as the player enters a tunnel, just add a fixed value to rubber. You then have to be careful to manage your state changes correctly so you don't make accounting errors; don't hesitate to add a member variable tracking the state. And after each larger change, you should call RequestSync() to have the clients informed about the sudden change. For the continuous method, you don't need to do that, the regular syncs should suffice.

Post Reply