Hey, we have forums!

Author Topic: Replacing the Main Character  (Read 17658 times)

0 Members and 1 Guest are viewing this topic.

Offline Don Andy

  • Giant Bit
  • ******
  • Posts: 209
    • View Profile
    • Last Ninja Online
Replacing the Main Character
« on: December 10, 2007, 08:57:58 pm »
Is it possible to change the graphics of the main character (well, Naija) in any way?
I found you can rearrange her limbs and animation in the Animation editor. But I'm still looking for a a way to give her completely new graphics. Any pointers in the right direction? It would, for example, be interesting to make new costumes for Naija that way, or even make a mod you play from the perspective of an enemy ;)

Offline Alec

  • Administrator
  • Dream Bit
  • **********
  • Posts: 2211
    • View Profile
Re: Replacing the Main Character
« Reply #1 on: December 11, 2007, 09:54:21 am »
Yeah, there are a couple of ways to do this!

Method 1: Skinning Naija / Editing Naija's Animation File

You can edit Naija's animation file and skins directly. I've included some in this WIP mod called "Aquaria Story"


(graphics by Adam Saltsman)

You can poke around in the naija.xml and skins/energyform.xml etc files to see how that's done.

(basically it makes all of her bones invisible except the body + replaces the body with the sprite)

But you can also replace all the bones to make a skin etc.

Method 2: Separate Entity

In terms of controlling a completely different entity, you can just write up a script for the entity that does things based on input. (not sure if there are enough functions to do this yet, but I'll look into it and add some if needed)

To do that, say you had an entity called "Frank" that could be controlled.

make a new node script file node_initfrank.lua

Code: [Select]
frank = 0

function init(me)
    frank = createEntity("Frank", "", entity_x(me), entity_y(me))
    cam_toEntity(frank) -- make the camera follow frank

    -- move naija to 0,0 and move frank to naija's old position
    n = getNaija()
    entity_setPosition(frank, entity_x(n), entity_y(n))
    entity_setPosition(n, 0, 0)
end

function update(me, dt)
end

Add the node to the desired level + reload.

Now the camera will be locked to frank instead of naija. I think you'd also need to disable all of naija's input, which I'm not sure can be done yet. (I'll check)
« Last Edit: December 12, 2007, 01:26:30 am by Alec »

Offline Don Andy

  • Giant Bit
  • ******
  • Posts: 209
    • View Profile
    • Last Ninja Online
Re: Replacing the Main Character
« Reply #2 on: December 11, 2007, 10:06:36 am »
Oooh, big thanks for the elaborate reply and (hopefully soon) example mod xD

This gives me some very interesting ideas :D

Offline Burton Radons

  • Mini Bit
  • **
  • Posts: 9
    • View Profile
Re: Replacing the Main Character
« Reply #3 on: December 11, 2007, 10:33:28 am »
Edit: Whoa! You hadn't responded while I was writing this, Alec. Thanks for the info!

Technically you can do so by calling "entity_initSkeletal(getNaija(), "priest")". This causes the avatar to change correctly while editing, but as soon as I switch back to the game it crashes. I think the problem is that entities often keep bones in their variables (such as the neck for hanging the cloak). These bone references are to pointers that change depending upon the skeleton, so when you change the skeleton the bone references are garbage and entity_getBoneByName needs to be called again. There should be a function in Naija's script that allows it to reinitialise those for costume changes, but I don't know how to call an entity's function from another script directly. I really doubt you can.

One way to hack this is to make a second entity that hides Naija and moves itself into her place. Here's a start of doing that:

Code: [Select]
dofile("scripts/entities/entityinclude.lua")

n = 0 -- Link to naija.

function init(me)
setupEntity(me)
entity_setEntityType(me, ET_ENEMY)
entity_initSkeletal(me, "mermanthin")
entity_setState(me, STATE_IDLE)

-- Find the Naija entity.
n = getNaija ()

-- Move the bones to the right positions.
entity_animate (me, "idle", LOOP_INF)
end

function update(me, dt)
-- Hide Naija.
entity_alpha (n, 0)

-- Face the same way as Naija; I don't know how to get rid of the transition.
entity_flipToSame (me, n)

-- Move to Naija's position.
entity_setPosition (me, entity_getPosition (n))

-- Change to Naija's angle.
entity_rotate (me, entity_getRotation (n))

-- Use the same animation as Naija if they're different.
-- If the skeleton doesn't have this animation then it turns into a body part jumble.
if entity_getAnimationName (me) ~= entity_getAnimationName (n) then
entity_animate (me, entity_getAnimationName (n), LOOP_INF)
end
end

