Jump to content

.script from object to .quest - Python3


Recommended Posts

Video:

Code:

def convert_to_quest(input_text, quest_name, state_name, npc_id, chat_option):
    quest_code = f"quest {quest_name} begin\n\tstate {state_name} begin\n\t\twhen {npc_id}.chat.\"{chat_option}\" begin\n"

    lines = input_text.split('\n')
    indentation_level = 0
    for line in lines:
        stripped_line = line.strip()

        if stripped_line.startswith("end"):
            indentation_level -= 1

        stripped_line = stripped_line.replace(" (", "(").replace(" )", ")")
        stripped_line = stripped_line.replace(" . ", ".")
        stripped_line = stripped_line.replace(' "', '"')

        indent = '\t' * (3 + indentation_level)
        quest_code += f"{indent}{stripped_line}\n"

        if stripped_line.startswith(("if", "while", "for")) and "end" not in stripped_line:
            indentation_level += 1

    quest_code += "\t\tend\n\tend\nend"

    return quest_code


def process_script_file(script_file_name, quest_name, state_name, npc_id, chat_option):
    with open(script_file_name, 'r', encoding='latin1') as f:
        input_text = f.read()

    quest_code = convert_to_quest(input_text, quest_name, state_name, npc_id, chat_option)

    quest_file_name = script_file_name.replace('.script', '.quest')
    with open(quest_file_name, 'w', encoding='latin1') as f:
        f.write(quest_code)


process_script_file('marriage_manage.start.0.script', 'weeding', 'start', 20358, 'Oldwoman')

 

Grzyb.ovh

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Announcements



×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.