It shakes strangely sometimes. I'd coded like that and then the same problem, at last I gave up and tried another way like "self.RotAngle = -(self.Vel.X / 32) * 0.5".
About the shield, I've written some codes to make it check if a MO is flying toward you, reflect the MO to correct direction instead of multiply its speed by -1.
for particle in MovableMan.Particles do local pardist = SceneMan:ShortestDistance(self.parent.Pos,particle.Pos,self.mapwrapx); local judgeX = (particle.Pos.X - self.parent.Pos.X) * (particle.Vel.X - self.parent.Vel.X); local judgeY = (particle.Pos.Y - self.parent.Pos.Y) * (particle.Vel.Y - self.parent.Vel.Y); local PX = particle.Pos.X - self.parent.Pos.X; local PY = particle.Pos.Y - self.parent.Pos.Y; local VX = particle.Vel.X - self.parent.Vel.X; local VY = particle.Vel.Y - self.parent.Vel.Y; local UV = -((PX*VX) + (PY*VY))/(PX^2 + PY^2); local NX = 2*PX*UV + VX; local NY = 2*PY*UV + VY; local paVel = math.sqrt(VX^2 + VY^2); ------------Another Method --local angP = math.atan((particle.Pos.Y - self.parent.Pos.Y)/(particle.Pos.X - self.parent.Pos.X)); --local angV = math.atan(spY/spX); --local paVel = math.sqrt(spY^2 + spX^2); --local angCA = angP - (angV - angP); --local flip = (-1 * spX) / math.abs(spX); ------------ if particle.HitsMOs == true and pardist.Magnitude < (58 + (paVel / 12)) and particle.PresetName ~= "Particle CutTool-X" then if judgeX < 0 or judgeY < 0 then if particle.ClassName == "MOPixel" then self.counterpar = CreateMOPixel(particle.PresetName); elseif particle.ClassName == "MOSParticle" then self.counterpar = CreateMOSParticle(particle.PresetName); elseif particle.ClassName == "MOSRotating" then self.counterpar = CreateMOSRotating(particle.PresetName); elseif particle.ClassName == "AEmitter" then self.counterpar = CreateAEmitter(particle.PresetName); end self.counterpar.Vel.X = NX + (30 * NX / math.sqrt(NX^2 + NY^2)); self.counterpar.Vel.Y = NY + (30 * NY / math.sqrt(NX^2 + NY^2)); ------------Another Method -- self.counterpar.Vel.X = ((math.cos(angCA) * paVel) + self.parent.Vel.X) * flip; -- self.counterpar.Vel.Y = ((math.sin(angCA) * paVel) + self.parent.Vel.Y) * flip; ------------ self.counterpar.Pos = particle.Pos; self.counterpar:SetWhichMOToNotHit(self.parent,-1); self.gloweffect = CreateMOPixel("X-CutTool Shield LittleGlow","X-Region.rte"); self.gloweffect.Pos = particle.Pos; MovableMan:AddMO(self.gloweffect); particle.ToDelete = true; MovableMan:AddParticle(self.counterpar); end end end
Feel free to take and adapt it for your great tank ^_^
Tue May 10, 2011 8:45 pm
Kettenkrad
Joined: Mon Oct 25, 2010 5:51 am Posts: 1198 Location: Sydney
Re: Tank project (3rd prototype)
Might want to add sounds to the flamer and incendiary grenades, and possibly map out the buttons a little better? I realize it will be difficult to find the right keys, but maybe 'r' 'f' 't' and 'g', just so its closer to 'wasd'.
Tue May 10, 2011 11:18 pm
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Tank project (3rd prototype)
Kettenkrad wrote:
Might want to add sounds to the flamer and incendiary grenades, and possibly map out the buttons a little better? I realize it will be difficult to find the right keys, but maybe 'r' 'f' 't' and 'g', just so its closer to 'wasd'.
I was just thinking the same.
Or you could do what Darlos did on DarkStorm and let the keys be easily customizable.
EDIT:
Sometimes while shooting with the MG the shield blocks the bullets. And the tank started shaking strangely and for a long while when I moved upwards.
EDIT:
I realised that the problem with the MG happens while moving forward and shooting, and it also happened to me (like once) that shooting the main cannon and moving forward resulted in the explosive exploding in front of me.
Wed May 11, 2011 1:50 am
Xery
Joined: Sat Feb 26, 2011 10:29 am Posts: 163
Re: Tank project (3rd prototype)
Asklar wrote:
Or you could do what Darlos did on DarkStorm and let the keys be easily customizable.
Also suggest to do this. Very useful and not hard to achieve (in my experience).
Wed May 11, 2011 4:41 am
mario972
Joined: Sun Feb 06, 2011 5:43 pm Posts: 29 Location: Piaseczno, Poland
The tank wobbles, and you need to change the weapons so it's more user friendly.
Thu May 12, 2011 1:01 am
Asklar
Data Realms Elite
Joined: Fri Jan 07, 2011 8:01 am Posts: 6211 Location: In your office, earning your salary.
Re: Tank project (3rd prototype)
Firing particles with negative mass at it makes the shield increase it's shield (I made a grenade which uses only negative mass particles, and it shield went to 254% for a short time).
And it doesn't have awesome gib sprites? D=
Thu May 12, 2011 4:23 am
Spider101
Joined: Sun Apr 10, 2011 5:25 pm Posts: 22 Location: Frolicking in the fields of newbinesism
Re: Tank project (3rd prototype)
A bit of wobble and whenever the body touchs something the terrain gets disintergrated :l
Sun May 15, 2011 12:04 pm
Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
Re: Tank project (3rd prototype)
Here I added sounds, solved the wobbleing problem, added an ammo display, made the keys customizable, made it easy to add new ammo types(no lua required), corrected an error in the shield script and a few other minor changes I don't remember. Read the file named "Readme.txt" to learn how to customize the keys and add new ammo types.
self.timer = Timer(); self.Shield = 100; --do not edit this
-----------Variables you can edit:-----------
self.healtime = 2000 --the actor will regenerate 1% of his health every self.healtime ms. self.ShieldPower = 7500; --this you can edit: a higher number will make the shield more powerful, a lower number less powerful self.ShieldRegen = 0.10; --the % of the shield that will be regenerated in 1 tick (60 ticks in a second if you haven't modified your DeltaTime) 1.25 <-> 1.25% / tick <-> 75% / sec. self.ShowRealShieldValue = false; --activating this will show you the real power of the shield instead of a %.
local f = require("io"); f.input("Tank.rte/Keys.ini");
local ok = -5;
for line in f.lines() do
if line == listkeys[0] then ok = 0; elseif line == listkeys[1] then ok = 1; elseif line == listkeys[2] then ok = 2; elseif line == listkeys[3] then ok = 3; elseif ok > -1 then if ok == 0 then self.FlamerKey = tonumber(line); elseif ok == 1 then self.AmmoChangeKey = tonumber(line); elseif ok == 2 then self.GrenadeKey = tonumber(line); elseif ok == 3 then self.MGKey = tonumber(line); end ok = -5; end
local fi = require("io"); fi.input("Tank.rte/AmmoList.ini");
local ook = -5; self.o = 0;
for line in fi.lines() do
if line == "Ammo:" then ook = 0; elseif line == "AmmoType:" then ook = 1; elseif line == "MuzzleVelocity:" then ook = 2; self.o = self.o+1; elseif ook > -1 then if ook == 0 then self.listammo[self.o] = line; elseif ook == 1 then self.listtype[self.o] = line; elseif ook == 2 then self.listvel[self.o-1] = tonumber(line); end ook = -5; end
end
fi.input():close();
end
function Destroy(self)
if MovableMan:ValidMO(self.i) then ToTDExplosive(self.i).ToDelete = true; end if MovableMan:ValidMO(self.altsensor1) then ToTDExplosive(self.altsensor1).ToDelete = true; end if MovableMan:ValidMO(self.altsensor2) then ToTDExplosive(self.altsensor2).ToDelete = true; end
end
function Update(self)
--propulsion, stabilisation
self.alt = self:GetAltitude(0,1);
if self.alt < self.setalt and self.Vel.Y > -10 then self.Vel.Y = self.Vel.Y - 0.5; end
if self.Vel.Y < -4.5 then self.Vel.Y = self.Vel.Y + 1.5; elseif self.Vel.Y > 4.5 then self.Vel.Y = self.Vel.Y - 1.5; end
self.AngularVel = 0.95 * self.AngularVel;
if self.Vel.X < 8 and self.c:IsState(3) then self.Vel.X = self.Vel.X + 1; elseif self.Vel.X > -8 and self.c:IsState(4) then self.Vel.X = self.Vel.X - 1; end
if self.setalt < 150 and self.c:IsState(5) then self.setalt = self.setalt + 0.75; elseif self.setalt > 25 and self.c:IsState(6) then self.setalt = self.setalt - 0.75; end
if self.Health <= 0 then self:GibThis(); end
--grenade launcher
if self:IsPlayerControlled() == true and UInputMan:KeyPressed(self.GrenadeKey) and self.Grenade>0 then local Gre = CreateAEmitter("Incendiary Tank Grenade","Tank.rte"); if self.HFlipped then Gre.Pos = Vector(self.Pos.X+10,self.Pos.Y-45); else Gre.Pos = Vector(self.Pos.X-10,self.Pos.Y-45); end Gre.Vel = Vector(self.Vel.X,self.Vel.Y-15); MovableMan:AddMO(Gre); self.Grenade = self.Grenade - 1;
local s = CreateAEmitter("Grenade Launch Sound","Tank.rte"); s.Pos = self.Pos; MovableMan:AddMO(s);
end
--terrain detection and automatic orientation
if MovableMan:ValidMO(self.altsensor1) and MovableMan:ValidMO(self.altsensor2) then if self.altsensor1.PresetName ~= "Entity" and self.altsensor2.PresetName ~= "Entity" then
if self.alt1 < self.alt2 and self.RotAngle < (math.pi/12) then local acc = (0.025*math.abs(self.alt1-self.alt2)); if acc > 1 then acc = 1; end self.AngularVel = self.AngularVel + acc; elseif self.alt2 < self.alt1 and self.RotAngle > -(math.pi/12) then local acc = (0.025*math.abs(self.alt1-self.alt2)); if acc > 1 then acc = 1; end self.AngularVel = self.AngularVel - acc; end
self.altsensor1:Activate(); self.altsensor2:Activate(); end
--energy shield
if self.timer:IsPastSimMS(self.healtime) and self.Health > 0 then if self.Health < 100 then self.Health = self.Health + 1; end if self.Grenade < 3 then self.Grenade = self.Grenade + 1; end self.timer:Reset(); end
if self.Shield < 100 then self.Shield = self.Shield + self.ShieldRegen; end if self.Shield > 100 then self.Shield = 100; end
local partvel;
for particle in MovableMan.Particles do partvel = particle.Vel - self.Vel; if math.abs(partvel.Magnitude) > 20 then
local dist = SceneMan:ShortestDistance(self.Pos, particle.Pos, true); local power = math.abs((0.5*particle.Mass*(partvel.Magnitude^2)*particle.Sharpness)/(self.ShieldPower));
if particle.ClassName == "AEmitter" then power = math.abs((0.5*particle.Mass*(partvel.Magnitude^2))/(0.075*self.ShieldPower)); end
if dist.Magnitude < 125 and particle.Age > 50 and (math.abs(partvel.Magnitude)) > 30 and (self.Shield) > power and particle.PresetName ~= "Mehman Frag 4" and particle.PresetName ~= "AP Shell" and particle.PresetName ~= "Particle AT" then
self.Shield = self.Shield - power;
local Glow = CreateMOPixel("Little Shield Glow","Tank.rte"); Glow.Pos = particle.Pos; MovableMan:AddMO(Glow);
if particle.ClassName == "AEmitter" then particle.Vel.X = - particle.Vel.X; particle.Vel.Y = - particle.Vel.Y; else particle.ToDelete = true; end
end end
end
if MovableMan:ValidMO(self.i) then if self.i.PresetName ~= "Entity" then if self.ShowRealShieldValue == false then self.i.PresetName = math.ceil(self.Shield).."%"; else self.i.PresetName = math.ceil( (self.Shield/100)*self.ShieldPower )..""; end self.i.Pos = self.AboveHUDPos + Vector(0,-8); self.i.Vel = self.Vel; if self.Health <= 0 or self.Status == 4 then self.i:Activate(); end end elseif self.Age > 250 then self.i = CreateTDExplosive("Null Device","Tank.rte"); self.i.Pos = self.AboveHUDPos + Vector(0,-8); self.i.Vel = self.Vel; MovableMan:AddMO(self.i); self.i.PresetName = math.ceil(self.Shield).."%"; end
--coaxial flamer
if ( self:IsPlayerControlled() == true and UInputMan:KeyHeld(self.FlamerKey) ) then
local rand = math.random(0,100); if rand > 10 then local fl = CreateAEmitter("Particle TankF","Tank.rte");
if ( self:IsPlayerControlled() == true and UInputMan:KeyPressed(self.AmmoChangeKey) ) then
if tonumber(self.PresetName) < self.o-1 then self.PresetName = tostring(tonumber(self.PresetName)+1); else self.PresetName = "0"; end
end
--MG
if MovableMan:ValidMO(self.MG) then
if self.MG.PresetName ~= "Entity" then
if self.HFlipped then self.MG.Pos = self.Pos + Vector(math.cos(self.RotAngle-0.2521198)*-42.45,math.sin(self.RotAngle-0.2521198)*42.45); self.MG.HFlipped = false; else self.MG.Pos = self.Pos + Vector(math.cos(self.RotAngle+0.2521198)*42.45,-math.sin(self.RotAngle+0.2521198)*42.45); self.MG.HFlipped = true; end
local MGAngle = (self.MG.RotAngle % (2*math.pi)) - math.pi;
if self.HFlipped then if MGAngle < -self.MGAim then self.MG.AngularVel = 1.5; elseif MGAngle > -self.MGAim then self.MG.AngularVel = -1.5; end else if MGAngle < self.MGAim then self.MG.AngularVel = 1.5; elseif MGAngle > self.MGAim then self.MG.AngularVel = -1.5; end end
self.MG.Vel = self.Vel;
if self:IsPlayerControlled() == true and UInputMan:MouseWheelMoved() == -1 then if self.MGAim > -0.75 then self.MGAim = self.MGAim - 0.05; end elseif self:IsPlayerControlled() == true and UInputMan:MouseWheelMoved() == 1 then if self.MGAim < 0.75 then self.MGAim = self.MGAim + 0.05; end end
if ( self:IsPlayerControlled() == true and UInputMan:KeyHeld(self.MGKey) and self.reload >= 6 ) then local rand = math.random(0,100); if rand < 75 then local bullet = CreateAEmitter("Particle Tank MG","Tank.rte"); if self.HFlipped then bullet.Pos = self.MG.Pos + Vector(math.cos(self.MG.RotAngle)*16,math.sin(self.MG.RotAngle)*-16); bullet.Vel = Vector(math.cos(self.MG.RotAngle)*16,math.sin(self.MG.RotAngle)*-16); else bullet.Pos = self.MG.Pos + Vector(math.cos(self.MG.RotAngle)*-16,math.sin(self.MG.RotAngle)*16); bullet.Vel = Vector(math.cos(self.MG.RotAngle)*-16,math.sin(self.MG.RotAngle)*16); end MovableMan:AddMO(bullet); else local bullet = CreateAEmitter("Particle Tank MGT","Tank.rte"); if self.HFlipped then bullet.Pos = self.MG.Pos + Vector(math.cos(self.MG.RotAngle)*16,math.sin(self.MG.RotAngle)*-16); bullet.Vel = Vector(math.cos(self.MG.RotAngle)*16,math.sin(self.MG.RotAngle)*-16); else bullet.Pos = self.MG.Pos + Vector(math.cos(self.MG.RotAngle)*-16,math.sin(self.MG.RotAngle)*16); bullet.Vel = Vector(math.cos(self.MG.RotAngle)*-16,math.sin(self.MG.RotAngle)*16); end MovableMan:AddMO(bullet); end
self.reload = 0; end
end elseif self.Age > 250 then self.MG = CreateTDExplosive("MG Turret","Tank.rte"); if self.HFlipped then self.MG.Pos = self.Pos + Vector(math.cos(self.RotAngle+0.2421198)*-42.45,math.sin(self.RotAngle+0.2421198)*42.45); else self.MG.Pos = self.Pos + Vector(math.cos(self.RotAngle+0.2421198)*42.45,-math.sin(self.RotAngle+0.2421198)*42.45); end self.MG.Vel = self.Vel; MovableMan:AddMO(self.MG); self.MG:Activate(); end
if self.reload <6 then self.reload = self.reload + 1; end
--Ammo Display
if MovableMan:ValidMO(self.ammodisplay) then if self.ammodisplay.PresetName ~= "Entity" then
self.ammodisplay.Pos = self.AboveHUDPos + Vector(0,40); self.ammodisplay.Vel = self.Vel; if self.Health <= 0 or self.Status == 4 then self.ammodisplay:Activate(); end end elseif self.Age > 250 then self.ammodisplay = CreateTDExplosive("Null Device","Tank.rte"); self.ammodisplay.Pos = self.AboveHUDPos + Vector(0,40); self.ammodisplay.Vel = self.Vel; MovableMan:AddMO(self.ammodisplay); self.ammodisplay.PresetName = self.listammo[tonumber(self.PresetName)]; end
end
489 lines, if you see any errors in my code please tell me.
Mon May 16, 2011 2:09 pm
Xery
Joined: Sat Feb 26, 2011 10:29 am Posts: 163
Re: Tank project (3rd prototype)
Mehman wrote:
Here I added sounds, solved the wobbleing problem, added an ammo display, made the keys customizable, made it easy to add new ammo types(no lua required), corrected an error in the shield script and a few other minor changes I don't remember. Read the file named "Readme.txt" to learn how to customize the keys and add new ammo types.
I think this is definitely going to be one of the longest scripts in CC's history: 489 lines, if you see any errors in my code please tell me.
In my mod there's a Lua of 501 lines, and the AI script of Independent.rte has about 800 lines of code. I think it's not realistic that a shield reflect object by just multiply by -1, and most Lua-made shield in CC can't judge whether the target paritcle is flying toward you or not(though it's easy to code out). That's why I write the code at last reply in this post.
Last edited by Xery on Mon May 16, 2011 4:00 pm, edited 1 time in total.
Mon May 16, 2011 3:40 pm
Mehman
Joined: Tue Nov 17, 2009 7:38 pm Posts: 909 Location: France
Re: Tank project (4th prototype)
Still it's a very long one and it's not finished yet, what's your mod with 501 lines?
Mon May 16, 2011 3:45 pm
Xery
Joined: Sat Feb 26, 2011 10:29 am Posts: 163
Re: Tank project (4th prototype)
This' my first, overpowered little mod, a combination of many other mods. I just dare not to release it because of worrying about my poor English, which can't support me to write the readme file clear enough.
Now one final thing I realised that makes generally the tank hard to control and aim, and it is its constant gliding/sliding. The tank doesn't actually stops, it is always moving, making aiming (specially on angled terrain) very complicated.
Maybe it's just me, but that is the biggest flaw it has since the beggining and I just noticed that.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot post attachments in this forum