Data Realms Fan Forums
http://45.55.195.193/

Random Head
http://45.55.195.193/viewtopic.php?f=73&t=45979
Page 1 of 1

Author:  SnowMonster20 [ Sun Aug 09, 2015 5:46 am ]
Post subject:  Random Head

Hi,

So I am aware that the Ronin use a small script to basically choose one frame from an "animated" head sprite to make it seem as though the head is random. My question would be is it easily possible to make it so that the random head is the actual attachable head instead of a frame on the sprite?

Let me try to elaborate:

Say I have head1000, head2000, and head3000. 3 separately coded heads with their own attachable and what-have-you. Can I edit the Ronin script to pick from one of these heads for any given actor? Would I attach the script to my base actor and then it would choose a random head from a table or something?

Also I'm sure it probably doesn't matter but would a head be displayed in the buy menu for the actor?

Author:  CaveCricket48 [ Wed Aug 12, 2015 2:04 am ]
Post subject:  Re: Random Head

There's not really a way to swap out the actual head of an actor. There are, however, workarounds, depending on what exactly you're trying to do.

For example, if your goal is: Actor has multiple random heads, with the only differences being different attachments on the heads (helmets, sunglasses, etc.).

Solution: The actor has a single head, and all possible attachables are attached to the head. The actor's head is scripted to randomly "choose" a set of attachments to use - all other attachments are deleted.


If that's not what you're trying to do, being a bit more specific would help.

Author:  SnowMonster20 [ Wed Aug 12, 2015 4:16 am ]
Post subject:  Re: Random Head

Ok I will try to explain better :grin:

lets say I have 3 heads that each have their own unique attachment, such as a helmet or hat or what-have-you.

Head001 has Hat001, Head002 has Hat002 and so-forth.

They will all use the same body.

Is there a workaround for such a thing? Basically what I'm trying to do is keep the mod more vanilla-ish with only 2 or 3 buy-able actors (light, med, heavy) but still being able to include a variety of unique sprites for fun and diversity.

All X heads are different, in terms of sprite dimensions and overall look, so it wouldn't be an option to do the Ronin animation thing I don't think. Also the attachables specific to a given head is important. Head001 cant wear Hat002 if that makes sense. The attachables are also important in that I dont want to include them as part of the head because I would like to stay away from my actor taking damage if he gets shot in the hat.

Or would it be easier or possible to make all the faces into frames in a sprite and make it so if, for example, frame001 is chosen through lua it will force it to have hat001?

Author:  p3lb0x [ Thu Aug 13, 2015 5:20 pm ]
Post subject:  Re: Random Head

You could have a Lua script on creation that picks a random head, and then positions the hat attachment appropriately while changing both of the sprites.

Author:  SnowMonster20 [ Fri Aug 14, 2015 4:59 am ]
Post subject:  Re: Random Head

So the script would make it so if head001 was picked it would choose hat001 and change the offsets of the hat to a specific point through lua? Or would it be head and hat are both frames in a sprite and it changes offsets depending on which hat frame it picked?

What would be needed to keep it from picking frame X if frame Y is chosen?

Like I said, if possible I'd like it so head a can't wear hat b.

Also if I don't make sense then let me know and I'll post the mod and sprites and pic of what I'm trying to do :)

Author:  CaveCricket48 [ Sat Aug 15, 2015 8:07 am ]
Post subject:  Re: Random Head

SnowMonster20 wrote:
What would be needed to keep it from picking frame X if frame Y is chosen?


self.Frame = Y;


You just tell it what to do.

Author:  p3lb0x [ Sat Aug 15, 2015 2:12 pm ]
Post subject:  Re: Random Head

Something like this pseudocode. While I am sure there's some distribution problems with this, something like it should work. Even if it's probably hella inefficient. You'd probably also need some code to find the hat attachable, but I don't remember enough about Cortex Commands lua to do anything about that

Code:
function Create(self)

local hatOffsets = {
                   {0,0},
                   {1,5},
                   etc
                   }
local legalHats = {
                  {1,5,13},
                  etc
                  }

self.headIndex = math.random(1, #legalHats)
self.head.frame = self.headIndex


repeat
   local legalHat = false
   self.hatIndex = math.random(1,#hatOffsets)
   for i = 1, 1, #legalHats[self.headIndex] do
      if(self.hatIndex == legalHats[self.headIndex][i]) then
         legalHat = true
         break
      end
   end
until legalHat == true

self.hat.frame = self.hatIndex
self.hat.jointOffset = hatOffets[self.hatIndex]

end

Author:  SnowMonster20 [ Sat Aug 15, 2015 8:54 pm ]
Post subject:  Re: Random Head

Would that attach to the head or the hat object?

would i have the ronin script on the head itself and have a script on the attachables to make it so if head x is picked then it picks hat x and sets the offsets?

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