Frictional Games Forum (read-only)
Problem with the CreateEntityAtArea - 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: Problem with the CreateEntityAtArea (/thread-19929.html)

Pages: 1 2


Problem with the CreateEntityAtArea - Red - 01-14-2013

Why this script doesn't work?
The sound works and stuff but the freaking Entity doesn't appear!

PHP Code:
void OnStart()
{

       
AddUseItemCallback("place""A""B","C"false);
}



void C(string &in asItemstring &in asEntity)
{

    
RemoveItem(asItem);
    
CreateEntityAtArea(asItemasItemasEntitytrue);
    
PlaySoundAtEntity("s""derb.snt""B"0false);
    } 



RE: Problem with the CreateEntityAtArea - The chaser - 01-14-2013

Instead that CreateEntity thing, use:

CreateEntityAtArea(string& asEntityName, string& asEntityFile, string& asAreaName, bool abFullGameSave);



Ergo:

CreateEntityAtArea("Nameofentity", "Entity.ent", "Areaname", true);


RE: Problem with the CreateEntityAtArea - Red - 01-14-2013

(01-14-2013, 07:15 PM)The chaser Wrote: Instead that CreateEntity thing, use:

CreateEntityAtArea(string& asEntityName, string& asEntityFile, string& asAreaName, bool abFullGameSave);



Ergo:

CreateEntityAtArea("Nameofentity", "Entity.ent", "Areaname", true);
The upper way doesn't work and the below way is not what i really was looking for.


RE: Problem with the CreateEntityAtArea - The chaser - 01-14-2013

The CreateEntityAtArea is what you did, it was what you were searching (or that I think :$)

You can have another item inactive and then just SetEntityActive.


RE: Problem with the CreateEntityAtArea - Your Computer - 01-14-2013

CreateEntityAtArea loads an ENT file at the area specified. It is not for duplicating already existing entities.


RE: Problem with the CreateEntityAtArea - Red - 01-14-2013

(01-14-2013, 07:55 PM)Your Computer Wrote: CreateEntityAtArea loads an ENT file at the area specified. It is not for duplicating already existing entities.
So the same item has to exist already in the inventory to work? It has to
be picked up in other level? So complicated.


RE: Problem with the CreateEntityAtArea - Your Computer - 01-14-2013

(01-14-2013, 08:07 PM)Pyöveli Wrote: So the same item has to exist already in the inventory to work? It has to
be picked up in other level? So complicated.

That has no direct relation to CreateEntityAtArea.


RE: Problem with the CreateEntityAtArea - darksky - 01-14-2013

maybe you should explain what you want to do


RE: Problem with the CreateEntityAtArea - TheGreatCthulhu - 01-14-2013

(01-14-2013, 07:00 PM)Pyöveli Wrote: Why this script doesn't work?
The sound works and stuff but the freaking Entity doesn't appear!

It doesn't work because you obviously have absolutely no idea what you are doing there (no disrespect intended).

First, in the editor and in code, don't name your items and entities with names like "A" and "B". Give them some names that are more descriptive, so that we (and you) can see from the code what is going on, and what you're trying to do.

"C" is also a poor name for a function.

Say you renamed your entities and the function somewhere along these lines (forfeiting about your actual game elements for the moment):
"A" --> "Acid_Bottle"
"B" --> "Oganic_Web"
"C" --> "OnUseAcid"

Also, that "place" parameter is just an internal name of the callback, which can be used by another predefined function to remove the callback at some different point in the script, so, in your case, it doesn't really matter what's written there.

You'll agree that
PHP Code:
AddUseItemCallback("id.useacid""Acid_Bottle""Oganic_Web""OnUseAcid"false); 
is much more comprehensible than
PHP Code:
AddUseItemCallback("place""A""B","C"false);  // what's A, B, C? o.O 

Now, this is why CreateEntityAtArea(asItem, asItem, asEntity, true) doesn't work. Let's go back to what The chaser told you:

(01-14-2013, 07:24 PM)Pyöveli Wrote:
(01-14-2013, 07:15 PM)The chaser Wrote: Instead that CreateEntity thing, use:

CreateEntityAtArea(string& asEntityName, string& asEntityFile, string& asAreaName, bool abFullGameSave);



Ergo:

CreateEntityAtArea("Nameofentity", "Entity.ent", "Areaname", true);
The upper way doesn't work and the below way is not what i really was looking for.

The "upper way" doesn't work because it's not a way, it's the declaration of the CreateEntityAtArea() function, which tells you, if you know how to read it, how the function is used, and what each part of it means. The "below way" demonstrates how to actually use the function in code, but you have to replace those strings with the names that correspond to the ones used on your map.

Looking at the "below way", this is what each of the parameters mean, and what you need to replace them with:
  • Nameofentity - this is the internal name, used by the game, for the entity that is to be created. You pick it yourself. It is similar to the name each entity has in the editor - there should be no two entities with the same name. Replace it with whatever you find suitable.
  • Entity.ent - this is the file which defines the entity, and the game will use this file to figure out which entity is supposed to be created. Replace it with the name of the entity file you want to use (monster, or some other entity), followed by the .ent extension.
  • Areaname - defines at which area the entity will spawn; obviously, there needs to be a corresponding area placed in the level editor. Replace it with the name of your script area.
  • true - just means that the state of the entity should be saved on game exit, leave it as is.

Now, with all that in mind, look what you did:
PHP Code:
CreateEntityAtArea(asItemasItemasEntitytrue); 

Here, the asItem parameter contains the name of the item you used, and asEntity contains the name of entity on which the item was used. So, you've passed along the item name as the internal ID for the new entity, then you again passed the item name in place of the entity file, and then you place the name of the use-target instead of an area where the entity is supposed to be created!

In my example with the Acid_Bottle and Organic_Web, you basically told that function:
Create entity "Acid_Bottle" at area "Organic_Web", and give it internal name "Acid_Bottle". This can't be what you wanted to do, and the script wouldn't know what to do with it anyway.

So go replace the parameter values as explained. If you can't figure it out yourself, come back here and explain in more detail what is it that you're trying to do, and tell us the names of the items and entities involved.


RE: Problem with the CreateEntityAtArea - Red - 01-15-2013

The script is just an example. I am not currently using it in any cs. You don't need to explain how to use the function. I already know.
It seems most of you misunderstood my point. And the issue has been already solved thanks to YourComputer in post #5.

But still, thanks to everyone who tried to help.