MFK 2 LUA Mod Resource v1.03| Fixed

Posted in Mod Resources
Unsubscribe from this topic
Heres a Quick Little program I have put together as a part of my C.S coursework.

Creating a Lua file from an MFK requires a Few things
  • All "\" need to be "\\"
  • All Commands need to have "Game." before them
  • You cant have ":" at the end of a line
  • All comments ("//") must be ("--")

Now you could do that all manually, but that would be a waste of time and silly wouldnt it...
I am aware that this is possible through NP++ and LUA-ify but this is just a nice little alternative i thought

This program will take an MFK file and Add a LUA file of the same name in the same direcotry it came from. Its Easy to use since it only has one button.

To run it open the download folder and run mfk2lua.exe. Also FYI this was created in python3 and then converted into a .exe which is why there are other files.

If you have any problems just tell me

Bug Fix Log v1.01
  • I have fixed a bug where in some scenarios a function might have two "Game."'s before it, for example ("Game.Game.AddStageWaypoint"). This problem was caused by me not being specific enough when searching for functions and it saw the AddStage Function inside of the AddStageWaypoint Function . However this is now fixed
  • Added Comment Feature
  • Added the Python source code at the bottom of this thread :)

Bug Fix Log v1.03
  • Gave it a niver GUI
  • Includes all game commands including ASF now


Python download -- Smaller file size and more reccomended to download however you will need to install the latest version of python 3 or atleast python 3.7.4 onwards
MFK2LUA Download
Latest Version of Python 3

SOURCE CODE
print("Loading Imports")
from tkinter import *
from tkinter import filedialog

print("Creating window")
root = Tk()
root.title("Stevens100's MFK to LUA converter")


