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 2284 285 286338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Twisted
User Off Offline

Quote
Is there a way to make it so if you walk over a certain spot with the flag, the flag gets returned and a entity gets triggered in the map maker?

old Re: Lua Scripts/Questions/Help

saladface27
User Off Offline

Quote
right now my function is this:

1
2
3
4
5
6
7
8
9
function choosePlacer(team)
	local teamarray
	if(team==1)then
		teamarray=player(0,"team1")
	else
		teamarray=player(0,"team2")
		end
	return teamarray
end

is there anyway to make it more efficient?

@Banaan: thanks
edited 1×, last 20.10.10 11:35:30 am

old Re: Lua Scripts/Questions/Help

Banaan
User Off Offline

Quote
saladface27 has written
right now my function is this:

1
2
3
4
5
6
7
8
9
function choosePlacer(team)
	local teamarray
	if(team==1)then
		teamarray=player(0,"team1")
	else
		teamarray=player(0,"team2")
		end
	return teamarray
end

is there anyway to make it more efficient?


1
2
3
function choosePlacer(team)
	return player(0,"team"..team)
end

old Re: Lua Scripts/Questions/Help

Triple H
User Off Offline

Quote
@CmDark: it's read like this is one file

1
ERROR: cannot play sound 'sfx/CoN_(FFA)(4FUN)/zxc2.CoN_(FFA)(4FUN)/ct20.wav' - file does not exist (sv_sound)

old Re: Lua Scripts/Questions/Help

byengul
User Off Offline

Quote
byengul has written
1
tilex, tiley = math.random(m.spawn1[1], m.spawn2[1], m.spawn3[1]), math.random(m.spawn1[2], m.spawn2[2], m.spawn3[2])

whats wrong?? please help me i want to make 3 spawn point


help please i need this to my tibia rpg 3 monster spawn point

old Re: Lua Scripts/Questions/Help

FASTDIE
User Off Offline

Quote
saladface27 has written
what player value could i use to test whether a player is alive

eg if(player(id,"alive")==1)then...


use this:
1
if player(id,"exists") then....
read info.txt in your lua dir

old Re: Lua Scripts/Questions/Help

TDShuft
User Off Offline

Quote
FaStDiE has written
saladface27 has written
what player value could i use to test whether a player is alive

eg if(player(id,"alive")==1)then...


use this:
1
if player(id,"exists") then....
read info.txt in your lua dir

he means alive not if the id exists,
its "if player(id,"health") >= 1 then"

edit: ... its wrong again the ps
is not >= 0 ,
thats if died or alive
he wants just alive so its
>= 1
or
> 0
edited 2×, last 20.10.10 05:54:21 pm

old Re: Lua Scripts/Questions/Help

FASTDIE
User Off Offline

Quote
TDShuft has written
FaStDiE has written
saladface27 has written
what player value could i use to test whether a player is alive

eg if(player(id,"alive")==1)then...


use this:
1
if player(id,"exists") then....
read info.txt in your lua dir

he means alive not if the id exists,
its "if player(id,"health") >= 1 then"

ohh.. i didn see older posts
p.s. >= 0

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
byengul has written
1
tilex, tiley = math.random(m.spawn1[1], m.spawn2[1], m.spawn3[1]), math.random(m.spawn1[2], m.spawn2[2], m.spawn3[2])


math.random has the following signature:

1
math.random(number) -- Note: At most 1 parameter.

Also, since the spawn points' components aren't interchangeable, you cannot randomize the order of both x and y. For example, if you have the following points:

sp1 = {1,2}
sp2 = {3,4}

Your spawn points are {1,2} and {3,4}, not {1,2}, {1,3}, {2,3}, and {2,4}

Hence:
1
2
local sp = "spawn"+tostring(math.random(3))
tilex, tiley = m[sp][1], m[sp][2]

@FastSide: A dead player also exists xP
Check to see whether a player's health is greater than 0: player(id, "health") > 0

Quote
Hi guys!
Is there any math.function which returns the radians of a player like 1-259?


Try math.rad(degree) and math.deg(radians), they are also easily implementable using trivial arithmetic.

@Triple H:
You can't concatenate the files, write them out as two parses.

old Re: Lua Scripts/Questions/Help

Tajifun
User Off Offline

Quote
@FaStDiE

FaStDiE has written
ohh.. i didn see older posts
p.s. >= 0


why >= 0 ?
It would include dead players, too.

>= 1 will work.

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
FaStDiE has written
>= 1 will work but wont work for player with 1 hp
ps: he edited this


YEs it will lol

> means above the number wich he've choosed 1

= means the number wich he've choosed 1

so

>= means the number and above the number

stop discussing about this

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
TDShuft has written
can i make like if the player is stoped in hook second he gets +1 mp and if he walking he gets nothing


Yes and no. You will need to find the average velocity of the player and make sure that it's zero. This can be done quite easily:

1
2
3
4
5
6
7
8
9
10
11
12
13
pos = {}
addhook("second", "check_players_pos")
function check_players_pos()
	for _,id in player(0, "table") do
		if not pos[id] then pos[id] = {0,0} end
		local dx, dy = player(id,"x")-pos[id][0], player(id, "y")-pos[id][1]
		if dx == 0 and dy == 0 then 
			local health = "sethealth %s %s"
			parse(health:format(id, player(id, "health")+1))
		end
		pos[id][0], pos[id][1] = pos[id][0] + dx, pos[id][1] + dy
	end
end

old Re: Lua Scripts/Questions/Help

Chex
User Off Offline

Quote
I can't make a random weapon generator!
All my comp does is close cs2d when I try to use it.
Here:



parse("sv_name battlefield")
parse("mp_infammo 1")
parse("mp_randomspawn 1")
parse("sv_gamemode 1")

--weapon randomization
addhook("spawn","maps.battlefield.weapon")
function maps.battlefield.weapon()
     if (player(i,"exists")) then
     equip(player,math.random)
     end
end

old Re: Lua Scripts/Questions/Help

Lee
Moderator Off Offline

Quote
Arcas has written
1
2
3
4
5
6
addhook("spawn","maps.battlefield.weapon")
function maps.battlefield.weapon()
	if (player(i,"exists")) then
	equip(player,math.random)
	end
end


1
2
3
4
5
math.randomseed(os.time())
addhook("spawn","battlefield_weapon")
function battlefield_weapon(id)
	parse(string.format("equip %s %s",id,math.random(10,49)))
end
To the start Previous 1 2284 285 286338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview