Facebook Twitter YouTube Frictional Games | Forum | Privacy Policy | Dev Blog | Dev Wiki | Support | Gametee


Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Help Spawning Item Randomly
Organic Shelter Offline
Junior Member

Posts: 22
Threads: 5
Joined: Mar 2018
Reputation: 0
#3
RE: Item Spawns Randomly

(04-01-2018, 04:04 PM)Romulator Wrote: Create a few ScriptAreas where your item is to spawn, giving them a name with an appended number. In your example, you state 5, we'll go with SpawnArea_1, SpawnArea_2, etc, up to SpawnArea_5. Place your key somewhere in the map, anywhere will do, so long as it is placed. I'll call it Chest_Key in this example.

To spawn it, we'll generate a Random Integer in code using RandInt(), which we will place in OnStart(). Then we can simply place the entity at the relevant ScriptArea, using the below code.

PlaceEntityAtEntity(string &in asName, string &in asTargetEntity, string &in asTargetBodyName, bool abUseRotation);

asName - Name of the entity to place.
asTargetEntity - Name of the other entity to place the first entity at.
asTargetBodyName - Name of the body of the entity to place the first entity at. If empty the first body is used (might be buggy, recommended to name a body anyway).
abUseRotation - Whether the entity should be rotated like the target entity.

PHP Code: (Select All)
void OnStart()
{
     
SetLocalVarInt("RandArea"RandInt(15));
     
PlaceEntityAtEntity("Chest_Key""SpawnArea_"+GetLocalVarInt("RandArea"), ""true);
     
AddDebugMessage("Key spawned inside chest "+GetLocalVarInt("RandArea"), false);


The final value on the PlaceEntityAtEntity, true, means you can rotate the ScriptArea a little horizontally and it will rotate the key relative to that direction.

I've tried it and the Amnesia crash. Should the ScriptArea small or big?
04-05-2018, 12:33 PM
Find


Messages In This Thread
Spawning Item Randomly - by Organic Shelter - 04-01-2018, 08:22 AM
RE: Item Spawns Randomly - by Romulator - 04-01-2018, 04:04 PM
RE: Item Spawns Randomly - by Organic Shelter - 04-05-2018, 12:33 PM
RE: Item Spawns Randomly - by Romulator - 04-05-2018, 01:00 PM
RE: Item Spawns Randomly - by Mudbill - 04-05-2018, 09:18 PM
RE: Item Spawns Randomly - by Organic Shelter - 04-06-2018, 12:50 PM
RE: Spawning Item Randomly - by Mudbill - 04-06-2018, 10:12 PM
RE: Spawning Item Randomly - by Organic Shelter - 04-08-2018, 05:03 AM
RE: Spawning Item Randomly - by Mudbill - 04-08-2018, 04:57 PM



Users browsing this thread: 2 Guest(s)