Frictional Games Forum (read-only)
[SCRIPT] Inverted Controls - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: [SCRIPT] Inverted Controls (/thread-26601.html)

Pages: 1 2


Inverted Controls - Neelke - 10-06-2014

So, I've wanted to create a script where the player gets his controls inverted. I tried doing it like this:

Code:
void CollideReverseControls(string &in asParent, string &in asChild, int alState)
{
    SetPlayerMoveSpeedMul(-1);
    SetPlayerRunSpeedMul(-1);
    SetPlayerLookSpeedMul(-1);
    
    FadePlayerFOVMulTo(1.75f, 5.0f);
    PlayGuiSound("27_thump", 1.0f);
    
    AddTimer(asParent, 0.5f, "TimerReverseControls");
}

void TimerReverseControls(string &in asTimer)
{
    FadePlayerFOVMulTo(1.0f, 2.0f);
}

This works for the look speed, but not the move and run speed. Instead it locks itself to just down and left. It refuses to go up or right no matter what I press. Could there be a way to do inverted controls another way?


RE: Inverted Controls - Viper85626 - 10-06-2014

I actually don't think it's possible through scripting. I may be wrong though.


RE: Inverted Controls - MrBehemoth - 10-07-2014

I think Viper is right.

...But I can't resist a scripting challenge! I'm guessing you're going for a drunk/drugged effect. I have an idea that you could do with the 1.3 patch, although it would be clunky and not quite what you're after, but interesting to experiment with...

Spoiler below!

This is just an idea - not tested, not guaranteeing it will work without tweaks, or work at all.

PHP Code:
void DrunkMode_Start()
{
    
SetPlayerLookSpeedMul(-1);
    
FadePlayerFOVMulTo(1.75f5.0f);
    
PlayGuiSound("27_thump"1.0f);
    
AddTimer("DrunkModeTimer"RandFloat(0.5f2.0f), "DrunkMode_Reset");
}

void DrunkMode_Stop()
{
    
FadePlayerFOVMulTo(1.0f2.0f);
    
RemoveTimer("DrunkModeTimer");
}

void DrunkMode_Reset(string &in asTimer)
{
    
SetGlobalVarFloat("PlayerPrevX"GetPlayerPosX());
    
SetGlobalVarFloat("PlayerPrevZ"GetPlayerPosZ());
    
AddTimer("DrunkModeTimer"0.1f"DrunkMode_Detect");
}

void DrunkMode_Detect(string &in asParentstring &in asChildint alState)
{
    if(
GetGlobalVarFloat("PlayerPrevX") > GetPlayerPosX())
    {
        
AddPlayerBodyForce(RandFloat(-10000.0f, -6000.0f), 0.0f0.0ffalse);
    }
    else if(
GetGlobalVarFloat("PlayerPrevX") < GetPlayerPosX())
    {
        
AddPlayerBodyForce(RandFloat(10000.0f6000.0f), 0.0f0.0ffalse);
    }
    
    if(
GetGlobalVarFloat("PlayerPrevZ") > GetPlayerPosZ())
    {
        
AddPlayerBodyForce(0.0f0.0fRandFloat(-10000.0f, -6000.0f), false);
    }
    else if(
GetGlobalVarFloat("PlayerPrevZ") < GetPlayerPosZ())
    {
        
AddPlayerBodyForce(0.0f0.0fRandFloat(10000.0f6000.0f), false);
    }
    
    
AddTimer("DrunkModeTimer"RandFloat(0.5f2.0f), "DrunkMode_Reset");


So, to switch it on you call DrunkMode_Start() and that does your visual effects and whatever, then kicks off DrunkMode_Reset() after a random interval.

DrunkMode_Reset() stores the current player x and z as globals, then calls DrunkMode_Detect() after 0.1s.

DrunkMode_Detect() compares the globals to the new current player x and z to check if the player has moved in the last 0.1s, and then applies a force in the oppposite direction.

DrunkMode_Stop() switches it all off.

In other words, while drunk mode is active, every 0.5 - 2.5s, if the player moves, they will be shoved in the opposite direction. Like I said, I've not tested it, but I think this will give a nice stumbling effect, depending on how you tweak the forces.

Also, did you know that if FOV < 0 then it will flip the screen?




RE: Inverted Controls - Neelke - 10-07-2014

Slightly yea. What makes it strange though is the fact that this works for when you look around, the controls of the camera gets inverted through this. It's just the run and move that doesn't work. Instead the problem happens that I explained above.

And I didn't see your example. When I get back home I'm gonna test it out. Thanks Wink


RE: Inverted Controls - Neelke - 10-07-2014

Update: It didn't work.

However, I did try adding a dot to the global string.

SetGlobalVarFloat("PlayerPrevX", GetPlayerPos.X());

They then told me I got an illegal use of an int. So we are on the right track here.


RE: Inverted Controls - Mudbill - 10-07-2014

Why would a period there help? GetPlayerPosX is the name of a script function that calculates the X position. I don't think GetPlayerPos has been implemented as its own function and have it accept inputs like that... if C++ even works that way.


RE: Inverted Controls - MrBehemoth - 10-08-2014

Yup, it definitely wouldn't have a dot.

Just checking: you're definitely using the 1.3 patch, right? It wouldn't work without it.

I'll test it tonight and debug if necessary. Smile


RE: Inverted Controls - Neelke - 10-08-2014

I don't actually use 1.3. Is it something I must have for this to work?


RE: Inverted Controls - Viper85626 - 10-08-2014

For that particular set of code, yes.


RE: Inverted Controls - Neelke - 10-08-2014

Crap. Well at least we can figure something out with this despite me not being able to use it. I could probably create something too for people with version 1.2, but we'll see I guess.

If nothing comes up, I guess I have to be happy with an inverted camera. It's hard too so it's fine Smile