Frictional Games Forum (read-only)
Scripting n00b in need of help. - Printable Version

+- Frictional Games Forum (read-only) (https://www.frictionalgames.com/forum)
+-- Forum: Amnesia: The Dark Descent (https://www.frictionalgames.com/forum/forum-6.html)
+--- Forum: Custom Stories, TCs & Mods (https://www.frictionalgames.com/forum/forum-35.html)
+--- Thread: Scripting n00b in need of help. (/thread-5425.html)

Pages: 1 2 3


Scripting n00b in need of help. - Akumasama - 11-13-2010

So I've done some action scripting (Flash), but not C++.
I see some stuff thats done the same way, but for the most part, I'm just confused.

So what I tried to make, was that when you walk in an area, a zombie spawns and walks into a door and then disappears.

I've gotten to the part that it spawns (I just place it down, but I'm not sure how to spawn it), and that it walks to the desired node I made.
The grunt automatically disappears as it should, so thats good Big Grin

Code:
void OnStart()
{  
   GiveItemFromFile("lantern", "lantern.ent");

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

void OnEnter()
{
AddEntityCollideCallback("Player", "scaretrigger", "scareactivate", true, 1);
AddEnemyPatrolNode("scaremonster", "scaremonsterpath1", 0, "");
}

void OnLeave()
{

}

I started out with the basic starting code, or however it was called Tongue
I'm going to delete the code of the tinderboxes and lantern later on when I'm going to do some actual play-testing.
I understand the code of the starting items a bit, except "int i=0;i<10;i++". What do the ";" mean in C++?

"scaretrigger" = the area I made in which it triggers. I've used the Area tool with the Script option...
"scareactivate" = the boolean that is created? If someone would explain this to me, I'd be gratefull.
"scaremonster" = the grunt, who is activated in the map editor.
"scaremonsterpath1" = the node where scaremonster walks to.

What I need now, is a way to trigger the monster to spawn and walk to "scaremonsterpath1".

I've searched through the forum, but I didnt get a real proper explaination of how it actually works. This might also be because I'm a real newbie to C++ though.

I've got the script functions from the wikipedia.
From what I've seen and done up to now, I understand that "string& asXXXX" is basically the name of an object/function?

Thanks in advance.


RE: Scripting n00b in need of help. - Cellrage - 11-13-2010

First, you should move your CollideCallback into the OnStart function.

Then, make a new function, (Not inside the OnStart, OnEnter, or OnLeave), which should look like:

Code:
void scareactivate(string &in asParent, string &in asChild, int alState)
{
}

Then you put whatever it is you want to be activated inside those brackets.

Your finished code should look something like this:
Code:
void OnStart()
{  
   GiveItemFromFile("lantern", "lantern.ent");

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

AddEntityCollideCallback("Player", "scaretrigger", "scareactivate", true, 1);
}

void scareactivate(string &in asParent, string &in asChild, int alState)
{
SetEntityActive("scaremonster", true);
AddEnemyPatrolNode("scaremonster", "scaremonsterpath1", 0, "");
}

Don't forget to set the monster to inactive in the level editor.


RE: Scripting n00b in need of help. - Akumasama - 11-13-2010

Quote:void scareactivate(string &in asParent, string &in asChild, int alState)

I'm not sure how this part works... Care to explain?

And now that I read it like this, when you start with void, bool, float or int, you create a new fuction. Correct?


RE: Scripting n00b in need of help. - Gamemakingdude - 11-13-2010

(11-13-2010, 01:54 AM)Akumasama Wrote:
Quote:void scareactivate(string &in asParent, string &in asChild, int alState)

I'm not sure how this part works... Care to explain?

And now that I read it like this, when you start with void, bool, float or int, you create a new fuction. Correct?

Nope. void creates an new function.

bool, float, int, string are variable types.

you put what you want for the proc under that proc.


RE: Scripting n00b in need of help. - Chilton - 11-13-2010

Ok, lets start simply. void creates a new function.

Anything in OnStart is a function that will either need to be detailed in its own void, or finalized right there in OnStart.

OnEnter are things that happen every time you enter an area.

OnLeave is every time you leave.

http://wiki.frictionalgames.com/hpl2/amnesia/script_functions
Should help a bit, but you just need to think of XML as being a ladder. You place the top of the ladder, then you need to fill in the missing rungs right down to the bottom. This can be hard to learn, but its easy once you know how its done.

Also, the community will assist you if you need a particular script written, as long as it isnt too complicated.

Also, the actual games scripts can make an excellent point of reference
Best of luck


RE: Scripting n00b in need of help. - Akumasama - 11-13-2010

I had that link you posted in my bookmarks, it's also where I got the script functions from which I used in my first post. Smile

Also, thanks for the explanation guys!

But I still don't really understand this part:
Code:
void scareactivate(string &in asParent, string &in asChild, int alState)

I'm not sure what they mean with the "string &in asXXXX" part...


RE: Scripting n00b in need of help. - Chilton - 11-13-2010

(11-13-2010, 01:56 PM)Akumasama Wrote: I had that link you posted in my bookmarks, it's also where I got the script functions from which I used in my first post. Smile

Also, thanks for the explanation guys!

But I still don't really understand this part:
Code:
void scareactivate(string &in asParent, string &in asChild, int alState)

I'm not sure what they mean with the "string &in asXXXX" part...

Its a syntax - You do not touch it. You put functions BELOW it, and the syntax makes them possible.


RE: Scripting n00b in need of help. - Akumasama - 11-13-2010

Mmmm...
Why may you not change the "scareactivate" syntax, but you may change the "AddEntityCollideCallback"?

How would I know what strings I have to place in the "scaretrigger" or similar functions?

Sorry if I sound dumb, but its my first script, really. Tongue


RE: Scripting n00b in need of help. - Chilton - 11-13-2010

We all start from somewere. I was just fortunate to know XML already Smile
The function is the name of the function itself - As in, you say AddEntityCollideCallback, then what you want it to affect and what you want it to do.

But scareactivate is the name of a result.

As in, Say you make a script zone. We're calling it Origin.
AddEntityCollideCallback("Player", "Origin", "scareactivate", true, 1); in OnStart {}
Means that when the Player Enters Origin, The scareactivate function will activate. You can rename scareactivate to anything, its irrelevant.

Then, you made
void scareactivate(string &in asParent, string &in asChild, int alState)
{
In here, you put the functions you want to activate when the player walks into Origin.
This can be health loss, sanity loss, gaining an item, end of the game, anything.
}

Hope this helps


RE: Scripting n00b in need of help. - Akumasama - 11-13-2010

So the function that you create with one of the functions in the list, has a standard syntax?
Code:
(string &in asParent, string &in asChild, int alState)

If so, then I think I'm beginning to understand how this scripting works alot better.

Also, you don't particularly need the onEnter, onStart and onLeave.
You only put those in when you want something to happen at start, enter area or leave area.