Frictional Games Forum (read-only)
[SCRIPT] How do I make a chair move? - 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] How do I make a chair move? (/thread-53393.html)

Pages: 1 2


RE: How do I make a chair move? - goodcap - 12-10-2016

(12-10-2016, 07:48 PM)Mudbill Wrote: Ok, well, I think then the safest (and possibly simplest though subjective) way would be:

Create a custom entity for the chair by opening the original and "Save As" a different name. Make it a MoveObject type. Set the axis to be the direction you want the chair to move in the level (either X or Z). You do this in the User Defined Variables in the Model Editor.

Spoiler below!
[Image: f53474051df7413b80fd10e37db1effb.png]

In the map, place the entity. Once the player hits a collision box, use SetMoveObjectState to move the chair along the axis. That's all you need to do.

In the User Defined Variables you can also specify the speed and accelleration of the chair, but instead of doing it here, you can use the function SetMoveObjectStateExt instead to specify it in the script (it's a bit easier if you need to change values often).

PS: If you want the player to be able to also grab the chair after it has moved, use ReplaceEntity to turn the entity back into a normal chair (which is a Grab object).



However if you don't mind the chair possibly falling over, you can probably just use the function AddPropForce alone...

Thanks, bud!

Guys, I tried everything..

-If I make the chair a waterlurker with pathnodes it's invisible and doesn't follow the pathnode
-If I make the chair a moveobject with the SetMoveObjectState script it does nothing.


RE: How do I make a chair move? - CarnivorousJelly - 12-10-2016

I tried to make a map to display the three techniques, third one is currently broken and I don't know enough about the script to fix it, second one is noisy. I know there's a way to shut off music for the enemies and disable insanity effects but heck if I can remember!

Everything's in the file attached to this post, script is below in the spoilers
Spoiler below!

PHP Code:
// Variable declaration for chair and player position
float playerX;
float playerZ;
float chairX;
float chairZ;

/////////////////////////
// START ANNOUNCEMENTS //
void func_Announce1(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""BlockPath"0.0f);
}
void func_Announce2(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""AsEnemy"0.0f);
}
void func_Announce3(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""PlayerAndChair"0.0f);
}
// END ANNOUNCEMENTS //
///////////////////////

///////////////////
// CHAIR SPOOK A //
void func_ChairA(string &in asParentstring &in asChildint alState)
{
    
AddPropForce("chair_nice01_1"2000.0f0.0f0.0f"World"); // pushes chair along X axis towards door
}
// END SPOOK A //
/////////////////

///////////////////
// CHAIR SPOOK B //
void func_ChairB(string &in asParentstring &in asChildint alState)
{
    
SetEnemyDisableTriggers("chair_mean01_1"false);
    
AddEntityCollideCallback("Player""announce_playerandchair""func_DisableEnemy"false1); // stops enemy chasing when player leaves area
}
void func_DisableEnemy(string &in asParentstring &in asChildint alState)
{
    
SetEnemyDisableTriggers("chair_mean01_1"true);
}
// END SPOOK B //
/////////////////
/*
///////////////////
// CHAIR SPOOK C //
void func_ChairC(string &in asParent, string &in asChild, int alState)
{
    TimerPushLoop("timer_Chair"); // start pushing loop
    AddEntityCollideCallback("Player", "area_triggerchairC", "func_StopChase", false, 1); // make a way to stop loop
}

void TimerPushLoop(string &in asTimer)
{
    AddTimer(asTimer, 0.1f, "TimerPushLoop");
    NudgeChairTowardsPlayer();
}

void NudgeChairTowardsPlayer()
{
    chairX = GetEntityPosX("chair_nice01_3"); // Gets chair position
    chairY = GetEntityPosZ("chair_nice01_3");
    playerX = GetPlayerPosX(); // Gets Player Position
    playerY = GetPlayerPosZ();
    
    float playerXinRelationToChair = playerX - chairX; // Calculates distance from player to chair
    float playerZinRelationToChair = playerZ - chairZ;
    
    float forceMultiplier = 500; // may need to be higher or lower depending on how fast you want the chair to be
    
    AddPropForce("chair_nice01_1", playerXinRelationToChair * forceMultiplier f, 0.0f, playerZinRelationToChair * forceMultiplier f, "World"); // pushes chair towards player
}

func_StopChase(string &in asParent, string &in asChild, int alState)
{
    RemoveTimer("timer_Chair"); // stops chair event
}
// END SPOOOK C //
//////////////////
*/
void OnStart()
{
    
//These just announce which room you're in
    
AddEntityCollideCallback("Player""announce_blockpath""func_Announce1"false1);
    
AddEntityCollideCallback("Player""announce_asenemy""func_Announce2"false1);
    
AddEntityCollideCallback("Player""announce_playerandchair""func_Announce3"false1);
    
    
//These start the chair events
    
AddEntityCollideCallback("Player""area_triggerchairA""func_ChairA"true1);
    
AddEntityCollideCallback("Player""area_triggerchairB""func_ChairB"true1);
    
AddEntityCollideCallback("Player""area_triggerchairC""func_ChairC"true1);
}
void OnEnter()
{

}
void OnLeave()
{






RE: How do I make a chair move? - goodcap - 12-10-2016

(12-10-2016, 08:58 PM)CarnivorousJelly Wrote: I tried to make a map to display the three techniques, third one is currently broken and I don't know enough about the script to fix it, second one is noisy. I know there's a way to shut off music for the enemies and disable insanity effects but heck if I can remember!

Everything's in the file attached to this post, script is below in the spoilers
Spoiler below!

PHP Code:
// Variable declaration for chair and player position
float playerX;
float playerZ;
float chairX;
float chairZ;

/////////////////////////
// START ANNOUNCEMENTS //
void func_Announce1(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""BlockPath"0.0f);
}
void func_Announce2(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""AsEnemy"0.0f);
}
void func_Announce3(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""PlayerAndChair"0.0f);
}
// END ANNOUNCEMENTS //
///////////////////////

///////////////////
// CHAIR SPOOK A //
void func_ChairA(string &in asParentstring &in asChildint alState)
{
    
AddPropForce("chair_nice01_1"2000.0f0.0f0.0f"World"); // pushes chair along X axis towards door
}
// END SPOOK A //
/////////////////

///////////////////
// CHAIR SPOOK B //
void func_ChairB(string &in asParentstring &in asChildint alState)
{
    
SetEnemyDisableTriggers("chair_mean01_1"false);
    
AddEntityCollideCallback("Player""announce_playerandchair""func_DisableEnemy"false1); // stops enemy chasing when player leaves area
}
void func_DisableEnemy(string &in asParentstring &in asChildint alState)
{
    
SetEnemyDisableTriggers("chair_mean01_1"true);
}
// END SPOOK B //
/////////////////
/*
///////////////////
// CHAIR SPOOK C //
void func_ChairC(string &in asParent, string &in asChild, int alState)
{
    TimerPushLoop("timer_Chair"); // start pushing loop
    AddEntityCollideCallback("Player", "area_triggerchairC", "func_StopChase", false, 1); // make a way to stop loop
}

void TimerPushLoop(string &in asTimer)
{
    AddTimer(asTimer, 0.1f, "TimerPushLoop");
    NudgeChairTowardsPlayer();
}

void NudgeChairTowardsPlayer()
{
    chairX = GetEntityPosX("chair_nice01_3"); // Gets chair position
    chairY = GetEntityPosZ("chair_nice01_3");
    playerX = GetPlayerPosX(); // Gets Player Position
    playerY = GetPlayerPosZ();
    
    float playerXinRelationToChair = playerX - chairX; // Calculates distance from player to chair
    float playerZinRelationToChair = playerZ - chairZ;
    
    float forceMultiplier = 500; // may need to be higher or lower depending on how fast you want the chair to be
    
    AddPropForce("chair_nice01_1", playerXinRelationToChair * forceMultiplier f, 0.0f, playerZinRelationToChair * forceMultiplier f, "World"); // pushes chair towards player
}

func_StopChase(string &in asParent, string &in asChild, int alState)
{
    RemoveTimer("timer_Chair"); // stops chair event
}
// END SPOOOK C //
//////////////////
*/
void OnStart()
{
    
//These just announce which room you're in
    
AddEntityCollideCallback("Player""announce_blockpath""func_Announce1"false1);
    
AddEntityCollideCallback("Player""announce_asenemy""func_Announce2"false1);
    
AddEntityCollideCallback("Player""announce_playerandchair""func_Announce3"false1);
    
    
//These start the chair events
    
AddEntityCollideCallback("Player""area_triggerchairA""func_ChairA"true1);
    
AddEntityCollideCallback("Player""area_triggerchairB""func_ChairB"true1);
    
AddEntityCollideCallback("Player""area_triggerchairC""func_ChairC"true1);
}
void OnEnter()
{

}
void OnLeave()
{




The first one was exactly what I was looking for. Thanks a lot dude. I was about to pull my hairs out of frustration. In your test level the chair falls over, but in mine it does not and just moves itself in front of the player to block it's path.


Thanks, guys <3


RE: How do I make a chair move? - Spelos - 12-11-2016

(12-10-2016, 06:05 PM)CarnivorousJelly Wrote: Spelos, you'd want the X and Z coordinates. Y is vertical in HPL2

You're right, thanks.



(12-10-2016, 08:58 PM)CarnivorousJelly Wrote: I tried to make a map to display the three techniques, third one is currently broken and I don't know enough about the script to fix it, second one is noisy. I know there's a way to shut off music for the enemies and disable insanity effects but heck if I can remember!

Everything's in the file attached to this post, script is below in the spoilers
Spoiler below!

PHP Code:
// Variable declaration for chair and player position
float playerX;
float playerZ;
float chairX;
float chairZ;

/////////////////////////
// START ANNOUNCEMENTS //
void func_Announce1(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""BlockPath"0.0f);
}
void func_Announce2(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""AsEnemy"0.0f);
}
void func_Announce3(string &in asParentstring &in asChildint alState)
{
    
SetMessage("Hints""PlayerAndChair"0.0f);
}
// END ANNOUNCEMENTS //
///////////////////////

///////////////////
// CHAIR SPOOK A //
void func_ChairA(string &in asParentstring &in asChildint alState)
{
    
AddPropForce("chair_nice01_1"2000.0f0.0f0.0f"World"); // pushes chair along X axis towards door
}
// END SPOOK A //
/////////////////

///////////////////
// CHAIR SPOOK B //
void func_ChairB(string &in asParentstring &in asChildint alState)
{
    
SetEnemyDisableTriggers("chair_mean01_1"false);
    
AddEntityCollideCallback("Player""announce_playerandchair""func_DisableEnemy"false1); // stops enemy chasing when player leaves area
}
void func_DisableEnemy(string &in asParentstring &in asChildint alState)
{
    
SetEnemyDisableTriggers("chair_mean01_1"true);
}
// END SPOOK B //
/////////////////
/*
///////////////////
// CHAIR SPOOK C //
void func_ChairC(string &in asParent, string &in asChild, int alState)
{
    TimerPushLoop("timer_Chair"); // start pushing loop
    AddEntityCollideCallback("Player", "area_triggerchairC", "func_StopChase", false, 1); // make a way to stop loop
}

void TimerPushLoop(string &in asTimer)
{
    AddTimer(asTimer, 0.1f, "TimerPushLoop");
    NudgeChairTowardsPlayer();
}

void NudgeChairTowardsPlayer()
{
    chairX = GetEntityPosX("chair_nice01_3"); // Gets chair position
    chairY = GetEntityPosZ("chair_nice01_3");
    playerX = GetPlayerPosX(); // Gets Player Position
    playerY = GetPlayerPosZ();
    
    float playerXinRelationToChair = playerX - chairX; // Calculates distance from player to chair
    float playerZinRelationToChair = playerZ - chairZ;
    
    float forceMultiplier = 500; // may need to be higher or lower depending on how fast you want the chair to be
    
    AddPropForce("chair_nice01_1", playerXinRelationToChair * forceMultiplier f, 0.0f, playerZinRelationToChair * forceMultiplier f, "World"); // pushes chair towards player
}

func_StopChase(string &in asParent, string &in asChild, int alState)
{
    RemoveTimer("timer_Chair"); // stops chair event
}
// END SPOOOK C //
//////////////////
*/
void OnStart()
{
    
//These just announce which room you're in
    
AddEntityCollideCallback("Player""announce_blockpath""func_Announce1"false1);
    
AddEntityCollideCallback("Player""announce_asenemy""func_Announce2"false1);
    
AddEntityCollideCallback("Player""announce_playerandchair""func_Announce3"false1);
    
    
//These start the chair events
    
AddEntityCollideCallback("Player""area_triggerchairA""func_ChairA"true1);
    
AddEntityCollideCallback("Player""area_triggerchairB""func_ChairB"true1);
    
AddEntityCollideCallback("Player""area_triggerchairC""func_ChairC"true1);
}
void OnEnter()
{

}
void OnLeave()
{




If used, I highly suggest refactoring. Remove all the comments that state the obvious like //Gets player position --- Try explaining things though code as supposed to comments.


RE: How do I make a chair move? - CarnivorousJelly - 12-11-2016

The commenting's there so goodcap can understand what I've written without having to search the entire document and figure it out for himself. There's nothing wrong with stating the obvious if it helps someone learn!

Also your code - or rather my rendition of your code - didn't work, any suggestions as to why? I ended up having to comment out the section so it won't run in order to get the other two examples to work.


RE: How do I make a chair move? - Spelos - 12-12-2016

(12-11-2016, 09:38 PM)CarnivorousJelly Wrote: Also your code - or rather my rendition of your code - didn't work, any suggestions as to why? I ended up having to comment out the section so it won't run in order to get the other two examples to work.

Well, that's because you slightly butchered it.
PHP Code:
AddPropForce("chair_nice01_1"playerXinRelationToChair forceMultiplier f0.0fplayerZinRelationToChair forceMultiplier f"World"); 

second argument expected "," but found "f". [f is not defined]
fourth argument, same thing.

Remove the "f" from both of those.
1) You don't need to specify a type since both variables are floats.
2) That's not how you specify a type. Would be casting it, but not in .hps

After that, I think it should work. =)
Thank you for the reminder.


RE: How do I make a chair move? - CarnivorousJelly - 12-13-2016

Butchered it!? :p

I actually added those while trying to debug it and forgot to remove them before posting. Without the "f" the script still won't load or calls an error on line 76, column 15 (line 77 in this version due to the /* */ added in, no I didn't have the section commented out during testing)


RE: How do I make a chair move? - Spelos - 12-16-2016

Alright, I finally got to check the script. It seems that you forgot to change the playerY and chairY variable names to their Z variants when renaming.

I'm not going to stress this too much, but:
"chairY is not defined" is a very simple error, especially when it tells you the line.
But sure, happens to all of us.

Working script:
Spoiler below!

PHP Code:
float playerX;
float playerZ;
float chairX;
float chairZ;

void OnStart()
{
    
AddEntityCollideCallback("Player""test_area""TestFunction"false1);
}

void TestFunction(string &in asParentstring &in asChildint alState)
{
    
TimerPushLoop("timer_Chair");
}

void TimerPushLoop(string &in asTimer)
{
    
AddTimer(asTimer0.1f"TimerPushLoop");
    
NudgeChairTowardsPlayer();
    
// Add some kind of break so that the chair doesn't follow you forever.
    // Or perhaps don't. =)
}

void NudgeChairTowardsPlayer()
{
    
chairX GetEntityPosX("chair");
    
chairZ GetEntityPosZ("chair");
    
playerX GetPlayerPosX();
    
playerZ GetPlayerPosZ();
    
    
float playerXinRelationToChair playerX chairX;
    
float playerZinRelationToChair playerZ chairZ;
    
    
float forceMultiplier 500;
    
    
AddPropForce("chair"playerXinRelationToChair forceMultiplier0.0fplayerZinRelationToChair forceMultiplier"World");



I AM HAVING TOO MUCH FUN WITH THE SCRIPT!
[video=youtube]https://youtu.be/Y5QPm5jl9hE[/video]

Thanks again,


RE: How do I make a chair move? - Daemian - 12-16-2016

Lol, gj.