Forum

> > CS2D > Scripts > Fire ball script
Forums overviewCS2D overview Scripts overviewLog in to reply

English Fire ball script

No replies
To the start Previous 1 Next To the start

old Fire ball script

Precel97
User Off Offline

Quote
Hi All !
I Have Problem With Fireball script -Bug
This Bug is when i say skill Double times
fireball this first fireball is disappears and this second ball is create
And Second Bug When you dead you can say skill and ball is create on this place where you dead

Can Who Fix This ??
And Add Delay 30 sec

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
addhook("say","sayskill")
function sayskill(id, txt)
     if(string.sub(txt,1,5)=="skill") then
     shootFireball(id)
	end
end

rpiconst = 180 / math.pi
imagepath = "sys/lua/fbmod/fireball.png" -- path to image
speed = 25 --speed of fireball
dmg = 100 --damage it does

function initArray(m,v)
     local array = {}
     for i = 1, m do
          array[i]=v
     end
     return array
end

fireball = {x = 0,y = 0,dir = 0,fid = 0,exists=0,rot = 0}
fireballs = initArray(32,fireball) -- each person can only have 1 fireball atm.

function shootFireball(id)
	if(fireballs[id].exists ~= 0) then
		freeimage(fireballs[id].fid)
	end
	fireballs[id] = {x = player(id,"x"),y = player(id,"y"),dir =toRad(player(id,"rot")),fid = 0,exists = 1,rot = player(id,"rot")}
	drawFireball(id)
end


function toRad(deg) -- from degrees to radian
	return (deg / rpiconst)
end

function collision(xpos,ypos,id)
	if((xpos > player(id,"x") - 30) and (xpos <  player(id,"x") + 30)) then
		if((ypos > player(id,"y") - 30) and (ypos <  player(id,"y") + 30)) then
			--msg("collision!")
			return true
		end
	end
	return false
end

function updateFireball(id) --update position, check for bounds
	fireballs[id].y = fireballs[id].y - (math.cos(fireballs[id].dir)*speed)
	fireballs[id].x = fireballs[id].x + (math.sin(fireballs[id].dir)*speed)

	local xpos = fireballs[id].x -- tired of typing the long thing ;P
	local ypos = fireballs[id].y -- ditto

	for i,v in ipairs(player(0,"table")) do -- collision
		if(i ~= id) then
			if(collision(xpos,ypos,i)) then
				parse("sethealth "..i.." "..(player(i,"health")-dmg))
			end
		end
	end


	if(fireballs[id].x > (map("xsize")*32) or fireballs[id].x < 0 or fireballs[id].y > (map("ysize")*32) or fireballs[id].y < 0) then --check for map boundaries
		fireballs[id].exists = 0
		freeimage(fireballs[id].fid)
	else
		imagepos(fireballs[id].fid,fireballs[id].x,fireballs[id].y,fireballs[id].rot)
	end
end

function drawFireball(id) -- draw and rotate.
	fireballs[id].fid=image(imagepath,fireballs[id].x,fireballs[id].y,1)
	imagepos(fireballs[id].fid,fireballs[id].x,fireballs[id].y,fireballs[id].rot)
end

addhook("ms100","my_ms100")
function my_ms100()
	for i,v in ipairs(fireballs) do
		if(v.exists==0) then
			return
		end
		updateFireball(i)
	end
end
To the start Previous 1 Next To the start
Log in to reply Scripts overviewCS2D overviewForums overview