Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- astimg=initArray2(512,0)
- astype=initArray2(512,0)
- asthealth=initArray2(512,0)
- astcomm=initArray2(512,0)
- astpos=doublearray(512,2,0)
- asts={}
- function createAsteroid(id,x,y,type,mineral)
- astimg[id]=image("gfx/space/asteroid_0"..type..".png",x*32+16,y*32+16,1)
- astype[id]=type
- asthealth[id]=type*100
- astcomm[id]=mineral
- astpos[id][1]=x
- astpos[id][2]=y
- table.insert(asts,id)
- end
- function killAsteroid(id,ply)
- freeimage(astimg[id])
- astimg[id]=0
- asthealth[id]=0
- if (astcomm[id]~=0) then
- commodities[ply][astcomm[id]]=commodities[ply][astcomm[id]]+astype[id]
- end
- astype[id]=0
- astpos[id][1]=0
- astpos[id][2]=0
- table.remove(asts,table.find(asts,id))
- end
- function createAsteroidField(density,mineral,x1,y1,x2,y2)
- local area=(x1+x2)*(y1+y2)
- if (area>=9) then
- if (density==1) then
- for ast=1,(math.floor(area/3)) do
- local function createast(x1,y1,x2,y2,mineral,id)
- local xx=math.random(x1,x2)
- local yy=math.random(y1,y2)
- local type=math.random(1,5)
- createAsteroid(xx,yy,type,mineral)
- end
- createast(x1,y1,x2,y2,mineral,ast)
- end
- elseif (density==2) then
- for ast=1,(math.floor(area/2)) do
- local function createast(x1,y1,x2,y2,mineral,id)
- local xx=math.random(x1,x2)
- local yy=math.random(y1,y2)
- createAsteroid(id,xx,yy,(math.random(1,5)),mineral)
- end
- createast(x1,y1,x2,y2,mineral,ast)
- end
- elseif (density==3) then
- for ast=1,(math.floor(area/1.5)) do
- local function createast(x1,y1,x2,y2,mineral,id)
- local xx=math.random(x1,x2)
- local yy=math.random(y1,y2)
- createAsteroid(id,xx,yy,(math.random(1,5)),mineral)
- end
- createast(x1,y1,x2,y2,mineral,ast)
- end
- end
- end
- end
- addhook("attack","killasteroids")
- function killasteroids(id)
- for range=1,192 do
- local x,y=csconvert(player(id,"rot"),player(id,"x"),player(id,"y"),range)
- if (#asts>1) then
- for aid=1,#asts do
- if (inRange(math.floor(x/32),math.floor(y/32),astpos[aid][1]-48,astpos[aid][2]-48,astpos[aid][1]+48,astpos[aid][2]+48)) then
- asthealth[aid]=asthealth[aid]-itemtype(player(id,"weapontype"),"dmg")
- msg("HIT! The health of asteroid #"..aid.." is now "..asthealth[aid])
- if (asthealth[aid]<=0) then
- killAsteroid(aid,id)
- end
- end
- end
- else
- if (#asts==1) then
- if (inRange(math.floor(x/32),math.floor(y/32),astpos[1][1]-48,astpos[1][2]-48,astpos[1][1]+48,astpos[1][2]+48)) then
- asthealth[1]=asthealth[1]-itemtype(player(id,"weapontype"),"dmg")
- msg("HIT! The health of asteroid #"..aid.." is now "..asthealth[aid])
- if (asthealth[1]<=0) then
- killAsteroid(1,id)
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment