Hard Light Productions Forums

Modding, Mission Design, and Coding => The Modding Workshop => Topic started by: Wanderer on July 19, 2007, 01:07:18 pm

Title: Some scripting fun...
Post by: Wanderer on July 19, 2007, 01:07:18 pm
So...

(http://i12.tinypic.com/4vsotv8.jpg)
Phear my scripting!

Short video.. http://video.tinypic.com/player.php?v=4p2ch7a

Personal containment field... :D

Title: Re: Some scripting fun...
Post by: TrashMan on July 19, 2007, 01:13:38 pm
How did you do that?
Title: Re: Some scripting fun...
Post by: Mustang19 on July 19, 2007, 01:40:11 pm
 :yes: ;7
Title: Re: Some scripting fun...
Post by: Wanderer on July 20, 2007, 03:41:08 am
That was originally supposed to be a reflection/deflection shield thingye.. To reflect hostile incoming stuff like ship was covered with impenetrable spherical mirror... er... forcefield... thing... Small mistake during the scripting with < and > caused the internal side of the sphere to reflect the shots (ie. collecting every shot) instead of the outer side (which would have reflected every shot).
Title: Re: Some scripting fun...
Post by: Stormkeeper on July 20, 2007, 03:46:22 am
Awesome. It'd make a good idea for some sort of super shield. Both the intended effect and the un-intended effect.

Imagine how'd it look with Subach beams instead. I don't suppose it stops beams, does it?
Title: Re: Some scripting fun...
Post by: Wanderer on July 20, 2007, 05:14:14 am
Yeah.. it doesn't stop beams. Mainly because beams do not exist as individual objects in-game. With all other stuff i can simply choose whether i want it to be deflected or not
Title: Re: Some scripting fun...
Post by: colecampbell666 on July 20, 2007, 07:32:44 am
Me likey. :lol: :lol:
Title: Re: Some scripting fun...
Post by: Nuke on July 20, 2007, 05:06:15 pm
heh cool. some of the coolest things ive done with scripting were on accident, but that is totally awesome. is it possible to fly those shots inbto an enemy? or will the sf mara get caught in the field too  :lol:
Title: Re: Some scripting fun...
Post by: jr2 on July 20, 2007, 05:54:33 pm
That's a Ulysses! :p
Title: Re: Some scripting fun...
Post by: Cobra on July 20, 2007, 07:38:39 pm
You know what I'm thinking? That would be great for a shield for the Lucifer, except the lasers reflect. :D
Title: Re: Some scripting fun...
Post by: Hades on July 20, 2007, 08:25:45 pm
Yes i was just thinking that. :lol: ;)
Title: Re: Some scripting fun...
Post by: jr2 on July 20, 2007, 09:19:56 pm
... This was a bug, I'm sure he's fixed it so that the outside reflects, but not the inside... right?
Title: Re: Some scripting fun...
Post by: Bobboau on July 20, 2007, 09:20:17 pm
That was originally supposed to be a reflection/deflection shield thingye.. To reflect hostile incoming stuff like ship was covered with impenetrable spherical mirror... er... forcefield... thing... Small mistake during the scripting with < and > caused the internal side of the sphere to reflect the shots (ie. collecting every shot) instead of the outer side (which would have reflected every shot).

oh, you mean like in starfox when a ship does a barrel roll? :D
what ever could ths be for?
Title: Re: Some scripting fun...
Post by: Wanderer on July 21, 2007, 11:18:31 am
Weeell...  ;)


EDIT:
... This was a bug, I'm sure he's fixed it so that the outside reflects, but not the inside... right?

Yeah
Title: Re: Some scripting fun...
Post by: Gregster2k on July 21, 2007, 11:55:20 am
Awesome idea! Can we play with it too? ;7

I wonder if ships can bounce off of it?

I have got to learn some scripting.

Title: Re: Some scripting fun...
Post by: Wanderer on July 21, 2007, 12:21:45 pm
Its mostly just math.. And ships can be made to bounce off too.. though it might some additional data (orientation data). One prob atm is that atleast turret shots which are bounced cant hit the parent ship but they cant hit the parent ship in normal FreeSpace anyway. However this can be changed too - at least for the standard primaries.

Mainly just usage of dot products and vector projection stuff..

Code: [Select]
#Global Hooks

$Simulation:

