View unanswered posts | View active topics It is currently Wed Dec 25, 2024 5:20 pm



Reply to topic  [ 5 posts ] 
 Finding the 'team' of a held item? 
Author Message
User avatar

Joined: Tue Mar 20, 2007 10:16 am
Posts: 186
Location: Australia
Reply with quote
Post Finding the 'team' of a held item?
I need some assistance with this lua magic stuff. I'm making deployables of sorts, and I have a grenade that spawns an actor via a regular AddGib. The actor is, by default, team 0 (red). The AI mode for this actor, via some arbitrary internal value, is also brainhunt.

This works as intended if the user is also team 0, but I need to make it team independant so the AI can also use these.

Essentially what it should do is spawn an actor when it gibs (via lua), and set the spawned actor's team to the team of the actor it belonged to. If it never belonged to an actor (spawned from the menu?) it should be team -1 (wildlife, shoots at everything but crabs).

I want it to mimic the functionality of the previous version as much as possible, so the grenades will still gib if dropped from a dropship, or after hitting the ground when the actor holding them is killed, but deploy the actor with the appropriate team and set its AI mode to brainhunt.


Mon Oct 01, 2012 5:44 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Finding the 'team' of a held item?
First, what you'd have it do is during the grenade's Update() function, check its RootID to see if it's being held by something (grenade needs to be GetsHitByMOs = 1). If the grenade's RootID is not the same as its ID (meaning it's held by something), use MovableMan:GetMOFromID() to grab the MO from the RootID. Check if the MO is an actor, and if it is, assign the grenade's Team to the actor's team.

To take care of drops from aircraft, cast a MORay in the opposite direction of the grenade's velocity in the Create() function. Check to see if it grabbed an MO, and if it did, check if it's an actor, and if it is, assign the team of the grenade to the team of the actor.

Finally, in the Destroy() function of the grenade (assuming you're using INI method for detonation), create your actor, assign the actor's team as the grenade's team, and give it the brainhunt AI mode (actor.AIMode = Actor.AIMODE_SENTRY).

Note that, if the grenade is in the actor's inventory and the grenade has never actually existed in the simulation (hasn't been picked up from the ground, hasn't been held in the actor's hands), there's nothing you can really do to give it the proper team if the actor holding the grenade gibs and drops it. However, if the actor switches to the grenade and then puts it away, the grenade will be able to grab the team of the actor.


Mon Oct 01, 2012 7:29 pm
Profile
User avatar

Joined: Tue Mar 20, 2007 10:16 am
Posts: 186
Location: Australia
Reply with quote
Post Re: Finding the 'team' of a held item?
CaveCricket48 wrote:
First, what you'd have it do is during the grenade's Update() function, check its RootID to see if it's being held by something (grenade needs to be GetsHitByMOs = 1). If the grenade's RootID is not the same as its ID (meaning it's held by something), use MovableMan:GetMOFromID() to grab the MO from the RootID. Check if the MO is an actor, and if it is, assign the grenade's Team to the actor's team.

To take care of drops from aircraft, cast a MORay in the opposite direction of the grenade's velocity in the Create() function. Check to see if it grabbed an MO, and if it did, check if it's an actor, and if it is, assign the team of the grenade to the team of the actor.

Finally, in the Destroy() function of the grenade (assuming you're using INI method for detonation), create your actor, assign the actor's team as the grenade's team, and give it the brainhunt AI mode (actor.AIMode = Actor.AIMODE_SENTRY).

Note that, if the grenade is in the actor's inventory and the grenade has never actually existed in the simulation (hasn't been picked up from the ground, hasn't been held in the actor's hands), there's nothing you can really do to give it the proper team if the actor holding the grenade gibs and drops it. However, if the actor switches to the grenade and then puts it away, the grenade will be able to grab the team of the actor.

So far so good. I actually like how the team isnt set untill you hold it, it can be advertised as more of a feature than a bug. It can be advantageous to the enemy if they gun down a soldier carrying these who hasn't "correctly set targeting parameters" prior to deployment, as they will begin to shoot everything in sight.

I'm just having trouble with ray casting. The team isn't set when dropping from craft, there's no errors.

Code:
function Create(self)

   self.myTeam = -1
   
   ID = SceneMan:CastMORay(self.Pos, (self.Vel * -1), self.ID, 4, 0, false, 0)
   
   if ID ~= nil then
      holder = MovableMan:GetMOFromID(ID)
      if MovableMan:IsActor(holder) then
         self.myTeam = holder.Team
      end
   end
   
end

function Update(self)
   
   if self.RootID ~= self.ID then
      local holder = MovableMan:GetMOFromID(self.RootID)
      if MovableMan:IsActor(holder) then
         self.myTeam = holder.Team
      end
   end
   
end

function Destroy(self)

   local actor = CreateAHuman("Prime Hover Drone", "RETARDS.rte")
   
   actor.Team = self.myTeam
   actor.Pos = self.Pos
   actor.AIMode = Actor.AIMODE_BRAINHUNT
   
   MovableMan:AddActor(actor)
   
end


Is it also possible to put a delay of a few seconds behind setting the AI mode, or is the reference to the actor lost as soon as the grenade gibs?


Tue Oct 02, 2012 12:20 pm
Profile
User avatar

Joined: Tue Jun 12, 2007 11:52 pm
Posts: 13144
Location: Here
Reply with quote
Post Re: Finding the 'team' of a held item?
First, you should probably make the variable storing the ID from the MORay into a local variable. Second, check to see if it's not 255, not if it's not nil. And third, try extending the MORay length maybe 30 pixels longer than its velocity's magnitude.

Delaying the AIMode setting wouldn't work, since as far as I know, the script only runs the Destroy() function once, and stops the script from running once the object gibs. You could spawn a scripted particle over the actor that locks onto the closest actor (which would hopefully be your actor), and sets the AIMode after a delay.


Tue Oct 02, 2012 9:35 pm
Profile
User avatar

Joined: Tue Mar 20, 2007 10:16 am
Posts: 186
Location: Australia
Reply with quote
Post Re: Finding the 'team' of a held item?
Works now. Using just their velocity was way too short.


Wed Oct 03, 2012 5:35 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.
[ Time : 0.053s | 13 Queries | GZIP : Off ]