Bombs

View previous topic View next topic Go down

Bombs

Post by DanielLC on Sat Mar 19, 2011 7:08 pm

Unfortunately, these aren't capable of doing any real damage, even with unbreakable off.

First, you have to make a model that sets DROP to the number of frames until the bomb goes off whenever you want to drop one. You should make it so it keeps you from just holding the button, although I think that would just cause the bomb to hover under the bomb bay.

Here's an example of a model that works:

Code:
Val
{
   start(default=0,min=0,max=1)
   up(default=0,min=-1000000,max=1000000)
   n(default=0,min=-1000000,max=1000000)
   s(default=0,min=-1000000,max=1000000)
   e(default=0,min=-1000000,max=1000000)
   w(default=0,min=-1000000,max=1000000)
   rot(default=0,min=-1000000,max=1000000)
   x(default=0,min=-1000000,max=1000000)
   y(default=0,min=-1000000,max=1000000)
   z(default=0,min=-1000000,max=1000000)
   ax(default=0,min=-6.28,max=6.28)
   ay(default=0,min=-6.28,max=6.28)
   az(default=0,min=-6.28,max=6.28)
   dax(default=0,min=-6.28,max=6.28)
   day(default=0,min=-6.28,max=6.28)
   daz(default=0,min=-6.28,max=6.28)
   trigger(default=0,max=1,step=1)
   timer(default=0,step=1)
   drop(default=0,step=99999999999)
}
Key
{
   0:y(step=1)
   1:y(step=-1)
   4:trigger(step=1)
}
Body {
  Core(name=BAY){
    N:Jet(power=n){}
    E:Jet(power=e){}
    S:Jet(power=s){}
    W:Jet(power=w){}
    N:Wheel(power=ROT,angle=180){}
  }
}
Lua
{
function main()
  if START==0 then
    X=_X(0)
    Y=_Y(0)
    Z=_Z(0)
  end

  DAX=AX-_AX(0)
  DAY=AY-_AY(0)
  DAZ=AZ-_AZ(0)

  AX=_AX(0)
  AY=_AY(0)
  AZ=_AZ(0)

  UP=(Y-_Y(0)-_VY(0))*10000
  N=UP-(_AX(0)-DAX)*10000
  S=UP+(_AX(0)-DAX)*10000
  E=UP-(_AZ(0)-DAZ)*10000
  W=UP+(_AZ(0)-DAZ)*10000
  ROT=-(_AY(0)-DAY)*10000

  if TRIGGER == 1 and TIMER == 0 then
    TIMER = 30
    DROP = 30
  end

  START=1
end
}

And for the script itself: bomb.rcs

Code:
function qmult(q1,q2)
  local q3={0,0,0,0}
  q3[1]=q1[2]*q2[3]-q1[3]*q2[2]+q1[4]*q2[1]+q1[1]*q2[4]
  q3[2]=q1[3]*q2[1]-q1[1]*q2[3]+q1[4]*q2[2]+q1[2]*q2[4]
  q3[3]=q1[1]*q2[2]-q1[2]*q2[1]+q1[4]*q2[3]+q1[3]*q2[4]
  q3[4]=q1[4]*q2[4]-q1[1]*q2[1]-q1[2]*q2[2]-q1[3]*q2[3]
  return(q3)
end

function qinv(q)
  return({-q[1],-q[2],-q[3],q[4]})
end

function rot(v,q)
  return qmult(qmult(q,v),qinv(q))
end
function drop()
  r = rot({0,-0.5,0,0},{_QX(BAY),_QY(BAY),_QZ(BAY),_QW(BAY)})
  _WARPOBJ(bomb,_X(BAY)+r[1],_Y(BAY)+r[2],_Z(BAY)+r[3])
  _ENERVATEOBJ(bomb)
  _FORCEOBJ(bomb,_VX(BAY)*_MOBJ(bomb)*300,_VY(BAY)*_MOBJ(bomb)*300,_VZ(BAY)*_MOBJ(bomb)*300)
  timer = DROP
end

function boom()
  local x = _OX(bomb)
  local y = _OY(bomb)
  local z = _OZ(bomb)

  _WARPOBJ(bomb,0,-256,0)

  for i = 1, nshrapnel do
    local dx = math.random(-1,1)/4
    local dy = math.random(-1,1)/4
    local dz = math.random(-1,1)/4
    local r = math.sqrt(dx*dx+dy*dy+dz*dz)
    if r == 0 then
      r = 0.01
    end
    local k = 5000000/r
    _WARPOBJ(shrapnel[i],x+dx,y+dy,z+dz)
    _ENERVATEOBJ(shrapnel[i])
    _FORCEOBJ(shrapnel[i],dx*k,dy*k,dz*k)
  end
end

function countdown()
  if timer > 0 then
    timer = timer - 1
    if timer == 0 then
      boom()
    end
  end
end

WindLevel=0
LastBall=-1

function OnFrame()
   
   if(_SKEYDOWN(0)>0) then
      LastBall=_ADDBALL(0.6, 2, _GETY(2,0)+6+LastBall, LastBall/10, 0.3)
      _SETOBJCOLOR(LastBall,1,0,1)
   end
   if(_SKEYDOWN(1)>0) then
      WindLevel=WindLevel+1
      if(WindLevel>3) then WindLevel=0 end
      if(WindLevel==0) then _SETWIND(0,0,0) end
      if(WindLevel==1) then _SETWIND(5,0,0) end
      if(WindLevel==2) then _SETWIND(16,0,0) end
      if(WindLevel==3) then _SETWIND(50,0,0) end
   end
   wx,wy,wz=_GETWIND()
   if(WindLevel~=0) then out(0,"Wind = ",wx," ",wy," ",wz) end
   if(LastBall>=0) then out(1,"Ball Count = ",LastBall+1) end

  countdown()

  if DROP ~= 0 then
    drop()
  end

--(size,x,y,z,density)
end

function OnInit()
   WindLevel=0
   LastBall=-1

  timer = 0
  nshrapnel = 16
  shrapnel = {}
  for i = 1, nshrapnel do
    table.insert(shrapnel,_ADDBALL(0.1,0,-256,0,100))
  end
  bomb = _ADDBALL(0.4,0,-256,0,10)
end

function OnReset()

end

This limits you to one bomb at a time. There's not much I can do about this. The game only lets you have 20 balls, and I'm using 16 of them just for the shrapnel.

DanielLC
Tank
Tank

Posts : 78
Join date : 2010-10-23

View user profile

Back to top Go down

View previous topic View next topic Back to top

- Similar topics

 
Permissions in this forum:
You cannot reply to topics in this forum