Data Realms Fan Forums
http://45.55.195.193/

Checking limb status
http://45.55.195.193/viewtopic.php?f=1&t=25956
Page 1 of 1

Author:  Zaneo [ Sun Oct 23, 2011 8:01 am ]
Post subject:  Checking limb status

I was wondering if there is a way to check the if any limbs are missing on a player, and if you are able to replace them? The idea was for a medical gun that once you are above 100 health, it will start replacing lost limbs. Sorry if this is available somewhere really easily, I took a cursory glance and didn't see it.

On a similar note, checking if a thruster has been destroyed on a dropship.

Author:  akblabla [ Wed Oct 26, 2011 6:21 pm ]
Post subject:  Re: Checking limb status

Zaneo wrote:
I was wondering if there is a way to check the if any limbs are missing on a player, and if you are able to replace them? The idea was for a medical gun that once you are above 100 health, it will start replacing lost limbs. Sorry if this is available somewhere really easily, I took a cursory glance and didn't see it.

On a similar note, checking if a thruster has been destroyed on a dropship.


It isn't unfortunately possible to replace individual missing limbs. A method though is to upon reaching 100% health check if it needs any limbs (checking if they are ~= nil and their ID ~= 255) then if it needs any, make it drop all his items and then spawn a new actor (use the preset name to get the original actor) then force all the new limbs RotAngle, Position, HFlipped, Velocity ect. to be exactly the same as their original counterparts. Then when the new actor is spawned, remove the old one (self.ToDelete = true), and add all the nearby items to the new actors inventory.

Hope it helps :)

Author:  Azukki [ Wed Oct 26, 2011 6:38 pm ]
Post subject:  Re: Checking limb status

Isn't deleting the actor going to delete what's in his inventory, not expel it?
Bah, I missed the bit where you specifically mentioned what I brought to question.
Unless you edited the post?

Author:  Zaneo [ Wed Oct 26, 2011 7:05 pm ]
Post subject:  Re: Checking limb status

That helps a lot, it is a bit silly that it has to be done like that though.

Author:  akblabla [ Wed Oct 26, 2011 7:10 pm ]
Post subject:  Re: Checking limb status

Azukki wrote:
Isn't deleting the actor going to delete what's in his inventory, not expel it?


self:DropAllInventory() before deleting it. Try waiting a frame before deleting if that doesn't.

Author:  Zaneo [ Tue Nov 01, 2011 5:33 am ]
Post subject:  Re: Checking limb status

What exactly would the mechanism for checking the limb though?

I attemted to get the thrusters on a dropship using Abduls Alhazred's code from his air support mod.

Code:
self.EngineA = nil
   self.EngineB = nil
   
   local foundA = nil
   local foundB = nil
   
   local selfID = ToActor(self).ID
   ConsoleMan:PrintString("Self ID: " .. selfID)
   local foundObject = nil
   for i = 1, MovableMan:GetMOIDCount()-1 do
      ConsoleMan:PrintString("Object ID: " .. i)
      foundObject = MovableMan:GetMOFromID(i)
      ConsoleMan:PrintString("Object Name: " .. foundObject.PresetName)
      if (i ~= selfID) and (MovableMan:GetRootMOID(i) == selfID) then   -- an obj without a parent has ID == RootID
         --foundObject = MovableMan:GetMOFromID(i)
         --ConsoleMan:PrintString("Object Name: " .. foundObject.PresetName)
         if foundObject.PresetName == "Drop Ship Engine A" then
            ConsoleMan:PrintString("Found Engine A")
            self.EngineA = ToAEmitter(foundObject)
            foundA = true
         elseif foundObject.PresetName == "Drop Ship Engine B" then
            ConsoleMan:PrintString("Found Engine A")
            self.EngineB = ToAEmitter(foundObject)
            foundB = true
         end
            if foundA and foundB then
            break
         end
      end


Code:
Self ID: 255
Object ID: 1
Object Name: Door Slide Short
Object ID: 2
Object Name: Door Slide Short A
Object ID: 3
Object Name: Door Slide Short
Object ID: 4
Object Name: Door Slide Short A
Object ID: 5
Object Name: Door Slide Short
Object ID: 6
Object Name: Door Slide Short A
Object ID: 7
Object Name: Door Slide Short
Object ID: 8
Object Name: Door Slide Short A
Object ID: 9
Object Name: Dummy Controller
Object ID: 10
Object Name: Door Rotate Short
Object ID: 11
Object Name: Door Rotate Short A
Object ID: 12
Object Name: Door Rotate Short
Object ID: 13
Object Name: Door Rotate Short A
Object ID: 14
Object Name: Brain Case
Object ID: 15
Object Name: Dummy
Object ID: 16
Object Name: Dummy Leg BG A
Object ID: 17
Object Name: Dummy Arm BG A
Object ID: 18
Object Name: Dummy Head A
Object ID: 19
Object Name: Dummy Leg FG A
Object ID: 20
Object Name: Dummy Arm FG A
Object ID: 21
Object Name: Dummy
Object ID: 22
Object Name: Dummy Leg BG A
Object ID: 23
Object Name: Dummy Arm BG A
Object ID: 24
Object Name: Dummy Head A
Object ID: 25
Object Name: Dummy Leg FG A
Object ID: 26
Object Name: Dummy Arm FG A
Object ID: 27
Object Name: Dummy
Object ID: 28
Object Name: Dummy Leg BG A
Object ID: 29
Object Name: Dummy Arm BG A
Object ID: 30
Object Name: Dummy Head A
Object ID: 31
Object Name: Dummy Leg FG A
Object ID: 32
Object Name: Dummy Arm FG A
Object ID: 33
Object Name: Dummy
Object ID: 34
Object Name: Dummy Leg BG A
Object ID: 35
Object Name: Dummy Arm BG A
Object ID: 36
Object Name: Dummy Head A
Object ID: 37
Object Name: Dummy Leg FG A
Object ID: 38
Object Name: Dummy Arm FG A
Object ID: 39
Object Name: Dreadnought
Object ID: 40
Object Name: Dummy Crab Leg BG
Object ID: 41
Object Name: Dummy Crab Leg BG
Object ID: 42
Object Name: Dummy Crab Leg FG
Object ID: 43
Object Name: Dummy Crab Leg FG
Object ID: 44
Object Name: Dummy Turret Large
Object ID: 45
Object Name: Dreadnought MG
Object ID: 46
Object Name: Dummy Turret Large B
Object ID: 47
Object Name: Dummy Turret Large A
Object ID: 48
Object Name: Dummy Turret Large D
Object ID: 49
Object Name: Dreadnought
Object ID: 50
Object Name: Dummy Crab Leg BG
Object ID: 51
Object Name: Dummy Crab Leg BG
Object ID: 52
Object Name: Dummy Crab Leg FG
Object ID: 53
Object Name: Dummy Crab Leg FG
Object ID: 54
Object Name: Dummy Turret Large
Object ID: 55
Object Name: Dreadnought MG
Object ID: 56
Object Name: Dummy Turret Large B
Object ID: 57
Object Name: Dummy Turret Large A
Object ID: 58
Object Name: Dummy Turret Large D
Object ID: 59
Object Name: Dummy
Object ID: 60
Object Name: Dummy Leg BG A
Object ID: 61
Object Name: Dummy Arm BG A
Object ID: 62
Object Name: Dummy Head A
Object ID: 63
Object Name: Dummy Leg FG A
Object ID: 64
Object Name: Dummy Arm FG A
Object ID: 65
Object Name: Dummy
Object ID: 66
Object Name: Dummy Leg BG A
Object ID: 67
Object Name: Dummy Arm BG A
Object ID: 68
Object Name: Dummy Head A
Object ID: 69
Object Name: Dummy Leg FG A
Object ID: 70
Object Name: Dummy Arm FG A
Object ID: 71
Object Name: Dummy
Object ID: 72
Object Name: Dummy Leg BG A
Object ID: 73
Object Name: Dummy Arm BG A
Object ID: 74
Object Name: Dummy Head A
Object ID: 75
Object Name: Dummy Leg FG A
Object ID: 76
Object Name: Dummy Arm FG A
Object ID: 77
Object Name: Crab
Object ID: 78
Object Name: Crab Leg BG A
Object ID: 79
Object Name: Crab Leg BG A
Object ID: 80
Object Name: Crab Leg FG A
Object ID: 81
Object Name: Crab Leg FG A
Object ID: 82
Object Name: AK-47
Object ID: 83
Object Name: Light Digger
Object ID: 84
Object Name: AK-47
Object ID: 85
Object Name: Shotgun
Object ID: 86
Object Name: SMG
Object ID: 87
Object Name: AK-47


When I looked in console though I didn't see any "Drop Ship Engine A/B" I assume there is a different way to access them? Or in hindsight the dropship isn't on screen yet so this doesn't work because it isn't registered on scene? If that is the case how would I access the thrusters before the ship is placed on scene?

Author:  Abdul Alhazred [ Tue Nov 01, 2011 9:01 am ]
Post subject:  Re: Checking limb status

You can access any MovableObject owned by the MovableManager with the method you mentioned. Note that the object has to have GetsHitByMOs set to 1, so the code below works on the big engines but not on the tiny thrusters.

Code:
function Create(self)
   local MoObj
   for i = 1, MovableMan:GetMOIDCount()-1 do
      if MovableMan:GetRootMOID(i) == self.ID then   -- an obj without a parent has ID == RootID
         MoObj = MovableMan:GetMOFromID(i)
         if MoObj.PresetName == "PresetNameOfLeftEngine" then
            self.LeftEngine = ToAEmitter(MoObj)
         elseif MoObj.PresetName == "PresetNameOfRightEngine" then
            self.RightEngine = ToAEmitter(MoObj)
         end
         
         if self.LeftEngine and self.RightEngine then
            break
         end
      end
   end
end


The limbs of an AHuman all have pointers since B26: http://wiki.datarealms.com/index.php/Lu ... Human#Head

Author:  Zaneo [ Tue Nov 01, 2011 1:10 pm ]
Post subject:  Re: Checking limb status

Hmm, I am still having the same problem it can't find the engines. When I set it announce all objects found, it doesn't list the engine objects. Lots of human parts, but no dropship parts.

Code:
Object: Door Slide Short
Object: Door Slide Short A
Object: Door Slide Short
Object: Door Slide Short A
Object: Door Slide Short
Object: Door Slide Short A
Object: Door Slide Short
Object: Door Slide Short A
Object: Dummy Controller
Object: Door Rotate Short
Object: Door Rotate Short A
Object: Door Rotate Short
Object: Door Rotate Short A
Object: Brain Case
Object: Dummy
Object: Dummy Leg BG A
Object: Dummy Arm BG A
Object: Dummy Head A
Object: Dummy Leg FG A
Object: Dummy Arm FG A
Object: Dummy
Object: Dummy Leg BG A
Object: Dummy Arm BG A
Object: Dummy Head A
Object: Dummy Leg FG A
Object: Dummy Arm FG A
Object: Dummy
Object: Dummy Leg BG A
Object: Dummy Arm BG A
Object: Dummy Head A
Object: Dummy Leg FG A
Object: Dummy Arm FG A
Object: Dummy
Object: Dummy Leg BG A
Object: Dummy Arm BG A
Object: Dummy Head A
Object: Dummy Leg FG A
Object: Dummy Arm FG A
Object: Dreadnought
Object: Dummy Crab Leg BG
Object: Dummy Crab Leg BG
Object: Dummy Crab Leg FG
Object: Dummy Crab Leg FG
Object: Dummy Turret Large
Object: Dreadnought MG
Object: Dummy Turret Large B
Object: Dummy Turret Large A
Object: Dummy Turret Large D
Object: Dreadnought
Object: Dummy Crab Leg BG
Object: Dummy Crab Leg BG
Object: Dummy Crab Leg FG
Object: Dummy Crab Leg FG
Object: Dummy Turret Large
Object: Dreadnought MG
Object: Dummy Turret Large B
Object: Dummy Turret Large A
Object: Dummy Turret Large D
Object: Dummy
Object: Dummy Leg BG A
Object: Dummy Arm BG A
Object: Dummy Head A
Object: Dummy Leg FG A
Object: Dummy Arm FG A
Object: Dummy
Object: Dummy Leg BG A
Object: Dummy Arm BG A
Object: Dummy Head A
Object: Dummy Leg FG A
Object: Dummy Arm FG A
Object: Dummy
Object: Dummy Leg BG A
Object: Dummy Arm BG A
Object: Dummy Head A
Object: Dummy Leg FG A
Object: Dummy Arm FG A
Object: Crab
Object: Crab Leg BG A
Object: Crab Leg BG A
Object: Crab Leg FG A
Object: Crab Leg FG A
Object: AK-47
Object: Light Digger
Object: AK-47
Object: Shotgun
Object: SMG
Object: AK-47

Author:  Abdul Alhazred [ Tue Nov 01, 2011 8:47 pm ]
Post subject:  Re: Checking limb status

Zaneo wrote:
Hmm, I am still having the same problem it can't find the engines. When I set it announce all objects found, it doesn't list the engine objects. Lots of human parts, but no dropship parts.
I just tested it and you are of course right. It turned out that my script only works when the craft is spawned by a script, and not when ordered form the buy menu. I always spawn stuff with scripts to save time so I never noticed. Thanks for bringing this up!

Try this instead:
Code:
function Update(self)
   if not self.searchedForEngines then
      self.searchedForEngines = true
      local MoObj
      for i = 1, MovableMan:GetMOIDCount()-1 do
         if MovableMan:GetRootMOID(i) == self.ID then   -- an obj without a parent has ID == RootID
             MoObj = MovableMan:GetMOFromID(i)
             if MoObj.PresetName == "Drop Ship Engine A" then
                  self.LeftEngine = ToAEmitter(MoObj)
             elseif MoObj.PresetName == "Drop Ship Engine B" then
                  self.RightEngine = ToAEmitter(MoObj)
             end
             
             if self.LeftEngine and self.RightEngine then
                  print("Found " .. self.LeftEngine.PresetName .. " and " .. self.RightEngine.PresetName)
                  break
             end
         end
      end
   end
   
   if self.LeftEngine then
      if self.LeftEngine:IsAttached() then
         self.LeftEngine:TriggerBurst()
      else
         self.LeftEngine = nil
      end
   end
   
   if self.RightEngine then
      if self.RightEngine:IsAttached() then
         self.RightEngine:EnableEmission(false)
      else
         self.RightEngine = nil
      end
   end
end

Author:  Zaneo [ Wed Nov 02, 2011 12:42 am ]
Post subject:  Re: Checking limb status

I must be doing it completely wrong... maybe this doesn't work on the default dropship?




Author:  Abdul Alhazred [ Wed Nov 02, 2011 8:01 am ]
Post subject:  Re: Checking limb status

Did you move the code from Create() to Update()?

Author:  Zaneo [ Wed Nov 02, 2011 11:54 am ]
Post subject:  Re: Checking limb status

Yup

Code:
function UpdateAI(self)
   if not self.DockMode == "NotDocked" then
      return
   end
   if not self.searchedForEngines then
      self.searchedForEngines = true
      local MoObj
      for i = 1, MovableMan:GetMOIDCount()-1 do
         if MovableMan:GetRootMOID(i) == self.ID then   -- an obj without a parent has ID == RootID
            MoObj = MovableMan:GetMOFromID(i)
            if MoObj.PresetName == "Drop Ship Engine A" then
               self.LeftEngine = ToAEmitter(MoObj)
            elseif MoObj.PresetName == "Drop Ship Engine B" then
               self.RightEngine = ToAEmitter(MoObj)
            end
            
            if self.LeftEngine and self.RightEngine then
              ConsoleMan:PrintString("Found " .. self.LeftEngine.PresetName .. " and " .. self.RightEngine.PresetName)
              break
            end
         end
       end      
      
       if not (self.LeftEngine and self.LeftEngine:IsAttached())then
         self.LeftEngine = nil
      end      
       if not (self.RightEngine and self.RightEngine:IsAttached()) then
         self.RightEngine = nil
       end
   end
       
   ...

end   

Author:  Abdul Alhazred [ Wed Nov 02, 2011 12:56 pm ]
Post subject:  Re: Checking limb status

No, that is the UpdateAI(self) function. The code that finds the emitters must be in the Update(self) function. The code that adjust the engine output can be in UpdateAI though.

I suspect the Create and UpdateAI functions are executed before a newly created object is registered in the MovableManager, but Update is executed afterwards.

Author:  Zaneo [ Wed Nov 02, 2011 2:07 pm ]
Post subject:  Re: Checking limb status

Ah right whoops, heh.

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