Creating empty entity(not unit or projectile,etc) and spawn?

Everything about mods can be found here.

Moderator: Morax

Creating empty entity(not unit or projectile,etc) and spawn?

Postby Redmoth » 14 Apr 2016, 00:17

Hi. Very quick question.

I know how to copy a unit's file and have it as a new unit in the game.

Is this possible with an entity? My plan is to have a script running on a unit I will spawn.
However i would much prefer it not actually being a 'unit'(ie no blueprint, no model, no display, no blip on radar etc, only the entity in the gameworld running the script I will write in it)

Thank you :)
Redmoth
 
Posts: 8
Joined: 13 Apr 2016, 04:49
Has liked: 4 times
Been liked: 0 time
FAF User Name: Redmoth

Re: Creating empty entity(not unit or projectile,etc) and sp

Postby Crotalus » 14 Apr 2016, 00:26

Something like this would create an entity:
Code: Select all
SomeUnit = Class(Unit) {
    OnCreate = function(self) {
        local spec = {
            Owner = unit
        }
   
        self.entity = Entity(spec)
        self:ForkThread(self.DoSomethingWithEntity)
    end),
}
Crotalus
Priest
 
Posts: 319
Joined: 27 Jan 2013, 20:37
Has liked: 2 times
Been liked: 102 times
FAF User Name: Crotalus

Re: Creating empty entity(not unit or projectile,etc) and sp

Postby Redmoth » 14 Apr 2016, 00:29

I see. Seeing it in a code's perspective, it makes me think: Is the unit what I actually want? eg:
Code: Select all
SomeUnit = Class(Unit) {
    OnCreate = function(self) {
      --[[local spec = {
            Owner = unit
        }
   
        local entity = Entity(spec)
        self:ForkThread(self.DoSomethingWithEntity)
        ]]--
        self:ForkThread(self.DoSomethingWithUnit)
    end)
}
Redmoth
 
Posts: 8
Joined: 13 Apr 2016, 04:49
Has liked: 4 times
Been liked: 0 time
FAF User Name: Redmoth

Re: Creating empty entity(not unit or projectile,etc) and sp

Postby Redmoth » 14 Apr 2016, 00:31

All I'm looking for is the clenest way to have a script Entirely on a seperate scd file, this is possibly by having a custom unit with the script triggering off OnCreate() and adding it to a players starting units

Edit: I know there are multiple ways, but looking for just about the simplest to comprehend since Im not inherently confortable with supcom's stuff
Redmoth
 
Posts: 8
Joined: 13 Apr 2016, 04:49
Has liked: 4 times
Been liked: 0 time
FAF User Name: Redmoth

Re: Creating empty entity(not unit or projectile,etc) and sp

Postby Crotalus » 14 Apr 2016, 00:55

If you're adding something to a starting player you probably put that code in SimInit.lua (OnCreateArmyBrain) or maybe somewhere in AIBrain.

You could immediately ForkThread from there and then have a separate code-path to do whatever you want.

Code: Select all
ForkThread(import('/link/to/some/module.lua').InitCleverAI, brain)
Crotalus
Priest
 
Posts: 319
Joined: 27 Jan 2013, 20:37
Has liked: 2 times
Been liked: 102 times
FAF User Name: Crotalus

Re: Creating empty entity(not unit or projectile,etc) and sp

Postby Redmoth » 14 Apr 2016, 01:03

I see. However, I think this is good pretty much only If I have one main loop, no?

Say I have 4 ais that benefit from the script. Say my script has a 'strategy' variable. With the unit or entity technique I know i can have access to the 'strategy' of that particulars player from itself without having, say, a main loop that does

Code: Select all
Exampleloop = function(self)

    CurPlayer = 0
    NbPlayer = 4
    For CurPlayer < NbPlayer do

       army = GetArmyIndex(CurPlayer)
       army:DoSomeFunction()
   

    end

   --OR
   
   Players = GetAllPlayersInGame
   For i, p in players do
   
   brain = GetaiBrain(player)
   brain:DoSomething()
   end


end,



Edit: this has to do with my question of yesterday. Since I dont understand how a class is instanciated in supcom (like the aiBrain being one instance Per player) So I do not know how to instanciate my CleverAI class the same way as an aiBrain. I would need a function like CreateaiBrain() but CreateCleverAI()

Edit2: I DO know however that If I CreateUnitHPR(), this will make an Instance of that unit. I can sadly not find any logical function that does CreateInstanceOfClass or CreateInstanceOfScript etc
Redmoth
 
Posts: 8
Joined: 13 Apr 2016, 04:49
Has liked: 4 times
Been liked: 0 time
FAF User Name: Redmoth

Re: Creating empty entity(not unit or projectile,etc) and sp

Postby Crotalus » 14 Apr 2016, 07:48

You instance a class by doing local obj = <Class-name>(args)

So you could make your own class:
Code: Select all
Cortex = Class ({
    __init = function(self, args)
        self.strategy = args.strategy
    end,
   
    DoSomething = function(self)
    end,
})


and put it on an individual brain here:
https://github.com/FAForever/fa/blob/re ... in.lua#L91
Code: Select all

OnCreateAI = function(self, planName)
    ...
    self.cortex = Cortex({strategy='Rush'})
    ...
end
Crotalus
Priest
 
Posts: 319
Joined: 27 Jan 2013, 20:37
Has liked: 2 times
Been liked: 102 times
FAF User Name: Crotalus

Re: Creating empty entity(not unit or projectile,etc) and sp

Postby Redmoth » 14 Apr 2016, 22:03

Wow! You got another like from me, Crotalus :) Thank you for all the help you are offering me, It helps enourmously!
Redmoth
 
Posts: 8
Joined: 13 Apr 2016, 04:49
Has liked: 4 times
Been liked: 0 time
FAF User Name: Redmoth


Return to Mods & Tools

Who is online

Users browsing this forum: No registered users and 1 guest