#Player-Owned Areas

1 messages · Page 1 of 1 (latest)

molten bridge
#

Special thanks to @austere nymph and @trail ruin !!!

austere nymph
#

Congrats on release!! Epic work HD

molten bridge
#

Thank you both!

tepid jacinth
#

very cool!

hard frigate
#

Very useful for dedicated servers!!!!!

molten bridge
#

Currently a pretty big bug right now. Don't use it yet. 😬 Will work on a fix as soon as possible.

hard frigate
#

🫡Good luck soldier

molten bridge
#

I will try to wrap my mind around the issue. It is a sync issue. Talking to Noita, it sounds like it is because I need something called Actions. As I am not familiar with multiplayer modding, I didnt foresee this as a requirement or even knew it was needed at all.

So I will look around at some examples and try to work my way through it.

trail ruin
#

I'll take a look at what your mod is doing sec

molten bridge
#

I can get you some screenshots of logs too. When Noita and I tested it on my test server, I claimed some areas and when his action was to be cancelled, the game would crash me out. I could log back in but the areas were no longer stored in my name.

#

Logout message is that the client was desynced from the server

trail ruin
#

Okay so I think the main thing is that commands are local

#

If you run a command, it's not sending the command to the server

molten bridge
#

oh 🤔

trail ruin
#

What you need to do is have an "action" between the command and the stuff you actually want to do

#

Debug Tools has this command:

    @Register.command("DebugToolsPermission")
    public debugToolsAccessCommand(_: any, player: Player, args: string) {
        if (!this.hasPermission()) {
            return;
        }

        const targetPlayer = game.playerManager.getByName(args);
        if (targetPlayer !== undefined && !targetPlayer.isLocalPlayer()) {
            const newPermissions = !this.getPlayerData(targetPlayer, "permissions");
            TogglePermissions.execute(localPlayer, targetPlayer, newPermissions);
            DebugTools.LOG.info(`Updating permissions for ${targetPlayer.getName().toString()} to ${newPermissions}`);
        }
    }
#

The important part in here is the TogglePermissions.execute line

#
export default new Action(ActionArgument.Player, ActionArgument.Boolean)
    .setUsableBy(EntityType.Human)
    .setUsableWhen(...defaultUsability)
    .setHandler((action, player, permissions) => {
        if (!player) return;

        Actions.DEBUG_TOOLS.setPlayerData(player, "permissions", permissions);
    });
#

This is TogglePermissions

#

You have to @Register.action the action you create

#
    @Register.action("TogglePermissions", TogglePermissions)
    public readonly actionTogglePermissions: ActionType;
#

So the idea is:

  1. Make an action that calls your area command functionality, taking ActionArguments that are equivalent to the arguments of your command processing functions
  2. Register the action in one of your registries
  3. In the @Register.command command function body, execute the action
#

Actions are executed on all sides with the right "timing", so there won't be any desyncs

molten bridge
#

🤪 I will digest this. lol

molten bridge
#

So question, I should be using an action to store the information rather than storing it in my function?

#

Example, my areas command and claim case I setup a new action execute operation (I would assume I remove the Areas.ClaimArea)

