View unanswered posts | View active topics It is currently Mon Oct 14, 2019 7:25 pm

 Page 1 of 1 [ 4 posts ]
 Print view Previous topic | Next topic
Spawning actors
Author Message

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
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.

Wed May 28, 2014 11:38 pm

Joined: Fri Sep 10, 2010 1:48 am
Posts: 661
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
end

Thu May 29, 2014 3:49 am

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Re: Spawning actors
Thanks, I'll test this out.

Thu May 29, 2014 8:09 am

Joined: Fri Nov 23, 2012 5:42 am
Posts: 143
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--

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").

Thu May 29, 2014 2:52 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 4 posts ]

#### Who is online

Users browsing this forum: No registered users

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ Cortex Command    Dev Log    Wiki    Game Discussion    Game and Licensing Support    Mod Making       Lua Scripting       Requests    Mod Releases       Older Mods    Scene Releases       Scene Making Planetoid Pioneers    Game Discussion    Pioneer Program Lounge Data Realms Off-Topic    Off Topic Chat       Gaming       Forum Games    Site Support & Feedback