Chasing character interaction.

  • #1, by ke4Monday, 14. September 2015, 18:38 10 years ago
    Hi, i have NPC chasing the main character, obejtcs has point where the character is supposed to stand on interation, but characters doesn't have that. I need the main character to be able to talk with the chasing character which is always on a different place. I can get the NPC position or align the main character to this NPC, but still i don't know where to send the main character, do you have some ideas how to deal with it?
    Thanks.

    Key Killer

    810 Posts


  • #2, by afrlmeMonday, 14. September 2015, 19:42 10 years ago
    If you left click on the character or execute a talk command (both immediate actions) then you could have the npc stop chasing character, stop, then use a line of Lua to send the active character to the npc position minus / plus x or y offset value depending on direction the npc is facing. Then you would add a wait until character (active) stops... then add the actions you want to execute on the npc.

    Just an idea / theory at this point as I've not tried to sort anything out like that before. Should work though.

    Imperator

    7285 Posts

  • #3, by ke4Monday, 14. September 2015, 20:07 10 years ago
    Nice idea,
    it looks like it will be a bit complicated, there is one more issue i can think of now that i can't send the character out of the way border, but that should be covered by the plus/minus from where the character comes to the NPC.

    Key Killer

    810 Posts

  • #4, by sebastianMonday, 14. September 2015, 20:32 10 years ago
    I guess you have to manually set the talkpositions for eachs scene to prevent the chasing char running to invalid places...
    My idea is that you could call the action (which you set and name them always the same in each scene) by the talk-action for the charactar via lua.

    So when using "talk"/"interact"/... on the chase-char you execute the a script like

    scene = game:getLink(VGameCurrentScene)
    startAction("scene.SceneActions[interact_chase]") *
    

    *I did not tested this razz

    Inside the "interact_chase" action for each scene you could tell the characters to go to different places. After they went to the correct place you can call another action which is the same for every "interact_chase" scene action to proceed further stuff

    Thread Captain

    2346 Posts

  • #5, by afrlmeMonday, 14. September 2015, 20:42 10 years ago
    Sure you could define pre-destinations for the NPC after stopping the chase which would be the simpler method, but it would be a lot more natural if the character could walk to the characters position instead give or take a few pixels.

    Imperator

    7285 Posts

  • #6, by ke4Monday, 14. September 2015, 20:46 10 years ago
    I wil try that and see what works best and then give you some feedback.

    Key Killer

    810 Posts

  • #7, by sebastianMonday, 14. September 2015, 21:10 10 years ago
    hmm regarding Lee's Idea you have to check if the chasers "new" position relative from the current char is inside the waysystem polygon

    Thread Captain

    2346 Posts

  • #8, by afrlmeMonday, 14. September 2015, 22:13 10 years ago
    It shouldn't matter. The engine automatically prevents player from walking outside of way border. It should automatically send player to nearest path point I think. You'd have to try it to verify though.

    Imperator

    7285 Posts

  • #9, by ke4Tuesday, 15. September 2015, 09:51 10 years ago
    Can send but not set.

    Stop chase

    local k, p, dx
    
    k = Characters["kolegaNormal"]:getPoint(VCharacterPosition)
    p = game.GameCurrentCharacter:getPoint(VCharacterPosition)
    
    if p.x >= k.x then
    dx = k.x + 150
    else
    dx = k.x - 150
    end
    
    game.GameCurrentCharacter:setValue(VCharacterDestination, {x=dx, y=k.y})
    


    Wait until character stops
    align characters
    Actions
    Start chase

    I don't know if thats bug or not, but if the character starts to chase again even if the character is not out of the range always goes a few pixel to the main character which looks bad, otherwise works great but i didn't try the way border thing yet.

    Key Killer

    810 Posts

  • #10, by afrlmeTuesday, 15. September 2015, 10:46 10 years ago
    You are mixing up shorthand with long hand (getObject) scripting methods.

    definition script...
    function getTalkDest(c)
     c = Characters[c].Position
     -- + --
     if game.CurrentCharacter.Position.x >= c.x then
      game.CurrentCharacter.Destination = { x = (c.x + 150), y = c.y }
     else
      game.CurrentCharacter.Destination = { x = (c.x - 150), y = c.y }
     end
    end
    

    example usage (inside execute a script action)
    getTalkDest("Tom") -- Tom being the npc character.
    


    Not tested & I've only just woken up, so a little groggy, but it should work.

    Imperator

    7285 Posts

  • #11, by ke4Tuesday, 15. September 2015, 11:10 10 years ago
    Don't need a function for that i will have only one chasing character.
    I was using what i found in the wiki not sure if there is more info about shorthands somewhere. It's working like that.

    local c = Characters["kolegaNormal"].Position
    
    if game.CurrentCharacter.Position.x >= c.x then
     game.CurrentCharacter.Destination = { x = (c.x + 150), y = c.y }
    else
     game.CurrentCharacter.Destination = { x = (c.x - 150), y = c.y }
    end
    

    Key Killer

    810 Posts