case "claim":
//?  Areas.ClaimArea(player);
  SetAreaData.execute(localPlayer, localPlayer, Areas.getAreaId(localPlayer));
  break;```

In my new action call, I have this.
```ts
export default new Action(ActionArgument.Player, ActionArgument.Object)
    .setUsableBy(EntityType.Human)
    .setUsableWhen(...defaultUsability)
    .setHandler((action, player, areaData) => {
        if (!player) return;


        var dataMgr = new DataManager;
        dataMgr.SetAreaData(areaData);

    });```
#

I see a lot of other stuff involved in the new actions of Debug Tools like the Actions.DEBUG_TOOLS reference that I did not emulate/copy (words are hard sometimes)

trail ruin
#

You could do that, or you could take what you have here:

@Register.command("Areas")
public CmdAreas(_: any, player: Player, args: string) {
    Commands.CmdAreas(_, player, args);
}

and make it:

@Register.command("Areas")
public CmdAreas(_: any, player: Player, args: string) {
    CommandAction.execute(player, args);
}

with

export default new Action(ActionArgument.String)
    .setUsableBy(EntityType.Player)
    .setUsableWhen(...defaultUsability)
    .setHandler((action, args) => {
      Commands.CmdAreas(null, action.executor, args);
    });
#

and then everything is handled without big code changes

#

the entire thing is just... you need to be handling the command on all ends, and just passing it through the action system makes that happen

molten bridge
#

🤔 OK so I think I followed all that better this time

#

So......... Essentially I am redirecting my action from the command register into the action, which just redirects to the logic.

trail ruin
#

yep

molten bridge
#

Will focus on this direction then.

#

OK well that was more painless.

#

Now I need to test.

molten bridge
#

it is running on server and I am able to use the mod

#

now just need to see if another player can try to break stuff

tepid jacinth
#

if you give me a few, i can help test

molten bridge
#

I actually was able to test thank you. There is some functions not working, like friends. I will need a new action there. But I will upload what I got to workshop so claimed areas can work for players

#

oops uploaded the same mod 2x... How can I replace the one?

#

or is that how this works?

tepid jacinth
#

when you upload, it should write an ID to your mod.json

#

so when you upload it again, it uses that ID

trail ruin
#

if somehow that didn't happen for you you can manually add it to your mod.json, it should be "publishedFileId": "2992525255" (the string of numbers at the end of the workshop link)

trail ruin
#

it did write it, but you wrote over it with your deploy_mod.ps1 script i think

#

if you add that and remove the duplicate it should work fine

#

you need that publishedFileId to be set in the mod when you're hosting your server

#

that's the reason why the mod doesn't show up in the tooltip for people connecting

molten bridge
#

You both rock. Even provided the ID from the workshop. Thank you kindly I verified it is the one I want to update.

The PS only pushes my mod from my dev environment (lol a folder) to the mods folder.

#

V1.0.1 is published with the biggest fix. Next fix I work on will be the friends portion. It did not work when tested on multiplayer. Will need an action as well.

#

ayyyyy

#

Thank you for helping me fumble through this

molten bridge
hard frigate
#

nice!

trail ruin
hard frigate
#

Thanks for helping him too! super cool of you

#

I'll probably refer back to this myself when I make stuff too there's useful stuff here, examples are a good way to learn

molten bridge
#

I forgot I need to add in more actions. I believe I also need to make the action of storing data. I logged into the server this morning and the area data was gone.

I set the workshop plugin to hidden as I dont have time right now to fully troubleshoot

#

wait I am confused. The server declared my first action turn 1.

#

Maybe there is an issue with the server, not the mod. Unfortunately I gtg for the day. Until next time!

molten bridge
#

Good news, in testing I found my server was not operating properly...

I tested the mod fully in GUI mode as my turn was incrementing properly. In console mode the server remained at turn 1 indefinitely. Additionally, in GUI mode, I found I could use command /save. I used this and reloaded both client and server. I was able to still see my areas as claimed.

Workshop post has been made public once again.

#

After reboot:

hard frigate
#

Nice!

molten bridge
# trail ruin No worries, looks good!

Question, if I want a client to check if a location is taken (not necessarily something all clients need to know at any given time, I think), do I technically not need to use an action for the client to check the local area?

IE: I am 1 of 2 people on a server. If I check an area, as it is now, will send an action. When I move and run logic to check if the new tile is a new area, I dont sent an action. Is this OK or should it be an action?

trail ruin
#

It depends on if the logic is running on an event that happens only clientside or if it happens both clientside and serverside

#

When I move and run logic to check if the new tile is a new area,
What event are you running this logic on

molten bridge
#

example: @EventHandler(EventBus.Players, "postMove")

#

I check if the area the player walked to is a new area. If not, then it wont run logic. If it is, it will check the new area to see if it is protected from the user.

#

If a user claims a space, I use an action to sync everyone. If there is no change in client-server data, I assume I dont need an action. Or at least I am trying to see

trail ruin
#

yeah that sounds fine

molten bridge
#

OK.

I will need to test the friend function. I did with Noita and he could not modify anything on an area I had in my name