Click.vbs

Description: You made a script? Submit it here to show your creation to the public, share, take reviews, provision of the help and support is here!
Moderators: Yoshi021, Lx Xzit, 5438A38A, TepigFan101, Moderators

Yoshi021 M
Topic author, Moderator
Moderator
Avatar
Yoshi021 M
Topic author, Moderator
Moderator
Age: 17
Reputation: 80
Posts: 637
Joined: 15 Feb 2016
Location: Yoshi's Island

Post #1by Yoshi021 » 2 Feb 2017, 4:01

Hello, today I present you CLICK.vbs. This script will give you values about the mouse and the cursor.

LEFT CLICK
  • Lclick = Returns -1 for the first frame the left mouse was clicked.
  • Lhold = Returns -1 when the left mouse is held.
  • Lrelease = Returns -1 for the first frame the left mouse was released.
NOTE: RECCOMENDED FOR DISABLE_EDITING BE ON DURING LEVELS.

RIGHT CLICK
  • Rclick = Returns -1 for the first frame the right mouse was clicked.
  • Rhold = Returns -1 when the right mouse is held.
  • Rrelease = Returns -1 for the first frame the right mouse was released.

Coordinate and Movement
  • X = The x coordinate of the cursor relative to the screen.
  • Y = The y coordinate of the cursor relative to the screen.
  • Xscene = The x coordinate of the cursor relative to the scene.
  • Yscene = The y coordinate of the cursor relative to the scene.
  • Xspeed = The x-speed of the cursor. (Negative values are left, and positive values are right)
  • Yspeed = The Y-speed of the cursor. (Negative values are up, and positive values are down)
  • Hspeed = The hypotenuse the cursor makes when it moves.

Cursor
  • cursor = -1 if the cursor is on.
  • cursorINT = the ID the cursor uses for bitmaps.
  • cursorOFFSETX = the X-offset the image is to the cursor.
  • cursorOFFSETY = the Y-offset the image is to the cursor.
NOTE: ONLY WORKS FOR 1 PLAYER

Other
  • Lhist = If the left mouse was held the previous frame
  • Rhist = If the right mouse was held the previous frame
  • Xhist = The xcoord of the cursor in the previous frame
  • Yhist = The ycoord of the cursor in the previous frame
  • camera = value depends on split camera
NOTE: THESE VALUES ARE NOT USEFUL AND ONLY SERVE FOR CALCULATIONS ON OTHER VARIABLES

SCRIPT WITH CURSOR:

Code: Select all

call bmpcreate(v(cursorINT), (89), 1, v(cursor), 0, 0,(320), (320), 0, 0, 1, 1, 0, 0, 0, -1)

do

  with bitmap(val(cursorINT))
    if v(cursor) = 0 then
      .hide = -1
    else
      .hide = 0
      .destX = v(X) + v(cursorOFFSETX)
      .destY = v(Y) + v(cursorOFFSETY)     
    end if
  end with

  val(X) = Keypress(-1)
  val(Y) = Keypress(-2)

  select case val(camera)
    case 0
      val(Xscene) = sysval(Player1scrX) + val(X)
      val(Yscene) = sysval(Player1scrY) + val(Y)
    case 1
      if val(X) >= 400 then
        val(Xscene) = sysval(Player2scrX) + val(X) - 400
        val(Yscene) = sysval(Player2scrY) + val(Y)
      else
        val(Xscene) = sysval(Player1scrX) + val(X)
        val(Yscene) = sysval(Player1scrY) + val(Y)     
      end if
    case 2
      if val(X) >= 400 then
        val(Xscene) = sysval(Player1scrX) + val(X) - 400
        val(Yscene) = sysval(Player1scrY) + val(Y)
      else
        val(Xscene) = sysval(Player2scrX) + val(X)
        val(Yscene) = sysval(Player2scrY) + val(Y)     
      end if
    case 3
      if val(Y) >= 300 then
        val(Xscene) = sysval(Player2scrX) + val(X)
        val(Yscene) = sysval(Player2scrY) + val(Y) - 300
      else
        val(Xscene) = sysval(Player1scrX) + val(X)
        val(Yscene) = sysval(Player1scrY) + val(Y)     
      end if
    case 4
      if val(Y) >= 300 then
        val(Xscene) = sysval(Player1scrX) + val(X) 
        val(Yscene) = sysval(Player1scrY) + val(Y) - 300
      else
        val(Xscene) = sysval(Player2scrX) + val(X)
        val(Yscene) = sysval(Player2scrY) + val(Y)     
      end if
  end select   


  val(Xspeed) = val(X) - val(Xhist)
  val(Yspeed) = val(Y) - val(Yhist)
  val(Hspeed) = sqr((v(Xspeed))^2 + (v(Yspeed))^2)

  val(Lhold) = Keypress(1)
  val(Rhold) = Keypress(2)



  if val(Lhold) = -1 and val(Lhist) = 0 then
    val(Lclick) = -1
  else
    val(Lclick) = 0
  end if

  if val(Lhold) = 0 and val(Lhist) = -1 then
    val(Lrelease) = -1
  else
    val(Lrelease) = 0
  end if

  if val(Rhold) = -1 and val(Rhist) = 0 then
    val(Rclick) = -1
  else
    val(Rclick) = 0
  end if

  if val(Rhold) = 0 and val(Rhist) = -1 then
    val(Rrelease) = -1
  else
    val(Rrelease) = 0
  end if

  val(LHist) = val(Lhold)
  val(RHist) = val(Rhold)
  val(Xhist) = val(X)
  val(Yhist) = val(Y)

  call sleep(1)
