How to Completely Clone Actor using Script?

● ARCHIVED · READ-ONLY
Started by watermark 15 posts View original ↗
  1. Pardon but can't seem to find this. In RPGVX Ace using script, how can I completely clone an actor in the database including name, features, graphics, equipment, etc.? Something like the pseudo code below:

    $game_actors[1] = $game_actors[2].clone

    This way the first actor will have the exact same data as the second actor.

    I was thinking of using the database as a template holder, and I can change the properties of the main characters this way.

    Thanks!
  2. You can look at this for reference

    http://www.rpgmakervxace.net/topic/1369-actor-clone-script/

    Two things

    First, you need to generate a new ID for the game actor. Depending on what you actually need to do, you may need to create a new record in the database as well.

    Second, even if you clone an object, the instance variables still hold the same references.

    class Test attr_accessor :id attr_accessor :nums def initialize(id, nums) @id = id @nums = nums endendt = Test.new(1, [1,2,3])t2 = t.clonet2.id = 2t2.nums << 5p t.numsYou create a Test object with [1,2,3].You clone it.

    You modify the clone by adding a new number.

    And now suddenly the original object also has the new number.

    This is why people use Marshal.load(Marshal.dump(obj))
  3. Thanks! However I ran into another problem. I can clone the actors now but I can't put them into the game_actors array. Why?

    This works:

    new_actor = $game_actors[1]

    But why does the game throw an error for this:

    $game_actors[1] = new_actor

    I need this to happen because the in game dialogue will use \n[1] tags for the character names, which will be user generated.
  4. why not use a dummy actor for the name input instead? Or why do you even need a new actor for name input?


    If you just need a new actor because you're modifying the name, then I tell you, you don't need a new actor for that. There's an event command for name input, you could also do it via scripts, and it only affects the actor on the current playthru, it doesn't modify the database. No need for a new actor just to have a different name.


    @Hime - Ah, so that's why Vlue used Marshal.load(Marshal.dump) in his affix/suffix script. :)
  5. I've moved this thread to RGSSx Script Support. Please be sure to post your threads in the correct forum next time. Thank you.
  6. I am making a system where the player can select character races and classes. I am thinking of using the actor database as template holders for racial traits. So when the player creates a new actor the actor can clone an existing racial template, say elf or dwarf. 
  7. But why clone? You can just use the actor itself and change classes using event commands.


    Or it's like the player can create lots of characters in a single play? Like a party of 4 elves or something?
  8. Yes. Exactly. The player can choose to have a party of 4 elven wizards if that's what he wants. It's not smart, but he can do it. So I need to clone. Also, there will be times when I need Actor 1 to speak with the \n[1] tag. With the party \p[1] tag it changes depending on order so I can't use that.
  9. You don't create a new Game_Actor - you create a new $data_actor. Clone the $data_actors object into a new one, change the actor id, then add a new Game_Actor using the new id, which will then look up the new $data_actor. Some of the methods in Game_Actor refer back to the original $data_actor object, so you need both.


    This means you will need to save $data_actors in your save file, which also means you'll need to reload $data_actors from the .rvdata2 file when you launch a new game.
  10. Actually, why not just change the sprites and classes using event commands? If he has racial feautures, you can simply make racial versions of the classes instead and add the racial features to them. And you can always have the racial classes still have the same name in case you need it.


    This way, you can achieve what you want with the base features that the editor has to offer.


    can you post a screenshot of your actor database? I just wanna check something...
  11. Oh, I just reread. Yeah, you're better off having just enough actors defined in the database to cover the number you're going to allow the player to have. Then change their class to what the player wants.
  12. basically, all you would do is have 4 actors with nothing in them. Then create the classes, 1 of each class per race.


    So let's say you have 2 classes (warrior and mage) and 2 races (human and orc), you will have a total of 4 classes. Human Warrior, Human Mage, Orc Warrior and Orc Mage. Give the human classes, the human features and the orc classes the orc features.


    Then when your player chooses a race, change his sprite (unless it's class specific too)


    then make him choose a class, then change the actor's class to the appropriate variation of that class for his race (and change sprite if needed)
  13. @Engr

    Thanks for the advice. I was hoping using both the actor and class list, the classes will automatically '"inherit" any changes I make to races. But I am sure the racial class method will work just as well in the practical sense. If I can't figure out this clone actor coding I will try the racial class method.

    @Shaz

    A new $data_actors is required? I will try to see if I can do this. Thanks!
  14. I would really suggest just using the racial class method, it's more hassle free IMHO. :)
  15. A new record in the database is not required if you are just going to use an existing record as a template.


    Look at how fomar does it.