View unanswered posts | View active topics It is currently Mon Jun 17, 2019 8:03 pm



Reply to topic  [ 4 posts ] 
 Spawning actors 
Author Message
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post 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
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 661
Location: Halifax, Canada
Reply with quote
Post 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


Thu May 29, 2014 3:49 am
Profile
User avatar

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


Thu May 29, 2014 8:09 am
Profile

Joined: Fri Nov 23, 2012 5:42 am
Posts: 143
Reply with quote
Post 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").


Thu May 29, 2014 2:52 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

Who is online

Users browsing this forum: No registered users


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

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.015s | 13 Queries | GZIP : Off ]