Send character to position_LUA [SOLVED]

  • #1, z red363Tuesday, 16. August 2022, 11:56 hodinky 2 years ago
    Hello!

    Sorry for the possibly stupid question.

    Can you suggest a script, the essence of which is:
    send a certain character to the given coordinates (his coordinates + some value).
    About:

    execute script:
    send character "name" to position (x=character"name"position.x+300, y=character"name"position.y+200)

    Thanks.

    Fanoušek fóra

    101 Posts


  • #2, z afrlmeTuesday, 16. August 2022, 13:34 hodinky 2 years ago
    Here's a quick workflow function for offsetting a character from their current position as that is what you appear to be asking for...


    Add the function below into the script section of the editor as a definition type script...

    function offsetChar(char, x, y)
    
      char = Characters[char] -- store the characters table in the char variable
    
      char.Destination = { x = char.Position.x + x, y = char.Position.y + y } -- update destination
    
    end


    To use the function wherever you need it, you can create an execute a script action part & then you would add some code along the lines of this into it...

    offsetChar("Tom", 300, 200)


    Quick note: if you use negative numbers then it will subtract from current position instead of adding. Example: -300

    Anyway, just in case you want to know how to send a character to absolute coordinates, then this is how you would go about it...

    game.CurrentCharacter.Destination = { x = 300, y = 200 } -- update playable character destination


    or...

    Characters["Tom"].Destination = { x = 300, y = 200 } -- update Tom's destination

    Imperátor

    7285 Posts

  • #3, z red363Tuesday, 16. August 2022, 16:32 hodinky 2 years ago
    Thank you very much for the answer, but the function offsetChar does not work for me.
    Nothing happens until I can figure out what the problem is...

    maybe I should write something in the definition script?

    Send a character to absolute coordinates works good.

    Fanoušek fóra

    101 Posts

  • #4, z afrlmeTuesday, 16. August 2022, 19:53 hodinky 2 years ago
    Are you using it correctly? You need to add the script I provided you with to the script section of the editor & the definition checkbox needs to be ticked. You can then call the function via execute a script action parts & will look  something like this...

    offsetChar("Tom", 300, 200)

    Quick note: names are case senstive & need to be written exactly how you named them, spaces & all.

    edit: I just tested out the function in one of my test ved & it works ok for me.

    Imperátor

    7285 Posts

  • #5, z red363Wednesday, 17. August 2022, 08:21 hodinky 2 years ago
    Thanks a lot, got it. The problem was that I had the Y value set too high (out of range) during testing, so the character refused to move. Now everything works.

    Fanoušek fóra

    101 Posts

  • #6, z afrlmeWednesday, 17. August 2022, 12:30 hodinky 2 years ago
    Probably also to do with the way paths you setup in your way system for the scene. The engine should auto-recalculate a new destination position if the player clicks outside of the way borders providing there's enough way path nodes for it to use for calculating nearest point, but I don't know if it does that if we force destination via script or only when a player actually clicks somewhere on the screen.

    Imperátor

    7285 Posts