Function Library |
Shamousey « Consul » 1381174140000
| 0 | ||
This thread contains a library of general functions that can be used in Lua to extend its functionality. Some can be used to extend the tfm. package in the Module API, and some are general Lua functions that can be used for different purposes. The functions in this section extend the table library. table.count Returns the number of items in an associative table. Useful because #table can't be used on associative tables. a dit : table.random Returns a random value from a table. a dit : table.contains Returns true or false, based on whether a value is located within a table. a dit : table.invert Inverts the key and value of a table. a dit : table.keys Returns an indexed list of keys in a table. a dit : table.copy Returns a deep or shallow copy of a table. a dit : table.unpack Returns a tuple (multiple return variables) that are in a given table. This is now a default function in Lua and doesn't need to be additionally defined. a dit : This section includes functions that extend the string library string.split Splits a string into separate elements in a table. a dit : string.contains Returns whether a substring is found in another string a dit : string.prefix Returns whether a string starts with a substring a dit : randomColor Returns a random HEX colour code. a dit : printTable Prints all of the information inside a table. a dit : stringtotable Changes a string to a table. a dit : tabletostring Changes a table into a string. a dit : pythag Detects if two points are within a radius of eachother. a dit : Dernière modification le 1429913820000 |
Shamousey « Consul » 1381174140000
| 0 | ||
tfm.exec.newGame("#V") Vanilla maps work as #V in tfm.exec.newGame() a dit : tfm.exec.giveWin Makes a player win (instead of running two separate functions each time). a dit : tfm.exec.giveWinAll Makes everyone in the room win. a dit : tfm.get.room.shaman Returns the shaman's name. Requires table.unpack a dit : tfm.get.room.alive Returns a list of players who are alive. a dit : tfm.get.misc.admins Returns a list of administrators. a dit : tfm.get.misc.mods Returns a list of moderators by community. a dit : tfm.get.misc.helpers Returns a list of helpers by community. a dit : tfm.get.misc.cfmTeam Returns a list of CheeseForMice staff by community. a dit : tfm.get.misc.mapCrew Returns a list of Map Crew members by community. a dit : tfm.get.misc.sentinels Returns a list of Sentinels by community. a dit : tfm.enum.shamanObject Extension Extends tfm.enum.shamanObject to support all objects. a dit : Clothing An organised list of all clothing with IDs, item names, cheese and fraise prices. a dit : loop Faster loop than eventLoop by using timers. Returns timer IDs if you need to stop them. a dit : trans Handles translating to different languages, falling back to English if translations for a certain community isn't there. a dit : Dernière modification le 1429913640000 |
Shamousey « Consul » 1381174140000
| 0 | ||
Reserved post for future functions *-* Remember that the lists of members in specific groups (mods/admins/etc.) and clothing won't always be up to date, although I'll try to update it as soon as any changes are needed. |
Enginfener « Citoyen » 1381266300000
| 0 | ||
So, look : 1;0,0,0,0,0,0,0,0,0 we add |
Mikuhl « Citoyen » 1381267440000
| 0 | ||
Shamousey a dit : We need a these to actually be real, then it would make for some cute welcome messages, like I heared rumored that cfmbot used to say, "Your [randomized shop item you are wearing] looks stunning!" |
Ethanrockz « Citoyen » 1381946340000
| 0 | ||
translations={ EN={ welcome="Hi." }, BR={ welcome="Oi." } } function trans(mes) if translations[tfm.get.room.community] and translations[tfm.get.room.community][mes] then return translations[tfm.get.room.community][mes] else return translations.EN[mes] end end This dosnt work for me ;-; |
Shamousey « Consul » 1381949280000
| 0 | ||
Ethanrockz a dit : This works fine. What exactly are you trying to use it? |
Ethanrockz « Citoyen » 1381949640000
| 0 | ||
I just went on br server and got my friends to say hi/Hi/Hi. but nothing happened (I did the Oi thing aswell) |
Shamousey « Consul » 1381949940000
| 0 | ||
Ethanrockz a dit : Getting people to say "hi" does nothing, this works when you need to print/display text in different languages. print(trans("welcome")) will display "Hi." on any server but "Oi." on the BR one. |
Ethanrockz « Citoyen » 1381949940000
| 0 | ||
Shamousey a dit : Thanks for helping me c: |
Theleetcoder « Citoyen » 1382972160000
| 0 | ||
U' can add : tfm.exec.chatMessage a dit : |
Safwanrockz « Censeur » 1382982000000
| 0 | ||
Theleetcoder a dit : But does it show to all the players? |
Shamousey « Consul » 1382983140000
| 0 | ||
Safwanrockz a dit : No, but it'd make transitioning from a tribehouse script to a public module much easier. |
Jeremiahmice « Citoyen » 1383111120000
| 0 | ||
i dont get it... someone help me! |
Fluffyshine « Citoyen » 1384002660000
| 0 | ||
nice one |
Thewildnes « Citoyen » 1384008660000
| 0 | ||
Good thread |
Abdeltif « Citoyen » 1387993980000
| 0 | ||
the loop function won't work for us, :( |
Safwanrockz « Censeur » 1387997520000
| 0 | ||
Abdeltif a dit : Yep, because it uses the system.newTimer function. Also, this function might be useful though. table.delete a dit : Deletes a value from a specific table. |
Woebegone « Citoyen » 1387997520000
| 0 | ||
How can you load a map onto the lua code? |
Safwanrockz « Censeur » 1387997640000
| 0 | ||
Juliantwofan a dit : tfm.exec.newGame(@MapCode). |