View unanswered posts | View active topics It is currently Thu Mar 28, 2024 4:53 pm



Reply to topic  [ 15 posts ] 
 attachment frame based on parent parts frame 
Author Message
User avatar

Joined: Mon Mar 03, 2014 6:20 pm
Posts: 19
Location: Japan, Ninja's den
Reply with quote
Post attachment frame based on parent parts frame
hi, i'm making skin tight armor(can break) for arm & leg.
therefore i must need their animation frame sync to parent parts(actuary arm & leg).

i make this code.
Code:
function Update(self)
    local actor = MovableMan:GetMOFromID(self.RootID);
   self.Frame = actor.FGLeg.Frame;
end

but this code don't working... :-(

please help me.


Tue Apr 01, 2014 5:30 am
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: attachment frame based on parent parts frame
Try this:
Code:
function Update(self)
    local actor = MovableMan:GetMOFromID(self.RootID);
    if MovableMan:IsActor(actor) then
        self.Frame = ToAHuman(actor).FGLeg.Frame;
    end
end

Remember though, that if you want to use it on both legs, you could do it with the same script like this:
Code:
function Update(self)
    local actor = MovableMan:GetMOFromID(self.RootID);
    if MovableMan:IsActor(actor) then
        if string.find(self.PresetName,"FG") then
            self.Frame = ToAHuman(actor).FGLeg.Frame;
        else
            self.Frame = ToAHuman(actor).BGLeg.Frame;
        end
    end
end


Last edited by 4zK on Tue Apr 01, 2014 1:11 pm, edited 1 time in total.



Tue Apr 01, 2014 6:11 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: attachment frame based on parent parts frame
One minor correction, unless I'm mistaken FGLeg and BGLeg are AHuman properties, not actor properties. So you should change ToActor in 4zk's code to ToAHuman.


Tue Apr 01, 2014 7:03 am
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: attachment frame based on parent parts frame
Oh right, that's what I meant to write, sorry.

Oh, also, if you plan on using it on arms, just change actor.FGLeg to actor.FGArm, etc.


Tue Apr 01, 2014 1:11 pm
Profile
User avatar

Joined: Mon Mar 03, 2014 6:20 pm
Posts: 19
Location: Japan, Ninja's den
Reply with quote
Post Re: attachment frame based on parent parts frame
thanks for tell me the code, it's work fine!

but have some questions.
1) in actor editor, this code don't seem to works.

2) arm/legs and their armor animation frame can be sync, but foot and foot and their armor animation frame can't be sync by any code?


Tue Apr 01, 2014 10:10 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: attachment frame based on parent parts frame
1) IIRC, Lua scripts don't work in the actor editor.

2) Feet have (at least in vanilla actors if I'm not wrong) GetsHitByMOs = 0, and Lua only check MOs with that set to 1. Not sure what would be the consequences of setting it to 1, but in case it doesn't end in random feet explosions you could iterate through the MOs of the actors and check the frame. The code would be a bit more complex than the ones on this thread.


Tue Apr 01, 2014 11:59 pm
Profile
User avatar

Joined: Mon Mar 03, 2014 6:20 pm
Posts: 19
Location: Japan, Ninja's den
Reply with quote
Post Re: attachment frame based on parent parts frame
Asklar wrote:
1) IIRC, Lua scripts don't work in the actor editor.