Just put that into an entity lua file, add it to entitygroups.txt, and then put it in the level (you can keep the editor open and just hit F1 to reload the level). As soon as you get out of the editor you should look like a mermanic jerk. His animations work for idling, swimming, surging, and sort of for wall hanging (he doesn't have a proper animation hanging onto the ground and he tries to walk along the wall).

Even if you could substitute a skeleton directly, the behaviour would be similar to what you see with this hack, with body part jumbles showing up if it doesn't have that animation. Naturally a sea turtle doesn't know how to hang onto walls, or even how to swim.

Edit edit: Here's an update of the animation part that allows you to substitute animations which don't work, and it also shows a nice way to use setControlHint to pass information about game state while testing. You can keep Naija from hanging by calling "avatar_fallOffWall ()" in the update function.

Code: [Select]
anim = entity_getAnimationName (n)
if entity_getAnimationName (me) ~= anim then
changeto = anim -- The animation to change to, or "no change" to ignore Naija.

-- We don't have "walllookup" (for when holding onto the floor), so use "wall" instead.
if anim == "walllookup" then
changeto = "wall"
end

if changeto ~= "no change" and entity_getAnimationName (me) ~= changeto then
entity_animate (me, changeto, LOOP_INF)
end

-- setControlHint ("Animation: " .. entity_getAnimationName (n), 0, 0, 0, 2)
end
« Last Edit: December 11, 2007, 11:10:18 am by Burton Radons »

Offline Alec

  • Administrator
  • Dream Bit
  • **********
  • Posts: 2211
    • View Profile
Re: Replacing the Main Character
« Reply #4 on: December 11, 2007, 11:18:12 am »
P.S. there is also a debug output console that you should be able to access with '~' (tilde)

debugLog(...) function takes a string, and you can see its results on the console (they'll also end up in the debug.log file)

Offline Burton Radons

  • Mini Bit
  • **
  • Posts: 9
    • View Profile
Re: Replacing the Main Character
« Reply #5 on: December 11, 2007, 06:20:20 pm »
P.S. there is also a debug output console that you should be able to access with '~' (tilde)

Nope! Doesn't work either in the mod game, in the editor, with the menu open, or with any alt-shift-control-windows-menu combinations. I tried (apparently) unlocking developer keys, but I can't get anything interesting going on with that.

Offline Crizzle

  • Extra Bit
  • *****
  • Posts: 108
    • View Profile
Re: Replacing the Main Character
« Reply #6 on: December 11, 2007, 08:16:32 pm »
Wow I love these in-depth responses from Alec and Derek, good stuff. Can't wait to get the full version and start modding. :D

Offline Alec

  • Administrator
  • Dream Bit
  • **********
  • Posts: 2211
    • View Profile
Re: Replacing the Main Character
« Reply #7 on: December 12, 2007, 12:30:23 am »
Oops! Sorry about that debug console thing. I thought I added it into the mod stuff, but I guess not. (those 7 days are a total blur lol)

I'll probably put that and whatever other solid mod suggestions come up into the next patch.

Offline Ixis

  • Bit
  • ***
  • Posts: 47
  • Doesn't approve of what you did with that nun...
    • View Profile
    • Ixis' deviantART site
Re: Replacing the Main Character
« Reply #8 on: December 12, 2007, 04:25:21 am »
Where is naija.xml and skins/energyform.xml and are those pixels in the data we've got?

Offline Alec

  • Administrator
  • Dream Bit
  • **********
  • Posts: 2211
    • View Profile
Re: Replacing the Main Character
« Reply #9 on: December 12, 2007, 04:27:27 am »
I have to upload the mod first. Either in a while or tomorrow. (starting to fall asleep)

Offline Ixis

  • Bit
  • ***
  • Posts: 47
  • Doesn't approve of what you did with that nun...
    • View Profile
    • Ixis' deviantART site
Re: Replacing the Main Character
« Reply #10 on: December 12, 2007, 05:44:46 am »
I have to upload the mod first. Either in a while or tomorrow. (starting to fall asleep)

Then don't worry about it right now, lol.

Offline SCORCHED YOU

  • One Bit
  • *
  • Posts: 1
    • View Profile
Re: Replacing the Main Character
« Reply #11 on: December 14, 2007, 07:06:20 am »
I have to upload the mod first. Either in a while or tomorrow. (starting to fall asleep)

But these xml files are included in the "data.000" archive, correct? Is it possible to unpack that? What tool would we use? The easiest way to learn how to make entities and whatnot would be to see exactly how you made the existing ones. I'm also starting to think about a mod that would need the interface to be changed. Is that possible?

Offline blackzeroflame

  • Bit
  • ***
  • Posts: 48
    • View Profile
Re: Replacing the Main Character
« Reply #12 on: December 14, 2007, 09:06:00 pm »
nice cave-story reference there by the way, Alec

Offline DavidBeoulve

  • Mini Bit
  • **
  • Posts: 8
    • View Profile
Re: Replacing the Main Character
« Reply #13 on: December 16, 2007, 01:33:54 am »
Any word on how to unpack the DATA.000 file?

I'd like to just modify Naija's sprite parts.