Frictional Games Forum (read-only)

Full Version: Question about scripting
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Right, so I was just wondering what scripting language Frictional used for Amnesia. Is it an in-house (built from scratch) language or is it based on some other language such as C and its counterparts? I've been trying to get into the scripting part of modding and I've done well this far but I've hit a snag it seems due to my inexperience in scripting

so I'm creating an encounter with a grunt that triggers when you try to open a door to an area

this is what I have in the OnStart() function. Some of the default stuff is from the Tools wiki and most of the actual encounter code I borrowed off of this post http://www.frictionalgames.com/forum/thr...l#pid36726

Quote:void OnStart()

SetEntityPlayerInteractCallback("castle_02", "FunctionToCall", true);

void FunctionToCall()
{
PlaySoundAtEntity("grunt_encounter", "/sounds/enemy/grunt/enabled02.ogg", castle, 0, false);
SetEntityActive("servant_grunt", true);


if(ScriptDebugOn())
{
GiveItemFromFile("lantern", "lantern.ent");

for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
}
}


void OnEnter()
{

}


void OnLeave()
{

}

It looks fine to me however when I try to compile/recompile the script in-game I get an "ERR: (3,1) Expected ',' or ";"" error. An answer to my question and to my problem would be appreciated, thanks.
(09-17-2010, 03:08 AM)w 1 z Wrote: [ -> ]It looks fine to me however when I try to compile/recompile the script in-game I get an "ERR: (3,1) Expected ',' or ";"" error. An answer to my question and to my problem would be appreciated, thanks.

You're missing a few brackets.

Instead of:
Code:
void OnStart()

SetEntityPlayerInteractCallback("castle_02", "FunctionToCall", true);

Do this:
Code:
void OnStart()
{
SetEntityPlayerInteractCallback("castle_02", "FunctionToCall", true);
}
Well it fixed that issue but now for some reason the script is somehow disabled ie: it's not giving the lantern and tinderboxes now when I'm in Script debug mode and the encounter won't trigger with opening the door. The script compiles with no errors displaying on screen and in the debug messages the function isn't being called so there's something up

Here's how it is now

Code:
void OnStart()
{
SetEntityPlayerInteractCallback("castle_2", "FunctionToCall", true);
}
void FunctionToCall(string &in entity)
{
PlaySoundAtEntity("grunt_encounter", "/sounds/enemy/grunt/enabled02.ogg", "castle", 0, false);
SetEntityActive("servant_grunt", true);

    if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");

        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
    }
}


void OnEnter()
{

}


void OnLeave()
{

}

Ok, the debug command for adding the lantern and tinderboxes is working now but there's still a problem. It's a little bit delayed for something which I'm not really worried about but the part I'm worried about is that the encounter still isn't triggering. I've looked over what I linked it to and it looks like everything should be in order. I might be missing a function or something somewhere.
Code:
if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");

        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
    }
This section of your code needs to be inside of void OnStart()


EDIT: I'll just post my new problem here.

I made a script to make a particle system appear and play a few sounds, as well as drain sanity, and now whenever I try to launch the game it says ERR: Unexpected end of file.

My .hps file ends normally, with
Code:
void OnLeave()
{

}

Anyone know why it's saying this?
(09-17-2010, 04:36 AM)Armored Cow Wrote: [ -> ]
Code:
if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");

        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
    }
This section of your code needs to be inside of void OnStart()

It worked before like the way I had it but instead of the command giving the things when you load the level it gives you them when you open the door that I set to trigger the encounter to start with and the encounter doesn't start at all.

Well for the time being I just moved the give lantern/tinderboxes commands down to void OnEnter() for the time being. There's still something up with the encounter trigger because even with the script debugon() removed it still won't trigger the encounter.

Alright, I narrowed it down. I added a GiveSanityDamage line to encounter function and when I opened the door it worked...Sort of. There's something going on with the other lines of code up there that I think I might've messed up or I'm missing a call for it somewhere.
So bascially thins happen when you interact with the door? So that means the function works but there is no enemy activated or sound played?

