Send character to position_LUA [SOLVED]

  • #1, by red363Tuesday, 16. August, 11:56 A month 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.

    Newbie

    81 Posts


  • #2, by afrlmeTuesday, 16. August, 13:34 A month 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

    Imperator

    7183 Posts

  • #3, by red363Tuesday, 16. August, 16:32 A month 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.

    Newbie

    81 Posts

  • #4, by afrlmeTuesday, 16. August, 19:53 A month 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.

    Imperator

    7183 Posts

  • #5, by red363Wednesday, 17. August, 08:21 A month 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.

    Newbie

    81 Posts

  • #6, by afrlmeWednesday, 17. August, 12:30 A month 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.

    Imperator

    7183 Posts

Write post