[

-- Reflection calculations

vectorFrontDirection = ba.createVector(0,0,1)
booleanReflection = 1
floatMissionTime = mn.getMissionTime()

if floatMissionTime > 0.5 then

   objectPlayer = hv.Player

   --Do not continue if player does not exist
   if objectPlayer:isValid() then

      --Continue only if trigger is set
      if booleanReflection == 1 then

         --Iterate through all the weapons
         for k=1,#mn.Weapons do
            objectWeapon = mn.Weapons[k]
            stringWeaponTeam = objectWeapon.Team.Name

            --Do this to all but friendly weapons
            --Could be expanded or to set to deflect only certain weapons etc.
            if stringWeaponTeam ~= "Friendly" then

               --Calculate distance between weapon and ship's centerpoint
               vectorWeaponPosition = objectWeapon.Position
               vectorPlayerPosition = objectPlayer.Position
               floatWeaponDistance = vectorPlayerPosition:getDistance(vectorWeaponPosition)

               --Continue only if weapon is close enough to the ship
               if floatWeaponDistance < 35 then

                  --Create reflection normal and calculate impact angle
                  vectorImpactNormal = vectorWeaponPosition - vectorPlayerPosition
                  vectorWeaponDirection = objectWeapon.Physics.Velocity
                  floatImpactAngle = vectorImpactNormal:getDotProduct(vectorWeaponDirection) / (vectorImpactNormal:getMagnitude() * vectorWeaponDirection:getMagnitude())

                  --Continue only if impact angle is proper
                  -- < causes the deflective shield (outer side deflects), angle is <90 degs
                  -- > causes the 'doomsphere'/containment field (inner side deflects), angle is >90 degs
                  if floatImpactAngle < 0 then

                     --Some vector math

                     ---Calculate vector projection along the reflection normal for the 'impact vector' and then multiply it by 2 to get proper reflection 'lenght'
                     floatReflectionModifier = 2 * vectorWeaponDirection:getDotProduct(vectorImpactNormal) / vectorImpactNormal:getDotProduct(vectorImpactNormal)

                     ---Create the proper reflection vector
                     vectorReflection = floatReflectionModifier * vectorImpactNormal

                     ---101 vector math...
                     vectorWeaponNewDirection = vectorWeaponDirection - vectorReflection

                     ---Set weapon flight direction and orientation according to the reflection vector.
                     orientationNewWeapon = vectorWeaponNewDirection:getOrientation()
                     objectWeapon.Orientation = orientationNewWeapon
                     floatWeaponVelocity = objectWeapon.Physics:getSpeed()
                     objectWeapon.Physics.Velocity = floatWeaponVelocity * vectorWeaponNewDirection / vectorWeaponNewDirection:getMagnitude()
                  end
               end
            end
         end
      end
   end
end

]

#End
Title: Re: Some scripting fun...
Post by: Snail on July 21, 2007, 12:24:43 pm
So I need a CVS build or something to use this? Or will it work with THREE dot SIX dot NINE?
Title: Re: Some scripting fun...
Post by: Wanderer on July 21, 2007, 12:29:56 pm
Ah.. no it doesn't work with 3.6.9 builds (or any of the 3.6 builds for that matter)... Practically all scripting is done with HEAD branch builds ATM.

You should be able to use for example http://www.hard-light.net/forums/index.php/topic,44659.0.html C05202007 (HEAD) build - just read the note below the download link. Those builds should eventually become 3.7 builds.
Title: Re: Some scripting fun...
Post by: Snail on July 21, 2007, 12:32:55 pm
Sweetness.

Thanks. :)


EDIT:
Weird, it doesn't seem to work against Tornado missiles? :confused:
Title: Re: Some scripting fun...
Post by: Getter Robo G on July 22, 2007, 12:59:41 am
In some trek games beams are models...

If you make a small tube pof controlled by teh beam data (ie generated as segments like a really fast gatlign gun?) but invisible and wrapped in a regular beam segment background would that work??? teh reflected segemnts should drag teh backgroudn with it no? *runs*...

I'm not high, but I should be!  :lol:
Title: Re: Some scripting fun...
Post by: Nuke on July 22, 2007, 06:28:53 am
that almost gave me an idea, but as it turns out, im too tired to think.
Title: Re: Some scripting fun...
Post by: Stormkeeper on July 22, 2007, 11:31:52 pm
In some trek games beams are models...

If you make a small tube pof controlled by teh beam data (ie generated as segments like a really fast gatlign gun?) but invisible and wrapped in a regular beam segment background would that work??? teh reflected segemnts should drag teh backgroudn with it no? *runs*...

I'm not high, but I should be!  :lol:

It sounds like the GTVA rapid fire laser.

And i think it'd look funny with a beam spinning around the fighter .... like an archon.










Awesome.
Title: Re: Some scripting fun...
Post by: Mav on July 24, 2007, 01:00:25 pm
Yikes! :lol:
Now take this effect and use it for some special sort of shielding... ;) And maybe even somehow make shots for it be generated automatically (could this be done with the "create-weapon" SEXP? I don't know because I haven't used it so far).