Author Topic: A couple of questions from a dabbling scripter  (Read 1924 times)

0 Members and 1 Guest are viewing this topic.

Offline IronBeer

  • 29
  • (Witty catchphrase)
    • Minecraft
A couple of questions from a dabbling scripter
Preamble: I know perfectly well that I can do what I'm about to describe in FRED. As kind of a personal challenge, to develop a better grasp on FSO's more arcane features, I want to do this via lua.

Ok, I've been bugging people on IRC about this for a while, and I finally got pointed towards the -script_output command line option (holla Zacam). The output, while very in-depth and intriguing, hasn't helped me towards my current goal: assembling a script that can register multikills (aka a number of kills in rapid succession). I think this would be fun for some single-player missions, and could potentially be entertaining in multi, but the biggest stumbling block I've ran across: I can't seem to find how FSO actually tracks "who killed what".

I mean, internally, there's some tracking system. That's obvious. What I'm wondering is if I can co-opt some of those functions. Digression: I'm a lua novice, but I've seen enough of the syntax and had enough general programming experience to figure things out as I go. I've got most of a script ready to go (I think), but I'm still missing a few key hooks.

Here's what I've got now, please let me know if I'm totally off-base or not:
Code: [Select]
[
multikill=0
timemark=(initialzed)
missiontime=mn.getMissionTime()
for i=1, mn.getNumShips() do
     shipteam=ship.Team
     if shipteam~=playerteam and (ship was killed by player)
        multikill++
        timemark=missiontime
if multikill==2
  ("double kill" praise/bonus of some sort)
(continue as far as desired)
if missiontime>(timemark+3)
   multikill=0
]
I'm currently co-opting some ideas from the death flash script, which is why I'm using that weird for loop. I'd much rather have this script checked on a kill-by-kill basis, rather than continuously (yeah yeah, I know the timing bits will need to run continuously).

Feedback?
"I have approximate knowledge of many things."

Ridiculous, the Director's Cut

Starlancer Head Animations - Converted

 
Re: A couple of questions from a dabbling scripter
I would try something like this:
Code: [Select]
$On Gameplay Start:
[
multikills = {}
multikills.counter = 0
multikills.time = 0
]

$On Death:
[
if hv.Self == <some conditions that it won't trigger for everything like friendlies (friendly fire and such) and cargo containers> and hv.Killer == hv. Player <or something similar> then
local missiontime = mn.getMissionTime()
if missiontime - multikills.time < <some value> then
multikills.counter = multikills.counter  + 1
else
multikills.counter = 1
end
multikills.time = missiontime
if multikills.counter == 2 then
<doublekill message>
elseif multikills.counter == 3 then
.
.
.
end
end
]
Not sure if the hook variables are correct. The only stuff I'm ever using is hv.Player and hv.Key  :D
Also it might need some validity checks and you might have to use shipnames in the compare operations.

E: You can also ask me things on IRC if you see me (Nick: Ams)
« Last Edit: January 25, 2013, 10:00:13 am by Admiral MS »
Here goes scripting and copy paste coding
Freespace RTS Mod
Checkpoint/Shipsaveload script

 

Offline zookeeper

  • *knock knock* Who's there? Poe. Poe who?
  • 210
Re: A couple of questions from a dabbling scripter
For reference, here's a basic version of how I'd do it in a way which tracks kills of every ship, not only the player's:

Code: [Select]
#Conditional Hooks

$Application: FS2_Open

$On Gameplay Start: [

    kills_per_ship = {}

]

$Object type: Ship

$On Death: [

    ship = hv.Self
    killer = hv.Killer

    if ship ~= nil and ship:isValid() and killer ~= nil and killer:isValid() then
        killer_sig = ship:getSignature()
        current_time = mn.getMissionTime()

        if kills_per_ship[killer_sig] == nil then
            kills_per_ship[killer_sig] = {}
            kills_per_ship[killer_sig].counter = 1
            kills_per_ship[killer_sig].kill_streak_started = current_time
            kills_per_ship[killer_sig].last_kill_time = current_time
        else
            kills_per_ship[killer_sig].counter = kills_per_ship[killer_sig].counter + 1
            last_kill_time = kills_per_ship[killer_sig].last_kill_time

            if current_time - last_kill_time > 3.0 then
                -- killstreak ended, check the counter and give praise

                kills_per_ship[killer_sig].counter = 0
                kills_per_ship[killer_sig].last_kill_time = current_time + 3.0
            end

            kills_per_ship[killer_sig].last_kill_time = current_time
        end
    end

]

#End

It should also work as a sort of a template for an easy way to record and retrieve other sorts of similar ship-specific metadata.

 

Offline guitarfan01

  • 25
  • Longtime Lurker
Re: A couple of questions from a dabbling scripter
If done like this, could certain numbers of kills be used to trigger messages from other ships, like wingmen, in order to simulate a kind of competition for kills like Legolas and Gimli in LOTR?

Or am I misunderstanding the possibilities?

 

Offline mjn.mixael

  • Cutscene Master
  • 212
  • Chopped liver
    • Steam
    • Twitter
Re: A couple of questions from a dabbling scripter
Yup, but that's pretty trivial to do without scripting as well.
Cutscene Upgrade Project - Mainhall Remakes - Between the Ashes
Youtube Channel - P3D Model Box
Between the Ashes is looking for committed testers, PM me for details.
Freespace Upgrade Project See what's happening.

 

Offline guitarfan01

  • 25
  • Longtime Lurker
Re: A couple of questions from a dabbling scripter
Ah, ok.

 

Offline General Battuta

  • Poe's Law In Action
  • 214
  • i wonder when my postcount will exceed my iq
Re: A couple of questions from a dabbling scripter
Yup, but that's pretty trivial to do without scripting as well.

Is it? I thought the kill counter was broken for all non-player ships.

 

Offline mjn.mixael

  • Cutscene Master
  • 212
  • Chopped liver
    • Steam
    • Twitter
Re: A couple of questions from a dabbling scripter
Even without the counter, I can think of at least one way to do it with a variable. (Untested(tm))
Cutscene Upgrade Project - Mainhall Remakes - Between the Ashes
Youtube Channel - P3D Model Box
Between the Ashes is looking for committed testers, PM me for details.
Freespace Upgrade Project See what's happening.