[SOLVED]How to save and restore the position of NPC ?

  • #1, by wimfThursday, 05. April 2018, 18:06 6 years ago
    I have an NPC walking in a scene. When my main character leaves the scene and comes back, my NPC restarts the walk from it starting position.

    I would like to be able to save the coordinates of the NPC when leaving the scene, and restore it when we the player return to this scene, so that my NPC continues to walk from this new point.

    An idea in Lua?

    thank you very much

    Forum Fan

    238 Posts

  • #2, by afrlmeThursday, 05. April 2018, 18:48 6 years ago
    It should automatically save the position of the character in the save file so it's probably something to do with how you have setup the at beginning of scene actions.

    Failing that, then sure you could use Lua script to store the coordinates inside of some vs values.

    Stop character, before changing to menu scene. Then with Lua you could store the coordinates in some values like so...
    Values["tom_x"].Int = Characters["tom"].Position.x
    Values["tom_y"].Int = Characters["tom"].Position.y

    In your at begin of scene action you can now check if character tom is on the scene & if they are then teleport them to the position in the values - I'm sure you can work it out from my code block above & then you can set their destination position.


    7278 Posts

  • #3, by wimfFriday, 06. April 2018, 13:39 6 years ago
    Yes, it's working, thank you AFRLme smile

    I have use this code in beginning scene :

    local NPC1 = getObject('Characters[visiteurcimetiere]')
    NPC1 :setValue(VCharacterDestination, {x, y} ) 

    Forum Fan

    238 Posts