Double click moviment

  • #1, by yoyanWednesday, 17. December 2014, 19:35 8 years ago
    Hi, i implemented this double click scrip : local dest, dir

    function getDest()
    if game:getLink(VGameCurrentCharacter):getPoint(VCharacterDestination) ~= nil then
    dest = game:getLink(VGameCurrentCharacter):getPoint(VCharacterDestination)
    startAction("Actions[act_dbl_click]")
    end
    end

    function setDest()
    if game:getLink(VGameCurrentCharacter):getInt(VCharacterState) == 3 then
    game:getLink(VGameCurrentCharacter):setValue(VCharacterPosition, dest)
    end
    end

    Ok, work. But if im doing doubleclick outside the way border, my character disappears. i can fix up but the efect change opacity character is lost.. sorry for my english ^^

    Newbie

    32 Posts


  • #2, by afrlmeWednesday, 17. December 2014, 19:48 8 years ago
    yeah because you've teleported character from current position to outside of way borders. I didn't really take way borders into consideration. When character is outside way border they tend to float off towards northwest somewhere, for some reason.

    I guess need to include something that checks if mouse cursor is inside of way border before updating position.

    Imperator

    7122 Posts

  • #3, by yoyanWednesday, 17. December 2014, 20:48 8 years ago
    Yes, i need a simple IF type( "if Current_position_Cursor is out/in way border" do some action)...But i dont know create this script..anyone can help me to doing this? Im trying, but I do not get ..alike thanks for everything

    Newbie

    32 Posts

  • #4, by afrlmeWednesday, 17. December 2014, 21:11 8 years ago
    I'm not sure how to write a script for that off the top of my head or whether it's even possible. I recently wrote a script for checking if mouse cursor is inside of a specified radius of a circle, but that's one thing. Way borders are a lot more complicated & I'm not sure if we can access their data via the data structure tables, well not without checking anyway.

    Imperator

    7122 Posts

  • #5, by yoyanWednesday, 17. December 2014, 21:29 8 years ago
    Can i see this script? please wink. mmm Ok, i will reread data structure in wiki. thanks for all.

    Newbie

    32 Posts

  • #6, by SimonSWednesday, 17. December 2014, 22:18 8 years ago
    What is your intent ? You want to set the character immediately to that destination ?
    Trick is here to set the destination to that point, the engine will immediately work out a point inside the border (if you have points) and then set the position.

    function teleport(type, pos)
    	if type == eEvtMouseLeftButtonDoubleClick then
    		game.CurrentCharacter.Destination = {x = pos.x + game.ScrollPosition.x, y = pos.y + game.ScrollPosition.y}
    		game.CurrentCharacter.Position = game.CurrentCharacter.Destination
    	end
    end
    registerEventHandler("mouseEvent", "teleport")
    

    Thread Captain

    1534 Posts

  • #7, by afrlmeWednesday, 17. December 2014, 22:46 8 years ago
    I guess you are probably right (about the way system I mean). I don't remember having any issues when I was testing the script I wrote. I didn't create a mouseEvent for mine though. I called it inside of the mouse properties tab in double click actions - if I remember correctly I think I also queried...
    if object below cursor does not exist
    

    to prevent it from performing double click teleport if player double clicks on an object but I suppose you could adapt code for that also by having it use the object position instead of cursor. smile

    Imperator

    7122 Posts

  • #8, by yoyanWednesday, 17. December 2014, 23:05 8 years ago
    ok, thanks a lots Lee! wink I will test some things..

    Newbie

    32 Posts

  • #9, by yoyanWednesday, 17. December 2014, 23:06 8 years ago
    and also thanks SymonS Of course!

    Newbie

    32 Posts

  • #10, by afrlmeWednesday, 17. December 2014, 23:39 8 years ago
    What Simon has posted should work ok too. But I would recommend adding in some queries to prevent it from being triggered when...

    a. current character is not on the current scene.
    b. cursor is over a scene object.

    ...adaption of Simon's mouseEvent handler script.
    function teleport(type, pos)
     if type == eEvtMouseLeftButtonDoubleClick and getObject("Game.GameCurrentCharacter.CharacterScene"):getName() == game.CurrentScene:getName() then
      if game.CurrentObject:isEmpty() then
       game.CurrentCharacter.Destination = { x = pos.x + game.ScrollPosition.x, y = pos.y + game.ScrollPosition.y }
      else
       game.CurrentCharacter.Destination = { x = game.CurrentObject.Position.x, y = game.CurrentObject.Position.y }
       game.CurrentCharacter.Direction = game.CurrentObject.Direction -- update character alignment to object.
      end
       game.CurrentCharacter.Position = game.CurrentCharacter.Destination -- update character position (instantly)
     end
    end
    
    registerEventHandler("mouseEvent", "teleport") -- creates the mouse event handler which is handled by teleport() function
    

    ...it seems to work. It's more or less same as Simon script but it queries if current character is on current scene & if no object exists below cursor then use mouse position else jump to objects position & align to defined object position. Just add it as a definition script to the script section.

    If you want to add character fade transparency in/out then you could do so by creating a called by other action & adding set character opacity action to 0% over x time > pause for x time > set character opacity to 100% over x time.

    Imperator

    7122 Posts