basic stealth coding question ???

Discussion in 'Javascript/Plugin Support' started by Unknown2001, Oct 6, 2019.

  1. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA
    Hello internet friends

    can I please have some help with my stealth code

    I am super new to rpg maker mv and have never used Java script before
    I am enjoying adding a little stealth level to my game
    I am mainly copying these cool tutorials even tho they are for vx ace and I am using





    I am trying to create a moving guard with a limited line of sight
    because the guard is moving (patrolling up and down) in such a long area they go off screen
    the guards limited line of sight/vision cone must move with them to prevent the player been seen from so far away that they can't even see the guard :(
    again I've never used java script b4
    so the code I'm trying to write is:
    ----------------------------------------------------------------------
    if ( $gamePlayer.x =<93 &&
    $gamePlayer.x =>103 &&
    $gameGuard.isFacing(down)
    $gamePlayer.y = ($gameGuard.y +6)
    {
    $gameMessage.add("HEY!?, You can't be in here!");
    $gamePlayer.reserveTransfer(Map_1, x, y, direction, fade type);
    }
    ------------------------------------------------------------------------

    what I am trying to do in my code:
    ------------------------------------------------------------------------
    if the player is inside the guards line of sight (setting the left border of guards vision)
    then setting the right border of guard vision
    and if the guard is facing down
    and if the player gets 6 squares away from the guard
    then show some text of guard saying "HEY!?, You can't be in here!"
    and transfer the player to another map (in this case a continue screen)
    -------------------------------------------------------------------------
    I found this link which helped


    but at this point beginning it's literally a new language for me
    the reason I'm trying to do this by coding is the 4th line where I'm trying to find a way to make the game react to the player getting within 6 squares of a moving guard

    I hope a coding hero can help with my coding quest please?
     
    #1
  2. Oddball

    Oddball Veteran Veteran

    Messages:
    1,667
    Likes Received:
    442
    First Language:
    English
    Primarily Uses:
    N/A
    #2
  3. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,509
    Likes Received:
    3,763
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    Galv's plugin is probably the best fit for this sort of thing, but it's pretty old so if there are problems with it, you could also look into Yanfly's Event Proximity Activate - you just need to do a bit of extra work to make sure the guard is looking in the correct direction.

    You have the right idea with your code, but here are a few reasons your code isn't working:
    if ( $gamePlayer.x =<93 &&
    $gamePlayer.x =>103 &&
    $gameGuard.isFacing(down)
    $gamePlayer.y = ($gameGuard.y +6)
    {
    $gameMessage.add("HEY!?, You can't be in here!");
    $gamePlayer.reserveTransfer(Map_1, x, y, direction, fade type);
    }

    Syntax errors in red, Logical errors in orange
    • First parenthesis ( is unmatched. There should be a closing parenthesis ) at the end of the fourth line.
    • =< and => are incorrect syntax; use <= and >= instead.
    • I don't know whether isFacing is a method or not. I usually use [[object]]._direction === 2 to see if [[object]] such as $gameGuard is facing down. 2 = down, 4 = left, 6 = right, 8 = up.
    • $gameGuard will only work if you've defined what $gameGuard is. Usually, you don't want to use a global variable (starting with a $) to refer to a map event, except for the player. You can refer to a map event with $gameMap.event(n) where "n" is the Event ID of the Guard.
    • Your fourth line has a serious logical error. This requires that the player is EXACTLY 6 tiles below the Guard. If you want to make it UP TO 6 tiles below the Guard, you could do Player Y >= Guard Y and Player Y <= Guard Y + 6.
    • Your first two lines together also present a serious logical error. The player's X cannot be both less than (or equal to) 93, and greater than (or equal to) 103, at the same time. You probably want to reverse the less than/greater than's.
    If your Guard isn't moving, you can simplify things greatly - just place invisible Touch Events wherever you want to trigger the Guard "seeing" you, and when the player steps on any of these, have that invisible event turn ON a Switch that makes the Guard see you (by having the Guard's "I see you!" eventing be on a second page that requires this Switch to be ON in its page conditions).

    If you're trying to make a big stealth game with very fine levels of detection, the best way to do this, I'd say, would be to use trigonometry to determine whether the player is in a guard's line of sight. To be really honest, RPG Maker isn't the best engine for that kind of thing, but it's doable. I don't know the exact code you'd need, but I think I know the logic. It's very complex, so only take a peek if you're trying to make an entire game out of stealth:
    I believe you want to get the difference between player's X and guard's X, and the difference between player's Y and guard's Y, then divide the Y difference by the X difference. Plug the result into an "arctan" (trigonometric arctangent) function to get the number of degrees, and determine the Guard's current direction that he's facing (right = 0 degrees; up = 90 degrees). If the difference between those is 45 degrees or less, the Guard is in the right direction to see you. Then, you also need to gauge the player's distance from the guard. Square (raise to the power of 2) both the X difference and Y difference, add them together, and take the square root to get the distance from the Guard to the Player. If that distance is less than or equal to N (the distance you want the Guard to be able to spot the Player from), and the Guard was facing in the correct direction (as established earlier), then the Guard "spots" the Player!
     
    #3
    caethyril and Oddball like this.
  4. Bex

    Bex Veteran Veteran

    Messages:
    1,267
    Likes Received:
    300
    First Language:
    German
    Primarily Uses:
    RMMV
    The following very Basic example is made with standard Editor:
    Code:
    Control Variable1 = PlayerMapX
    Control Variable2 = PlayerMapY
    Control Variables1 - Guard1MapX
    Control Variables2 - Guard1MapY
    
    If Guard1 is Facing Down
    If Variable1 is equal or more than -1
    If Variable1 is equal or less than 1
    If Variable2 is equal or more than 0
    If Variable2 is equal or less than 6
     If all yes: Textbox you got caught.
    
    If Guard1 is Facing Left
    If Variable1 is equal or more than -6
    If Variable1 is equal or less than 0
    If Variable2 is equal or more than -1
    If Variable2 is equal or less than 1
     If all yes: Textbox you got caught.
    
    If Guard1 is Facing Right
    If Variable1 is equal or more than 0
    If Variable1 is equal or less than 6
    If Variable2 is equal or more than -1
    If Variable2 is equal or less than 1
     If all yes: Textbox you got caught.
    
    If Guard1 is Facing Up
    If Variable1 is equal or more than -1
    If Variable1 is equal or less than 1
    If Variable2 is equal or more than -6
    If Variable2 is equal or less than 0
     If all yes: Textbox you got caught.
    Line of sight for Guard Facing right is: (X= In Range, G = Guard)

    X X X X X X X
    G X X X X X X
    X X X X X X X
     
    #4
    caethyril, Wavelength and Oddball like this.
  5. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA
    ======================================


    Thank you for your help I have changed my code to
    ---------------------------------------------------------------------------------------------------------------
    if ( $gamePlayer.x >=93 &&

    $gamePlayer.x <=103 &&

    [[Guard01]]._direction===2

    $gamePlayer.y >= [[Guard01]].y && $gamePlayer.y <= [[Guard01]].y + 6

    )

    {

    $gameMessage.add("HEY!?, You can't be in here!");

    }
    ------------------------------------------------------------------------------------------------------------------

    but I did not really understand your 3rd dot point and how you write an object, in other programs I used it was: obj.example
    could you please simplify it, this is the first line of code I am writing on RPG maker MV
     
    #5
  6. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA
    =======================================

    thank you for your help
    would I just paint this into script option?
     
    #6
  7. Bex

    Bex Veteran Veteran

    Messages:
    1,267
    Likes Received:
    300
    First Language:
    German
    Primarily Uses:
    RMMV
    No Script thingys, just use the corresponding Eventcommands and rebuild it in your RPG Maker. If statement = Conditional Branch Eventcommand
    Create a Parallel Event and insert:
    - The Code
    - And Eventcommand Wait 15Frames, because 60Frames = 1Second, and Eventpages of Events when Parallel run again around every Frame, and this doesnt need to be checked up to 60 Times per second.
     
    #7
  8. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA
    thank you this pluggin looks great and with my skill level right now I would like to stick to pluggins but I'm finding it hard to work out how to use this one because this guys demos never work for me so I'll look for a tutorial,
    any advice you have would be great please?
     
    #8
  9. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA


    I am not at my best right now, I am guessing you create a conditioinal branch, 4, script then type in
    Galv.DETECT.event(Guard01,6,true)
    ???????

    from the pluggin instructions:
    ----------------------------------------------------------------------------

    Conditional Branch SCRIPT

    ----------------------------------------------------------------------------

    You can use the below script call to check if an event can detect the player

    at the time the conditional branch is called. (Yes this can be used in a

    parallel process event if required)



    Galv.DETECT.event(id,dist,los) // id = event ID that is a detector

    // dist = tile distance from player

    // los = true or false for line of sight



    This will return true if the player is in distance range of the event and

    if los is true, it will also check if player is in line of sight to it.

    ----------------------------------------------------------------------------
     
    #9
  10. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,509
    Likes Received:
    3,763
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    Yeah, the form for referring to objects is similar to that in other programs. For example $gamePlayer._direction === 2 will return true when the player is facing down (and false otherwise). $gameGuard._direction === 2 will work if you've already defined what $gameGuard is. Otherwise, $gameMap.event(n)._direction === 2 will work for the Event on your map with Event ID n.

    Bex's suggestions are not code so you don't use the Script event command for them. They are event commands of their own. For example, his first four lines use the Control Variable event command, and the next line after that is a Conditional Branch event command with stuff inside the branch. I recommend becoming extremely familiar with all the event commands in the game before trying to use code in RPG Maker. Most stuff you want to do can be done much more easily with event commands.

    Finally, in the future please do not Double-Post. (Double-Posting is posting directly after yourself with no one else posting in-between.) If you need to quote multiple people, use the Multi-Quote feature (hit the little "+ Quote" label on the posts you want to quote, then hit the "Insert Quotes" button that appears below the text entry box). If you need to add more to your last post a bit later, just use the "Edit" label.
     
    #10
  11. Oddball

    Oddball Veteran Veteran

    Messages:
    1,667
    Likes Received:
    442
    First Language:
    English
    Primarily Uses:
    N/A
    @Unknown2001 He also puts examples of what to do in the script. Just look at the help file
     
    #11
  12. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA

    your right I was looking through the help file and reading this part

    Conditional Branch SCRIPT

    ----------------------------------------------------------------------------

    You can use the below script call to check if an event can detect the player

    at the time the conditional branch is called. (Yes this can be used in a

    parallel process event if required)



    Galv.DETECT.event(id,dist,los) // id = event ID that is a detector

    // dist = tile distance from player

    // los = true or false for line of sight



    This will return true if the player is in distance range of the event and

    if los is true, it will also check if player is in line of sight to it.

    ----------------------------------------------------------------------------

    but I found it a liitle hard to understand, I don't think I'm writting the event id correct? could you please give some advice
    the example given is Galv.DETECT.event(id,dist,los)

    so I tried: Galv.DETECT.event(Guard01,6,true)

    but no success yet
     
    #12
  13. Oddball

    Oddball Veteran Veteran

    Messages:
    1,667
    Likes Received:
    442
    First Language:
    English
    Primarily Uses:
    N/A
    Here. I'll show you an example from the vx ace version
    You need to us event_id instead of gaurd
    Detector example.png
     
    #13
  14. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA
    thank you for continuing to try to help
    I cannot understand this section in the help text


    ----------------------------------------------------------------------------
    Conditional Branch SCRIPT
    ----------------------------------------------------------------------------
    You can use the below script call to check if an event can detect the player
    at the time the conditional branch is called. (Yes this can be used in a
    parallel process event if required)

    Galv.DETECT.event(id,dist,los) // id = event ID that is a detector
    // dist = tile distance from player
    // los = true or false for line of sight

    This will return true if the player is in distance range of the event and
    if los is true, it will also check if player is in line of sight to it.
    ----------------------------------------------------------------------------

    I have a guard character event walking up and down
    I am trying to trigger some show text
    inside their event I have made a conditional branch with option 4, then script option
    inside that script option I have tried typing:

    Galv.DETECT.event(guard,6,true)
    also Galv.DETECT.event(event_id,6,true)
    also Galv.DETECT.event(@event_id,6,true)

    what do I type in the script section of the conditional branch

    I am using rpg maker mv
    do I have to set the guards event to player touch, or parallel or even create this in an outside event?


     
    #14
  15. Oddball

    Oddball Veteran Veteran

    Messages:
    1,667
    Likes Received:
    442
    First Language:
    English
    Primarily Uses:
    N/A
    This ^^^^^^^

    Otherwise, it won't run the event stuff until the trigger happens. setting it to action button means the player would have to interact with the event. Player touch/event touch means they would have to touch in order for the conditinal branches to run. Auto run would just do it automaticly, and lock out most other processees even player movement. Parallel process does thing along side other processes. hence "paralel" I hope that is helpful
     
    #15
  16. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA

    thank you for answering that part of my question
    I am almost there I just need to know what I write in my conditional branch script section

    what do I change this >>>Galv.DETECT.event(id,dist,los)<<< too?

    I have tried
    Galv.DETECT.event(guard,6,true)
    Galv.DETECT.event(event_id,6,true)
    Galv.DETECT.event(@event_id,6,true)
    Galv.DETECT.event(event_guard,6,true)
    Galv.DETECT.event(@event_guard,6,true)
    Galv.DETECT.event(guard,6,false)

    what do I change this >>>Galv.DETECT.event(id,dist,los)<<< too?
     
    #16
  17. Oddball

    Oddball Veteran Veteran

    Messages:
    1,667
    Likes Received:
    442
    First Language:
    English
    Primarily Uses:
    N/A
    Third one down looks correct going off of his vx ace version
     
    #17
  18. Unknown2001

    Unknown2001 Veteran Veteran

    Messages:
    31
    Likes Received:
    4
    First Language:
    English
    Primarily Uses:
    RMVXA
    no it does not work, I tried it again but the list with the 3rd one down, that list is of all the sequences that I tried so far
    I appreciate that you are trying to help, but I feel like you are not reading my full posts :(
    [​IMG]

    https://i.postimg.cc/tRPTR6F2/reeeeeeeeeeee.png
     
    #18

Share This Page