Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Inverted Controls
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#1
Inverted Controls

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

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?

Derp.
10-06-2014, 09:55 PM
Find
Viper85626 Offline
Junior Member

Posts: 46
Threads: 6
Joined: Apr 2013
Reputation: 2
#2
RE: Inverted Controls

I actually don't think it's possible through scripting. I may be wrong though.
(This post was last modified: 10-06-2014, 10:32 PM by Viper85626.)
10-06-2014, 10:31 PM
Find
MrBehemoth Offline
Senior Member

Posts: 408
Threads: 19
Joined: Feb 2014
Reputation: 40
#3
RE: Inverted Controls

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: (Select All)
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?


10-07-2014, 01:17 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#4
RE: Inverted Controls

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

Derp.
(This post was last modified: 10-07-2014, 07:56 AM by Neelke.)
10-07-2014, 07:54 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#5
RE: Inverted Controls

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.

Derp.
(This post was last modified: 10-07-2014, 07:52 PM by Neelke.)
10-07-2014, 07:51 PM
Find
Mudbill Offline
Muderator

Posts: 3,881
Threads: 59
Joined: Apr 2013
Reputation: 179
#6
RE: Inverted Controls

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.

10-07-2014, 10:44 PM
Find
MrBehemoth Offline
Senior Member

Posts: 408
Threads: 19
Joined: Feb 2014
Reputation: 40
#7
RE: Inverted Controls

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

10-08-2014, 07:33 AM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#8
RE: Inverted Controls

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

Derp.
(This post was last modified: 10-08-2014, 07:41 AM by Neelke.)
10-08-2014, 07:39 AM
Find
Viper85626 Offline
Junior Member

Posts: 46
Threads: 6
Joined: Apr 2013
Reputation: 2
#9
RE: Inverted Controls

For that particular set of code, yes.
10-08-2014, 03:44 PM
Find
Neelke Offline
Senior Member

Posts: 668
Threads: 82
Joined: Apr 2013
Reputation: 26
#10
RE: Inverted Controls

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

Derp.
(This post was last modified: 10-08-2014, 03:55 PM by Neelke.)
10-08-2014, 03:55 PM
Find




Users browsing this thread: 2 Guest(s)