FreeSpace Releases > Scripting Releases
Increasingly less simple repair gun
Alan Bolte:
This is the first script I've got working, so while it's probably simple and obvious to the real coders here I thought I'd share it for anyone else who's just getting started.
--- Code: ---#Conditional Hooks
$State: GS_STATE_GAME_PLAY
$Weapon class: Nanite Repair Gun
$On Ship Collision:
[
local repairValue = 40
hv.Ship.HitpointsLeft = hv.Ship.HitpointsLeft+repairValue
if (hv.Ship.HitpointsLeft > hv.Ship.HitpointsMax) then
hv.Ship.HitpointsLeft = hv.Ship.HitpointsMax
end
hv.Self.LifeLeft = 0
]
+Override: true
#End
--- End code ---
The 'if' statement is necessary: without it, you can 'repair' your target to well over 100%
This is intended to be used with a custom primary named "Nanite Repair Gun" that does 0 damage. Of course, this doesn't fix the many problems one would expect from such a weapon, including:
Friendly AI will evade your fire.
AI would never use this.
I got rid of the damage particles by using +override and setting lifeleft to 0, but there's no impact effect at all. That could probably be fixed. However, if you don't care about the aesthetics you could let the player use this as-is to repair a cruiser or transport that he's escorting. Careful FREDing might also force the AI to use this in tightly-scripted scenarios.
I don't think shooting your friends with a 0 damage gun will make you a traitor, but the traitor code is complicated. Also, I haven't tested it, but I think this script is flexible enough to be used with a secondary or beam.
SypheDMar:
The GTDr 3301 uses a repair beam, but it's AI-specific. It shoots at stationary targets, though. Would this script help for the AI if it needs to target players?
Alan Bolte:
I don't understand the question. If I had to guess, I'd say you were describing a zero-damage beam being fired at the same time a repair SEXP is active on the same target.
This script causes the weapon object itself (e.g. blob) to repair whatever it impacts. If you can make a ship or turret target players via SEXPs or a different script, then you can use this script to replace that weapon's impact damage with healing. I haven't done any tests with blast weapons.
Also, it occurs to me that if you want a impact particles your best bet it to try to adapt m!m's particle scripts to the purpose, which I have no intention of messing with because wow is that stuff complicated. I'm working on a simple impact explosion, but using the position of the weapon doesn't work because it's inside the hull. LastPosition doesn't seem to work with weapon objects. Currently I'm trying to figure out the collision information that was added in 3.6.13. :banghead: LastPosition was also added in 3.6.13.
So far this does not work with beams. I think the issue is that since beam collisions are handled differently than primary and secondary collisions, I'd need a completely different method. Probably use On Weapon Fired instead of the collision hook, then mess around with frame-by-frame detection of each beam collsiion until the beam shuts down.
Secondaries work, but as expected it only repairs based on a direct impact, the blast has no effect.
Alan Bolte:
Here's a variant with an impact effect. Requires 3.6.13 or later. Also requires MediaVPs 3.6.12 unless you change the impact explosion. Since I used LastPosition instead of the collision point, the effect tends to occur slightly above the hull in a way that looks odd at point blank range, but looks fine most of the time.
--- Code: ---#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[
--impact explosion, check the MediaVP wep.tbm files for which one you want and what radius to use
local texturename = "Akheton_Impact"
imageRadius = 1.8
repairImpactImage = gr.loadTexture(texturename, true)
]
$State: GS_STATE_GAME_PLAY
$Weapon class: Nanite Repair ;;Weapon class is the same name as is displayed on the HUD
$On Ship Collision:
[
local repairValue = 20 --use lower values for weapons with a high rate of fire and vice versa.
hv.Ship.HitpointsLeft = hv.Ship.HitpointsLeft+repairValue
if (hv.Ship.HitpointsLeft > hv.Ship.HitpointsMax) then
hv.Ship.HitpointsLeft = hv.Ship.HitpointsMax
end
local createPos = hv.Self.LastPosition --can be replaced with proper collision detection if you're picky
local velocity = ba.createVector(0,0,0)
ts.createParticle(createPos, velocity, 1, imageRadius, PARTICLE_BITMAP, -1, false, repairImpactImage)
hv.Self.LifeLeft = 0 -- weapon dies near the end of next frame
hv.Self.Physics.Velocity = hv.Ship.Physics.Velocity --hack to prevent multiple collisions
]
+Override: true
#End
--- End code ---
I'm not sure if I should be doing something to unload the texture from memory. There's a function for doing so, but somehow I can't figure out the syntax, and I'm not sure it's desirable to do so anyway.
I'm thinking about adding the ability to repair the subsystem or turret you hit with this, but I should probably add a config file first.
m!m:
You could load the animation in an On Game Init hook and then use the returned handle for the particle animation. In that case you don't need to unload the texture as that will be done when the game is closed.
You can also add beam checking using an On Frame hook where you check every beam which should repair for a collision and then repair the ship that got hit.
Navigation
[0] Message Index
[#] Next page
Go to full version