#Help with generating script to play demo

1 messages · Page 1 of 1 (latest)

compact pulsar
#

Hello! I am having trouble with generating a script to load a demo, go to a tick, go to a players POV, wait for a bit and go to the next.

Here is basically what I use to generate one:

#!/bin/bash
DEMOFILE=~/tf/tf/demos/$(basename "$1")
PARSER=tfdemoparse
RECORD_BUFFER=1000

function _() {
    echo -n "$*;"
}

function gen-header() {
    _ "echo starting" $1
    _ "sv_cheats 1"
    _ "sv_allow_wait_command 1"
    _ "playdemo demos/$(basename -s .dem $1)"
    _ "wait 10000"
}

function gen-stemp() {
    _ "echo --------------> going to "  $(($1 - RECORD_BUFFER))
    _ "demopause"
    _ "demo_gototick" $(($1 - RECORD_BUFFER))
    _ "wait 5000"
    _ "spec_player LabRicecat"
    _ "spec_mode 4"
    _ "demo_resume"
    _ "wait" $((RECORD_BUFFER * 5))
}

function gen-tail() {
    _ "stopdemo"
    _ "echo done loading"
}

function get-drops() {
    "$PARSER" "$DEMOFILE" | jq | grep -A 1 "DROPPED" | grep -Eo "[0-9]+" 
}

if [[ ! -f "$DEMOFILE" ]]; then
    return 1 >/dev/null 2>&1
    exit 1
else 
    DROPS=$(get-drops "$DEMOFILE")

    if [[ ! -z "$DROPS" ]]; then 
        gen-header "$DEMOFILE"

        for i in $(get-drops); do 
            gen-stemp $i
        done 
    
        gen-tail
    fi 
fi

The problem seem to be the wait commands, as they are not synced. They either end too early or are just not where I want my demo to start.
This is indeed kind of a hack, but has someone an idea on what I did wrong tf2 scripting wise?

floral flint
#

i'm not very experienced in bash scripting, but i should mention that the wait command utilizes frames rather than milliseconds, not sure if that matters for your script but i thought i should mention it

#

also, i don't think putting the wait command on its own line does anything

#

normally it's used in command chains (with semicolons, i.e. echo hello;wait 300;echo goodbye)

compact pulsar
compact pulsar
floral flint
compact pulsar
#

hm i will try that

compact pulsar
#

Can I somehow do something like "do this when this finishes" ?

floral flint
#

if it doesn't work with semicolons though, then i don't think there's a way to do it within the base game unfortunately

#

maybe @lunar herald would know

lunar herald
#

@compact pulsar I have some bad news for you

#

what I had to do was to enable demo_debug (forgot the name of the cvar, but its the one that prints to console every tick) then read console.log until you see the tick you want to stop at

#

oh wait, you wanna do it through a cfg file

#

yea, you simply can't, sorry.\

#

I think you could generate that file that the demoui generates where you can specify actions for specific ticks

#

and then just use that instead of a cfg file to control demo playback

compact pulsar
#

are there any resources about it?

lunar herald
lunar herald
# compact pulsar Where can I find it?

after you edit the demo through the demoui and save some changes like fast forward and stuff, I think the file appears in the same dir as the demo file

compact pulsar
#

oh nice

lunar herald
#

I'm sorry I can't be more precise, I'm not at my PC rn

odd hillBOT
#

*I'm sorry I can't

be more precise, I'm not at

my PC rn*

compact pulsar
#

no thats enough already, thanks!

compact pulsar