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 2174 175 176338 339 Next To the start

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
• math.randomseed() + os.clock()
1
math.randomseed(os.clock())
• math.random()
1
print(math.random(1100))

old Re: Lua Scripts/Questions/Help

goweiwen
User Off Offline

Quote
@Terminator
For your money thing, try using another value to store the player's money, serverside. Update it every time the player gets money, and use hudtxt2 to show the value on his screen.

1
LUA ERROR:sys/lua/samples/Bounty_Hunter_DEMO.lua:61:attemp to index field 'mainmenu' (a function value)
You are trying to index mainmenu, which is a function.
Instead of using mainmenu to store the players' selections, use another table with a different name.

@DRoNE
Use math.random()
1
math.random(0, 5)
That returns a random number from 0 to 5.

EDIT: ninja'd

old Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

Quote
1
parse ("sv_sound \"blabla/"[b]..math.random(1,3)..[/b]"\"")

is this good? if i want random sound file of 3 soundifles

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Script which loads all T & CT spawns in table.
When do you want to spawn players at spawn base?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
-- Players Spawn (Table) Script --

blazz = { spawn_t_x = {}, spawn_t_y = {}, spawn_ct_x = {}, spawn_ct_y = {} }

function blazz.load()
	local x, y, name
	for x = 0, map([[xsize]]) do
		for y = 0, map([[ysize]]) do
			if entity(x,y,[[exists]]) then
				name = entity(x,y,[[typename]])
				if name == [[Info_T]] then
					table.insert(blazz.spawn_t_x, x)
					table.insert(blazz.spawn_t_y, y)
				elseif name == [[Info_CT]] then
					table.insert(blazz.spawn_ct_x, x)
					table.insert(blazz.spawn_ct_y, y)
				end
			end
		end
	end
end

blazz.load()

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
This script switch T & CT spawn places
That's example how to use those tables.
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
37
blazz = { spawn_t_x = {}, spawn_t_y = {}, spawn_ct_x = {}, spawn_ct_y = {} }

function blazz.load()
	local x, y, name
	for x = 0, map([[xsize]]) do
		for y = 0, map([[ysize]]) do
			if entity(x,y,[[exists]]) then
				name = entity(x,y,[[typename]])
				if name == [[Info_T]] then
					table.insert(blazz.spawn_t_x, x * 32)
					table.insert(blazz.spawn_t_y, y * 32)
				elseif name == [[Info_CT]] then
					table.insert(blazz.spawn_ct_x, x * 32)
					table.insert(blazz.spawn_ct_y, y * 32)
				end
			end
		end
	end
end

blazz.load()

function blazz.setpos(p) -- Random Terrorists Spawning
	local team, id = player(p,[[team]])
	if team == 2 then
		id = math.random(#blazz.spawn_t_x)
		parse(string.format([[setpos %s %s %s]],p,blazz.spawn_t_x[id],blazz.spawn_t_y[id]))
	elseif team == 1 then
		id = math.random(#blazz.spawn_ct_x)
		parse(string.format([[setpos %s %s %s]],p,blazz.spawn_ct_x[id],blazz.spawn_ct_y[id]))
	end
end

addhook([[spawn]],[[blazz.spawn]])
function blazz.spawn(p)
	blazz.setpos(p)
end

old Re: Lua Scripts/Questions/Help

DRoNe
User Off Offline

Quote
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
37
drspawn = { spawn_t_x = {}, spawn_t_y = {}, spawn_ct_x = {}, spawn_ct_y = {} }

function drspawn.load()
     local x, y, name
     for x = 0, map([[xsize]]) do
          for y = 0, map([[ysize]]) do
               if entity(x,y,[[exists]]) then
                    name = entity(x,y,[[typename]])
                    if name == [[Info_CT]] then
                         table.insert(drspawn.spawn_ct_x, x * 32)
                         table.insert(drspawn.spawn_ct_y, y * 32)
                    end
               end
          end
     end
end

drspawn.load()

function pldie(p)
local team, id = player(p),[[team]])
	if (team==2) then
		if (dr.lifes[id] >= 6) then
			if (player(id,die)) then
				id = math.random(#drspawn.spawn_ct_x)
				parse(string.format([[setpos %s %s %s]],p,drspawn.spawn_ct_x[id],drspawn.spawn_ct_y[id]))
				dr.lifes[id] = dr.lifes[id] - 1
				msg2(id,"©000255000Your lifes : '..dr.lifes[id]..'/4@C")			
			end
		end
	end
end

addhook([[spawn]],[[drspawn.spawn]])
function drspawn.spawn(p)
     drspawn.setpos(p)
end

will this work? i chages your values(blazz) to (drspawn)
i combine your script with my ..
edited 3×, last 14.03.10 06:37:10 pm

old Re: Lua Scripts/Questions/Help

byengul
User Off Offline

Quote
Hi guyz;

I'm making a big Role-Playing Map and i want a level script how can i make a script like this;

•Killing Players Gives Exp
•Breaking Breakable things Gives Exp

I've another question but first i must know this level script

old Re: Lua Scripts/Questions/Help

Noxic
User Off Offline

Quote
Spoiler >

I was asked to show the code, here it is. As you can see the color-coding is at the beginning of the string. Maybe it's simply because I'm trying to do it through Lua?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@Noxic: Maybe you used the wrong code for ©?
If I'm not wrong, you should use the Alt+169 code.
Btw, what did you mean by your character encoding?
To the start Previous 1 2174 175 176338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview