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 2221 222 223338 339 Next To the start

old Re: Lua Scripts/Questions/Help

Fehu
User Off Offline

Quote
vesa-omar has written
IVe been posting this 3 times now and no help omg

I need a script when you press like a button called hm1
then a menu shows up

and a script when you walk over X 1000 and Y 1000 you die
addhook("move","die")
function die(id,x,y)
if (x == 1000) and (y == 1000) then
parse("killplayer "..id.."")
end
end

i dont test this script

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
vesa-omar has written
IVe been posting this 3 times now and no help omg


Well, you don't want help, you just want someone to do something for you.

@Celil_can:
I made this script some months ago I just hope it still works.
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
CARS = {}
MetaCars = {}
MetaCars.__index = MetaCars


math.pi = 3.14--15926535
car_rotatespeed = 0.03 --you can tweak this value to change the angle of the green line

function MetaCars.new(cx,cy,crot)
	local newcar = {
		x = cx,
		y = cy,
		rot = standardangle(crot),
		img = image("gfx/cars/car"..math.random(1,23)..".bmp",0,0,1),
		dpl = 0,
		is = true
	}
	if crot < 0 then crot = crot +180 else crot = crot -180 end
	imagepos(newcar.img,cx,cy,crot)
	return setmetatable(newcar,MetaCars)
end

function MetaCars:reset(cx,cy,crot)
	self.x = cx
	self.y = cy
	self.rot = standardangle(crot)
	freeimage(self.img)
	self.img = image("gfx/cars/car"..math.random(1,23)..".bmp",0,0,1)
	self.dpl = 0
	self.is = true
	if crot < 0 then crot = crot +180 else crot = crot -180 end
	imagepos(self.img,cx,cy,crot)
end

function MetaCars:rotate(pl_rot,rot_spd)
	local difference = pl_rot - self.rot
	
	if rot_spd >= math.abs(difference) then
		self.rot = pl_rot --Prevent car from "shaking"
		return 0
	end
	
	local pi = math.pi
	if difference < 0 then
		if difference <= -pi then
			self.rot = self.rot + rot_spd
		else
			self.rot = self.rot - rot_spd
		end
	else
		if difference > pi then
			self.rot = self.rot - rot_spd
		else
			self.rot = self.rot + rot_spd
		end
	end
	
	if self.rot <= -pi then
		self.rot = -self.rot
	elseif self.rot > pi then
		self.rot = -pi*2+self.rot
	end
end

function MetaCars:move(speed)
	local ceil = math.ceil
	local floor = math.floor
	local x = self.x + math.cos(self.rot)*speed
	local y = self.y + math.sin(self.rot)*speed

	--Map bounds checking
	if x >= 0 and y >= 0 then
		if x <= map("xsize")*32 and y <= map("ysize")*32 then
			--Wall collision checking
			if tile(floor(x/32-1), floor(y/32-1), "walkable") then
				if tile(ceil(x/32), ceil(y/32), "walkable") then
			
					parse("setpos "..self.dpl.." "..x.." "..y)
					self.x, self.y = x, y
					
				end
			end
			
		end
	end
	imagepos(self.img, self.x, self.y, cs2dAngle(self.rot))
end

function standardangle(angle) --CS2D system
	if angle <= 180 and angle >= -90 then
		angle = angle - 90
	else
		angle = angle + 270
	end
	return math.rad(angle)
end

function cs2dAngle(angle)
	local pi = math.pi
	if angle <= pi and angle >= -pi*0.5 then
		angle = angle - 0.5*pi
	else
		angle = angle + 1.5*pi
	end
	return math.deg(angle)
end



addhook("startround","cars_startround")
function cars_startround()
	local c_cars = 1
	for y=1,map("ysize") do
		for x=1,map("xsize") do
			if entity(x,y,"exists") then
				if entity(x,y,"name") == "car" then
					if not CARS[c_cars] then
						table.insert(CARS,MetaCars.new( x*32, y*32, entity(x,y,"int4") ))
					else
						CARS[c_cars]:reset( x*32, y*32, entity(x,y,"int4") )
					end
					c_cars = c_cars + 1
				end
			end
		end
	end
end


addhook("always","cars_frame")
function cars_frame()
	if #CARS>0 then
		local car_move = MetaCars.move
		local car_rotate = MetaCars.rotate
		for i,CAR_TBL in ipairs(CARS) do
			if CAR_TBL.is then
				if CAR_TBL.dpl > 0 then
					local p = CAR_TBL.dpl
					if player(p,"exists") and player(p,"health") > 0 then
						car_rotate(CAR_TBL,standardangle( player(p,"rot") ),car_rotatespeed)
						car_move(CAR_TBL,4)
					else
						CARS[i].dpl = 0
					end
				end
			end
			CARS[i] = CAR_TBL
		end
	end
end

addhook("use","entercar")
function entercar(id,event)
	if event == 0 then
		local x = player(id,"x")
		local y = player(id,"y")
		for i=1,#CARS do
			if CARS[i].dpl == id then
				CARS[i].dpl = 0
				parse("speedmod "..id.." 0")
				return 0
			end
		end
		for i=1,#CARS do
			if math.abs(CARS[i].x - x+16) <= 24 then
				if math.abs(CARS[i].y - y) <= 24 then
					if CARS[i].dpl == 0 then
						CARS[i].dpl = id
						parse("setpos "..id.." "..CARS[i].x.." "..CARS[i].y)
						parse("speedmod "..id.." -100")
						break
					end							
				end
			end
		end
	end
end

addhook("die","leave_car")
function leave_car(v,k)
	for i=1,#CARS do
		if CARS[i].dpl == v then
			CARS[i].dpl = 0
			break
		end
	end
end

You just have to place an env_sprite entity on the map and name it 'car'. You can also adjust the rotation.

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
i need help with this script wont work

I need a menu with names of the ID's

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
name = {}

function admin_menu_kick_p1(id)
	menu(id,"Kick Menu P1@b,"..name[1]..","..name[2]..","..name[3]..","..name[4]..","..name[5]..","..name[6]..","..name[7]..","..name[8]..",Next")
end

function admin_menu_kick_p2(id)
	menu(id,"Kick Menu P2@b,"..name[9]..","..name[10]..","..name[11]..","..name[12]..","..name[13]..","..name[14]..","..name[15]..","..name[16]");
end

addhook("menu","admin_menu_kick_menu_p1")
function admin_menu_kick_menu_p1(id,menu,button)
	if menu=="Kick Menu P1" then
		if button==1 then
			parse("kick "..name[1])
		elseif button==2 then
			parse("kick "..name[2])
		elseif button==3 then
			parse("kick "..name[3])
		elseif button==4 then
			parse("kick "..name[4])
		elseif button==5 then
			parse("kick "..name[5])
		elseif button==6 then
			parse("kick "..name[6])
		elseif button==7 then
			parse("kick "..name[7])
		elseif button==8 then
			parse("kick "..name[8])
		elseif button==9 then
			admin_menu_kick_p2(id)
		end
	end
end

addhook("menu","admin_menu_kick_menu_p2")
function admin_menu_kick_menu_p2(id,menu,button)
	if menu=="Kick Menu P2" then
		if button==1 then
			parse("kick "..name[9])
		elseif button==2 then
			parse("kick "..name[10])
		elseif button==3 then
			parse("kick "..name[11])
		elseif button==4 then
			parse("kick "..name[12])
		elseif button==5 then
			parse("kick "..name[13])
		elseif button==6 then
			parse("kick "..name[14])
		elseif button==7 then
			parse("kick "..name[15])
		elseif button==8 then
			parse("kick "..name[16])
		end
	end
end

old Re: Lua Scripts/Questions/Help

StirlizZ-Fapicon
Super User Off Offline

Quote
Hey guys! I`m near to complete my ZP max script (YES!). But I have one problem: I don`t know how to make more then 250hp for zombies. I has this script but I`m lost him. Somebody can get me it? I want upload scrpt to us

old Re: Lua Scripts/Questions/Help

Flacko
User Off Offline

Quote
@vesa-omar:
Well, since you atleast tried I will do this for you.
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
function initArray(s,v)
	local t = {}
	for i=1,s do t[i] = v end
	return t
end

function strtok(s,tok)
	local buff = {}
	tok = tok or " "
	tok = "[^"..tok.."]+"
	for w in string.gmatch(s,tok) do
		table.insert(buff,w)
	end
	return buff
end

function getPlayersByTeam(team)
	local list = player(0,"table")
	local str = initArray(math.floor(#list/8)+1,"")
	players = {}
	local pages = 1
	for i=1, #list do
		if player(list[i],"team") == team then
			str[math.floor(#players/8)+1] = str[math.floor(#players/8)+1]..","..player(list[i],"name").."|"..list[i]
			table.insert(players,list[i])
		end
	end
	return {str,players}
end


addhook("serveraction","svac")
function svac(id,action)
	if action == 1 then
		menu(id,"Kick - Team Menu,Terrorist,Counter-Terrorist")
	end
end

addhook("menu","menu_click")
function menu_click(id,title,button)

	if title=="Kick - Team Menu" then
		if button == 1 then
			local a = getPlayersByTeam(1)
			local menustr = "Kick Ts Page 1"..a[1][1]
			if #a[2] > 8 then menustr = menustr..",NextPage" end
			menu(id,menustr)
		elseif button == 2 then
			local a = getPlayersByTeam(2)
			local menustr = "Kick CTs Page 1"..a[1][1]
			if #a[2] > 8 then menustr = menustr..",NextPage" end
			menu(id,menustr)
		end
	else
		local split = strtok(title)
		local page = tonumber(split[#split])
	
		local team = 0
		if split[2] == "Ts" then team = 1 elseif split[2] == "CTs" then team = 2 end
		
		if button < 9 then
			parse("kick "..getPlayersByTeam(team)[2][8*(page-1)+button])
		else
			local a = getPlayersByTeam(team)
			local t_str = ""
			if team==1 then t_str="Ts" elseif team==2 then t_str="CTs" end
			
			local menustr = "Kick "..t_str.." Page "..(page+1)..a[1][page+1]
			
			if #a/8 > page then
				menustr = menustr..",NextPage"
			end
			menu(id,menustr)
		end
	end
end

I think your script was wrong so I rewrote it completely

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
Thanks,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
tiptimer=0

addhook("second","tiptimersec")
function tiptimersec()
	tiptimer=tiptimer+1
	if tiptimer==0 then
		parse('hudtxt 1 "©000255000TIP: Press F2 if your Admin" 13 135')
	elseif tiptimer==10 then
		parse('hudtxt 1 "©000255000TIP: Dont ask for Admin" 13 135
	elseif tiptimer==20 then
		parse('hudtxt 1 "©000255000TIP: Write myusgn in console to get your usgn" 13 135')
	elseif tiptimer==30 then
		tiptimer=0
	end
end

Need help with that script wont work -.-

old Re: Lua Scripts/Questions/Help

RyceR
User Off Offline

Quote
Why it dont work??

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
addhook("move","positon_move")
function positon_move(id,x,y)
	if position=1 then
		parse('hudtxt2 '..id..' 1 "©000255015Position X: '..x..' Y: '..y..' " 13 105')
		return 1
	end
end

addhook("movetile","positon_movet")
function positon_movet(id,x,y)
	if position=1 then
		parse('hudtxt2 '..id..' 2 "©000255015Tile Position X: '..x..' Y: '..y..' " 13 130')
		return 1
	end
end

addhook("spawn","position_spawn")
function position_spawn(id,x,y)
parse('hudtxt2 '..id..' 1 "©000255015Position X: '..x..' Y: '..y..' " 13 105')
end

addhook("parse","position_parse")
function position_parse(cmd)	
	if(cmd=="position 1") then
		position=1
		print("©255255255Position Text activated!")
		return 1
	end
	if(cmd=="position") then
		position=0
		print("©255255255Position Text deactivated!")
		return 1
	end
end

@EDIT: Sorry, i change it and now work
edited 1×, last 22.07.10 03:55:14 pm

old CS:S custom weapon reload lua

Phenixtri
User Off Offline

Quote
Hello guys I need some help. Im working on my CS:S mini mod & I need a custom reload lua scripts.
I have 2 sound sets to work with both Valve & Streloks realistic sounds ( I have his permission :3 ) I still have to edit the reload sounds as they are in separate files for each part IE slide action clip in clip out exc.
Heres what I need to do.

1) Custom reload sounds for each weapon. ( I am working on wav. files with FLStudio 9 :3 )

reload A will be when ever the gun still has ammo IE just the clip sounds. the lua will also have to cancel the sounds when & if the player continues to shoot the remaining ammo.

reload B will only work when the weapon is empty & the sounds will include reload As clip sfx + the action IE bolt pull / slide action depending on the gun.

2) The lua may also trigger weapons sprites ( Not decided yet on weather or not I will do this )

Basically during the reload B cycle certain guns will show a new temporary weapon sprite. IE when a pistol is empty it will be replaced by a model that shows its slide back during the reload only.

3) I need a lua specific only to the M4A1 & USP. When the player uses the silencer on either of these guns then the drop model will also show the silencer on the guns like in CS:S.

4) A lua only for FAMAS & Glock. When the player activates the 3 round burst function the normal firing sounds will be replaced with a 3 rounds burst sfx.

I know this is probably going to be a lot of work but I have plenty of time to learn & work. All Help is welcome & if u make a script for me Ill include u in the creds when I release my CS:S Mini mod

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
@Flacko
It gives me error here

1
local menustr = "kick "..t_str.." Page "..(page+1)..a[1][page+1]

it says LUA ERROR: sys/lua/adminscript/admin_script.lua:163: attempt to perform arithmetic on local 'page' (a nil value)

old Re: Lua Scripts/Questions/Help

RyceR
User Off Offline

Quote
I need a script like this:

if I say !message sample text in game is text: MSek[message]: sample text

and if i say !pm "PLAYER ID" "sample text" player has private message like: MSek[PM]: sample text

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
@MSek
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
addhook("say", "say_hook")

function string.split(split)
	local t = {};
	for word in string.gmatch(split, "(%w*)") do
		table.insert(t, word);
	end
	return t;
end

function say_hook(id, text)
	text = text:split()
	if ( string.lower(text[1]) == "!pm" ) then
		msg2(tonumber(text[3]), player(id, "name")..": "..table.concat(text," ",5);
	elseif ( string.lower(text[1]) == "!message" ) then
		msg(player(id, "name")..": "..table.concat(text," ",3));
	end
end
I used semicolons to help me remember them in a diff language. They won't affect the script.
Edit: Updated the script.
edited 2×, last 23.07.10 12:31:45 am

old Re: Lua Scripts/Questions/Help

StirlizZ-Fapicon
Super User Off Offline

Quote
I`m tried to make more then 250 hp for zombies, but its not working:

1
2
3
4
5
6
7
8
9
10
addhook('health','zombiehp')
function zombiehp(id,hp)
	 (zm_health[id]=500)
		if (player(id,'team')==1) then
		if (zm_health[id]>1) then
		return
		elseif (zm_health[id]<1) then
	parse("killplayer "..id)
		
end

Can somebody fix it?

old Re: Lua Scripts/Questions/Help

archmage
User Off Offline

Quote
To do something like that you would need:
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
addhook("hit", "zm_hit")
addhook("second", "zm_sec")

zm_health = 500
zm_chp = {}
zm_mhp = {}
zm_lasthit={}

for i = 1, 32 do
	zm_chp[i] = zm_health
	zm_mhp[i] = zm_health
	zm_lasthit[i]=i
end

function zm_sec ()
	for i = 1, 32 do
		if ( zm_chp[i] <= 0 or zm_chp[i] > zm_health ) then
			zm_chp[i] = zm_health
		end
		if ( not player(i, "dead") ) then
			if ( zm_mhp[i] - zm_chp[i] >= tonumber(game("mp_zombierecover")) ) then
				zm_chp[i] = zm_chp[i] + tonumber(game("mp_zombierecover"))
			else
				zm_chp[i] = zm_health
			end
		end
	end
end

function zm_hit(id,src,w,h,a)
	zm_lasthit[id] = src
	if (player(id, "team") == 1 ) then
		if ( zm_chp[i] - h <= 0 ) then
			parse("customkill "..id.." killed "..zm_lasthit[id])
		else
			zm_chp[i] = zm_chp[i] - h
		end
		return 1
	end
end

Edit:
You should really read info.txt. health is not even a hook.

old Re: Lua Scripts/Questions/Help

HaRe
User Off Offline

Quote
Fapicon has written
BIG THX TI DARK BYTE! I will add you to credits.txt in my script (over 10 helpers)

But where will show zombie hp?


1
2
3
4
5
function zombie_health_show(id)
	if (player(id,"team") == 1) then
		parse('hudtxt2 '..id..' 1 "©000255000Health: '..zm_health[id]..'" 13 135')
	end
end
i think like that

Btw ive did an little script for an Smoker class

1
2
3
4
5
6
7
8
9
10
11
12
13
14
parse("mp_wpndmg laser 0")

addhook("hit","zombie_smoker_dragback")
function zombie_smoker_dragback(id,source,weapon,hpdmg,apdmg)
px = player(source,"x")
py = player(source,"y")
idname = player(id,"name")
	if (weapon==45) then
		parse("setpos "..id.." "..px.." "..py)
		parse("strip "..source.." 45")
		msg2(source,"©255000000Youve smoked "..idname.." ")
		msg2(id,"©000000500Youve got smoked by "..idname.." ")
	end
end
edited 1×, last 23.07.10 02:10:21 pm

old Lua problem?

VegBerg
User Off Offline

Quote
Hello, I'm very n00b in Lua and tried to make it that when I say @ before a message it will be in the middle but I have a problem... Please help

1
2
3
4
5
6
7
8
9
10
11
12
13
adhook("say", "adminsay")
function adminsay(id, message)
	if (player(id,"usgn")==62805) then
		if (message == @*) then
			return 1
			parse("msg"..id(message, "text").."@C"
		else
			return 0
		end
	else
		return 0
	end
end

I think it can be a problem with the say hook or the @*

---
edit: Is it possible to take USGN's from a text list on the internet?
edited 1×, last 23.07.10 03:05:06 pm

old Re: Lua Scripts/Questions/Help

StirlizZ-Fapicon
Super User Off Offline

Quote
Dark Byte:

game find errors there:

1
2
3
4
5
6
7
8
9
10
11
function zm_hit(id,src,w,h,a)
     zm_lasthit[id] = src
     if (player(id, "team") == 1 ) then
          if ( zm_chp[i] - h <= 0 ) then
               parse("customkill "..id.." killed "..zm_lasthit[id])
          else
 	      zm_chp[i] = zm_chp[i] - h
          end
          return 1
     end
end

LUA ERROR: sys/lua/zhe.lua:33: attempt to perform arithmetic on field '?' (a nil value)
To the start Previous 1 2221 222 223338 339 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview