Forum

> > CS2D > Scripts > Car script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Car script

3 replies
To the start Previous 1 Next To the start

old Car script

Flame
BANNED Off Offline

Quote
Who can make a script for me when u press f2 it displays a car buying menu

old Re: Car script

Bowlinghead
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
-- Untestet - like every time
addhook("serveraction","fuuuuuu")
function fuuuuuu(id,b)
	if b==1 then
		menu(id,"Cars,First Car,Second Car")
	end
end
addhook("menu","fuuuuuu2")
function fuuuuuu2(id,t,b)
	if t=="Cars" then
		if b==1 then
			if player(id,"money")>=1000 then
				-- Code for Car
			end
		elseif b==2 then
			if player(id,"money")>=5000 then
				-- Code for car
			end
		end
	end
end

EDIT:
http://www.unrealsoftware.de/files_cat.php?cat=15&lan=2&f=car&o=0&d=1

old Re: Car script

Flame
BANNED 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
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
function Vehicle.new(tab)
	VehicleTab.List = VehicleTab.List + 1
	local id = VehicleTab.List
	VehicleTab[id] = {
		x = tab.x,
		y = tab.y,
		maxchanges = tab.maxchanges,
		currentchange = 0,
		driver = 0,
		rot = tab.rot,
		img = image(tab.img,0,1,1),
		imgdir = tab.img,
		speed = 0,
		spritescale = {x = tab.spritescale.x/2,y = tab.spritescale.y/2},
		Fuel = tab.fuel,
		drivercantact = 0,
		health = tab.health,
		lockstatus = false,
		brings = {}
	}
	imagepos(VehicleTab[id].img,tab.x,tab.y,tab.rot)
	return id
end

function Vehicle.setRot(id,rot)
	if VehicleTab[id] then
		if VehicleTab[id].driver == 0 then
			VehicleTab[id].rot = rot
			imagepos(VehicleTab[id].img,VehicleTab[id].x,VehicleTab[id].y,VehicleTab[id].rot)
			return true
		end
		return false
	end
end

function Vehicle.move(id,x,y)
	if VehicleTab[id] then
		local D = VehicleTab[i].driver
		if x < (map("xsize")+1)*32 and y < (map("ysize")+1) * 32 and x > 0 and y > 0 then
			if D > 0 then
				parse("setpos "..D.." "..x.." "..y)
			end
			VehicleTab[id].x = x
			VehicleTab[id].y = y
			imagepos(VehicleTab[id].img,x,y,VehicleTab[id].rot)
		end
	end
end

function Vehicle.setHealth(id,health)
	if VehicleTab[id] then
		VehicleTab[id].health = health
	end
end

function Vehicle.setMaxChanges(id,maxchanges)
	if VehicleTab[id] then
		VehicleTab[id].maxchanges = maxchanges
	end
end

function Vehicle.setFuel(id,fuel)
	if VehicleTab[id] then
		VehicleTab[id].Fuel = fuel
	end
end

function Vehicle.lock(id)
	if VehicleTab[id] then
		VehicleTab[id].lockstatus = true
	end
end

function Vehicle.unlock(id)
	if VehicleTab[id] then
		VehicleTab[id].lockstatus = false
	end
end

function Vehicle.remove(id)
	if VehicleTab[id] then
		freeimage(VehicleTab[id].img)
		VehicleTab[id] = nil
	end
end

function FindVehicleTo(id)
	for i = 1, VehicleTab.List do
		if VehicleTab[i] then
			if VehicleTab[i].driver == id then
				return i
			end
		end
	end
	return false
end

function DrawHudTo(id)
	local v = FindVehicleTo(id)
	if v then
		parse('hudtxt2 '..id..' 1 "Fuel: '..(VehicleTab[v].Fuel/100)..'L" 15 145')
		parse('hudtxt2 '..id..' 2 "Current Change: '..VehicleTab[v].currentchange..'" 15 160')
		parse('hudtxt2 '..id..' 3 "Act Timer: '..VehicleTab[v].drivercantact..'" 15 175')
		parse('hudtxt2 '..id..' 4 "Speed: '..(VehicleTab[v].speed*14.5)..'Km/H" 15 190')
		parse('hudtxt2 '..id..' 5 "Health: '..(VehicleTab[v].health)..'" 15 205')
	else
		parse('hudtxt2 '..id..' 1 "" 0 0')
		parse('hudtxt2 '..id..' 2 "" 0 0')
		parse('hudtxt2 '..id..' 3 "" 0 0')
		parse('hudtxt2 '..id..' 4 "" 0 0')
		parse('hudtxt2 '..id..' 5 "" 0 0')
	end
end

function FindBringTo(id)
	for i = 1, VehicleTab.List do
		if VehicleTab[i] then
			for k, p in pairs(VehicleTab[i].brings) do
				if p == id then
					return i, k
				end
			end
		end
	end
	return nil
end

addhook("serveraction","Carmod.Serveraction")
function Carmod.Serveraction(id,act)
	if FindVehicleTo(id) and not FindBringTo(id) then
		local i = FindVehicleTo(id)
		if act == 1 and VehicleTab[i].drivercantact == 0 then
			if VehicleTab[i].currentchange < VehicleTab[i].maxchanges then
				VehicleTab[i].currentchange = VehicleTab[i].currentchange + 1
			end
		elseif act == 2 and VehicleTab[i].drivercantact == 0 then
			if VehicleTab[i].currentchange >= 0 then
				VehicleTab[i].currentchange = VehicleTab[i].currentchange - 1
			end
		end
	end
	if act == 3 and not FindVehicleTo(id) then
		if not FindBringTo(id) then
			for i = 1, VehicleTab.List do
				if VehicleTab[i] then
					local Range = (VehicleTab[i].spritescale.x+VehicleTab[i].spritescale.y)/2
					if math.sqrt((player(id,"x")-VehicleTab[i].x)^2 + (player(id,"y")-VehicleTab[i].y)^2) < Range then
						table.insert(VehicleTab[i].brings,id)
						break
					end
				end
			end
		else
			local Car, bring = FindBringTo(id)
			VehicleTab[Car].brings[bring] = nil
			parse("speedmod "..id.." 0")
		end
	end
end

addhook("ms100","Carmod.MS")
function Carmod.MS()
	for i = 1, VehicleTab.List do
		if VehicleTab[i] then
			if VehicleTab[i].drivercantact > 0 then
				VehicleTab[i].drivercantact = VehicleTab[i].drivercantact - 1
			end
			if VehicleTab[i].Fuel > 0 then
				VehicleTab[i].Fuel = VehicleTab[i].Fuel - (VehicleTab[i].speed/20)
			elseif VehicleTab[i].Fuel <= 0 and VehicleTab[i].currentchange ~= 0 then
				VehicleTab[i].currentchange = 0
			end
			local speed = VehicleTab[i].currentchange * 3
			if VehicleTab[i].speed < speed then
				VehicleTab[i].speed = VehicleTab[i].speed + 0.5
			elseif VehicleTab[i].speed > speed then
				VehicleTab[i].speed = VehicleTab[i].speed - 0.5
			end
			if VehicleTab[i].health <= 380 then
				VehicleTab[i].health = VehicleTab[i].health - math.random(0,3)
				parse('effect "fire" '..VehicleTab[i].x..' '..VehicleTab[i].y..' 1 1')
				if VehicleTab[i].health <= 0 then
					parse('explosion '..VehicleTab[i].x..' '..VehicleTab[i].y..' 100 500')
					freeimage(VehicleTab[i].img)
					local id = VehicleTab[i].driver
					if id > 0 then
						parse("killplayer "..id)
					end
					VehicleTab[i] = nil
				end
			end
		end
	end
end

addhook("always","Carmod.Always")
function Carmod.Always()
	for i = 1, VehicleTab.List do
		if VehicleTab[i] then
			local D = VehicleTab[i].driver
			if not player(D,"exists") then
				D = 0
				VehicleTab[i].driver = 0
			end
			if D > 0 and VehicleTab[i].drivercantact == 0 then
				VehicleTab[i].rot = math.floor(player(D,"rot"))
			end
			if VehicleTab[i].speed ~= 0 then
				local x = VehicleTab[i].x + (math.sin(math.rad(VehicleTab[i].rot)) * VehicleTab[i].speed)
				local y = VehicleTab[i].y - (math.cos(math.rad(VehicleTab[i].rot)) * VehicleTab[i].speed)
				if tile(math.floor(x/32),math.floor(y/32),"walkable") then
					VehicleTab[i].x = x
					VehicleTab[i].y = y
				else
					if VehicleTab[i].currentchange <= 1 then
						SoundRadius("starkkz/carmod/vehicle_impact_medium"..math.random(1.4)..".wav",VehicleTab[i].x,VehicleTab[i].y,380)
					else
						SoundRadius("starkkz/carmod/vehicle_impact_heavy"..math.random(1,4)..".wav",VehicleTab[i].x,VehicleTab[i].y,420)
					end
					VehicleTab[i].drivercantact = math.abs(math.floor(VehicleTab[i].speed))
					VehicleTab[i].currentchange = 0
					VehicleTab[i].speed = math.floor(-VehicleTab[i].speed/2)
					VehicleTab[i].health = VehicleTab[i].health - (VehicleTab[i].drivercantact*3)
					if VehicleTab[i].health <= 0 then
						parse('killplayer '..id)
						parse('explosion '..VehicleTab[i].x..' '..VehicleTab[i].y..' 100 500')
						freeimage(VehicleTab[i].img)
						VehicleTab[i] = nil
					end
				end
				if VehicleTab[i] then
					if D > 0 then
						parse("setpos "..D.." "..VehicleTab[i].x.." "..VehicleTab[i].y)
					end
					imagepos(VehicleTab[i].img,VehicleTab[i].x,VehicleTab[i].y,VehicleTab[i].rot)
				end
			end
			if VehicleTab[i] then
				for k, p in pairs(VehicleTab[i].brings) do
					if player(p,"exists") and player(p,"health") > 0 then
						if player(p,"x") ~= VehicleTab[i].x or player(p,"y") ~= VehicleTab[i].y then
							parse("setpos "..p.." "..VehicleTab[i].x.." "..VehicleTab[i].y)
							if player(p,"speedmod") > -100 then
								parse("speedmod "..p.." -100")
							end
						end
					else
						VehicleTab[i].brings[k] = nil
					end
				end
			end
		end
	end
	for _, id in pairs(player(0,"table")) do
		DrawHudTo(id)
	end
end

addhook("die","onDie")
function onDie(id)
	if FindVehicleTo(id) then
		local v = FindVehicleTo(id)
		onUse(id,v)
	end
end

addhook("hit","onHit")
function onHit(id,source,wpn,hpdmg,apdmg)
	if FindVehicleTo(id) then
		local v = FindVehicleTo(id)
		VehicleTab[v].health = VehicleTab[v].health - hpdmg
		if VehicleTab[v].health <= 0 then
			parse('killplayer '..id)
			parse('explosion '..VehicleTab[v].x..' '..VehicleTab[v].y..' 100 500')
			freeimage(VehicleTab[v].img)
			VehicleTab[v] = nil
		end
		return 1
	end
	if FindBringTo(id) then
		return 1
	end
end

addhook("use","onUse")
function onUse(id,event)
	if event == 0 and not FindBringTo(id) then
		if not FindVehicleTo(id) then
			for i = 1, VehicleTab.List do
				if VehicleTab[i] then
					if VehicleTab[i].driver == 0 then
						if VehicleTab[i].lockstatus == false then
							local Range = (VehicleTab[i].spritescale.x+VehicleTab[i].spritescale.y)/2
							if math.sqrt((player(id,"x")-VehicleTab[i].x)^2 + (player(id,"y")-VehicleTab[i].y)^2) < Range then
								VehicleTab[i].driver = id
								parse("setpos "..id.." "..VehicleTab[i].x.." "..VehicleTab[i].y)
								parse("speedmod "..id.." -100")
								SoundRadius("starkkz/carmod/vehicle_ignition.wav",VehicleTab[i].x,VehicleTab[i].y,300)
								return 1
							end
						else
							msg2(id,"This car is locked!")
						end
					end
				end
			end
		else
			local v = FindVehicleTo(id)
			VehicleTab[v].x = player(id,"x")
			VehicleTab[v].y = player(id,"y")
			VehicleTab[v].driver = 0
			VehicleTab[v].currentchange = 0
			parse("speedmod "..id.." 0")
		end
	end
end

addhook("leave","onLeave")
function onLeave(id)
	if FindVehicleTo(id) then
		onUse(id)
	end
end

addhook("startround","onStart")
function onStart()
	VehicleTab = {List = 0}
	for _, id in pairs(player(0,"table")) do
		parse("speedmod "..id.." 0")
	end
end

function string:split(b)
	local cmd = {}
	if type(self) == "string" then
	if not b then match = "[^%s]+" else match = "[^"..b.."]+" end
	for word in string.gmatch(self,match) do
			table.insert(cmd,word)
		end
	end
	return cmd
end

addhook("parse","onparse")
function onparse(txt)
	local s = txt:split()
	if s[1] == "spawncar" then
		local x = tonumber(s[2])
		local y = tonumber(s[3])
		local maxchanges = tonumber(s[4])
		local rot = tonumber(s[5])
		local sprite = tostring(s[6])
		local spritescalex = tonumber(s[7])
		local spritescaley = tonumber(s[8])
		local fuel = tonumber(s[9])
		local health = tonumber(s[10])
		if x and y and maxchanges and rot and sprite and spritescalex and spritescaley and fuel and health then
			Vehicle.new({x = x,y = y,maxchanges = maxchanges,rot = rot,img = sprite,spritescale = {x = spritescalex,y = spritescaley},fuel = fuel,health = health})
		end
		return 1
	end
end

Vehicle.new({
     x = 146,
     y = 586,
     maxchanges = 20,
     rot = 180,
     img = "gfx/RaceServer/police.png",
     spritescale = {
          x = 4,
          y = 18
     },
     fuel = 1000000000000000000000000000000000000000000000,
     health = 1000
})

Vehicle.new({
     x = 270,
     y = 591,
     maxchanges = 10,
     rot = 180,
     img = "gfx/RaceServer/1.png",
     spritescale = {
          x = 8,
          y = 18
     },
     fuel = 1000000000000000000000000000000000000000000000,
     health = 1000
})

how can i make with this one ? when i press f4 it displays the buy menu
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview