×

Langue

Fermer
Atelier 801
  • Forums
  • Dev Tracker
  • Connexion
    • English Français
      Português do Brasil Español
      Türkçe Polski
      Magyar Română
      العربية Skandinavisk
      Nederlands Deutsch
      Bahasa Indonesia Русский
      中文 Filipino
      Lietuvių kalba 日本語
      Suomi עברית
      Italiano Česky
      Hrvatski Slovensky
      Български Latviešu
      Estonian
  • Langue
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Script] Colored Conjuration
[Script] Colored Conjuration
Mikuhl
« Citoyen »
1388365140000
    • Mikuhl#3311
    • Profil
    • Derniers messages
    • Tribu
#1
  0
First off credit to Jordynl. I totally wasnt sneaking around your Lua rooms. *-*

Just as the title suggests. Colorable Conjuration.

a dit :

function main()
areas = {}
id = 0
end

function eventLoop(time,remaining)
-- The Function
-- Remove this if your going to use it.
-- Just for demonstration.
conjure(math.random(0,800),math.random(0,400),10000,string.format('%x', math.random(0x000000, 0xFFFFFF)))
--
for id,textArea in ipairs(areas) do
if textArea[1] <= os.time()-textArea[3] then
ui.removeTextArea(textArea[2])
table.remove(areas,id)
end
end
end

function eventNewGame()
for id,textArea in ipairs(areas) do
ui.removeTextArea(textArea[2])
end
areas = {}
end

function conjure(x,y,t,c)
tfm.exec.addConjuration(x/10,y/10,t)
id = id + 1
ui.addTextArea(id,"<font size='13' color='#"..c.."'>■</font>",nil,math.floor(x/10)*10-3,math.floor(y/10)*10-5,nil,nil,0)
table.insert(areas,{os.time(),id,t})
end

main()

How to use:
a dit :

conjure(Int xPosition, Int yPosition, Int timeInMiliseconds, String hexCode)
Larenwa
« Citoyen »
1388388480000
    • Larenwa#0000
    • Profil
    • Derniers messages
#2
  0
Cool! :D
Livcorish
« Citoyen »
1388432340000
    • Livcorish#0000
    • Profil
    • Derniers messages
#3
  0
Sweet!
Safwanrockz
« Censeur »
1388435280000
    • Safwanrockz#0095
    • Profil
    • Derniers messages
    • Tribu
#4
  0
Well scripted.
Babyaftchris
« Citoyen »
1388508780000
    • Babyaftchris#0000
    • Profil
    • Derniers messages
    • Tribu
#5
  0
Excited to try this out! After I gather 500 more cheese ;n;
Evilsantah
« Citoyen »
1388611200000
    • Evilsantah#0000
    • Profil
    • Derniers messages
#6
  0
Safwanrockz a dit :
Well scripted.

table.remove while looping through the same table is a bad habit and can go horribly wrong, also math.random(0x000000,0xFFFFFF) gives back a number, not a string :DDD ily jack, I like it.

E: not sure if it's platform dependant but for me the textarea doesn't have the correct size and position, anyway for me, this did the job:
a dit :
ui.addTextArea(id,"<font size='14' color='#"..c.."'>■</font>",nil,math.floor(x/10)*10-4,math.floor(y/10)*10-6,nil,nil,0)
Safwanrockz
« Censeur »
1388612460000
    • Safwanrockz#0095
    • Profil
    • Derniers messages
    • Tribu
#7
  0
Evilsantah a dit :
also math.random(0x000000,0xFFFFFF) gives back a number, not a string

e/ Nvm, it's supposed to be an integer.
Evilsantah
« Citoyen »
1388613240000
    • Evilsantah#0000
    • Profil
    • Derniers messages
#8
  0
Safwanrockz a dit :
So is it supposed to be 0x..math.random(0x00000,0xFFFFFF)?

No, not at all. math.random will give back a number between 0x00000 and 0xFFFFFF, or in decimal 0 to 16777215. This means when passed to a function, it will be seen as a number. When you concat a string and a number (the .. operator) it converts the number to a string, and when this happens it will display it in decimal numeral system. In HTML, the color attribute takes different syntax but when prefixed with #, it will assume whatever's behind it is a hexadecimal value of 6 (or 3 like #FFF) characters, thus you will only get colors from #000000 to #999999. This is not what you wanted, you see :)

tldr; use the %x string token to format hexadecimal numbers:
Evilsantah a dit :

local color = math.random(0x000000, 0xFFFFFF)
local str = string.format('#%x', color)

print(str)

Hope this clears up this conflict.
Mikuhl
« Citoyen »
1388613480000
    • Mikuhl#3311
    • Profil
    • Derniers messages
    • Tribu
#9
  0
I see. Back in my nooby days I saw it used, I guess I didnt check if it was correct because It gave me a color anyway so I thought it worked.

EDIT: Updated, thanks to Evilsantah, the random hex colors are correctly used.
Also, when you play another map and the conjuration dissappears so, do the color.
Oyga
« Citoyen »
1389371220000
    • Oyga#0000
    • Profil
    • Derniers messages
    • Tribu
#10
  0
Hastpotower quote.

Topic-556714
  • Forums
  • /
  • Transformice
  • /
  • Modules
  • /
  • [Script] Colored Conjuration
© Atelier801 2018

Equipe Conditions Générales d'Utilisation Politique de Confidentialité Contact

Version 1.27