More work on NTSL and world/Topic()

Includes a plethora of new NTSL functions, courtesy of Donkieyo (thread: http://nanotrasen.com/phpBB3/viewtopic.php?f=16&t=8153)


Bugfix for a weird runtime generated when an AI tries to interact with telecomms machinery directly.

git-svn-id: http://tgstation13.googlecode.com/svn/trunk@3347 316c924e-a436-60f5-8080-3fe189b3f50e
This commit is contained in:
vageyenaman@gmail.com
2012-03-23 19:59:00 +00:00
parent fc83354e02
commit 6a8a665132
4 changed files with 167 additions and 17 deletions

View File

@@ -123,3 +123,114 @@
if(container)
if(istype(container, /list) || istext(container))
return length(container)
// BY DONKIE~
// String stuff
/proc/n_lower(var/string)
if(istext(string))
return lowertext(string)
/proc/n_upper(var/string)
if(istext(string))
return uppertext(string)
//Makes a list where all indicies in a string is a seperate index in the list
// JUST A HELPER DON'T ADD TO NTSCRIPT
proc/string_tolist(var/string)
var/list/L = new/list()
var/i
for(i=1, i<=lentext(string), i++)
L.Add(copytext(string, i, i))
return L
proc/string_explode(var/string, var/separator)
if(istext(string))
if(istext(separator) && separator == "")
return string_tolist(string)
var/i
var/lasti = 1
var/list/L = new/list()
for(i=1, i<=lentext(string)+1, i++)
if(copytext(string, i, i+1) == separator) // We found a separator
L.Add(copytext(string, lasti, i))
lasti = i+1
L.Add(copytext(string, lasti, lentext(string)+1)) // Adds the last segment
return L
proc/n_repeat(var/string, var/amount)
if(istext(string) && isnum(amount))
var/i
var/newstring = ""
for(i=0, i<=amount, i++)
newstring = newstring + string
return newstring
proc/n_reverse(var/string)
if(istext(string))
var/newstring = ""
var/i
for(i=lentext(string), i>0, i--)
world << copytext(string, i, i+1)
newstring = newstring + copytext(string, i, i+1)
return newstring
// I don't know if it's neccesary to make my own proc, but I think I have to to be able to check for istext.
proc/n_str2num(var/string)
if(istext(string))
return text2num(string)
// Number shit
proc/n_num2str(var/num)
if(isnum(num))
return num2text(num)
// Squareroot
proc/n_sqrt(var/num)
if(isnum(num))
return sqrt(num)
// Magnitude of num
proc/n_abs(var/num)
if(isnum(num))
return abs(num)
// Round down
proc/n_floor(var/num)
if(isnum(num))
return round(num)
// Round up
proc/n_ceil(var/num)
if(isnum(num))
return round(num)+1
// Round to nearest integer
proc/n_round(var/num)
if(isnum(num))
if(num-round(num)<0.5)
return round(num)
return n_ceil(num)
// Clamps N between min and max
proc/n_clamp(var/num, var/min=-1, var/max=1)
if(isnum(num)&&isnum(min)&&isnum(max))
if(num<=min)
return min
if(num>=max)
return max
return num
// Returns 1 if N is inbetween Min and Max
proc/n_inrange(var/num, var/min=-1, var/max=1)
if(isnum(num)&&isnum(min)&&isnum(max))
return ((min <= num) && (num <= max))
// END OF BY DONKIE :(