Forum

> > CS2D > Scripts > Lua Scripts/Questions/Help
Forums overviewCS2D overview Scripts overviewLog in to reply

English Lua Scripts/Questions/Help

6,770 replies
Page
To the start Previous 1 2117 118 119338 339 Next To the start

old How do u import your own sounds?

VenomEXsoldier
User Off Offline

Quote
Hello

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

old Re: Lua Scripts/Questions/Help

Deatherr
User Off Offline

Quote
I have a "Give Money" lua that works.You can give money to other players,but there is still a bug.You can say !give [id] -16000 and you take money from the player!
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
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

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
-WiLSoN- has written
what's the difference between:
math.random and math.randomseed
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.
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

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
No Clip is very simple, just equip current weapon when he reloads or attacks.

• Through walls (Serveractions to control speed) :
Spoiler >

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@TKD:
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
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
That way you can "encrypt" a string because equal seeds produce equal sequences of numbers

old Re: Lua Scripts/Questions/Help

- Dark Void -
User Off Offline

Quote
I downloaded a script it was one of blazzings it was either Gun Game or Super hero and it showed messages at the start besides serverinfo and the mapname.txt so I wanted to know how to do that but show them whenever not just at start. I am not talking about msg it is in a window.

old Re: Lua Scripts/Questions/Help

NozliW
User Off Offline

Quote
@TKD And Flacko
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

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@-WiLSoN-
Basic Example (As you asked) :
Spoiler >

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
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

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Hey, did someone get to call a function in a table through timers?
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

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@Flacko,
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.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Ok, since this is getting weird, I'll post some script
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
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.

old Re: Lua Scripts/Questions/Help

NozliW
User Off Offline

Quote
@Blazzingxx
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 ?

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
1
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" ?

old Re: Lua Scripts/Questions/Help

Deatherr
User Off Offline

Quote
I have a "Give Money" lua that works.You can give money to other players,but there is still a bug.You can say !give [id] -16000 and you take money from the player!
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
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
To the start Previous 1 2117 118 119338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview