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 285 86 87338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Try this

1
2
3
4
5
6
7
8
9
addhook("hit","rdmhit")
function rdmhit(id,src,wpn,hpdmg,apdmg)
	local rdm = math.random(0, 2)
	if rdm == 0 then
		local pname = player(id,"name")
		msg(" Critical hit made by : "..pname.." ! +8 dmg!")
		parse ("sethealth "..id.." "..player(id,"health")-8)
	end
end

old Re: Lua Scripts/Questions/Help

CmDark
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function spawnobject(otype,x,y,rot,mode,team,id)
     parse("spawnobject "..otype.." "..x.." "..y.." "..rot.." "..mode.." "..team.." "..id)
end

addhook("say","objectsp")
function objectsp(id,txt)
     tilex = player(id,"tilex")+1
     tiley = player(id,"tiley")+1
     if (string.sub(txt, 1, 1) == "#") then
          obj = tonumber(string.sub(txt, 2, string.len(txt)) )
          spawnobject(obj,tilex,tiley,0,mode,player(id,"team"),id)
          return 1
     end
end

know how to add another string

since right now its # oid

i wanna make # oid mode

old Re: Lua Scripts/Questions/Help

Admir
User Off Offline

Quote
Flacko has written
Nope
Spoiler >


Thanks for that Flacko, I understand a bit only, because I'm noob at scripting , I still dont get at
for i = 5,37 there, why need 5? not 1?

old Re: Lua Scripts/Questions/Help

ohaz
User Off Offline

Quote
for i=5,37 starts at i = 5. You can use it if you (for example) want that the first 5 players on the server (id 1-5) won't get affected of changes like this one:
1
2
3
for i = 5,32 do
	msg2(i,"You are not one of the first 5 players")
end

old Re: Lua Scripts/Questions/Help

CarbonLord
User Off Offline

Quote
CarbonLord has written
Hi everyone
I am new here.. I think you can help me.
I gonna start.
Can someone do a script for me...
I want to do a Space battle something mod.
Can anyone do for me a script, that CT have got name hmmm... Galactic troopers or something, and TT have got name hmm... Confederacy or something.
And there must (please ) be a level script.
And, the last one, classes.
Marine (slower, but nice weapon on a start... maybe galil or something)
Pilot (faster, but only deagle on a start)
Can you do, that only pilots can open some doors? Exactly doors to starfighter?
Thanks for help
~Carbon



Can someone do this please? Remember, that you can send me other script, and I will edit it.


@Edit
Hay do you know how to do (and can do for me) that CT and TT have gotother classes?
I have tryied to edit Zombie mod, but there only TT (zombieeeeeees) have got other classes. CT have got only survivours.

old Re: Lua Scripts/Questions/Help

Flacko
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
function initarray(s,v)
	local asd={}
	for i=1,s do
		asd[i]=v
	end
	return asd
end

function hudtext2(id,tid,color,txt,x,y)
	local toprint = ("©"..color.." "..txt)
	parse('hudtxt2 '..id..' '..tid..' "'..toprint..'" '..x.." "..y)
end

function standardangle(angle)
	if (angle<-90) then angle = (angle + 360)	end
	return math.rad(math.abs( angle + 90 ))-math.pi
end

function cs2dangle(angle) --MUST BE 2*Pi
	angle = math.deg(angle) - 90
	if(angle > 180 ) then angle = angle -360 end
	return angle
end

function doublerad(angle)
	return angle + math.pi
end
function singlerad(angle)
	return angle - math.pi
end

ship_rotation = initarray(32,0)

addhook("startround","setcarsprites")
function setcarsprites()
	ship_sprite = initarray(32,nil)
	for i=1,64 do
		if(i<=32) then
			ship_sprite[i]=image("gfx/car_t.bmp",0,0,1)
		else
			ship_sprite[i]=image("gfx/car_ct.bmp",0,0,1)
		end
		imageblend(ship_sprite[i],0)
	end
end

addhook("always","rotateplayers")
function rotateplayers()
	for p in pairs( player(0,"table") ) do
		if(player(p,"health")>0 ) then
		
			local pl_rot = doublerad(  standardangle( player(p,"rot") )  )
			local sp_rot = doublerad(  ship_rotation[p]  )
		
			if(pl_rot > sp_rot) then
				if(pl_rot - sp_rot <= math.pi) then
					sp_rot = sp_rot + 0.05
				elseif(pl_rot - sp_rot > math.pi) then
					sp_rot = sp_rot - 0.05
				end				
			elseif(pl_rot < sp_rot) then
				if(sp_rot - pl_rot <= math.pi) then
					sp_rot = sp_rot -0.05
				elseif(sp_rot - pl_rot > math.pi) then
					sp_rot = sp_rot + 0.05
				end
			end
		
			if(sp_rot < 0) then sp_rot = sp_rot + (math.pi*2) end --Correct the angle if it is less than 0
			if(sp_rot > math.pi*2) then sp_rot = sp_rot - (math.pi*2) end --Correct the angle if it is more that 2*Pi
			
			sp_rot = singlerad( sp_rot ) --Remove my fancy 2Pi system
		
			local x = player(p,"x") + math.cos(sp_rot)*4
			local y = player(p,"y") + math.sin(sp_rot)*4
			
			if(x >= 0 and y >= 0) then --Make sure we aren't "setposing" outside the map (LEFT AND TOP)
				if(x <= map("xsize")*32 and y <= map("ysize")*32) then --Same here (RIGHT AND BOTTOM)
					parse("setpos "..p.." "..x.." "..y) --Set the position
					
					local sprite_to_show = p
					
					if(player(p,"team") == 2) then sprite_to_show = sprite_to_show + 32 end--If CT, show CT car sprite
					imagepos(ship_sprite[sprite_to_show],x,y,cs2dangle(sp_rot) )--Draw the car
				end
			end
			ship_rotation[p]=sp_rot
		end
	end
end

Wohoo, finally, car sprites
Place the car sprite you want under the folder gfx with the names car_t.bmp and car_ct.bmp
Enjoy

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@Flacko,
I wanted to put car script first
However, your script is alpha, walls...
And others cant go to your car.

By the way, try tile() lua function.

Somehow it always returns false >.>

1
2
3
4
5
6
7
8
9
for x = 1, 30 do
	for y = 1, 30 do
		if (tile(x,y,'walkable')) then
			print(x..' '..y..' - its true')
		else
			print(x..' '..y..' - its false')
		end
	end
end

Can you suggest something?

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
I liked that the cars went through walls, Lol.
But you are right, when I just tried it, the tile function wasn't working
Also, other players won't get into other player's car because the script assumes that every player is in a car...
You can edit the script if you want

old Re: Lua Scripts/Questions/Help

BetaM
User Off Offline

Quote
Thanks Flacko, I'll definetly add that in the next Houses RPG. By the way, how to actually use the effect function in lua?
I tried this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function tf2d.dominate(id,team,x,y)
	if team==1 then
		parse('effect "flare" '..x..' '..y..' 100 100 255 0 0')
		if chexx==0 then
			chexx=1
			timersec=10
		end
		if timersec==0 then
			return 0
		end
		return 1
	elseif team==2 then
		parse('effect "flare" '..x..' '..y..' 100 100 0 0 255')
		if chexx==0 then
			timersec=10
			chexx=1
		end
		if timersec==0 then
			return 0
		end
		return 1
	end
end
No errors, but nothing happens. No effects, and the dominate point triggers immediately.
(timersec is good, don't know if the chexx works)

@Blazzingxx
Thank you
edited 2×, last 11.11.09 03:03:33 pm

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
Hell!

Oh, I though effect flare will reveal fog

My car script is different

@Mat5b
1
2
3
4
5
6
7
8
function zp_second()
	local i
	for i = 1, p_cnt do
		if (player(i,'exists') and player(i,'health') > 0) then
			parse('effect "flare" '..player(i,'x')..' '..player(i,'y')..' 15 50 150 150 150')
		end
	end
end
edited 1×, last 11.11.09 03:01:36 pm

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Blazzingxx has written
Hell!

Oh, I though effect flare will reveal fog

My car script is different


I guess it's the one you posted before

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
It's definitely different.
Only for car cordinates.
One car for map.

It will look like in CS 1.6, lol.

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
Ok
1
2
3
4
5
6
7
8
print(type(tile(1,1,"wall"))) --OMG IT'S A BOOLEAN!
for y=1,map("ysize") do
	for x=1,map("xsize") do
		if(tile(x,y,"walkable")==true) then
			print("OMG IT WORX!!!") --OMG IT DOESN'T PRINT ANYTHING
		end -- T_T
	end
end

It doesn't work at all.

old Re: Lua Scripts/Questions/Help

BetaM
User Off Offline

Quote
1
2
3
4
5
6
7
8
9
10
function tf2d.drawhealth()
	for id=1,player_count do
hudtxt2(id,3,COLOR_NORMAL,""..player(id,"health").."",80,400,LEFT)
		if (player(id,"team")==1) then
			image("gfx/tf2/status_red1.png",70,440,2)
		elseif (player(id,"team")==2) then
			image("gfx/tf2/status_blu1.png",70,440,2)
		end
	end
end
Says that player(id,"health") is a boolean. What the heck?

old Re: Lua Scripts/Questions/Help

SQ
Moderator Off Offline

Quote
@mat5b
Yes, it's boolean valuable. Learn basics!
You are using my ideas about hud texts.

Fixed. Bold part solve your problem.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
function drawhealth()
	local player_count = 32
	local id
	for id=1,player_count do
		[b]if player(id,"exists") then[/b]
			parse('hudtxt2 '..id..' 3 "'..player(id,"health")..'" 80 400 1')
         			if (player(id,"team")==1) then
				image("gfx/tf2/status_red1.png",70,440,2)
			elseif (player(id,"team")==2) then
				image("gfx/tf2/status_blu1.png",70,440,2)
			end
		[b]end[/b]
	end
end

Got it, got how it works?
edited 1×, last 11.11.09 05:17:30 pm
To the start Previous 1 285 86 87338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview