Участник:Alexix: различия между версиями

Материал из Chaotic Onyx
Перейти к навигацииПерейти к поиску
 
(не показано 15 промежуточных версий этого же участника)
Строка 1: Строка 1:
Педаль на грине, редактирую вики.
+
<center>'''Уйди'''</center>
  
Скриптовый язык NT(NT Script или NTSL) новая технология, которая была реализована технических департаментом НТ, чтобы увеличить возможности коммуникаций. Его синтаксис это смесь с PHP, C++ и JavaScript. Большинство программ NT Script не являются объективно-ориентированными и не содержат возможности различия классов. Вместо этого они используют систему памяти ROBUST™ чтобы сохранять данные в виде дерева. Однако, NT Script разрешают функции в одном ряду.
+
<!--Здравствуйте, я занимаю нейтральную позицию на анимусе и не примыкаю ни к революционерам, ни к шепардистам. Всё это - большой цирк. Я хочу сказать, что за мой долгий срок игры в Спэйс Стэйшон я устал. Ничего не меняется. Петухи-революционеры, петухи-шепардисты, не более. Сейчас очень трудная ситуация с нерфом на басурманских серверах. Ни к чему хорошему это не приведёт. Мне очень жаль людей, которые тратят своё время на эту пожирающую игру, которая прямо таки затягивает каждого. Я жалею, что за 4 лет я не сделал ничего хорошего ИРЛ. Пожалуйста, не тратьте своё время на эту игру, а особенно и на русское коммьюнити.-->
 
 
Готовые примеры могут быть найдены [[NTSL Scripts|здесь]].
 
 
 
== Простой гайд по использованию скриптов ==
 
# Прийдите в комнату управления коммуникациями.
 
# Откройте окошко Telecommunications Traffic Control Console консоли.
 
# Нажмите на ''Insert ID'', когда держите свою карту в руке.
 
# ''[Scan]'' для поиска серверов.
 
# Нажмите на сервер, в который хотите загрузить скрипт.
 
# ''[Edit Code]'' чтобы увидеть код сервера.
 
# Напишите свой [[NTSL_Scripts|код]] в окне.
 
# Нажмите ''Compile''
 
# Закройте вкладку.
 
# Смените Signal Execution на ''ALWAYS''
 
# Поздравляю!
 
#* Повторять с 5 по 10 шаг для каждого канала.
 
 
 
== Гайд по синтаксису ==
 
 
 
NT Script использует простой синтаксис для людей с разным уровнем программирования. Табуляция игнорируется, точка с запятой и скобочки требуются.
 
 
 
 
 
=== Переменные ===
 
 
 
Переменные используются для временного сохранение информации, которое можно будет запросить. Вот так вы можете создать переменную:
 
 
 
$myVariable = 5; // $ обозначает переменную.
 
 
 
Вы также можете переменной текст.
 
 
 
$myVariable = "Hello world!";
 
 
 
 
 
=== Функции ===
 
 
 
Функции могут быть использованы по разному. Вот пример использования функций:
 
 
 
 
 
$myVariable = getNumber();
 
 
 
В этом примере, номер ''$myVariable'' с помощью функции getNumber() значение вернётся. Каждая функция возвращает значение, даже если переменная не задана. Вот несколько примеров:
 
 
 
broadcast($myVariable);
 
broadcast("Hello world!");
 
broadcast("Griffing assistants in T-minus " + $myVariable + " seconds.");
 
 
 
 
 
Вы также можете использовать вашу функцию, используя ''def''.
 
 
 
def getNumber() {
 
    return 5;
 
}
 
 
 
 
 
=== Code Blocks ===
 
 
 
Blocks of code are called when a specific piece of code signals that it is a representation of a block of code. Variables defined in one code block cannot be applied or changed in other nonrelated code blocks; this is known as scope. For example:
 
 
 
$myGlobalVariable = getNumber();
 
 
while($myGlobalVariable != 0) {
 
   
 
    $myLocalVariable = 0;
 
    $myGlobalVariable = $myLocalVariable;
 
}
 
 
$myLocalVariable = 50; // this is invalid; myLocalVariable does not exist in this scope
 
 
 
Once the interpreter reads the closing bracket, it destroys all variable definitions within the scope, therefore you cannot use any of the variables that existed in that particular block of code.
 
 
 
 
 
=== Conditionals ===
 
 
 
The while() loop in the previous example is considered a conditional because it only continues executing when the condition between the parentheses is true. The ''!='' is known as a relational operator which returns true to the interpreter if myGlobalVariable does not equal 0. It can be read as "while myGlobalVariable does not equal 0, execute the following block of code".
 
 
 
Here is a list of all relational operators:
 
 
 
<br>'''==''' : Equals
 
<br>'''!='''  : Does not equal
 
<br>'''<'''    : Less than
 
