Frictional Games Forum (read-only)
Spawning entity by pressing a key? - 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 - Development (https://www.frictionalgames.com/forum/forum-38.html)
+---- Forum: Development Support (https://www.frictionalgames.com/forum/forum-39.html)
+---- Thread: Spawning entity by pressing a key? (/thread-24415.html)



Spawning entity by pressing a key? - Slanderous - 01-20-2014

Hey guys.

I was wondering if there is a way to spawn entity in Area by pressing a key, for example T

Thanks in advance.


RE: Spawning entity by pressing a key? - DreamScripters - 01-21-2014

To keep it short i'm almost positive no. I have never seen it anywhere else where someone was able to bind a certain key to a script. I mean, if you really wanted to you could do something such as making a script that loops maybe every 0.1 seconds that will check if the player has his lantern out and if so you could make it so it spawns the entity and turns the lantern back off. It would be something to the effect of binding the "f" key to the script.

If you are interested in using this method though here's how I believe the script would be set up:

Code:
void OnStart()
{
     //Goes to "LoopStart" function.
     LoopStart();
}

void LoopStart()
{
     //Adds timer to go to "LanternCheck" function.
     AddTimer("lantern_check", 0.1f, LanternCheck);
}

void LanternCheck(string &in asTimer)
{
     //Checks if lantern is on.
     if(GetLanternActive() == true) {
          //Sets your entity active. (Replace "your_entity" with your entity name.)
          SetEntityActive("your_entity", true);
          //Makes the lantern turn off.
          SetLanternActive(false, false);
     }
     //Else if the lantern is not on.
     else {
          //Make it loop all over again. (Change "0.1f" with any number to change the time intervals it loops.)
          AddTimer("LanternCheck", 0.1f, "LanternCheck");
     }
}

Nothing too fancy but I believe if you wanted to use this method it would work. Best of luck on whatever you're aiming to do! Big Grin


RE: Spawning entity by pressing a key? - Traggey - 01-21-2014

Actually, in Horizon we had plenty of that stuff.

I on the other hand do not know how to, but it is doable!






RE: Spawning entity by pressing a key? - Daemian - 01-21-2014

I don't think it's possible, I tried once, but the closest connection between keys and script is the lantern callback.
Maybe in the new update there is another way.

The video above -I'm guessing- is using keys, but only the ones the game allows for movement -W A S D-
It has 4 areas around the player to detect his movement and one extra above to detect the using of space -jump-.

So still, no "T" to spawn anything.
That's what I think, you can always go and try it yourself.
You may find something.


RE: Spawning entity by pressing a key? - The chaser - 01-23-2014

Aaaaw, this is an old-school script! Here:

void OnStart() //Or you can put the following stuff in OnEnter()
{
SetEntityCallbackFunc("YOUR_KEY", "OnPickup");
}

void OnPickup(string &in asEntity, string &in type)
{
SetEntityActive("YOURENTITY", true);
}

/////OR YOU CAN USE

void OnPickup(string &in asEntity, string &in type)
{
CreateEntityAtArea("Your_entity_name", "ENTITY.ENT", "AREATOBESPAWNEDATNAME", false);
}

EDIT: Oh my god, I misread your post... spawning an entity pressing a keyboard key... nope, nothing that I know of.