Extra TeaScript Functions

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: 75
Posts: 623
Joined: 15 Feb 2016
Location: Yoshi's Island

Post #1by Yoshi021 » 28 Aug 2017, 5:50

This is a list of functions that I have made that can be helpful when writing scripts. To use these functions copy and paste the function to the bottom of your script. Please tell me if you notice any errors in this list.

Example

Code: Select all

v(myVar) = rand(1,5)

script rand(min as double, max as double, return double)
   return rnd*(param(max) - param(min)) + param(min)
end script



This function will return a random number between the two parameters.
RAND

Code: Select all

script rand(min as double, max as double, return double)
  return rnd*(param(max) - param(min)) + param(min)
end script


PARAMETERS:
rand(min,max)
  • MIN: The minimum value that can be generated.
  • MAX: The maximum value that can be generated.



This function will return a random integer between the two parameters.
RANDINT

Code: Select all

script randInt(min as double, max as double, return double)
  return round(rnd*(param(max) - param(min)) + param(min), 0)
end script


PARAMETERS:
randInt(min,max)
  • MIN: The minimum value that can be generated.
  • MAX: The maximum value that can be generated.

This function will return a random character in the string provided.
RANDSUB

Code: Select all

script randSub(inp as string, return string)
  return mid(strparam(inp), randInt(1,len(strparam(inp))), 1)
end script


PARAMETERS:
randSub(string)
  • STRING: The string that will be used.

This function returns the string found in between the parameters.
SUBSTRING

Code: Select all

script substring(inp as string, start as double, finish as double, return string)
  if param(finish) > len(strparam(inp)) then
    return mid(strparam(inp), param(start), len(strparam(inp)))
  else
    return mid(strparam(inp), param(start), param(finish) - param(start))
  end if
end script


PARAMETERS:
sub(string,start,end)
  • STRING: The string used to get the substring.
  • START: The starting position of the substring.
  • END: The ending position of the substring.

Will return the SMBX color value.
COLOR

Code: Select all

script color(r as double, g as double, b as double, a as double, return double)
  if param(a)*256^3 + param(r)*256^2 + param(g)*256 + param(b) > 2147483647 then
    return param(a)*256^3 + param(r)*256^2 + param(g)*256 + param(b) - 4294967296
    else
    return param(a)*256^3 + param(r)*256^2 + param(g)*256 + param(b)
    end if
end script


PARAMETERS:
color(red, green, blue, alpha)
  • RED: The red value (must between 0-255)
  • GREEN: The green value (must between 0-255)
  • BLUE: The blue value (must between 0-255)
  • ALPHA: The opacity value (must between 0-255)

Will return the distance between two points.
DISTANCE

Code: Select all

script distance(Xone as double, Yone as double, Xtwo as double, Ytwo as double, return double)
  return sqr((param(Xone) - param(Xtwo))^2 + (param(Yone) - param(Ytwo))^2)
end script


PARAMETERS:
distance(x1, y1, x2, y2)
  • X1: The x coordinate of the first value.
  • Y1: The y coordinate of the first value.
  • X2: The x coordinate of the second value.
  • Y2: The y coordinate of the second value.

Will return the smaller value of the two parameters.
MIN

Code: Select all

script min(a as double, b as double, return double)
  if param(a) < param(b) then
    return param(a)
  else
    return param(b)
  end if 
end script


PARAMETERS:
min(value1, value2)
  • VALUE1: The first value.
  • VALUE2: The second value.

Will return the larger value of the two parameters.
MAX

Code: Select all

script max(a as double, b as double, return double)
  if param(a) > param(b) then
    return param(a)
  else
    return param(b)
  end if 
end script


PARAMETERS:
max(value1, value2)
  • VALUE1: The first value.
  • VALUE2: The second value.

Will force a value to stay between two numbers. If the value flows out of the boundary, then it will force it to loop.
TIE

Code: Select all

script tie(num as double, min as double, max as double, return double)
  if param(num) > param(max) then
    return param(num) - param(max)
  elseif param(num) < param(min) then
    return param(max) - param(num)
  else
    return param(num)
  end if
end script


PARAMETERS:
tie(number, min, max)
  • NUMBER: The number that is checked.
  • MIN: The minimum value.
  • MAX: The maximum value.

Will force a value to stay between two numbers. If the value flows out of the boundary, then it will force it to stay in with the boundary.
KNOT

Code: Select all

script knot(num as double, min as double, max as double, return double)
  if param(num) > param(max) then
  return param(min)
  elseif param(num) < param(min) then
      return param(max)
    else
      return param(num)
  end if
end script


PARAMETERS:
knot(number, min, max)
  • NUMBER: The number that is checked.
  • MIN: The minimum value.
  • MAX: The maximum value.

Will return the sign (-1, 0, 1) of a number.
SIGN

Code: Select all

script sign(num as double, return double)
  if param(num) > 0 then
    return 1
  elseif param(num) = 0 then
    return 0
  else
    return -1
  end if
end script


PARAMETERS:
sign(number)
  • NUMBER: The number to check the sign.

Will return the angle between two points in this format..
ANGLE

Code: Select all

script angle(width as double, height as double, return double)
  if param(width) = 0 then
    if param(height) > 0 then
      return 270
  elseif param(height) = 0 then
    return 0
    else
      return 90
    end if
  end if
  if param(height) = 0 then
    if param(width) < 0 then
      return 180
    else
      return 0
    end if
  end if

  if param(height) < 0 then
    return 90 + atn(param(width)/param(height))*180/pi
  else
    return 270 + atn(param(width)/param(height))*180/pi
  end if
end script


PARAMETERS:
angle(width, height)
  • WIDTH: The x distance between the two points.
  • HEIGHT: The y distance between the two points.

Will check if two rectangles are colliding. Will return 1 if yes, otherwise 0.
COLLIDE

Code: Select all

script collide(xone as double, yone as double, wone as double, hone as double, xtwo as double, ytwo as double, wtwo as double, htwo as double, return double)
  if param(xone) + param(wone) => param(xtwo) and param(xone) <= param(xtwo) + param(wtwo) and param(yone) + param(hone) >= param(ytwo) and param(yone) <= param(ytwo) + param(htwo) then
    return 1
  else
    return 0
  end if 
end script


PARAMETER
collide(x1,y1,width1,height1,x2,y2,width2,height2)
  • X1: The x-coordinate of the top left corner of the first rectangle.
  • Y1: The y-coordinate of the top left corner of the first rectangle.
  • WIDTH1: The width of the first rectangle.
  • HEIGHT1: The height of the first rectangle.
  • X2: The x-coordinate of the top left corner of the second rectangle.
  • Y2: The y-coordinate of the top left corner of the second rectangle.
  • WIDTH2: The width of the second rectangle.
  • HEIGHT2: The height of the second rectangle.

This function will check if a rectangle is colliding with the player. Will return 1 if yes, otherwise 0.
PCOLLDE

Code: Select all

script pcollide(p as double, x as double, y as double, w as double, h as double, return double)
  if char(param(p)).x + char(param(p)).pwidth => param(x) and char(param(p)).x <= param(x) + param(w) and char(param(p)).y + char(param(p)).pheight >= param(y) and char(param(p)).y <= param(y) + param(h) then
    return 1
  else
    return 0
  end if 


PARAMETER:
pcollide(player, x, y, width, height)
PLAYER: Either 1 or 2 that represent player 1 and 2.
  • X: The x-coordinate of the top left corner of the rectangle.
  • Y: The y-coordinate of the top left corner of the rectangle.
  • WIDTH: The width of the rectangle.
  • HEIGHT: The height of the rectangle.

This function will check if a rectangle is inside the camera.
INSIDECAM
REQUIRES TWO VARIABLES CALLED "tmp1" and "tmp2" FOR THE SCRIPT TO WORK.

Code: Select all

script insideCam(p as double, x as double, y as double, w as double, h as double, return double)
  if sysval(scrsplitstyle) = 0 then
    v(tmp1) = 800
    v(tmp2) = 600
  elseif sysval(scrsplitstyle) = 1 or sysval(scrsplitstyle) = 2 then
      v(tmp1) = 800
    v(tmp2) = 300
  else
    v(tmp1) = 400
    v(tmp2) = 600
  end if
  if param(p) = 1 then
    if sysval(Player1scrX) + v(tmp1) => param(x) and sysval(Player1scrX) <= param(x) + param(w) and sysval(Player1scrY) + v(tmp2) >= param(y) and sysval(Player1scrY) <= param(y) + param(h) then
    return 1
    end if
  elseif param(p) = 2 then
    if sysval(Player2scrX) + v(tmp1) => param(x) and sysval(Player2scrX) <= param(x) + param(w) and sysval(Player2scrY) + v(tmp2) >= param(y) and sysval(Player2scrY) <= param(y) + param(h) then
    return 1
    end if
  end if
  return 0
end script


PARAMETER:
insideCam(player, x, y, width, height)
  • PLAYER: Either 1 or 2 that represent player 1 and 2.
  • X: The x coordinate

This function will check if a number is an integer. Will return 1 if yes, otherwise 0.
ISINTEGER

Code: Select all

script isInteger(num as double, return double)
  if param(num) = fix(param(num)) then
    return 1
  else
    return 0
  end if
end script


PARAMETER:
isInteger(number)
  • NUMBER: The number that will be checked.

Will check if a string starts with another string. Will return 1 if yes, otherwise 0.
STARTSWITH

Code: Select all

script startsWIth(inp as string, chk as string, return double)
  if len(strparam(chk)) <= len(strparam(inp)) and strparam(chk) = mid(strparam(inp), 1, len(strparam(chk))) then
    return 1
  else
    return 0
  end if
end script


PARAMETER:
startsWith(string, start)
  • STRING: The string that is checked.
  • START: The string that the first string starts with.

Will check if a string ends with another string. Will return 1 if yes, otherwise 0.
ENDSWITH

Code: Select all

script endsWith(inp as string, chk as string, return double)
    if len(strparam(chk)) <= len(strparam(inp)) and strparam(chk) = mid(strparam(inp), len(strparam(inp)) - len(strparam(chk)) + 1, len(strparam(chk))) then
  return 1
    else
  return 0
  end if
end script


PARAMETER:
startsWith(string, end)
  • STRING: The string that is checked.
  • END: The string that the first string ends with.

Will replace all uppercase letters in a string with lowercase ones.
TOLOWERCASE
REQUIRES TWO VARIABLES CALLED "tmp1" and "tmp2" FOR THE SCRIPT TO WORK.

Code: Select all

script toLowerCase(inp as string, return string)
  str(tmp1) = ""
  for v(tmp2) = 1 to len(strparam(inp)) step 1
    if asc(mid(strparam(inp), v(tmp2), 1)) >= 65 and asc(mid(strparam(inp), v(tmp2), 1)) <= 90 then
      str(tmp1) = str(tmp1) & chr(asc(mid(strparam(inp), v(tmp2), 1)) + 32)
    else
      str(tmp1) = str(tmp1) & mid(strparam(inp), v(tmp2), 1)
    end if
  next
  return str(tmp1)
end script


PARAMETERS:
toLowerCase(string)
  • The string that will be used

Will replace all lowercase string with upper ones.
TOUPPERCASE
REQUIRES TWO VARIABLES CALLED "tmp1" and "tmp2" FOR THE SCRIPT TO WORK.

Code: Select all

script toUpperCase(inp as string, return string)
  str(tmp1) = ""
  for v(tmp2) = 1 to len(strparam(inp)) step 1
    if asc(mid(strparam(inp), v(tmp2), 1)) >= 97 and asc(mid(strparam(inp), v(tmp2), 1)) <= 122 then
      str(tmp1) = str(tmp1) & chr(asc(mid(strparam(inp), v(tmp2), 1)) - 32)
    else
      str(tmp1) = str(tmp1) & mid(strparam(inp), v(tmp2), 1)
    end if
  next
  return str(tmp1)
end script


PARAMETERS:
toUpperCase(string)
  • The string that will be used

Will return the x position ordered in a horizontal way.
TILEROWGETX

Code: Select all

script tileRowGetX(index as double, width as double, return double)
  return (param(index) - 1) mod param(width) + 1
end script


PARAMETERS:
tileRowGetX(index, width)
  • INDEX: The index of the tile.
  • WIDTH: The width of the tile group.

Will return the y position ordered in a horizontal way.
TILEROWGETY

Code: Select all

script tileRowGetY(index as double, width as double, return double)
  return fix((param(index) - 1)/param(width)) + 1
end script


PARAMETERS:
tileRowGetY(index, width)
  • INDEX: The index of the tile.
  • WIDTH: The width of the tile group.

Will return an index by giving an x and y position using this format.
TILEROWGETINDEX

Code: Select all

script tileRowGetIndex(x as double, y as double, width as double, return double)
  return (param(y) - 1)*param(width) + param(x)
end script


PARAMETERS:
tileRowGetIndex(x, y, width)
  • X: The x position.
  • Y: The y position.
  • WIDTH: The width of the tile group.

Will return the x position ordered in a vertical way.
TILECOLUMNGETX

Code: Select all

script tileColumnGetX(index as double, height as double, return double)
  return fix((param(index) - 1)/param(height)) + 1
end script


PARAMETERS:
tileColumnGetX(index, height)
  • INDEX: The index of the tile.
  • HEIGHT: The height of the tile group.

Will return the y position ordered in a vertical way.
TILECOLUMNGETY

Code: Select all

script tileColumnGetY(index as double, height as double, return double)
  return (param(index) - 1) mod param(height) + 1
end script


PARAMETERS:
tileColumnGetX(index, height)
  • INDEX: The index of the tile.
  • HEIGHT: The height of the tile group.

Will return an index by giving an x and y position using this format.
TILECOLUMNGETINDEX

Code: Select all

script tileColumnGetIndex(x as double, y as double, height as double, return double)
  return (param(x) - 1)*param(height) + param(y)
end script


PARAMETERS:
tileRowGetIndex(x, y, width)
  • X: The x position.
  • Y: The y position.
  • WIDTH: The width of the tile group.
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