Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: IronBeer on January 25, 2013, 12:26:40 am

Title: A couple of questions from a dabbling scripter
Post by: IronBeer on January 25, 2013, 12:26:40 am
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 (http://www.hard-light.net/wiki/index.php/Script_-_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?
Title: Re: A couple of questions from a dabbling scripter
Post by: Admiral MS on January 25, 2013, 09:52:47 am
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)
Title: Re: A couple of questions from a dabbling scripter
Post by: zookeeper on February 08, 2013, 08:17:55 am
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.
Title: Re: A couple of questions from a dabbling scripter
Post by: guitarfan01 on February 09, 2013, 05:51:50 pm
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?
Title: Re: A couple of questions from a dabbling scripter
Post by: mjn.mixael on February 09, 2013, 05:59:13 pm
Yup, but that's pretty trivial to do without scripting as well.
Title: Re: A couple of questions from a dabbling scripter
Post by: guitarfan01 on February 10, 2013, 12:31:09 am
Ah, ok.
Title: Re: A couple of questions from a dabbling scripter
Post by: General Battuta on February 10, 2013, 01:00:55 am
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.
Title: Re: A couple of questions from a dabbling scripter
Post by: mjn.mixael on February 10, 2013, 01:32:28 am
Even without the counter, I can think of at least one way to do it with a variable. (Untested(tm))