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
Romulator Offline
Not Tech Support ;-)

Posts: 3,628
Threads: 63
Joined: Jan 2013
Reputation: 195
#2
RE: Item Spawns Randomly

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.

Discord: Romulator#0001
[Image: 3f6f01a904.png]
04-01-2018, 04:04 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: 1 Guest(s)