PACI Publicado 21 de Febrero del 2014 Reportar Compartir Publicado 21 de Febrero del 2014 Hola. Durante el día de hoy pensé en empezar a hacer mi próprio questlib, pero nah que como la pereza es grande, solo hice un par de funciones simples y las vengo a postear. Empezé haciendo un num2str(num) en el que a cualquier numero que pongamos entre () devolviese su nombre, por ejemplo: print(num2str(100))-> one hundredPero al llegar al millón me aburrí y lo dejé xDDD --[[ Checks if something is a number.Syntax e.g: if is_number(1) then ...]]function is_number(val) return type(val) == 'number'end--[[ Checks if something is a string.Syntax e.g: if is_string('TEST') then ...]]function is_string(str) return type(str) == 'string' end--[[ Checks if something is a table.Syntax e.g: if is_table({'TEST1','TEST2', 1, 2}) then ...]]function is_table(tab) return type(tab) == 'table'end--[[ Returns the number of online players.Quest: when login begin game.set_event_flag('online_players', game.get_event_flag('online_players')+1) end when logout begin game.set_event_flag('online_players', game.get_event_flag('online_players')-1) end]]function get_online_players() return game.get_event_flag('online_players')end-- This function reads the line we want from a file.-- Syntax e.g: readline('/game/test.txt', 4) -> reads line 4 from test.txt filefunction readline(path, x) local linetable = {} for line in io.lines(path) do table.insert(linetable, line) end return linetable[x]end--[[ This function writes in a file the text we want. To do a change line we must write "[ENTER]". Syntax e.g: write_in_file('/game/test.txt', 'We are testing[ENTER]write_in_file function.') --> "We are testing write_in_line function."--]]function write_in_file(path, text) if string.find(text, "%[ENTER%]") then text = string.gsub(text, "%[ENTER%]", "n") end local file = io.open(path, 'w') file:write(text) file:close()end-- Gets player's empire name-- Syntax e.g: notice_all('A new character has been created in '..get_empire_name()..' kingdom!')function get_empire_name() return ({'Shinsoo','Chunjo','Jinno'})[pc.get_empire()]end-- Gets player's job name-- Syntax e.g: notice_all('A new '..get_job_name()..' has been created!')function get_job_name() return ({'Warrior','Ninja','Sura','Shaman'})[pc.get_job()+1]end--[[ Spawns more than one mob wherever we want.Syntax e.g: local mobspawns = {{8001, 100, 200, 1},{8002, 200, 300, 2}} multiple_spawn(mobspawns)It will spawn one mob which vnum is 8001 in (100,200) coordinates and it'll spawn 2 mobs which vnum is 8002 in (200,300)]]function multiple_spawn(array) for i = 1, table.getn(array) do mob.spawn(array[i][1], array[i][2], array[i][3], array[i][4]) endend-- Converts a string to a number. If a string cannot be converted, it returns 0.function str2num(str) return tonumber(str) or 0end-- Converts a number into a string.function num2str(num) return tostring(num)end Jfirewall y LovePlay reacciono a esto 2 Citar Enlace para comentar Compartir en otros sitios Mas opciones de compartir...
Rafa23Alzira Publicado 28 de Febrero del 2014 Reportar Compartir Publicado 28 de Febrero del 2014 Gracias Citar Enlace para comentar Compartir en otros sitios Mas opciones de compartir...
Mensajes recomendados
Unirse a la conversación
Puedes publicar ahora y registrarte más tarde. Si tienes una cuenta, regístrate para publicar con su cuenta.