Author Topic: Using Vector functions  (Read 1951 times)

0 Members and 1 Guest are viewing this topic.

Offline k7g

  • 25
Using Vector functions
hello,

May I ask, how do I use these following functions in a script? Just for information, I would this script to allow the turrets to manually aim at a enemy ship (via the vectors), so then I can make them fire (via another part of the script) at them. I'm using the capital ship script by Dragon (just editing it around a bit, and posting him the changes :P).

These are pulled from the wiki:
Code: [Select]
vector LastPosition = vector -- to what I know, this gives the last know vector position of the target
and
boolean rotateTurret(vector Pos[, boolean reset=false -- and this one will turn the turret to its location

I got the NextFireTimestamp function working before but i cannot get it to again (due this would help me...lol)

If you look in his script, the area where I'm wanting the code to work in is in the 'doInput()' function of it.
And I don't mind if I have to add other functions to do it, so any help is fine.



 

Offline FelixJim

  • 28
  • User 11092
Re: Using Vector functions
By manually aim, do you mean you really need to specify a vector? It would be better just to tell the turret which ship you want it to target by changing its .Target. Not only would that be much easier, but it wouldn't be "out of date" as soon as the target ship moved and you wouldn't have to worry about manually firing the turret either. The only use I can think of for specifying the vectors manually is if you want to aim at a specific part of a large ship, but it would be a nightmare to work out the orientations, distances and model features. Maybe your situation is one I haven't considered though, so here's a rapid rundown of how those functions should work:

Assuming you've loaded a subsystem (which is a turret) handle into a variable called t and a ship handle into a variable called s:

Code: [Select]

pos = s.LastPosition     --Loads the last position of the ship into the variable pos (now a vector object)

t:rotateTurret(pos, false)  --Rotates the turret to face pos


Here's a sample script: create a mission with a ship called "ship" (an Orion or something is a good choice). Every time you press the 1 key all of its turrets will rotate to face you. Here the ship handle is hv.Player, and the turret handle(s) are stored in s.

Code: [Select]
#Conditional Hooks

$Application: FS2_Open
$State: GS_STATE_GAME_PLAY
$On Key Pressed:
[
if hv.Key == "1" then
local pos = hv.Player.LastPosition
local s = mn.Ships['ship']
for i=1,#s do
if s[i]:isTurret() then
s[i]:rotateTurret(pos, false)
end
end
end
]

#End

Edit: Localising variables for the sake of good practice.
In-Mission Techroom Script v0.4 - See information from the techroom in game
Simple Animation Script v0.2 - Make your own on-screen animations for FSO
Visible Waypoints Script - Makes waypoints visible in-game
Run From File Script - Get around the pesky 31 character limit for script-eval

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Using Vector functions
Yeah, the problem with completely taking over a turret is that you have to do everything yourself, including target position prediction and ****. It's almost always better to just use the high-level approach of telling the turret what object to target, and let the AI handle the rest.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: Using Vector functions
Yeah, the problem with completely taking over a turret is that you have to do everything yourself, including target position prediction and ****. It's almost always better to just use the high-level approach of telling the turret what object to target, and let the AI handle the rest.
So true. Firing a turret manually is just a huge scripting nightmare that the turret AI can handle much better. The only thing that is truly missing would be a .SubsystemTarget function for more precise shooting. I guess I'll try to code that if no one else does it before me.
Here goes scripting and copy paste coding
Freespace RTS Mod
Checkpoint/Shipsaveload script

 

Offline k7g

  • 25
Re: Using Vector functions
Hello again,

I would like to thank FelixJim for helping me with getting the vectors into a variable therefor making them usable, and in-turn allowed me to make the turrets move to and 'track' its targets vector position actively!  :D

Of course, now with that out of the way, i just now need to figure out the ':fireWeapon()' command....  :banghead:. I've made it like :fireWeapon(1) even :fireWeapon(1,100), but both refuse to fire the turrets weapons. unless it is for gun/missile mounts that the player uses, if it, is there a way to fire these turrets? (single or multiple weapons).

Just a thought about the AI targeting system...It would have to based around the 'Position' / 'LastPosition' and 'fireWeapon()' any how to allow the turrets to track and fire at its target but yet, as script writers, we find it hard to do in a script...weird right?

 
Re: Using Vector functions
If I understand the code correctly :fireWeapon() will only fire if NextFireTimestamp has passed (or something like this). In case the weapon has no targetingOverride it'll probably not fire at all. Additionally, there may be some other conditions that prevent it from firing.

Also, did you consider maximum rotation speed of all multipart turrets when they follow your vector? Not sure if it does this automatically.
Here goes scripting and copy paste coding
Freespace RTS Mod
Checkpoint/Shipsaveload script

 

Offline k7g

  • 25
Re: Using Vector functions
Ok, I'll look at adding the 'NextFireStamp' to the script when I can. Also, the turrets (via the ship .tbm file), have no flag for rotation speed so they point at the vector instantly. If the 'NextFireStamp' does not work, I'll try and look around for the other conditions. If I cannot find them, I'll ask for the SCP team to add a command to fire turrets like we want too  ;)

edit: I just had a bit of a brain-storm (finally ;)), the reason why the turrets are not firing is due to the fact I'm calling the turrets 'script' name, not its table name, so therefor it is not firing the turret. Now I just need to type in some code for it.
« Last Edit: June 18, 2013, 06:40:35 pm by k7g »