Well I am new hear and am started to make a few maps of my own but I have a question of how do I import my own sounds? like custom tracks of wind or guns and etc
Forum
CS2D Scripts Lua Scripts/Questions/HelpWell I am new hear and am started to make a few maps of my own but I have a question of how do I import my own sounds? like custom tracks of wind or guns and etc
This belongs in the Map Section
http://unrealsoftware.de/forum_posts.php?post=24893#lastpost
math.random and math.randomseed
I don't want this to happen but how?
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
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
function toTable(t,match) local cmd = {} if not match then match = "[^%s]+" else match = "[^"..match.."]+" end for word in string.gmatch(t, match) do table.insert(cmd, word) end return cmd end addhook("say","sayz") function sayz(id, text) local ptxt = toTable(text) if ptxt[1] == "!give" and #ptxt == 3 then --Ok the format would be "!give PLAYER MONEY" local rcvp = tonumber(ptxt[2]) --Recieving player local rcvm = tonumber(ptxt[3]) --Money if player(rcvp,"exists") then --If the player exists if player(id,"money") >= rcvm then --and this dude has enough money if player(rcvp,"money") + rcvm <= 16000 then --check if we won't give him too much money (so we don't waste cash) parse("setmoney "..id.." "..player(id,"money")-rcvm) parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm) elseif player(rcvp,"money") < 16000 then --Ok this guy would overpass $16000 with our donation so we deduct this rcvm = 16000 - player(rcvp,"money") --Here parse("setmoney "..id.." "..player(id,"money")-rcvm) parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm) end end end end end
edited 1×, last 16.12.09 12:17:58 am
-WiLSoN- has written
PCs can't really do random. So you need some number on which the pc does some mathematics and then tells you the result as a random number.what's the difference between:
math.random and math.randomseed
math.random and math.randomseed
math.randomseed() sets the "random generator". Use it as:
math.randomseed(os.time) or anything else which changes very often.
after setting the generator you should use
math.random() at least twice without using the result, to make sure the number has a higher level of randomcy (neologism?)
then you should be able to use math.random so that your results are nearly really random numbers
Through walls (Serveractions to control speed) :
You also forgot to say that equal seeds produce equal sequences of numbers, you can sometimes take adventage from this.
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
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
function encrypt(password) 	local seed = os.time() 	math.randomseed(seed) 	local buffer = "" 	for i=1, password:len() do 		local otherbuffer = tostring( 			string.byte( string.sub(password,i,i) ) + math.random(1,256) ) 		if otherbuffer:len() < 3 then 			for i=1, math.abs(otherbuffer:len() - 3) do 				otherbuffer = "0"..otherbuffer 			end 		end 		buffer = buffer..otherbuffer 	end 	return {buffer, seed} end function decrypt(password,seed) 	math.randomseed(seed) 	local decrypted = "" 	for i = 1, password:len(), 3 do 		local cchar = tonumber( string.sub(password,i,i+2) ) - math.random(1,256) 		decrypted = decrypted..string.char(cchar) 	end 	return decrypted end
Nice code. I like it.
Maybe i should learn more lua and create more serious scripts.
This?
1st: http://unrealsoftware.de/userscreens/u5537f4s1.jpg
Or this?
2nd: http://unrealsoftware.de/userscreens/u5537f3s3.jpg
So which one your are talking about?
I don't know what you are talking about...
Thank you both
@Anyone
I've Got another question:
how to get a random value between 6 weapons ?
i mean get that value and equip that weapon.
thanks
Basic Example (As you asked) :
Also you should check previous page, you will see multiple random weapons script.
Random Weapons Rounds By Blazzingxx
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
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
addhook("startround","fun_startround") addhook("buy","fun_buy") addhook("drop","fun_drop") weapons_table = {{38,21},{11},{24,5},{30,51},{32,51},{34,35},{87,88},{10,47}} -- Multiple Table Of Weapons - [level][Weapons] speed_table = {0,0,0,0,0,0,0,0,0} -- Table Of Speed For Each Level function fun_startround() 	local i 	local m 	local msg_wpn = "" 	local items = math.random(1,#weapons_table) 	for i = 1,32,1 do		 		for m = 1,#weapons_table[items],1 do 			parse("equip "..i.." "..weapons_table[items][m]) 		end 		if (speed_table[items] == true) then 			parse('speedmod '..i..' '..speed_table[items]) 		end 	end 	for i = 1, #weapons_table[items] do 		if (i > 1) then 			msg_wpn = msg_wpn.." + " 		end 		msg_wpn = msg_wpn..""..itemtype(weapons_table[items][i],"name") 	end 	msg("©000255000"..msg_wpn.." Round!@C") end function fun_buy() 	return 1 end function fun_drop() 	return 1 end
I can't do it without crashing my CS2D
Edit: I got it not to crash anymore but it prints in console "Attempt to call a nil value"
edited 1×, last 15.12.09 10:39:44 pm
There is few problem ways you should check:
1st, You added hook without function. Hook function nil.
2nd, (almost same as 1st) - timer calls nil function.
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
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
function initArray(size,value) 	local tbl={} 	local istable = false 	if type(value) == "table" then istable = true end 	for i = 1, size do 		if istable then 			tbl[i] = {} 			for d,v in pairs(value) do 				tbl[i][d]=v 			end 		else 			tbl[i] = value 		end 	end 	return tbl end mytable = initArray( 	32, 	{ 		thisprint = function(s) 			print(s) 		end 	} ) mytable[1]['thisprint']("Hi") --Prints "Hi" in console timer(1000,"mytable[1]['thisprint']","Bye") --Prints "LUA ERROR: Attempt to call a nil value" in console >.>
The first call successfully prints Hi in console, but when called through a timer it outputs an error.
thanks i've made the random weapons thing work except for 1 thing:
when i select random weapons again i get the same weapons i had last time,that will happen everytime i get random weapons,is this fixable ?
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
function rwep() 	math.random() 	local result = math.random(1,90) 	return result end rwep() --[[-- Use parse("equip "..id.." "..rwep()) --]]--
Isn't this more "real" ?
I don't want this to happen but how?Help Please.....
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
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
function toTable(t,match) local cmd = {} if not match then match = "[^%s]+" else match = "[^"..match.."]+" end for word in string.gmatch(t, match) do table.insert(cmd, word) end return cmd end addhook("say","sayz") function sayz(id, text) local ptxt = toTable(text) if ptxt[1] == "!give" and #ptxt == 3 then --Ok the format would be "!give PLAYER MONEY" local rcvp = tonumber(ptxt[2]) --Recieving player local rcvm = tonumber(ptxt[3]) --Money if player(rcvp,"exists") then --If the player exists if player(id,"money") >= rcvm then --and this dude has enough money if player(rcvp,"money") + rcvm <= 16000 then --check if we won't give him too much money (so we don't waste cash) parse("setmoney "..id.." "..player(id,"money")-rcvm) parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm) elseif player(rcvp,"money") < 16000 then --Ok this guy would overpass $16000 with our donation so we deduct this rcvm = 16000 - player(rcvp,"money") --Here parse("setmoney "..id.." "..player(id,"money")-rcvm) parse("setmoney "..rcvp.." "..player(rcvp,"money")+rcvm) end end end end end