Data Realms Fan Forums
http://forums.datarealms.com/

Spawning actors
http://forums.datarealms.com/viewtopic.php?f=73&t=45720
Page 1 of 1

Author:  4zK [ Wed May 28, 2014 11:38 pm ]
Post subject:  Spawning actors

Making a better one man army survival mode.

For it, I want actors to spawn in intervals, positioned on the surface and at a certain distance to the player brain. The distance could be, for example, screen width.

How do I did this.

Author:  Bad Boy [ Thu May 29, 2014 3:49 am ]
Post subject:  Re: Spawning actors

Untested, and not actually working code but it'll give you the groundwork.

You'll need to create the timer in the create function of course.

For the distances, I did a random distance between 100 and 10 + the width of the player's screen away from their brain (you'll also need to give the correct name for the brain of course). You can also use FrameMan.ResX if you don't want it to change depending on the width of the player's screen, since this'll change for multiple players (if multiple players are even possible in one man army, which would seem weird to me).

Code:
if mytimer:IsPastSimMS(interval) then
   local act = CreateAHuman("Actor Name", "ActorRTE.rte");
   act.Team = #Team_Number;
   local y1, y2;
   if math.random() < 0.5 then
      y1 = playerbrain.Pos - FrameMan.PlayerScreenWidth - 100;
      y2 = playerbrain.Pos - FrameMan.PlayerScreenWidth - 10;
   else
          y1 = playerbrain.Pos + FrameMan.PlayerScreenWidth + 10;
          y2 = playerbrain.Pos + FrameMan.PlayerScreenWidth + 100;
   end
   act.Pos = SceneMan:MovePointToGround(Vector(math.random(y1, y2), 0), act.Height, 5); --The 2nd argument is the distance above the ground, the 3rd is the accuracy, more accurate is laggier but closer
   act:AddInventoryItem(CreateHDFirearm("Gun Name or Whatever", "GunRTE.rte");
   MovableMan:AddActor(act);
end

Author:  4zK [ Thu May 29, 2014 8:09 am ]
Post subject:  Re: Spawning actors

Thanks, I'll test this out.

Author:  clunatic [ Thu May 29, 2014 2:52 pm ]
Post subject:  Re: Spawning actors

Since you're trying to spawn enemy actors, you'll probably want to do something like this, rather than spawning specific actors/weapons using their presetnames:

Code:
if math.random() < 0.7 then
   act = RandomAHuman("Light Infantry", "ModuleNameHere")
else
   act = RandomAHuman("Heavy Infantry", "ModuleNameHere")
end

--team and pos stuff--

act:AddInventoryItem(RandomHDFirearm("Primary Weapons", "ModuleNameHere"))
act:AddInventoryItem(RandomHDFirearm("Secondary Weapons", "ModuleNameHere"))
MovableMan:AddActor(act)


This does mean you'll need to select a module in the create function, probably using code like this:

Code:
self.CPUTechName = self:GetTeamTech(self.CPUTeam)


That code will just get the module from the faction selection screen that comes up when an activity starts. If using this you can just replace the "ModuleNameHere" with self.CPUTechName.

Alternatively, you can also leave the module out of the random functions, in which case it will spawn random actors from any module except base.rte, armed with random weapons from any module except base.rte.

Option three, the most complicated one, is a combination of the last 2: You could leave out the module name for the actors, but then use the actors' module to spawn weapons. So you never know what kind of actors you might face, but the actors will always have weapons from their own tech. This option requires some extra code, that I can't easily copy/paste right now, so let me know if you want to go this route and I'll put together some workable code later.

Edit: You can also change the group in the random weapon line, any group defined in an ini is a valid option. So Light, Heavy, Sniper or Explosive Weapons can all be used.

Expanding it to have some more if math.random() checks to sometimes give the actors grenades, or diggers, is also possible of course. Using RandomTDExplosive("Grenades") and RandomHDFirearm("Diggers").

Page 1 of 1 All times are UTC [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/