2) Feet have (at least in vanilla actors if I'm not wrong) GetsHitByMOs = 0, and Lua only check MOs with that set to 1. Not sure what would be the consequences of setting it to 1, but in case it doesn't end in random feet explosions you could iterate through the MOs of the actors and check the frame. The code would be a bit more complex than the ones on this thread.

random feet explosions is still occur in B30?


Wed Apr 02, 2014 6:47 am
Profile
User avatar

Joined: Mon Oct 11, 2010 1:15 pm
Posts: 594
Location: Finlandia
Reply with quote
Post Re: attachment frame based on parent parts frame
Since feet don't even receive any damage, it shouldn't really matter whether they have armor or not. Just make the base sprite of the feet look like they're armored.


Wed Apr 02, 2014 11:46 am
Profile
User avatar

Joined: Mon Mar 03, 2014 6:20 pm
Posts: 19
Location: Japan, Ninja's den
Reply with quote
Post Re: attachment frame based on parent parts frame
feet their own don't receive any damage. but can't sync to other armor damage?
eg: if lowerbody armor is destroy, leg and feet armor also destroy.

and i need method of searching certain parts from actor.


Thu Apr 03, 2014 1:42 am
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: attachment frame based on parent parts frame
Code:
   local i = 1
   while i < MovableMan:GetMOIDCount() do
      if MovableMan:GetMOFromID(i).RootID == self.ID and i ~= self.ID then
         self.att = MovableMan:GetMOFromID(i)
         if string.find(self.att.PresetName, "PresetName of the thing you are looking for") then
            self.ThingIWasLookingFor = ToAttachable(self.att)
         end
      end
      i = i + 1
   end


Not sure if the fastest way to do it, but it works. You can also add some elseif to make more variables with some specific parts you might want. Note how it says ToAttachable(self.att) in the if. Logically, you'd be looking for attachables with this script, since using it to store body parts would be redundant and would give you errors depending on the part (IIRC, arms or legs are actors or something), unless you changed it to ToActor(self.att) or whatever.

You could also be even more fancy and store everything read by that code on a table, in that way, you'd have all the MOs of the actor stored (which would also include any held devices like weapons or shields held by the actor when the script runs).

Not sure if this script would work, but modifying a bit the previous one into something like:

Code:
   self.MOTable = {}
   local i = 1
   while i < MovableMan:GetMOIDCount() do
      if MovableMan:GetMOFromID(i).RootID == self.ID and i ~= self.ID then
         self.att = MovableMan:GetMOFromID(i)
         self.MOTable[self.att.PresetName] = self.att
      end
      i = i + 1
   end


(Thanks Bad Boy for the tables guide, never thought about using them in Cortex Command)

Using that script should store all the MOs that are part from the actor into the self.MOTable, and accesing things from there shouldn't be hard; for example, if you wanna access the lower body armor you'd use something like self.MOTable["Lower Body Armor PresetName"]. Then if you want to check if something is missing you'd only have to check if it's ID is 255, if it is, the MO doesn't exist anymore. Though it'd store redundant information like the head/arms/legs, which can already be accessed with the "self.BodyPart" thing.

Since I don't know if the script of the tables I posted there would even work at all, you should try using the first one better if you don't come up with any other method or someone else doesn't post something better. Also, I'll eventually check in if this method table I posted would work, since it looks pretty cool and smart (again, thanks Bad Boy for the tables guide).


Thu Apr 03, 2014 2:39 am
Profile

Joined: Fri Sep 10, 2010 1:48 am
Posts: 666
Location: Halifax, Canada
Reply with quote
Post Re: attachment frame based on parent parts frame
Oh man, someone appreciated my table tutorial, thank god, I'm glad it was of some use!

Asklar, that seems solid, though I'd suggest a for loop (for i = 1, MovableMan:GetMOIDCount() do) over a while loop since the former is just more elegant for this sort of thing.

Also I vaguely recall a post (one of xenoargh's I think) mentioning that trying to do much with feet caused some very weird issues. I've been meaning to look it up and see if it's relevant to this, but keep in mind that what you're trying to do may not be doable. However, if you can find the foot position you should be able to at least fake adding attachables to it so maybe it'll be fine.


Thu Apr 03, 2014 4:33 pm
Profile
User avatar

Joined: Mon Mar 03, 2014 6:20 pm
Posts: 19
Location: Japan, Ninja's den
Reply with quote
Post Re: attachment frame based on parent parts frame
thanks for tell me code.


i need write code like this?
Code:

function Update(self)
   self.MOTable = {}
   local i = 1
   while i < MovableMan:GetMOIDCount() do
      if MovableMan:GetMOFromID(i).RootID == self.ID and i ~= self.ID then
         self.att = MovableMan:GetMOFromID(i)
         self.MOTable[self.att.MyMod LowerArmor] = self.att
      end
      i = i + 1
   end

   if (detection code of [self.att.MyMod LowerArmor]) then
        if string.find(self.MyMod LowerArmor,"FG") then
            self.Frame = ToAHuman(self.att).FGLeg.Frame;
        else
            self.Frame = ToAHuman(self.att).BGLeg.Frame;
        end
      break
   else
      (destroy with gib code of self)
   end

end



Thu Apr 03, 2014 8:44 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: attachment frame based on parent parts frame
Bad Boy wrote:
Oh man, someone appreciated my table tutorial, thank god, I'm glad it was of some use!

Asklar, that seems solid, though I'd suggest a for loop (for i = 1, MovableMan:GetMOIDCount() do) over a while loop since the former is just more elegant for this sort of thing.


:grin:

Arkblade, kinda. First, the code to iterate through all the body parts should go on the function Create(self). Making it run on the Update one wouldn't make it crash or anything, but it would make it more laggy, specially if you have many of those actors in game.

Now, I think you mixed a bit the two scripts. If you pay attention to it, on every cycle of the while loop, you'd constantly overwrite the value of "self.MOTable[self.att.MyMod LowerArmor]" (which doesn't even seem to be a valid value :P).

Let's correct it a bit;
Code:
function Create(self)
   self.MOTable = {}
   local i = 1
   while i < MovableMan:GetMOIDCount() do
      if MovableMan:GetMOFromID(i).RootID == self.ID and i ~= self.ID then
         self.att = MovableMan:GetMOFromID(i)
         self.MOTable[self.att.PresetName] = self.att
      end
      i = i + 1
   end
end


That would be the first part, it would create the table with all the things you need. Now, let's suppose you named your attachables like this: "Lower Armor", "Feet Armor FG", "Feet Armor BG", "Leg Armor FG", "Leg Armor BG" (This is just a supposition, you should replace the names I put here for the real ones in your mod).

If you wanted to, say, check if your lower armor still exists, you would do something like "self.MOTable["Lower Armor"].RootID == self.ID", being true if it still exists.

Then the rest of the code would look kinda like:

Code:
function Update(self)

    if self.MOTable["Leg Armor FG"].RootID == self.ID then
            ToAttachable(self.MOTable["Leg Armor FG"]).Frame = self.FGLeg.Frame;
    else
            ToAttachable(self.MOTable["Feet Armor FG"]):GibThis();
    end

    if self.MOTable["Leg Armor BG"].RootID == self.ID then
            ToAttachable(self.MOTable["Leg Armor BG"]).Frame = self.BGLeg.Frame;
    else
            ToAttachable(self.MOTable["Feet Armor BG"]):GibThis()
    end

    if self.MOTable["Arm Armor FG"].RootID == self.ID then
            ToAttachable(self.MOTable["Arm Armor FG"]).Frame = self.FGArm.Frame;
    end

    if self.MOTable["Arm Armor BG"].RootID == self.ID then
            ToAttachable(self.MOTable["Arm Armor BG"]).Frame = self.BGArm.Frame;
    end   

end


So basically you go checking if each piece of armor exists; if it exists, you set it's frame to the respective body part's frame. In the case of leg armor, if the leg armor doesn't exist anymore, you destroy the feet armor.

The whole code would look like


If it doesn't work, we could always go back to the no-tables way, or maybe someone might post another good way to do it.


Fri Apr 04, 2014 1:24 am
Profile
User avatar

Joined: Mon Mar 03, 2014 6:20 pm
Posts: 19
Location: Japan, Ninja's den
Reply with quote
Post Re: attachment frame based on parent parts frame
thanks for tell me the code.
but i'm busy this weekend. i test the code later.


Sun Apr 06, 2014 2:01 pm
Profile
Data Realms Elite
Data Realms Elite
User avatar

Joined: Fri Jan 07, 2011 8:01 am
Posts: 6211
Location: In your office, earning your salary.
Reply with quote
Post Re: attachment frame based on parent parts frame
No problem. Just remember to put the script on the actor itself and not on the armor like the previous scripts, and remember to change the placeholder names (like "Leg Armor FG") for the real names used in your mod.


Sun Apr 06, 2014 7:51 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 15 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.089s | 16 Queries | GZIP : Off ]