<br>'''>'''    : Greater than
 
<br>'''<=''' : Less than or equal to
 
<br>'''>=''' : Greater than or equal to
 
 
 
 
 
Relational operators can be used in if(), and elseif(), statements, which are used the following way:
 
 
 
if($myVariableNumber == 50) // if my number is 50
 
{
 
    // code block
 
}
 
elseif($myVariableNumber <= 30) // if not, is my number 30 or less?
 
 
    // code block
 
}
 
else // if not either 50 OR 30 or more, do this instead
 
{
 
    // code block
 
}
 
 
 
== Математика ==
 
Обычные математические операторы.
 
 
 
* - умножение
 
 
 
+ - добавление
 
 
 
- - отнимание
 
 
 
/ - деление
 
 
 
^ - вывод в степень
 
 
 
== NT Deluxe Namespaces ==
 
 
 
Nanotrasen будет усовершенствовать некоторые функции, вот некоторые из них:
 
 
 
 
 
=== Number ===
 
 
 
:{|style="background:#999999"
 
!align="left" width="200"| Синтаксис
 
!align="left" width="100"| Выводит
 
!align="left" width="800"| Описание
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| prob(number) || число || Выводит число (не ноль) если вывелось true. Выводит ноль, если вывелось false.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| sqrt(number) || число || Квадратный корень из заданного числа.
 
|-
 
| abs(number) || число || Модуль заданного числа.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| floor(number) || число || Округляет заданное число к меньшему. 1.2 и 1.8 станет 1.0, -1.2 станет -2.0.
 
|-
 
| ceil(number) || число || Округляет заданное число к большему. 1.2 и 1.8 станет 2.0, -1.2 станет -1.0.
 
|-
 
| round(number) || число || Округляет заданное число. 1.5 станет 2, 1.49 becomes 1.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| clamp(number, number, number) || число || Clamps Arg.1 between min(Arg.2) and max(Arg.3). clamp(30, -30, 25) = 25
 
|-
 
| inrange(number, number, number) || number || Returns 1 if Arg.1 is inbetween min(Arg.2) and max(Arg.3).
 
|-
 
| min(...) || number || Returns the smallest value of all arguments.
 
|-
 
| max(...) || number || Returns the largest value of all arguments.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| tostring(number) || string || Returns a sting value of the number.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| rand(number, number) || number || Returns a random integer that is inbetween min(Arg.1) and max(Arg.2).
 
|-
 
| rand(number) || number || Returns a random integer that is inbetween 0 and max(Arg.1).
 
|-
 
| rand() || number || Returns a random float that is inbetween 0 and 1.
 
|-
 
| randseed(number) || || Resets the RNG with this value.
 
|-
 
| sin(value) || number || Returns the sine of the value.
 
|-
 
|cos(value) || number || Returns the cosine of the value.
 
|-
 
|asin(value) || number || Returns the arcsine of the value.
 
|-
 
|acos(value) || number || Returns the arcossine of the value.
 
|-
 
|log(value) || number || Returns the logarithm of the value.
 
|}
 
 
 
=== String ===
 
 
 
A string is a sequence of characters. A string is defined by two quote marks.<br>
 
"Hello world!" is a string. <br>
 
A strings length is the amount of letters and blankspaces it contains.<br>
 
 
 
:{|style="background:#999999"
 
!align="left" width="200"| Syntax
 
!align="left" width="100"| Returns
 
!align="left" width="800"| Description
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| find(string, string) || number || Returns the position of the first occurrence of Arg.2 in Arg.1 or 0 if no matches were found.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| length(string) || number || Returns the length of the string.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| substr(string, number, number) || string || Returns a substring from Arg.1 based on start (Arg.2) to end (Arg.3).
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| replace(string, string, string) || string || Returns a instance of the string (Arg.1) where all occurences of Arg.2 are replaced by Arg.3.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| lower(string) || string || Converts the string to lowercase.
 
|-
 
| upper(string) || string || Converts the string to uppercase.
 
|-
 
| proper(string) || string || Converts the first character to uppercase, rest to lowercase.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| explode(string, string) || vector || This will split the string(Arg.1) at every place that matches the separator(Arg.2) in to a vector. explode("Hello there young friend", " "), will produce a vector with 4 indices, "Hello", "there", "young", "friend". This is very useful for chat commands: if(at(explode($content, " "),1)=="/bot"){dostuff} will make dostuff only run if the first word was /bot.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| repeat(string, number) || string || Repeats the string n(Arg.2) amount of times.
 
|-
 
| reverse(string) || string || Reverses the string.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| tonum(string) || number || Converts the string in to a number.
 
|-
 
|}
 
 
 
=== Vector ===
 
 
 
Vectors are resizeable data containers for storing any form of entities inside. They are very useful for serving as lists; their members can be instantly accessed provided you have an appropriate position.
 
People call them arrays in other languages.
 
Vector indexes in NTSL start at 1, unlike in other languages where arrays are usually zero-indexed.
 
 
 
:{|style="background:#999999"
 
!align="left" width="200"| Syntax
 
!align="left" width="100"| Returns
 
!align="left" width="800"| Description
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| vector(...) || vector || Returns a vector with a given number of entities. You can add an infinite number of entries, or no entries at all.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| at(vector, number, var) || var || Sets the cell at Arg.2 index in the Arg.1 vector to Arg.3 if Arg.3 is supplied, otherwise, returns the value located at Arg.2.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| copy(vector, number, number) || vector || Returns a new vector based on Arg.1, ranging from minimum index Arg.2 to Arg.3.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| push_back(vector, ...) || || Adds Arg.2 (and every item after) to the end of the vector. Deprecated by the += operator.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| remove(vector, ...) || || Loops through the vector and deletes the items matching the Args.
 
|-
 
| cut(vector, number, number) || || Cuts out entries from Arg.2 to Arg.3 in the Arg.1 vector.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| swap(vector, number, number) || || Swaps the entries's position at Arg.2 and Arg.3 in the Arg.1 vector.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| insert(vector, number, var) || || Inserts Arg.3 into Arg.1 at index Arg.2.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| find(vector, var) || var || Searches the Arg.1 vector for Arg.2, returns 0 if not found.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| length(vector) || number || Returns the length of the vector. (amount of indices)
 
|-
 
|}
 
 
 
=== Miscellaneous Definitions ===
 
 
 
:{|style="background:#999999"
 
!align="left" width="200"| Syntax
 
!align="left" width="100"| Returns
 
!align="left" width="800"| Description
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| pick(...) || var || Returns a randomly-selected entry from the parameters. Note: vector parameters will add their entries into the "raffle". The function will never return a vector.
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| time() || number || Returns the real time of the server in a number. You can then use this to see how much time has passed since the code has last been run via mem().
 
|-
 
| bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" | || bgcolor="#AAAAAA" |
 
|-
 
| timestamp(format) || string || Returns a string of the time, formatted by the parameter. E.g: "DDD MMM DD hh:mm:ss YYYY" or "hh:mm:ss" or "DD MM YY".
 
|}
 
 
 
=== Prefab Variables ===
 
 
 
'''PI''' = 3.141592653;
 
'''E''' = 2.718281828;
 
'''SQURT2''' = 1.414213562;
 
'''FALSE''' = 0; // true/false are just Boolean shortcuts to 0 and 1
 
'''TRUE''' = 1;
 
'''NORTH''' = 1;
 
'''SOUTH''' = 2;
 
'''EAST''' = 4;
 
'''WEST''' = 8;
 
 
'''$common''' = 1459
 
'''$science''' = 1351
 
'''$command''' = 1353
 
'''$medical''' = 1355
 
'''$engineering''' = 1357
 
'''$security''' = 1359
 
'''$supply''' = 1347
 
 
'''HUMAN''' = 1
 
'''MONKEY''' = 2
 
'''ALIEN''' = 4
 
'''ROBOT''' = 8
 
'''SLIME''' = 16
 
'''DRONE''' = 32
 
 
 
'''$robot''' = "robot"
 
'''$loud''' = "yell"
 
'''$emphasis''' = "italics"
 
'''$wacky''' = "sans"
 
 
 
== Traffic Control Systems Implementation ==
 
 
 
The [[Telecommunications]] system is directly tied to the TCS scripting implementation. It comes with the following functions and features.
 
 
 
 
 
=== Realtime signal modification ===
 
 
 
If the code is set to execute automatically, signals will first execute stored server code. Signal information is stored in the following variables:
 
 
 
$source  // the source of the signal
 
$content  // the content of the signal
 
$freq    // the frequency of the signal
 
$pass    // determines if the signal will be broadcasted
 
$job      // the job (only for radio messages) of the operator
 
$language // the language of the signal. Can be any of HUMAN, MONKEY, ALIEN, ROBOT, SLIME or DRONE. Or a combination of them
 
$filters  // The voice filter of the signal. Includes bolding, italics, as well as silicon and wacky fonts. '''These must be given as a vector!'''
 
$say      // The verb used in a radio messages ending in "."
 
$ask   // The verb used in messages ending in "?". Example: COMMON SERVER asks, "Why?"
 
$exclaim  // The verb used in a radio messages ending in "!" Note that having more exclamation points changes it to "$yell".
 
$yell   // The verb used in a radio messages ending in "!!" or more exclamation points. By default, these messages are bolded.
 
 
 
=== Functions ===
 
 
 
TCS also comes with the following functions (parameters may be ignored for automatic assignment):
 
 
 
 
==== broadcast() ====
 
 
 
broadcast(message, frequency, source, job)
 
 
 
Sends a radio signal to neighboring subspace broadcasters to broadcast with the following parameters.
 
 
 
'''message''': The radio message
 
<br>'''frequency''': The frequency to broadcast to
 
<br>'''source''': The name of the broadcaster. If the source name is not in a server-side voice databank (voice analysis is performed every time a person speaks over a channel) the name will appear in UPPERCASE and Italicized to indicate a synthesized voice
 
job
 
<br>'''job''': The job of the orator.
 
 
 
Examples:
 
 
 
broadcast("Hello world!");
 
 
 
'''defaults''':
 
<br>frequency: 1459
 
<br>source: the server name
 
<br>job: None
 
 
 
broadcast("HELP GRIEFF", 1459, "Burer", "Security Officer");
 
 
 
==== signal() ====
 
 
 
signal(frequency, code)
 
 
 
Sends a signal to the frequency, with the code. This works exactly like a remote signaler.
 
 
 
'''frequency''': The frequency to send to.
 
<br>'''code''': The code to attach to the signal.
 
 
 
Examples:
 
 
 
signal(1359, 25);
 
 
 
'''defaults''':
 
<br>frequency: 1459
 
<br>code: 30
 
 
 
==== mem() ====
 
 
 
mem(key, value)
 
 
 
Variables declared in a script expire after the script has finished executing (duh). The mem function allows you to save persistent information to the server's memory to be retrieved by future executions of the script.
 
Each telecommunications server contains its own separate databank, which is basically a hash table/dictionary, a data structure consisting of a set of key-value pairs.
 
When called with just the key as an argument, mem will return the associated value. When called with two arguments, mem will set the value associated with the key.
 
 
 
'''key''': A string used to identify the variable to be saved.
 
<br>'''value''': The information you want to store for future use. Can be any type.
 
 
 
Examples:
 
 
 
$source = "Jarsh Mellow";
 
mem($source + "'s Mom");  // returns the value associated with the key "Jarsh Mellow's Mom". Returns null/0 if not found
 
mem($source + "'s Mom", "Lindsay Donk"); // sets the value associated with the key "Jarsh Mellow's Mom" to "Lindsay Donk".
 
 
 
[[Category:Guides]]
 
 
 
== Examples ==
 
 
 
Here are a few examples. You can find more useful snippets [[NTSL Scripts|here]].
 
 
 
=== Chat calculator ===
 
A simple chat calculator.<br>
 
Type "/calc 1+1" in chat and watch the magic happen. NB: division is not implemented due to budget cuts.
 
$expld1 = explode($content, " ");
 
if(at($expld1, 1) ==  "/calc")
 
{
 
$s = at($expld1, 2);
 
$found = 0;
 
if(find($s, "+") && $found == 0)
 
{
 
$expld2 = explode($s, "+");
 
broadcast($s + " = " + tostring(tonum(at($expld2,1)) + tonum(at($expld2,2))), $freq, "LINDSAY", "CALCULATER");
 
$found = 1;
 
}
 
if(find($s, "-") && $found == 0)
 
{
 
$expld2 = explode($s, "-");
 
broadcast($s + " = " + tostring(tonum(at($expld2,1)) - tonum(at($expld2,2))), $freq, "LINDSAY", "CALCULATER");
 
$found = 1;
 
}
 
if(find($s, "*") && $found == 0)
 
{
 
$expld2 = explode($s, "*");
 
broadcast($s + " = " + tostring(tonum(at($expld2,1)) * tonum(at($expld2,2))), $freq, "LINDSAY", "CALCULATER");
 
$found = 1;
 
}
 
}
 
$pass = 1;
 
 
 
=== Magic 8-Ball ===
 
A simple Magic 8-Ball that will answer anyone's question.<br>
 
Type in "/8ball <your question>" and you will get a magical response!
 
 
 
$explodeString = explode($content, " ");
 
if(at($explodeString, 1) ==  "/8ball")
 
{
 
//By Giacomand
 
$pass = 0;
 
$8ball = pick("It is certain", "It is decidedly so", "Without a doubt", "Yes – definitely",
 
"You may rely on it", "As I see it, yes", "Most likely", "Outlook good", "Yes", "Signs point to yes",
 
"Reply hazy, try again","Ask again later","Better not tell you now","Cannot predict now","Concentrate and ask again","Don't count on it","My reply is no",
 
"My sources say no","Outlook not so good","Very doubtful");
 
$content = substr($content, 7, length($content)+1);
 
broadcast("Magic 8-Ball... " + $content, $freq, $source, $job);
 
broadcast($8ball + ".", $common, "Magic 8-Ball", "Magic 8-Ball");
 
 
}
 

Текущая версия от 17:36, 26 октября 2016

Уйди