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
Problem with script
swamphag Offline
Junior Member

Posts: 2
Threads: 1
Joined: Aug 2012
Reputation: 0
#1
Problem with script

Hello everyone.

I am new to the amnesia level editor and today i was scripting, but when I tested out the script in game, it didn't work.. basically, I made a script so when I used a crowbar on a locked cabinet, it unlocked. When I try using the crowbar on it, it does become the crowbar joint, although when I try to move the joint to unlock it, it doesn't work. It just moves around, doing nothing.

Here is the code:




void OnStart()
{
AddUseItemCallback("", "crowbar_1", "cabinet_simple_1", "UsedCrowbarOnDoor", true);
AddEntityCollideCallback("crowbar_joint_1", "ScriptArea_1", "CollideAreaBreakDoor", true, 1);
}


void UsedCrowbarOnDoor(string &in asItem, string &in asEntity)
{
AddTimer("", 0.2, "TimerSwitchShovel");
RemoveItem("crowbar_1");
}


void TimerSwitchShovel(string &in asTimer)
{
PlaySoundAtEntity("","puzzle_place_jar.snt", "", 0, false);
SetEntityActive("crowbar_joint_1", true);
}


void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
AddPlayerSanity(25);
PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
SetSwingDoorLocked("cabinet_simple_1", false, true);
AddPropImpulse("cabinet_simple_1", 0, 0, -50, "World");
SetSwingDoorDisableAutoClose("cabinet_simple_1", true);
SetSwingDoorClosed("cabinet_simple_1", false, false);
SetMoveObjectState("cabinet_simple_1", 1);
PlaySoundAtEntity("","break_wood_metal", "AreaBreakEffect", 0, false);
CreateParticleSystemAtEntity("", "ps_hit_wood", "AreaBreakEffect", false);
SetEntityActive("crowbar_joint_1", false);
SetLocalVarInt("Door", 1);
}


void OnEnter()
{
}


void OnLeave()
{
}


Also, whilst I'm here I want to ask, how do you put items (e.g lantern) inside a cabinet?
08-21-2012, 07:27 PM
Find
Robby Offline
Posting Freak

Posts: 2,549
Threads: 38
Joined: Jun 2009
Reputation: 47
#2
RE: Problem with script

(08-21-2012, 07:27 PM)swamphag Wrote: Hello everyone.

I am new to the amnesia level editor and today i was scripting, but when I tested out the script in game, it didn't work.. basically, I made a script so when I used a crowbar on a locked cabinet, it unlocked. When I try using the crowbar on it, it does become the crowbar joint, although when I try to move the joint to unlock it, it doesn't work. It just moves around, doing nothing.

Here is the code:




void OnStart()
{
AddUseItemCallback("", "crowbar_1", "cabinet_simple_1", "UsedCrowbarOnDoor", true);
AddEntityCollideCallback("crowbar_joint_1", "ScriptArea_1", "CollideAreaBreakDoor", true, 1);
}


void UsedCrowbarOnDoor(string &in asItem, string &in asEntity)
{
AddTimer("", 0.2, "TimerSwitchShovel");
RemoveItem("crowbar_1");
}


void TimerSwitchShovel(string &in asTimer)
{
PlaySoundAtEntity("","puzzle_place_jar.snt", "", 0, false);
SetEntityActive("crowbar_joint_1", true);
}


void CollideAreaBreakDoor(string &in asParent, string &in asChild, int alState)
{
AddPlayerSanity(25);
PlayMusic("10_puzzle01.ogg", false, 0.7, 0.1, 10, false);
SetSwingDoorLocked("cabinet_simple_1", false, true);
AddPropImpulse("cabinet_simple_1", 0, 0, -50, "World");
SetSwingDoorDisableAutoClose("cabinet_simple_1", true);
SetSwingDoorClosed("cabinet_simple_1", false, false);
SetMoveObjectState("cabinet_simple_1", 1);
PlaySoundAtEntity("","break_wood_metal", "AreaBreakEffect", 0, false);
CreateParticleSystemAtEntity("", "ps_hit_wood", "AreaBreakEffect", false);
SetEntityActive("crowbar_joint_1", false);
SetLocalVarInt("Door", 1);
}


void OnEnter()
{
}


void OnLeave()
{
}


Also, whilst I'm here I want to ask, how do you put items (e.g lantern) inside a cabinet?
I can't help with the script, but I can with the lantern though.

Just select the cabinet, "focus" on it (you know, make it appear on the center), zoom in so you're inside the cabinet, grab the lantern from the "items" section of the "Entities" bar, and place it in there. Use the option "Create on Surface" if necessary.

Infrequently active. Don't expect an immediate response. Best to contact me at a different locale. If I create a thread, expect me to be quite active.
08-21-2012, 07:37 PM
Website Find
swamphag Offline
Junior Member

Posts: 2
Threads: 1
Joined: Aug 2012
Reputation: 0
#3
RE: Problem with script

Thank you very much, Nemet.



Is there someone out there who could possibly help with the script?
08-21-2012, 07:40 PM
Find
Robby Offline
Posting Freak

Posts: 2,549
Threads: 38
Joined: Jun 2009
Reputation: 47
#4
RE: Problem with script

(08-21-2012, 07:40 PM)swamphag Wrote: Thank you very much, Nemet.



Is there someone out there who could possibly help with the script?
There is an alternate solution to this, but you might not like that. You could just try using the crowbar on the door, and it unlocks like with the key (but it plays that break sound). If the crowbar breaks, you spawn the broken crowbar pieces mid-air.

Like I said, you may not like it, but it is a better solution.

Infrequently active. Don't expect an immediate response. Best to contact me at a different locale. If I create a thread, expect me to be quite active.
08-21-2012, 07:44 PM
Website Find
Adny Offline
Posting Freak

Posts: 1,766
Threads: 6
Joined: Mar 2012
Reputation: 173
#5
RE: Problem with script

The script is fine, except under the function "TimerSwitchShovel", the line "PlaySoundAtEntity" doesn't have an entity to be played at, just the sound.

As for the crowbar part: you using the proper entity for the task? Are you using proper crowbar_joint, or one of the other crowbar entities? If you are and still have an issue, it is most likely 1 of 2 things:

-the placement of the crowbar in the door isn't right; make sure you don't have grid snap on when placing it. Getting the proper angle + amount inside of the door will take some time.

-the script area isn't close enough to collide with the crowbar; try moving it closer in the level editor.

Hope that helped.

I rate it 3 memes.
08-21-2012, 07:55 PM
Find
Robby Offline
Posting Freak

Posts: 2,549
Threads: 38
Joined: Jun 2009
Reputation: 47
#6
RE: Problem with script

(08-21-2012, 07:55 PM)andyrockin123 Wrote: The script is fine, except under the function "TimerSwitchShovel", the line "PlaySoundAtEntity" doesn't have an entity to be played at, just the sound.

As for the crowbar part: you using the proper entity for the task? Are you using proper crowbar_joint, or one of the other crowbar entities? If you are and still have an issue, it is most likely 1 of 2 things:

-the placement of the crowbar in the door isn't right; make sure you don't have grid snap on when placing it. Getting the proper angle + amount inside of the door will take some time.

-the script area isn't close enough to collide with the crowbar; try moving it closer in the level editor.

Hope that helped.
Yeah, just like he said. I wasn't sure about the script, so I didn't know how to help. But ^ sorted it out. +rep goes to him too.

Infrequently active. Don't expect an immediate response. Best to contact me at a different locale. If I create a thread, expect me to be quite active.
08-21-2012, 08:12 PM
Website Find




Users browsing this thread: 4 Guest(s)