First, you do not need to play the sound for the enemy to enable, it will automatically play that sound when an enemy is activated. So remove that line.

Then as for SetEntityActive("servant_grunt", true); make sure that the enemy really is called "servant_grunt" in the level editor, if you have not renamed him it is more likely that the name is "servant_grunt_1". Also make sure that the enemy has the Active box unchecked, so that he really only activates when you interact with the door.
(09-17-2010, 07:11 AM)jens Wrote: [ -> ]So bascially thins happen when you interact with the door? So that means the function works but there is no enemy activated or sound played?

First, you do not need to play the sound for the enemy to enable, it will automatically play that sound when an enemy is activated. So remove that line.

Then as for SetEntityActive("servant_grunt", true); make sure that the enemy really is called "servant_grunt" in the level editor, if you have not renamed him it is more likely that the name is "servant_grunt_1". Also make sure that the enemy has the Active box unchecked, so that he really only activates when you interact with the door.

Yeah I figured this out by poking around a few of scripts in the official maps. I got it to work and I removed that line. Thanks.
I'm still having the problem of the "Unexpected end of file" error whenever I try to load the game(map).

I don't know what to do, and I can't test anything until I fix it Sad
Add the whole file so we can see where the error is. I am guessing there is missing or too many { } so it does not open and close evenly.
Code:
////////////////////////
// Run first time starting map
void OnStart()
{
    //Begin ambient music
    PlayMusic("04_amb.ogg", true, 0.5, 3, 0, true);
    
    //Callback to sound steps and door slam
    AddEntityCollideCallback("Player", "area_door_slam", "CollideDoorSlam", true, 1);
    
    //Callback to disable ambient music
    AddEntityCollideCallback("Player", "area_end", "CollideEnd", true, 1);
    
    //Callback to create smoke monster
    AddEntityCollideCallback("Player", "area_smoke_trigger", "CollideSmoke", true, 1);
    
    //Key1
    AddUseItemCallback("", "key_study", "door_1", "UseKey", true);
    
    //Key2
    AddUseItemCallback("", "key_study2", "door_2", "UseKey", true);

    //Free Lantern and Tinderboxes
    if(ScriptDebugOn())
    {
        GiveItemFromFile("lantern", "lantern.ent");
        
        for(int i=0;i<10;i++) GiveItemFromFile("tinderbox_"+i, "tinderbox.ent");
    }
}

////////////////////////
//Function called when using a key that unlocks the door
void UseKey(string &in asItem, string &in asEntity)
{
    SetSwingDoorLocked(asEntity, false, true);

    RemoveItem(asItem);
}

//This function is called when the player steps into area_smoke_trigger
void CollideSmoke(string &in asParent, string &in asChild, int alState)
{
    CreateParticleSystemAtEntity("", "ps_cloud_thing02.ps", "area_smoke", false);    
    
    PlaySoundAtEntity("", "13_machine_fail.snt", "area_smoke", 0, false);    
    
    PlaySoundAtEntity("", "sanity_pant1.snt, "Player", 0, false);    
    
    GiveSanityDamage(15.0f, true);
}

//This function is called when the player steps into area_door_slam
void CollideDoorSlam(string &in asParent, string &in asChild, int alState)
{
    PlaySoundAtEntity("walking", "04_big_feet.snt", "AreaSFX", 0, false);
    
    AddTimer("10_close_door.snt", 9.3f, "TimerSoundSequence");
}

void TimerSoundSequence(string &in asTimer)
{
    PlaySoundAtEntity("sound_1", "10_close_door.snt", "AreaSFX", 0, false);
}

//This function is called by area_end and disables ambient music
void CollideEnd(string &in asParent, string &in asChild, int alState)
{
    StopMusic(3, 0);
}

////////////////////////
// Run when entering map
void OnEnter()
{

}

////////////////////////
//Run when leaving map
void OnLeave()
{

}
Pages: 1 2