Skip to content

Conversation

jerethk
Copy link
Contributor

@jerethk jerethk commented Apr 2, 2025

The motive of this is to support the feature I am creating which allows the camera (eye) to be switched between the player object and other objects.
I want to be able to stop the player from moving while (for example) a cinematic sequence is playing and the eye is elsewhere.

I've allowed separate control over movement, rotation and firing so that modders can have fine-tuned control. Someone might want to suppress firing while still allowing movement, and so on.

}
}

void disableMovement()
Copy link
Owner

@luciusDXL luciusDXL Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably replace this with flags:
int s_playerActionFlags = ACTION_DISABLE_NONE; // or whatever
enum
{
ACTION_DISABLE_NONE = 0,
ACTION_DISABLE_MOVE = 1 << 0,
ACTION_DISABLE_ROTATE = 1 << 1,
ACTION_DISABLE_FIRE = 1 << 2,
ACTION_DISABLE_ALL = ACTION_DISABLE_MOVE | ACTION_DISABLE_ROTATE | ACTION_DISABLE_FIRE
};

And then have a only few functions in the script API, even if you add more actions you can disable.
bool isActionEnabled(int actionFlags) {}
void enableActions(int actionFlags) {}
void disableActions(int actionFlags) {}

The main reason is that, as it is now, you have to add multiple functions for every type of player action you want to change. My thought, instead, is to just add a flag and keep the API to the same set of functions. So to freeze all actions: player.disableActions(ACTION_DISABLE_ALL); instead of another function call. You get the idea. :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent suggestion, thank you very much!
(Should have thought of it myself)

I have done as you recommended with the scripting API.
In the game code, I'm leaving it as separate variables because I think that is easier and more readable there

@jerethk jerethk force-pushed the scripting_player_disable branch from e9f943d to 22f2c7e Compare April 3, 2025 12:25
@jerethk jerethk requested a review from luciusDXL April 3, 2025 12:29
@luciusDXL
Copy link
Owner

This greatly simplified the script API, thanks.

@luciusDXL luciusDXL merged commit a341d71 into luciusDXL:master Apr 16, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants