Data Realms Fan Forums http://45.55.195.193/ |
|
Reasonable Lua Requests from miles http://45.55.195.193/viewtopic.php?f=73&t=15238 |
Page 1 of 1 |
Author: | Miles_T3hR4t [ Sun Jun 07, 2009 12:05 pm ] |
Post subject: | Reasonable Lua Requests from miles |
Hey, I suck at lua, and can only really edit existing code at the moment, until I learn more, but had some things I wanted. I would have put it under Requests but its Lua related, so I figure it goes here. But anyway I'd like to request a few basic lua scripts. I would like the script itself that can just be used in an object, as well as an explenation of how and why it works First of all, and this one is important. I need to make an MOS Rotating, that is a gib, and is HitsMos and GetsHitMos = 0, explode after X Milliseconds. (3000 in this case). It's going to be an AEmitter, that fires a high-mass TDE, that turns into THESE particles, which then explode. I didn't want them to have more attached AEmitters, because that would mean that you could shoot at them and set them off, which I do NOT want. So I'd like to revert to lua, otherwise I have to make them out of something like test, and make it emit particles that can wound test. but using lua you can start a timer, and then tell it to gib itself. I just don't know how to do that. Second is probably more complex.... A lua script included in 'object A' which could be a MOSR, or even a particle, that on a collision with ANY MOs, including actors, and guns, the object that gets hit, gains 100% of the velocity of said scripted object. So a bullet moving at a velocity of 60 on a 45 degree angle, hits an actor, which is now instantly moving at 60 at 45 after impact. The idea is to make a sort of a repeller gun on steroids. I've also seen the entire "i shoot a stake that hits an actor and it follows a path" crap, that have fixed paths. it should seriously be by an inherited velocity, thats actually why I wanted to see this done. Anyway I already know that half of you will want to flame me for this post, and complain and find everything to say that isn't productive, so can we just skip that? also, to the mods, if this does actually belong in requests, could you please move it? thanks. |
Author: | zalo [ Sun Jun 07, 2009 4:32 pm ] |
Post subject: | Re: Reasonable Lua Requests from miles |
The first one, you could just use a TDExplosive and attach an emitter to that? I don't know. EDIT: Oh, it's a gibbed TDE. Yeah, then you'd have to use a simple Lua script. A very simple one. Something like: Code: OnCreate(self) GibTimer = Timer(); end OnUpdate(self) if GibTimer:IsPastSimMS(3000) then self:GibThis(); end end You'll have to look at the wiki, or other people's mods for the exact code, but that's the basic gist of it. For the second one, there really is no "OnCollision" event function whatever, so it'd have to be calculated by proximity. And if you did that, you'd have to sacrifice doing it to big objects, or just make it do everything in a large radius. |
Author: | Grif [ Sun Jun 07, 2009 5:45 pm ] |
Post subject: | Re: Reasonable Lua Requests from miles |
Zalo's code is actually just about correct, though it'd be function Update(self) and function Create(self). As for no.2, I think you're looking at CastMORay, or whatever it is. Don't ask me to tell you how to use it; I'm utterly lost. But the recent stake launcher mod uses the same technique. |
Author: | Miles_T3hR4t [ Sun Jun 07, 2009 10:55 pm ] |
Post subject: | Re: Reasonable Lua Requests from miles |
Grif wrote: Zalo's code is actually just about correct, though it'd be function Update(self) and function Create(self). As for no.2, I think you're looking at CastMORay, or whatever it is. Don't ask me to tell you how to use it; I'm utterly lost. But the recent stake launcher mod uses the same technique. first, so.... Code: function Create(self) GibTimer = Timer(); end function Update(self) if GibTimer:IsPastSimMS(3000) then self:GibThis(); end end Now second is that stake gun. That makes the object struck follow the path the stake would follow, and doesn't take into account anything else, such as thrusters on a drop ship, or AirResistance. If there's a variable we can access to check velocity you could probably do something like CopyOfVelocity = Velocity(self) (and probably another for angle of velocity, like I said I don't know quite what I'm doing) Then when it gets close enough for a 'collision' it would set the 'struck' object's velocity to 0, then add the copied velocity. The problem is I don't know how that looks in code. also I'm guessing you have to have Function Create(self) and Function Update(self) in any lua script. Is there also a Function End(self)? if so we could do all sorts of crazy. But anyway, thanks i'm gonna start tampering with these now. ---Edit Does it run lua while in inventory? just curious. |
Author: | Grif [ Sun Jun 07, 2009 11:05 pm ] |
Post subject: | Re: Reasonable Lua Requests from miles |
function Create(self), function Update(self), function Destroy(self) Also lua is not run on any held devices at all, inventory or otherwise. |
Author: | Miles_T3hR4t [ Sun Jun 07, 2009 11:11 pm ] |
Post subject: | Re: Reasonable Lua Requests from miles |
Grif wrote: function Create(self), function Update(self), function Destroy(self) Also lua is not run on any held devices at all, inventory or otherwise. then how the hell does the minigun work? |
Author: | Grif [ Sun Jun 07, 2009 11:12 pm ] |
Post subject: | Re: Reasonable Lua Requests from miles |
Uh, Activation and DeactivationDelay? Program Files\Data Realms\Cortex Command\Coalition.rte\Devices\Weapons\Machineguns\GatlingGun.ini |
Author: | Miles_T3hR4t [ Sun Jun 07, 2009 11:18 pm ] |
Post subject: | Re: Reasonable Lua Requests from miles |
Grif wrote: Uh, Activation and DeactivationDelay? Program Files\Data Realms\Cortex Command\Coalition.rte\Devices\Weapons\Machineguns\GatlingGun.ini Yeah, I just noticed that, and feel stupid. |
Author: | CrazyMLC [ Mon Jun 08, 2009 7:17 am ] |
Post subject: | Re: Reasonable Lua Requests from miles |
Wouldn't you just make it gib an explosive? |
Author: | piipu [ Mon Jun 08, 2009 9:14 am ] |
Post subject: | Re: Reasonable Lua Requests from miles |
A copypaste from my modified harpoon gun lua file. It makes the harpoon hit stuff properly. The harpoon needs to be hitsmos = 0 and getshitbymos = 0 Code: function Create(self) self.LTimer = Timer(); self.unpinned = 1 end function Update(self) if self.LTimer:IsPastSimMS(50) then if self.unpinned == 1 then --if the object isn't attached to anything self.atarget = (SceneMan:CastMORay(Vector(self.Pos.X - self.Vel.X,self.Pos.Y - self.Vel.Y),Vector(self.Vel.X,self.Vel.Y),0,0,true,5)) --this checks if the object has hit anything, and if yes, returns the MOID of the collided object self.target = MovableMan:GetMOFromID(MovableMan:GetRootMOID(self.atarget)) --this gets the pointer of the root MO so we can actually do something with it if self.target ~= nil then --if we have hit something self.unpinned = 0 --set it attached self.offsetX = self.Pos.X - self.target.Pos.X --calculate the offsets from the root MO for attaching self.offsetY = self.Pos.Y - self.target.Pos.Y self.offsetMagnitude = math.sqrt(self.offsetX ^ 2 + self.offsetY ^ 2) --how long is the offset vector self.target:AddAbsImpulseForce(Vector(self.Vel.X * self.Mass * 6, self.Vel.Y * self.Mass * 6) , self.Pos) self.target.Vel = Vector(self.target.Vel.X + self.Vel.X * self.Mass * 3 / self.target.Mass , self.target.Vel.Y + self.Vel.Y * self.Mass * 3 / self.target.Mass) --Add an impulse to the root object to achieve a hit-like effect self.startangle = math.atan2(self.offsetX,self.offsetY) --the angle of the offset vector if self.HFlipped == 0 then self.startangle = self.startangle + math.pi; end -stuff to make it rotate properly end end if self.LTimer:IsPastSimMS(6000) then self:GibThis() ; end if (MovableMan:IsActor(self.target) or MovableMan:IsParticle(self.target)) and self.unpinned == 0 then --if attached self.Pos = Vector(self.target.Pos.X + self.offsetMagnitude * math.cos(math.pi-(self.target.RotAngle + self.startangle)),self.target.Pos.Y + self.offsetMagnitude * math.sin(math.pi-(self.target.RotAngle + self.startangle))) --set position according to the offset vector self.RotAngle = self.target.RotAngle + self.startangle --rotate self end end end This works pretty well, but the attaching can be a bit off sometimes. |
Author: | Miles_T3hR4t [ Tue Jun 09, 2009 4:21 am ] |
Post subject: | Re: Reasonable Lua Requests from miles |
---EDIT Oh and for the first one it had to be Code: function Create(self) self.sometimer = Timer() end function Update(self) if self.sometimer:IsPastSimMS(1500) then self:GibThis() end end piipu wrote: A copypaste from my modified harpoon gun lua file. It makes the harpoon hit stuff properly. The harpoon needs to be hitsmos = 0 and getshitbymos = 0 Code: function Create(self) self.LTimer = Timer(); self.unpinned = 1 end function Update(self) if self.LTimer:IsPastSimMS(50) then if self.unpinned == 1 then --if the object isn't attached to anything self.atarget = (SceneMan:CastMORay(Vector(self.Pos.X - self.Vel.X,self.Pos.Y - self.Vel.Y),Vector(self.Vel.X,self.Vel.Y),0,0,true,5)) --this checks if the object has hit anything, and if yes, returns the MOID of the collided object self.target = MovableMan:GetMOFromID(MovableMan:GetRootMOID(self.atarget)) --this gets the pointer of the root MO so we can actually do something with it if self.target ~= nil then --if we have hit something self.unpinned = 0 --set it attached self.offsetX = self.Pos.X - self.target.Pos.X --calculate the offsets from the root MO for attaching self.offsetY = self.Pos.Y - self.target.Pos.Y self.offsetMagnitude = math.sqrt(self.offsetX ^ 2 + self.offsetY ^ 2) --how long is the offset vector self.target:AddAbsImpulseForce(Vector(self.Vel.X * self.Mass * 6, self.Vel.Y * self.Mass * 6) , self.Pos) self.target.Vel = Vector(self.target.Vel.X + self.Vel.X * self.Mass * 3 / self.target.Mass , self.target.Vel.Y + self.Vel.Y * self.Mass * 3 / self.target.Mass) --Add an impulse to the root object to achieve a hit-like effect self.startangle = math.atan2(self.offsetX,self.offsetY) --the angle of the offset vector if self.HFlipped == 0 then self.startangle = self.startangle + math.pi; end -stuff to make it rotate properly end end if self.LTimer:IsPastSimMS(6000) then self:GibThis() ; end if (MovableMan:IsActor(self.target) or MovableMan:IsParticle(self.target)) and self.unpinned == 0 then --if attached self.Pos = Vector(self.target.Pos.X + self.offsetMagnitude * math.cos(math.pi-(self.target.RotAngle + self.startangle)),self.target.Pos.Y + self.offsetMagnitude * math.sin(math.pi-(self.target.RotAngle + self.startangle))) --set position according to the offset vector self.RotAngle = self.target.RotAngle + self.startangle --rotate self end end end This works pretty well, but the attaching can be a bit off sometimes. So if I add this to a bullet of some kind, and fly over a dropship, and shoot DOWN at the dropship, it will make the dropship go down, AND the dropship's engines will still try to push up, and slow it down? I got a bit lost at. Code: self.target:AddAbsImpulseForce(Vector(self.Vel.X * self.Mass * 6, self.Vel.Y * self.Mass * 6) , self.Pos) self.target.Vel = Vector(self.target.Vel.X + self.Vel.X * self.Mass * 3 / self.target.Mass , self.target.Vel.Y + self.Vel.Y * self.Mass * 3 / self.target.Mass) --Add an impulse to the root object to achieve a hit-like effect That doesn't make sense to me. Velocity X mass X 6? Velocity + mass X 3/mass? a mass of 1... 3/1 = 3... a mass of 6, 3/6 = 0.5... I don't want mass to have any effect, and that adds a HUGE effect. I just want a direct copy of velocity. I don't know if this is correct but Target.Vel.X = (Target.Vel.X + Self.Vel.X) and Target.Vel.Y = (Target.Vel.Y + Self.Vel.Y) Thats what I want. so would shortening the line to this work? Code: self.target.Vel = Vector(self.target.Vel.X + self.Vel.X , self.target.Vel.Y + self.Vel.Y) ALSO, I don't want the shot to still be visible after impact, so after the velocity is added, would I be able to replace Code: if (MovableMan:IsActor(self.target) or MovableMan:IsParticle(self.target)) and self.unpinned == 0 then --if attached self.Pos = Vector(self.target.Pos.X + self.offsetMagnitude * math.cos(math.pi-(self.target.RotAngle + self.startangle)),self.target.Pos.Y + self.offsetMagnitude * math.sin(math.pi-(self.target.RotAngle + self.startangle))) --set position according to the offset vector self.RotAngle = self.target.RotAngle + self.startangle --rotate self end end with just a single self:GibThis() ? you know, maybe add some fancy flash for the impact as gibs? Or would I have to do the full thing? Code: if (MovableMan:IsActor(self.target) or MovableMan:IsParticle(self.target)) and self.unpinned == 0 then --if attached self:GibThis() ; end I'm sorry if this is really cluttered... its just... thats alot of code and I'm not used to dealing with alot of code. |
Author: | piipu [ Tue Jun 09, 2009 8:03 am ] |
Post subject: | Re: Reasonable Lua Requests from miles |
That makes the bullet or whatever cause a normal hit to the object it hits with six times more force than it should. To make it work like you want you need this code Code: function Update(self) if self.LTimer:IsPastSimMS(50) then if self.unpinned == 1 then --if the object isn't attached to anything self.atarget = (SceneMan:CastMORay(Vector(self.Pos.X - self.Vel.X,self.Pos.Y - self.Vel.Y),Vector(self.Vel.X,self.Vel.Y),0,0,true,5)) --this checks if the object has hit anything, and if yes, returns the MOID of the collided object self.target = MovableMan:GetMOFromID(MovableMan:GetRootMOID(self.atarget)) --this gets the pointer of the root MO so we can actually do something with it if self.target ~= nil then --if we have hit something self.target.Vel = self.Vel self:GibThis() end end end end |
Page 1 of 1 | All times are UTC [ DST ] |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |