Forum

> > CS2D > Scripts > how to make variable math.random?
ForenübersichtCS2D-Übersicht Scripts-ÜbersichtEinloggen, um zu antworten

Englisch how to make variable math.random?

11 Antworten
Zum Anfang Vorherige 1 Nächste Zum Anfang

alt how to make variable math.random?

mr_s
User Off Offline

Zitieren
hi all, i was making a script custom say color but, when i close server and re-open it it makes another color
i want every-second color
1
2
if level[id] == 1 then
							m(id,cmds.colors.""..math.random(100,999)..""..math.random(100,999)..""..math.random(100,999).."",player(id,"name").." [Admin]: "..message,1)

alt Random

IRAN TOWN
User Off Offline

Zitieren
60 models.
Change per second. (with restart server)
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("say","say_hook")

RND=os.date("%S")
for i=1,RND do
color=math.random(100000000,255255255)
end

function say_hook(id,message)
if level[id]==1 then
msg2(id,"©"..color..player(id,"name").." [Admin]: "..message)
return 1
end
end
Or Is beautiful. (without restart server)
1
2
3
4
5
6
7
8
9
10
11
12
13
addhook("say","say_hook")
addhook("second","second_hook")

function second_hook()
color=math.random(100000000,255255255)
end

function say_hook(id,message)
if level[id]==1 then
msg2(id,"©"..color..player(id,"name").." [Admin]: "..message)
return 1
end
end
5× editiert, zuletzt 30.05.13 23:09:28

alt Colored say text Lua script

KimKat
GAME BANNED Off Offline

Zitieren
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
--[[
	math.randomseed(os.time())
	The above code is not vital nor necessary since at least Lua version 5.2.1.
	Older Lua interpreters however do require it.
--]]
function b()
	--[[
		Returns a bit sequence.
	--]]
	local r=math.random(0,255)
	if(r>=0 and r<=9)then r='00'..r
	elseif(r>=10 and r<=99)then r='0'..r
	elseif(r>=255)then r='000' end
	return tostring(r)
end
function c()
	--[[
		Returns bit sequences as a whole.
	--]]
	return(b()..b()..b())
end
addhook("say","s")
function s(p,t)
     if (player(p,"exists")) then
          --[[
               Checks if player exists.
          --]]
          if (t) then
               --[[
                    Colorizes each chat message.
               --]]
               msg("©"..c()..""..player(p,"name").."©090090090: ©220220220"..t)
          return 1
          end
     end
end
Compiled version:
> color_say.compiled.lua (719 B)


I'm pretty sure this will work as I followed the Lua references on Lua websites quite accurately. Fixed a couple of bugs. It should run smoothly and efficiently, so report back any problems here. I personally experienced no problems at all. Enjoy the script, feel free to modify it as you please!

Source(s):
• Lua 5.1 Manual
• Function Call Tutorial
• Math Library Tutorial

> A previous test!

> Test #1!
> Test #2!
> Test #3!
6× editiert, zuletzt 01.06.13 00:54:36

alt Random Say Color

IRAN TOWN
User Off Offline

Zitieren
Zitat
If you'd like you can add a 100% random color function in.

Run Faster - Without Additional Algorithms
1
2
3
4
5
6
7
8
9
10
11
12
addhook("second","ChangeColor")
function ChangeColor()
	color=""
		for i=1,3 do
		color=string.lower(math.random(0,2)..math.random(0,5)..math.random(0,5))..color
		end
end
addhook("say","onSay")
function onSay(p,t)
	msg("©"..color..player(p,"name")..": "..t)
	return 1
end
Or
1
color=string.lower(math.random(0,2)..math.random(0,5)..math.random(0,5)..math.random(0,2)..math.random(0,5)..math.random(0,5)..math.random(0,2)..math.random(0,5)..math.random(0,5))
Or
1
color=(string.sub(math.random(1000000000,1255255255),2,10))
Or ...
9× editiert, zuletzt 01.06.13 14:57:20

alt Re: how to make variable math.random?

Flacko
User Off Offline

Zitieren
You have to use math.randomseed(os.time()) once in your script before calling math.random()

Btw, you may also want to have a function called generatecolorbyte or sth that can return a string correctly formatted.

alt Re: how to make variable math.random?

KimKat
GAME BANNED Off Offline

Zitieren
@user mr_s: If you wanted predefined colors for say text in Lua. You could add that in without too much work. Just compare a if statement with a array containing your U.S.G.N. ID and make that correspond to a color in another array and you're all set.
Zum Anfang Vorherige 1 Nächste Zum Anfang
Einloggen, um zu antworten Scripts-ÜbersichtCS2D-ÜbersichtForenübersicht