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 How do I make a chair move?
goodcap Offline
Member

Posts: 193
Threads: 112
Joined: Jun 2012
Reputation: 3
#11
RE: How do I make a chair move?

(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.
(This post was last modified: 12-10-2016, 08:57 PM by goodcap.)
12-10-2016, 08:08 PM
Find
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#12
RE: How do I make a chair move?

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





Attached Files
.zip   movingchairtest.zip (Size: 767.66 KB / Downloads: 113)

[Image: quote_by_rueppells_fox-d9ciupp.png]
12-10-2016, 08:58 PM
Find
goodcap Offline
Member

Posts: 193
Threads: 112
Joined: Jun 2012
Reputation: 3
#13
RE: How do I make a chair move?

(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: (Select All)
// 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
12-10-2016, 09:17 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#14
RE: How do I make a chair move?

(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: (Select All)
// 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.
(This post was last modified: 12-11-2016, 09:04 AM by Spelos.)
12-11-2016, 09:00 AM
Find
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#15
RE: How do I make a chair move?

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.

[Image: quote_by_rueppells_fox-d9ciupp.png]
12-11-2016, 09:38 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#16
RE: How do I make a chair move?

(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: (Select All)
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.
12-12-2016, 08:19 PM
Find
CarnivorousJelly Offline
Posting Freak

Posts: 1,196
Threads: 41
Joined: Dec 2012
Reputation: 80
#17
RE: How do I make a chair move?

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)

[Image: quote_by_rueppells_fox-d9ciupp.png]
(This post was last modified: 12-13-2016, 03:38 PM by CarnivorousJelly.)
12-13-2016, 03:38 PM
Find
Spelos Away
Banned

Posts: 231
Threads: 19
Joined: Sep 2014
#18
RE: How do I make a chair move?

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: (Select All)
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,
12-16-2016, 09:36 AM
Find
Daemian Offline
Posting Freak

Posts: 1,129
Threads: 42
Joined: Dec 2012
Reputation: 49
#19
RE: How do I make a chair move?

Lol, gj.

12-16-2016, 06:01 PM
Find




Users browsing this thread: 1 Guest(s)