Frictional Games Forum (read-only)

Full Version: Scripts Recollection
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3 4 5 6 7 8 9 10 11 12
Whats would be the script for making the player look at something and give sanity damage when he enters an area??
void OnStart()
{
AddEntityCollideCallback("Player", "AreaSanity", "CollideAreaSanity", true, 1);
}

void CollideAreaSanity(string &in asParent, string &in asChild, int alState)
{
StartPlayerLookAt("objectname", 2.0f, 2.0f, "");
GiveSanityDamage(50.0f, true);
AddTimer("xyz", 1.0f, "TimerStopLookAt");
}

void TimerStopLookAt(string &in asTimer)
{
StopPlayerLookAt();
}
(02-26-2011, 05:28 PM)Ongka Wrote: [ -> ]void OnStart()
{
AddEntityCollideCallback("Player", "AreaSanity", "CollideAreaSanity", true, 1);
}

void CollideAreaSanity(string &in asParent, string &in asChild, int alState)
{
StartPlayerLookAt("objectname", 2.0f, 2.0f, "");
GiveSanityDamage(50.0f, true);
AddTimer("xyz", 1.0f, "TimerStopLookAt");
}

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

Much Appreciated
(02-26-2011, 05:28 PM)Ongka Wrote: [ -> ]void OnStart()
{
AddEntityCollideCallback("Player", "AreaSanity", "CollideAreaSanity", true, 1);
}

void CollideAreaSanity(string &in asParent, string &in asChild, int alState)
{
StartPlayerLookAt("objectname", 2.0f, 2.0f, "");
GiveSanityDamage(50.0f, true);
AddTimer("xyz", 1.0f, "TimerStopLookAt");
}

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

If I were to add a sound would I add

PlaySoundAtEntity("", "Sound_3", "player", 0.5f, false);

under

AddTimer("xyz", 1.0f, "TimerStopLookAt");

I'm a newbe to this...
(02-26-2011, 05:49 PM)Zinnkio Wrote: [ -> ]If I were to add a sound would I add

PlaySoundAtEntity("", "Sound_3", "player", 0.5f, false);

under

AddTimer("xyz", 1.0f, "TimerStopLookAt");

I'm a newbe to this...

if you want the sound to be played when you're done whith looking at the object, you should put it under AddTimer.
When you want the sound to be played when the player is looking at the object, you should put it under CollideAreaSanit.
If I were to add a sound would I add

PlaySoundAtEntity("", "Sound_3", "player", 0.5f, false);

under

AddTimer("xyz", 1.0f, "TimerStopLookAt");

I'm a newbe to this...
[/quote]

if you want the sound to be played when you're done whith looking at the object, you should put it under AddTimer.
When you want the sound to be played when the player is looking at the object, you should put it under CollideAreaSanit.
[/quote]

All sorted, thanks anyway. Any Feedback on my Test.map would be great.
[attachment=1120]
I changed Subitemname on the key but I couldn't do it on the door.
But then when I load the Story this comes up:

FATAL ERROR: Could not load script file 'custom_stories/***/maps/***.hps'! main (21, 1) : ERR : Unexpected token '{'.

And this is how my script looks like:
{
AddUseItemCallback("", "key_prison_1", "prison_section_plain_6", "KeyOnDoor", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("prison_section_plain_6", true);
PlaySoundAtEntity("", "unlock_door.snt", "prison_section_plain_6", 0.0f, true);
}
I suppose its OnStart() or OnEnter()?
Did it Worked before?
No, I haven't gotten it to work at all
OnStart()
{
AddUseItemCallback("", "key_prison_1", "prison_section_plain_6", "KeyOnDoor", true);
}

void KeyOnDoor(string &in asItem, string &in asEntity)
{
SetSwingDoorLocked("prison_section_plain_6", true);
PlaySoundAtEntity("", "unlock_door.snt", "prison_section_plain_6", 0.0f, true);
}
The { and } encompass a body of a function - the function body is where you put all the work that needs to be done.
The { and } obviously need to match.

This is preceded by a function signature, comprising of:
return_type FunctionName(parameter_list)
where parameter_list may be empty.

So, whenever you get a similar error (unexpected token '{'), you either have an extra (or a few extra) of { or }, or as in your case, you have a missing function signature.

The previous posters most likely guessed the candidate methods correctly, since you would typically assign callback functions for this type of events in OnStart() or OnEnter().

Except for one thing: you should type
void OnStart()
{
// whatever...
}


BTW, can someone more experienced with HPL2 scripting tell me what is the key difference between OnStart() and OnEnter(), their descriptions are a little vague?
When is OnStart() called? When the level is first loaded? Just once?
And OnEnter() - is it called every time the player comes back to the level?
What?
Pages: 1 2 3 4 5 6 7 8 9 10 11 12