commands = [
        #CON Commands
        "SetMass",
        "SetGasScale",
        "SetHighSpeedGasScale",
        "SetGasScaleSpeedThreshold",
        "SetSlipGasScale",
        "SetBrakeScale",
        "SetTopSpeedKmh",
        "SetMaxWheelTurnAngle",
        "SetHighSpeedSteeringDrop",
        "SetTireGrip",
        "SetNormalSteering",
        "SetSlipSteering",
        "SetEBrakeEffect",
        "SetCMOffsetX",
        "SetCMOffsetY",
        "SetCMOffsetZ",
        "SetSuspensionLimit",
        "SetSpringK",
        "SetDamperC",
        "SetSuspensionYOffset",
        "SetHitPoints",
        "SetBurnoutRange",
        "SetMaxSpeedBurstTime",
        "SetDonutTorque",
        "SetSlipSteeringNoEBrake",
        "SetSlipEffectNoEBrake",
        "SetWeebleOffset",
        "SetWheelieRange",
        "SetWheelieOffsetY",
        "SetWheelieOffsetZ",
        "SetShadowAdjustments",
        "SetShininess",
        "SetDriver",
        "SetGamblingOdds",
        "SetHasDoors",
        "SetCharactersVisible",
        "SetIrisTransition",
        "SetAllowSeatSlide",
        "SetHighRoof",
        "SetCharacterScale",
        "SuppressDriver",

        #MFK Commands
        "InitLevelPlayerVehicle",
        "PlacePlayerCar",
        "AddPurchaseCarReward",
        "SetPostLevelFMV",
        "CreatePedGroup",
        "AddPed",
        "ClosePedGroup",
        "UsePedGroup",
        "BindReward",
        "CreateTrafficGroup",
        "AddTrafficModel",
        "CloseTrafficGroup",
        "SetCarAttributes",
        "SetTotalGags",
        "SetTotalWasps",
        "AddGlobalProp",
        "CreateChaseManager",
        "DisableHitAndRun",
        "EnableHitAndRun",
        "SetHitAndRunMeter",
        "SetNumChaseCars",
        "SetChaseSpawnRate",
        "KillAllChaseAI",
        "ResetHitAndRun",
        "SetHitAndRunDecay",
        "SetHitAndRunDecayInterior",
        "AddMission",
        "AddBonusMission",
        "SetMissionNameIndex",
        "SelectMission",
        "SetMissionResetPlayerInCar",
        "SetMissionResetPlayerOutCar",
        "SetDynaLoadData",
        "AddBonusObjective",
        "SetForcedCar",
        "CloseMission",
        "SetDemoLoopTime",
        "StreetRacePropsLoad",
        "StreetRacePropsUnload",
        "UseElapsedTime",
        "AttachStatePropCollectible",
        "ShowHUD",
        "SetNumValidFailureHints",
        "AddStage",
        "SetStageMessageIndex",
        "SetStageTime",
        "AddStageTime",
        "AddStageVehicle",
        "MoveStageVehicle",
        "ActivateVehicle",
        "AddStageWaypoint",
        "AddStageCharacter",
        "AddStageMusicChange",
        "SetStageMusicAlwaysOn",
        "SetCompletionDialog",
        "StageStartMusicEvent",
        "SetMusicState",
        "SetStageCamera",
        "RESET_TO_HERE",
        "SetMaxTraffic",
        "AddSafeZone",
        "SetBonusMissionStart",
        "ShowStageComplete",
        "SetHUDIcon",
        "SetIrisWipe",
        "SetFadeOut",
        "CloseStage",
        "SetVehicleAIParams",
        "PlacePlayerAtLocatorName",
        "msPlacePlayerCarAtLocatorName",
        "SwapInDefaultCar",
        "SetSwapPlayerLocator",
        "SetSwapDefaultCarLocator",
        "SetSwapForcedCarLocator",
        "NoTrafficForStage",
        "ClearTrafficForStage",
        "SetStageAIRaceCatchupParams",
        "SetStageAIEvadeCatchupParams",
        "SetStageAITargetCatchupParams",
        "SetCharacterToHide",
        "SetLevelOver",
        "SetGameOver",
        "StayInBlack",
        "AllowMissionAbort",
        "SetParTime",
        "SetRaceEnteryFee",
        "PutMFPlayerInCar",
        "SetStatepropShadow",
        "AddObjective",
        "CloseObjective",
        "SetDestination",
        "AddNPC",
        "RemoveNPC",
        "AddDriver",
        "RemoveDriver",
        "SetTalkToTarget",
        "SetDialogueInfo",
        "SetDialoguePositions",
        "SetRaceLaps",
        "TurnGotoDialogOff",
        "MustActionTrigger",
        "SetCoinFee",
        "SetDurationTime",
        "AddCollectible",
        "SetCollectibleEffect",
        "BindCollectibleTo",
        "AllowUserDump",
        "SetVehicleToLoad",
        "SetObjTargetVehicle",
        "SetObjDistance",
        "SetObjTargetBoss",
        "AddCollectibleStateProp",
        "SetPickupTarget",
        "AllowRockOut",
        "AddCondition",
        "CloseCondition",
        "SetFollowDistances",
        "SetCondTargetVehicle",
        "SetConditionPosition",
        "SetCondTime",
        "SetHitNRun",
        "EnableTutorialMode",
        "SetConversationCamName",
        "SetConversationCamPcName",
        "SetConversationCamNpcName",
        "SetConversationCam",
        "SetConversationCamDistance",
        "AmbientAnimationRandomize",
        "ClearAmbientAnimations",
        "AddAmbientPcAnimation",
        "AddAmbientNpcAnimation",
        "CharacterIsChild",
        "SetPresentationBitmap",
        "SetAnimCamMulticontName",
        "SetAnimatedCameraName",
        "SetMissionStartMulticontName",
        "SetMissionStartCameraName",
        "SetCamBestSide",
        "SetFMVInfo",
        "StartCountdown",
        "AddToCountdownSequence",
        "SetCarStartCamera",
        "GoToPsScreenWhenDone",
        "SetPlayerCarName",
        "SetCondMinHealth",
        "LoadP3DFile",
        "LoadDisposableCar",
        "SetRespawnRate",
        "AddCharacter",
        "AddNPCCharacterBonusMission",
        "SetBonusMissionDialoguePos",
        "AddAmbientCharacter",
        "AddBonusMissionNPCWaypoint",
        "AddObjectiveNPCWaypoint",
        "AddAmbientNPCWaypoint",
        "AddPurchaseCarNPCWaypoint",
        "ActivateTrigger",
        "DeactivateTrigger",
        "CreateAnimPhysObject",
        "CreateActionEventTrigger",
        "LinkActionToObjectJoint",
        "LinkActionToObject",
        "SetCoinDrawable",
        "SetParticleTexture",
        "SetCharacterPosition",
        "ResetCharacter",
        "AddTeleportDest",
        "SetInitialWalk",
        "AddVehicleSelectInfo",
        "ClearVehicleSelectInfo",
        "AddFlyingActor",
        "AddFlyingActorByLocator",
        "AddBehaviour",
        "SetCollisionAttributes",
        "AddSpawnPoint",
        "AddSpawnPointByLocatorScript",
        "SetProjectileStats",
        "PreallocateActors",
        "SetActorRotationSpeed",
        "AddShield",
        "ClearGagBindings",
        "AddGagBinding",
        "GagBegin",
        "GagSetInterior",
        "GagSetCycle",
        "GagSetWeight",
        "GagSetSound",
        "GagSetTrigger",
        "GagPlayFMV",
        "GagSetPosition",
        "GagSetRandom",
        "GagSetIntro",
        "GagSetOutro",
        "GagSetCameraShake",
        "GagSetCoins",
        "GagSetSparkle",
        "GagSetAnimCollision",
        "GagEnd",
        "GagSetLoadDistances",
        "GagSetSoundLoadDistances",
        "GagSetPersist",
        "GagCheckCollCards",
        "GagCheckMovie",

        #ASF Con Commands
        "AddVehicleCharacter",
        "AddVehicleCharacterSuppressionCharacter",
        "SetConditionalParameter",
        "SetVehicleCharacterAnimation",
        "SetVehicleCharacterJumpOut",
        "SetVehicleCharacterScale",
        "SetVehicleCharacterVisible",

        #ASF Level MFK Commands
        "SetCarChangeHitAndRunChange",
        "SetHitAndRunDecayHitAndRun",
        "SetHitAndRunFine",
        "AddParkedCar",

        #ASF Mission MFK Commands
        "SetHUDMapDrawable",
        "SetParkedCarsEnabled",
        "SetPedsEnabled",
        "UseTrafficGroup",

        #ASF Stage MFK Commands
        "AddStageVehicleCharacter",
        "DisableTrigger",
        "RemoveStageVehicleCharacter",
        "ResetStageHitAndRun",
        "SetNoHitAndRunMusicForStage",
        "SetStageAllowMissionCancel",
        "SetStageCarChangeHitAndRunChange",
        "SetStageCharacterModel",
        "SetStageHitAndRun",
        "SetStageHitAndRunDecay",
        "SetStageHitAndRunDecayHitAndRun",
        "SetStageHitAndRunDecayInterior",
        "SetStageHitAndRunFine",
        "SetStageNumChaseCars",
        "SetStagePayout",
        "SetStageVehicleAllowSeatSlide",
        "SetStageVehicleCharacterAnimation",
        "SetStageVehicleCharacterJumpOut",
        "SetStageVehicleCharacterScale",
        "SetStageVehicleCharacterVisible",
        "SetStageVehicleNoDestroyedJumpOut",
        "SetStageVehicleReset",

        #ASF Objective MFK Commands
        "AddObjTargetModel",
        "SetCollectibleSoundEffect",
        "SetObjCameraName",
        "SetObjMulticontName",
        "SetObjCanSkip",
        "SetObjDecay",
        "SetObjExplosion",
        "SetObjMessageIndex",
        "SetObjNoLetterbox",
        "SetObjSound",
        "SetObjSpeedKMH",
        "SetObjThreshold",
        "SetObjTotal",
        "SetObjTrigger",
        "SetObjUseCameraPosition",
        #ASF Condition MFK Commands
        "AddCondTargetModel",
        "SetCondDecay",
        "SetCondDelay",
        "SetCondDisplay",
        "SetCondMessageIndex",
        "SetCondSound",
        "SetCondSpeedRangeKMH",
        "SetCondThreshold",
        "SetCondTotal",
        "SetCondTrigger",]

