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


Thread Rating:
  • 16 Vote(s) - 4.44 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Scripts Recollection
Arvaga Offline
Junior Member

Posts: 8
Threads: 1
Joined: Oct 2010
Reputation: 1
#1
Information  Scripts Recollection

Add an item to your inventory
Spoiler below!
GiveItem(name, type, subType, image, amount);
name: The name identifying your object.
type: The type of your object (not sure exactly for what, the game's inventory.hps always uses "Puzzle" as type).
subType: Here goes the name of your item in the .lang file (only what goes after the "ItemName_" part).
image: The name of the graphic to display in the menu, for default the graphics are in ".../redist/graphics/item/" (be sure to include the extension, .tga in this case)
amount: The amount to give? (in the game's inventory.hps the amount they used was always 0, dunno why)
Example:
GiveItem("handdrill", "Puzzle", "hand_drill", "hand_drill.tga", 0);
// To remove an item:
RemoveItem(name);
// To check if player has item (returns true or false)
HasItem(name);


Make a monster appear after a trigger (taken from this thread) by Kyle
Spoiler below!
void OnStart()
{
  AddEntityCollideCallback("Player" , "ScriptArea_1" , "MonsterFunc1" , true , 1);
}
void MonsterFunc1(string &in asParent , string &in asChild , int alState)
{
  SetEntityActive("servant_grunt" , true);
}
"ScriptArea_1" is the name of the script area where you collide which causes the monster to spawn.
"MonsterFunc1" is the name of the function used later on when you want to add to the script instead of it doing nothing.
"servant_grunt" is the name of the monster that spawns.
Remember to set the monster's entity to not active.

Make objects float by Frontcannon

Add entries to the Journal by mastersmith98

Force player to look somewhere by mastersmith98
Spoiler below!

StartPlayerLookAt(ScriptArea, viewacceleration, maxviewvelocity, onlook);
ScriptArea is the name of the area script you place in your map and where the player looks.
viewacceleration controls how fast the player looks.
maxviewvelocity controls the max speed the player looks.
onlook is a function you call when the player's view is centered on the target.
To stop the player from looking at a spot, call StopPlayerLookAt();
Example:
void TimerDoneLookAt(string &in asTimer)
{
  StopPlayerLookAt();
}

//When player starts the level, make him look at this spot.
void OnStart()
{
  // Function argument is empty since we don't want to call a function.
  StartPlayerLookAt("AreaLookAt", 2, 2, "");

  //Make the player look for 2.5 seconds
  AddTimer("donelook", 2.5f, "TimerDoneLookAt");
}


Make a locked door and a key to unlock it by Frontcannon
Spoiler below!

void OnStart()
{
    AddUseItemCallback("", "R01_Key1", "mansion_1", "KeyOnDoor", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("mansion_1", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "mansion_1", 0.0f, true);
}
What it does:
AddUseItemCallback - calls a function when an item is used on an entity
R01_Key1 - the item used, in this case our key
mansion_1 - the entity the key is used on, the normal mansion door
KeyOnDoor - the function the callback calls (true means to remove it when called once)

SetSwingDoorLocked - locks/unlocks a door, false means to set it NOT locked, and the true is to wether use effects or not
PlaySoundAtEntity - plays a sound at an entity, in this case the "unlocked a door"- sound at mansion_1, our door, the float value is the time it takes to fade in and the true is some strange boolean


Teleport player when he touches an area by house
Spoiler below!

void CollidePlayerTeleport(string &in asParent, string &in asChild, int alState)
{
   TeleportPlayer(teleport_name);
   // Optional fading effects to make a better teleporting transition.
   FadeOut(0);
   FadeIn(20);
}
-teleport_name: Name of what to teleport to, I recommend making another PlayerStartArea and giving the name of the extra player spawn.


Make a reusable function to unlock doors by Arvaga
Spoiler below!

// This function is to be called from an AddUseItemCallback function:
// AddUseItemCallback(callback_name, item_name, door_name, function, auto_destroy);
// Usage example: AddUseItemCallback("", "my_key", "my_door", "UnlockDoor", true);
void UnlockDoor(string &in asItem, string &in asEntity)
{
  // Unlock the entity asEntity (since it's the door we targeted)
  SetSwingDoorLocked(asEntity, false, true);
  // Optional sound effect for when our door opens.
  PlaySoundAtEntity("", "unlock_door", asEntity, 0, false);
  // Optional removal of the item used in the door.
  RemoveItem(asItem);
}


Make player float by anzki
Spoiler below!

Also you can make player float by:
AddPlayerBodyForce(float afX, float afY, float afZ, bool abUseLocalCoords);
Where float afX,float afY and float afZ are forces to X,Y,Z directions, and bool abUseLocalCoords is true or false if it should use LocalCoords, which is based on where player looks; where X is nothing, Y is right/left and Z is forward/backward. Also force is required to be high for player to move; ie. 2000 makes him move about 1 m.


Play a sound by anzki
Spoiler below!

Also you can add sound by using:
PlaySoundAtEntity(string& asSoundName, string& asSoundFile, string& asEntity, float afFadeTime, bool abSaveSound);
-Where string& asSoundName is name of a sound.(Can be left blank, unless you want it to loop, and later stop.
-string& asSoundFile is sound file; the file you want to be played.
-string& asEntity is entity you want it to be played.(For example "player" makes it play at player, but if you want the sound to be heard from elsewhere; let's say a piano called "piano1", you put that("piano1") there.
-float afFadeTime is time it should fade, for example 1.0f would put 1 second fade time.
-bool abSaveSound. I am not sure what this is Just set it to false.

And you can stop it by using:
StopSound(string& asSoundName, float afFadeTime);
-Where string& asSoundName is name of a sound(see above.)
-float afFadeTime; fade time, see above.


Add message by anzki
Spoiler below!

1.Make category to language file with any name you want to! Let's say category named:"Example". (To easily add this use HPLangtool found in the same folder as the level editor.)
2.Inside the category ("Example", or anything you have put it's name.) create entry with any name you want. Example; "Entry1".
3.Use this script where you want the message to be showed:
SetMessage(string &asTextCategory, string &asTextEntry, float afTime);
-string &asTextCategory and string &asTextEntry will be the name of a category and entry.
-float afTime will be the time the message is on screen in form; 1.0f(=1 second.)

Example using category "Example" and entry "Entry1", showing the entry for 20 seconds:
SetMessage("Example", "Entry1", 20.0f);


Make a lever functional by Arvaga
Spoiler below!

// Callback function for when the lever's state changes
// EntityName is the name of the lever
// alState is the current state of the lever, -1 being low, 0 middle and 1 high *
void OnLeverStateChange(string &in EntityName, int alState)
{
    // Do something when the state changes
        // Optional debug message
    AddDebugMessage(EntityName + "'s current state: " + alState, false);

    if (alState == -1)
    {
        // Do something if the lever's state is low (or change it to 0 or 1)
    }
}
// * low, middle and high are relative to its rotation.
In the lever's entity properties write the function to "ConnectionStateChangeCallback", in this case you should write "OnLeverStateChange".

Functions List

Anything helps, even if it's just as basic as a single line of code (like adding an item to your inventory).
(This post was last modified: 11-11-2010, 05:30 PM by Arvaga.)
10-20-2010, 02:57 AM
Find
mastersmith98 Offline
Junior Member

Posts: 21
Threads: 3
Joined: Oct 2010
Reputation: 0
#2
RE: Scripts Recollection

I wrote a tutorial on how to create diaries and such on the wiki, http://hpl2.frictionalgames.com/tutorial...omakenotes, and I'd be open to any suggestions that would help improve it.

The problem is that with most of these things you can pretty easily understand how to do them if you look at the wiki pages and frictional's own work. Things like playing music or sounds are fairly simple. But I'd agree that we could use some more general purpose tutorials, like tutorials on how to make keys unlock doors, to help people completely unfamiliar with any of this get ahead.

Join the Amnesia Modders group on Moddb!
10-20-2010, 05:59 AM
Find
Kyle Offline
Posting Freak

Posts: 911
Threads: 36
Joined: Sep 2010
Reputation: 7
#3
RE: Scripts Recollection

I've been wondering how to force the player to look somewhere... Smile

10-20-2010, 12:01 PM
Find
Vincent Offline
Member

Posts: 91
Threads: 7
Joined: Jul 2010
Reputation: 0
#4
RE: Scripts Recollection

Would be a great idea!

I'm pretty experienced with the Level Editor, but I can't script AT ALL!

So it would be much appreciated!

[Image: 14014353645647cc447974.gif]
10-20-2010, 01:05 PM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#5
RE: Scripts Recollection

Some simple functions covering the basics for the people being completely new to scripting?
Let's see what I can find..

How to make a locked door and a key to unlock it

Spoiler below!

void OnStart()
{
    AddUseItemCallback("", "R01_Key1", "mansion_1", "KeyOnDoor", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked("mansion_1", false, true);
    PlaySoundAtEntity("", "unlock_door.snt", "mansion_1", 0.0f, true);
}

What it does:
AddUseItemCallback - calls a function when an item is used on an entity
R01_Key1 - the item used, in this case our key
mansion_1 - the entity the key is used on, the normal mansion door
KeyOnDoor - the function the callback calls (true means to remove it when called once)

SetSwingDoorLocked - locks/unlocks a door, false means to set it NOT locked, and the true is to wether use effects or not
PlaySoundAtEntity - plays a sound at an entity, in this case the "unlocked a door"- sound at mansion_1, our door, the float value is the time it takes to fade in and the true is some strange boolean Big Grin



╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
10-20-2010, 02:20 PM
Find
mastersmith98 Offline
Junior Member

Posts: 21
Threads: 3
Joined: Oct 2010
Reputation: 0
#6
RE: Scripts Recollection

Here's the function you use to make a player look at a spot

StartPlayerLookAt(ScriptArea, viewacceleration, maxviewvelocity, onlook);
ScriptArea is the name of the area script you place in your map and where the player looks

viewacceleration controls how fast the player looks

maxviewvelocity controls the max speed the player looks

onlook is a function you call when the player's view is centered on the target.

To stop the player from looking at a spot, call StopPlayerLookAt();

So A quick example of how you would make the player look at a spot for a few seconds.

Note: ** just means we don't want a function called.

void TimerDoneLookAt(string &in asTimer)
{
StopPlayerLookAt();
}

//When player starts the level, make him look at this spot.
void OnStart()
{
StartPlayerLookAt("AreaLookAt", 2, 2, **);

//Make the player look for 2.5f seconds
AddTimer("donelook", 2.5f, "TimerDoneLookAt");
}

Join the Amnesia Modders group on Moddb!
10-20-2010, 10:18 PM
Find
Arvaga Offline
Junior Member

Posts: 8
Threads: 1
Joined: Oct 2010
Reputation: 1
#7
RE: Scripts Recollection

This is great, thanks.
Keep 'em coming, I'll keep this thread updated.

BTW should I change the subject? To something like: "How to... Compilation" or something more descriptive.

And what would be a good way to organize scripts? Alphabetically? (Somewhat weak).
I say lets categorize each script.
I dont know... something like:
Item Related
Monster Related
Player Related

or

Basic
Intermediate
Advanced

So how should I categorize the scripts?

Visit the scripts recollection thread to find scripts for your custom stories.
10-20-2010, 11:03 PM
Find
Alex7754 Offline
Member

Posts: 75
Threads: 6
Joined: Oct 2010
Reputation: 0
#8
RE: Scripts Recollection

I need to know how to make it so when you enter an area a sound or song starts playing, Im also trying to figure out how to make it so you can examine the environment "example- clicking on a bookshelf would display a description, something like "Its a bookshelf, It seems to be very old". Like in the penumbra games. Thanks
10-20-2010, 11:54 PM
Find
Frontcannon Offline
Senior Member

Posts: 538
Threads: 10
Joined: Jul 2010
Reputation: 2
#9
RE: Scripts Recollection

(10-20-2010, 11:54 PM)Alex7754 Wrote: I need to know how to make it so when you enter an area a sound or song starts playing, Im also trying to figure out how to make it so you can examine the environment "example- clicking on a bookshelf would display a description, something like "Its a bookshelf, It seems to be very old". Like in the penumbra games. Thanks

Look for MulleDK19's area trigger tutorial on the Wiki, you should be able to change the necessary lines of codes yourself.

The Penumbra Examine feature is great, you just have to make an examine area and create a fitting entry for it in the extra_eng.lang file. A tutorial on that is in the workings..

(10-20-2010, 10:18 PM)mastersmith98 Wrote:
StartPlayerLookAt(ScriptArea, viewacceleration, maxviewvelocity, onlook);

The line of code in the Wiki is different ._.

void  StartPlayerLookAt(string& asEntityName, float afSpeedMul, float afMaxSpeed, string &asAtTargetCallback)


╔═════════════════╗
☺ Smoke weed everyday ☺
╚═════════════════╝
10-21-2010, 01:35 AM
Find
The worst submarine Offline
Junior Member

Posts: 11
Threads: 2
Joined: Oct 2010
Reputation: 0
#10
RE: Scripts Recollection

(10-21-2010, 01:35 AM)Frontcannon Wrote:
(10-20-2010, 10:18 PM)mastersmith98 Wrote:
StartPlayerLookAt(ScriptArea, viewacceleration, maxviewvelocity, onlook);

The line of code in the Wiki is different ._.

void  StartPlayerLookAt(string& asEntityName, float afSpeedMul, float afMaxSpeed, string &asAtTargetCallback)

Smith's code is simplified. I understand it better then the wiki's, even though the wiki's is technically more correct.
10-21-2010, 02:54 AM
Find




Users browsing this thread: 2 Guest(s)