loop


SCRIPT WITHOUT CURSOR

Code: Select all

do

  val(X) = Keypress(-1)
  val(Y) = Keypress(-2)

  select case val(camera)
    case 0
      val(Xscene) = sysval(Player1scrX) + val(X)
      val(Yscene) = sysval(Player1scrY) + val(Y)
    case 1
      if val(X) >= 400 then
        val(Xscene) = sysval(Player2scrX) + val(X) - 400
        val(Yscene) = sysval(Player2scrY) + val(Y)
      else
        val(Xscene) = sysval(Player1scrX) + val(X)
        val(Yscene) = sysval(Player1scrY) + val(Y)     
      end if
    case 2
      if val(X) >= 400 then
        val(Xscene) = sysval(Player1scrX) + val(X) - 400
        val(Yscene) = sysval(Player1scrY) + val(Y)
      else
        val(Xscene) = sysval(Player2scrX) + val(X)
        val(Yscene) = sysval(Player2scrY) + val(Y)     
      end if
    case 3
      if val(Y) >= 300 then
        val(Xscene) = sysval(Player2scrX) + val(X)
        val(Yscene) = sysval(Player2scrY) + val(Y) - 300
      else
        val(Xscene) = sysval(Player1scrX) + val(X)
        val(Yscene) = sysval(Player1scrY) + val(Y)     
      end if
    case 4
      if val(Y) >= 300 then
        val(Xscene) = sysval(Player1scrX) + val(X) 
        val(Yscene) = sysval(Player1scrY) + val(Y) - 300
      else
        val(Xscene) = sysval(Player2scrX) + val(X)
        val(Yscene) = sysval(Player2scrY) + val(Y)     
      end if
  end select   


  val(Xspeed) = val(X) - val(Xhist)
  val(Yspeed) = val(Y) - val(Yhist)
  val(Hspeed) = sqr((v(Xspeed))^2 + (v(Yspeed))^2)

  val(Lhold) = Keypress(1)
  val(Rhold) = Keypress(2)



  if val(Lhold) = -1 and val(Lhist) = 0 then
    val(Lclick) = -1
  else
    val(Lclick) = 0
  end if

  if val(Lhold) = 0 and val(Lhist) = -1 then
    val(Lrelease) = -1
  else
    val(Lrelease) = 0
  end if

  if val(Rhold) = -1 and val(Rhist) = 0 then
    val(Rclick) = -1
  else
    val(Rclick) = 0
  end if

  if val(Rhold) = 0 and val(Rhist) = -1 then
    val(Rrelease) = -1
  else
    val(Rrelease) = 0
  end if

  val(LHist) = val(Lhold)
  val(RHist) = val(Rhold)
  val(Xhist) = val(X)
  val(Yhist) = val(Y)

  call sleep(1)
loop


CAMERA SCRIPT

Code: Select all

do
  if sysval(Player1scrX) - sysval(Player2scrX) <= -400 then
    v(camera) = 1
  elseif sysval(Player1scrX) - sysval(Player2scrX) >= 400 then
    v(camera) = 2
  elseif sysval(Player1scrY) - sysval(Player2scrY) <= -300 then
    v(camera) = 3
  elseif sysval(Player1scrY) - sysval(Player2scrY) >= 300 then
    v(camera) = 4
  else
    v(camera) = 0
  end if

  call sleep(1)
loop

To use the script, make sure that the first script starts on level-start. Camera Script is only needed for 2-player levels. If the level is for one player, then make sure the variable 'camera' is 0, and you do not have to include the script.

Click-vbs.lvl
(16.21 KiB) Downloaded 49 times

Patcher
Links
ImageImageImage
Image
Image
"Going to University is FUN!" :pardon:

Return to “Script submission”

Who is online (over the past 5 minutes)

Users browsing this forum: 1 guest