def output(file):
    entrybox.delete(1.0,END)
    entrybox.insert(END,file)


def openFile(filetype):

    if filetype == "MFK":
            note = "MFK Files"
            extension = ".mfk"
    elif filetype == "CON":
            note = "CON Files"
            extension = ".con"

    mfkfile = filedialog.askopenfile(filetypes=[(note, extension)])
    if mfkfile:
        print("\nReading MFK")
        file = mfkfile.read()

        print("Converting MFK features into LUA")

        changeDictionary = {"\\":"\\\\", "//":"--"}

        for change in changeDictionary:
            file = file.replace(change,changeDictionary[change])

        print("Formatting Functions")
        for command in commands:
            file = file.replace(f"{command}(",f"Game.{command}(")

        print("Creating new file and writing new script\n")
        try:
            newFile = mfkfile.name[:-3]+"lua"
            with open(newFile,"w+") as new:
                new.write(file)

            output(file)
            print("Done")
        except PermissionError:
            print("Permission Error, Printing file in Console...")
            output(file)
        except Exception:
            output(file)

title = Label(root,text="MFK/CON --> LUA converter",fg="red",font=30)
title.grid(row=0,column=0,columnspan=2)

openCONB = Button(root,text="Open a CON File",fg="blue",command = lambda : openFile("CON"))
openMFKB = Button(root,text="Open a MFK File",fg="blue",command = lambda : openFile("MFK"))

openCONB.grid(row=1,column=1,sticky=E+W)
openMFKB.grid(row=1,column=0,sticky=E+W)


frame0 = Frame(root)
frame0.grid(row=2,column=0,columnspan=2)

entrybox = Text(frame0,width=100,wrap=NONE)
entrybox.grid(row=0,column=0)

yScroll = Scrollbar(frame0, command=entrybox.yview,orient=VERTICAL)
yScroll.grid(row=0, column=1, sticky=N + S)
xScroll = Scrollbar(frame0, command=entrybox.xview,orient=HORIZONTAL)
xScroll.grid(row=1, column=0,columnspan=1, sticky=E + W)

entrybox.config(yscrollcommand = yScroll.set,xscrollcommand=xScroll.set)



print("Running Window")
root.mainloop()
Finally updated it to fix some small issues
  • Because if the way I coded it things like `SetDynaLoadData` would lose the semi colon which is quite important, But that is fixed now
  • If you converted a file however MFK2LUA idoesnt have permision to write a newfile in the location, It will now print the file contents in the console window instead of just crashing.
  • Added "support" for .CON files
Unsubscribe from this topic
Please login to contribute to the conversation.