• Print view

## 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: Lx Xzit, Yoshi021, 5438A38A, Moderators, Semi-moderatos

 Yoshi021 Topic author, Moderator Yoshi021 Topic author, Moderator Age: 18 Reputation: 123 Posts: 667 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.ExampleCode: 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`Will return the factorial of a positive integer.FACTORIALREQUIRES TWO VARIABLES CALLED "tmp" and "i" FOR THE SCRIPT TO WORK.Code: Select all`script factorial(num as double, return double)   v(tmp) = 1   for v(i) = 1 to param(num)     v(tmp) = v(tmp)*v(i)   next   return v(tmp)end script`PARAMETERS:factorial(number)The positive integer to get the factorial of. This function will return a random number between the two parameters.RANDCode: 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.RANDINTCode: 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.RANDSUBCode: 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.SUBSTRINGCode: 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 ifend 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.COLORCode: 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 ifend 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.DISTANCECode: 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.MINCode: 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.MAXCode: 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.TIECode: 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 ifend 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.KNOTCode: 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 ifend 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.SIGNCode: 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 ifend script`PARAMETERS:sign(number)NUMBER: The number to check the sign.Will return the angle between two points in this format..ANGLECode: Select all`'IN DEGREESscript angle(width as double, height as double, return double) return 360*getangle(param(width), param(height))end script`Code: Select all`'IN RADIANSscript angle(width as double, height as double, return double) return 2*pi*getangle(param(width), param(height))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.COLLIDECode: 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`PARAMETERcollide(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.PCOLLDECode: 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.INSIDECAMREQUIRES 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 0end script`PARAMETER:insideCam(player, x, y, width, height)PLAYER: Either 1 or 2 that represent player 1 and 2.X: The x coordinateThis function will check if a number is an integer. Will return 1 if yes, otherwise 0.ISINTEGERCode: Select all`script isInteger(num as double, return double)  if param(num) = fix(param(num)) then    return 1  else    return 0  end ifend 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.STARTSWITHCode: 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 ifend 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.ENDSWITHCode: 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 ifend 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.TOLOWERCASEREQUIRES 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 usedWill replace all lowercase string with upper ones.TOUPPERCASEREQUIRES 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 usedWill return the x position ordered in a horizontal way.TILEROWGETXCode: Select all`script tileRowGetX(index as double, width as double, return double)  return (param(index) - 1) mod param(width) + 1end 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.TILEROWGETYCode: Select all`script tileRowGetY(index as double, width as double, return double)  return fix((param(index) - 1)/param(width)) + 1end 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.TILEROWGETINDEXCode: 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.TILECOLUMNGETXCode: Select all`script tileColumnGetX(index as double, height as double, return double)  return fix((param(index) - 1)/param(height)) + 1end 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.TILECOLUMNGETYCode: Select all`script tileColumnGetY(index as double, height as double, return double)  return (param(index) - 1) mod param(height) + 1end 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.TILECOLUMNGETINDEXCode: 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"Going to University is FUN!"

 HugoMDM Banned HugoMDM Banned Reputation: 41 Posts: 64 Joined: 17 Apr 2016 Post #2by HugoMDM » 7 Mar 2018, 9:52 Thanks for this, now i can understand this Visit my YouTube Channel: HugoMDM

 Return to “Script submission” Jump to