mirror of
https://github.com/FlightControl-Master/MOOSE_Demos.git
synced 2025-08-15 10:37:47 +00:00
Updated Moose.lua
This commit is contained in:
parent
b27d2214cd
commit
24f7d7b68a
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,116 +1,116 @@
|
|||||||
---
|
---
|
||||||
-- Author: kaltokri
|
-- Author: kaltokri
|
||||||
-- Created: 08.06.2024
|
-- Created: 08.06.2024
|
||||||
-- Contributors: -
|
-- Contributors: -
|
||||||
-- Modified: -
|
-- Modified: -
|
||||||
--
|
--
|
||||||
-- # Documentation:
|
-- # Documentation:
|
||||||
-- https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/Utilities.Utils.html##(UTILS).LoadFromFile
|
-- https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/Utilities.Utils.html##(UTILS).LoadFromFile
|
||||||
-- https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/Utilities.Utils.html##(UTILS).SaveToFile
|
-- https://flightcontrol-master.github.io/MOOSE_DOCS_DEVELOP/Documentation/Utilities.Utils.html##(UTILS).SaveToFile
|
||||||
--
|
--
|
||||||
-- # Description:
|
-- # Description:
|
||||||
-- DCS must be desanitized!
|
-- DCS must be desanitized!
|
||||||
-- https://flightcontrol-master.github.io/MOOSE/advanced/desanitize-dcs.html
|
-- https://flightcontrol-master.github.io/MOOSE/advanced/desanitize-dcs.html
|
||||||
--
|
--
|
||||||
-- # Guide:
|
-- # Guide:
|
||||||
-- - Start the mission and choose role of GAME MASTER.
|
-- - Start the mission and choose role of GAME MASTER.
|
||||||
-- - Wait for the message about lfs and io.
|
-- - Wait for the message about lfs and io.
|
||||||
-- - Open radio menu by pressing #, then choose "Other...".
|
-- - Open radio menu by pressing #, then choose "Other...".
|
||||||
-- - Activate "Load points from file".
|
-- - Activate "Load points from file".
|
||||||
-- - You will get an error message, because the file does not exist yet.
|
-- - You will get an error message, because the file does not exist yet.
|
||||||
-- - Open menu again and activate "Show points". Both sides have 0 points.
|
-- - Open menu again and activate "Show points". Both sides have 0 points.
|
||||||
-- - Go into menu and choose "Give 100 points to RED" -> Blue 0, Red 100.
|
-- - Go into menu and choose "Give 100 points to RED" -> Blue 0, Red 100.
|
||||||
-- - Now give blue 300 points by choosing "Give 100 points to BLUE" three times -> Blue 300, Red 100.
|
-- - Now give blue 300 points by choosing "Give 100 points to BLUE" three times -> Blue 300, Red 100.
|
||||||
-- - Now use "Save points to file". A file will be created on your hard disk.
|
-- - Now use "Save points to file". A file will be created on your hard disk.
|
||||||
-- - Switch to the desktop and open the file with Notepad++ and take a look at the content. Close it.
|
-- - Switch to the desktop and open the file with Notepad++ and take a look at the content. Close it.
|
||||||
-- - Switch back to DCS and choose "Reset points" -> Blue 0, Red 0.
|
-- - Switch back to DCS and choose "Reset points" -> Blue 0, Red 0.
|
||||||
-- - Activate "Load points from file" -> Blue 300, Red 100.
|
-- - Activate "Load points from file" -> Blue 300, Red 100.
|
||||||
-------------------------------------------------------------------------
|
-------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
-- Define some configuration values
|
-- Define some configuration values
|
||||||
local fileNamePoints = "Demo-UTL-001-Save-and-Load-Data.txt"
|
local fileNamePoints = "Demo-UTL-001-Save-and-Load-Data.txt"
|
||||||
|
|
||||||
-- Define some global variables
|
-- Define some global variables
|
||||||
Points = {
|
Points = {
|
||||||
Blue = 0,
|
Blue = 0,
|
||||||
Red = 0
|
Red = 0
|
||||||
}
|
}
|
||||||
|
|
||||||
-- Show points of both coalition
|
-- Show points of both coalition
|
||||||
function ShowPoints()
|
function ShowPoints()
|
||||||
local messageText = string.format("Mission points of both coalition:\nRED: %04d\nBLUE: %04d", Points['Red'], Points['Blue'] )
|
local messageText = string.format("Mission points of both coalition:\nRED: %04d\nBLUE: %04d", Points['Red'], Points['Blue'] )
|
||||||
MESSAGE:New( messageText, 25, "INFO" ):ToAll():ToLog()
|
MESSAGE:New( messageText, 25, "INFO" ):ToAll():ToLog()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- A function to give points to a coalition
|
-- A function to give points to a coalition
|
||||||
function AddPoints(coalition, amount)
|
function AddPoints(coalition, amount)
|
||||||
local messageText = string.format("Adding %d points to coalition %s", amount, coalition)
|
local messageText = string.format("Adding %d points to coalition %s", amount, coalition)
|
||||||
MESSAGE:New( messageText, 25, "INFO" ):ToAll():ToLog()
|
MESSAGE:New( messageText, 25, "INFO" ):ToAll():ToLog()
|
||||||
Points[coalition] = Points[coalition] + amount
|
Points[coalition] = Points[coalition] + amount
|
||||||
ShowPoints()
|
ShowPoints()
|
||||||
end
|
end
|
||||||
|
|
||||||
function ResetPoints()
|
function ResetPoints()
|
||||||
MESSAGE:New( "Reseting points", 25, "INFO" ):ToAll():ToLog()
|
MESSAGE:New( "Reseting points", 25, "INFO" ):ToAll():ToLog()
|
||||||
Points['Blue'] = 0
|
Points['Blue'] = 0
|
||||||
Points['Red'] = 0
|
Points['Red'] = 0
|
||||||
ShowPoints()
|
ShowPoints()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Save points to a file to make them persistent
|
-- Save points to a file to make them persistent
|
||||||
function SavePointsToFile( fileName, folderPath )
|
function SavePointsToFile( fileName, folderPath )
|
||||||
|
|
||||||
-- Create data string to be stored
|
-- Create data string to be stored
|
||||||
local data = string.format( "Red:%d;Blue:%d", Points['Red'], Points['Blue'] )
|
local data = string.format( "Red:%d;Blue:%d", Points['Red'], Points['Blue'] )
|
||||||
|
|
||||||
local messageText = string.format("Saving points to file.\nPath: %s\nFile: %s\nData: %s", folderPath, fileName, data )
|
local messageText = string.format("Saving points to file.\nPath: %s\nFile: %s\nData: %s", folderPath, fileName, data )
|
||||||
MESSAGE:New( messageText, 25, "INFO" ):ToAll():ToLog()
|
MESSAGE:New( messageText, 25, "INFO" ):ToAll():ToLog()
|
||||||
|
|
||||||
UTILS.SaveToFile( folderPath, fileName, data )
|
UTILS.SaveToFile( folderPath, fileName, data )
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Load data from file and save it into the table Points.
|
-- Load data from file and save it into the table Points.
|
||||||
-- You have to take care of the interpetation of the data yourself.
|
-- You have to take care of the interpetation of the data yourself.
|
||||||
function LoadPointsFromFile( fileName, folderPath )
|
function LoadPointsFromFile( fileName, folderPath )
|
||||||
|
|
||||||
local messageText = string.format("Loading points from file.\nPath: %s\nFile: %s", folderPath, fileName )
|
local messageText = string.format("Loading points from file.\nPath: %s\nFile: %s", folderPath, fileName )
|
||||||
MESSAGE:New( messageText, 25, "INFO" ):ToAll():ToLog()
|
MESSAGE:New( messageText, 25, "INFO" ):ToAll():ToLog()
|
||||||
|
|
||||||
-- It returns a boolean and a table with one entry per line
|
-- It returns a boolean and a table with one entry per line
|
||||||
local outcome, data = UTILS.LoadFromFile( folderPath, fileName )
|
local outcome, data = UTILS.LoadFromFile( folderPath, fileName )
|
||||||
|
|
||||||
-- Check if the loading was successful
|
-- Check if the loading was successful
|
||||||
if outcome then
|
if outcome then
|
||||||
-- We know our data is only 1 line, so data[1] is okay.
|
-- We know our data is only 1 line, so data[1] is okay.
|
||||||
-- If you save more complex data you need to iterate over each line!
|
-- If you save more complex data you need to iterate over each line!
|
||||||
MESSAGE:New( "Raw data loaded from file: " .. data[1], 25, "INFO" ):ToAll():ToLog()
|
MESSAGE:New( "Raw data loaded from file: " .. data[1], 25, "INFO" ):ToAll():ToLog()
|
||||||
|
|
||||||
MESSAGE:New( "Converting and sending into points table.", 25, "INFO" ):ToAll():ToLog()
|
MESSAGE:New( "Converting and sending into points table.", 25, "INFO" ):ToAll():ToLog()
|
||||||
for key, value in string.gmatch(data[1], "(%w+):(%w+)") do
|
for key, value in string.gmatch(data[1], "(%w+):(%w+)") do
|
||||||
Points[key] = value
|
Points[key] = value
|
||||||
end
|
end
|
||||||
ShowPoints()
|
ShowPoints()
|
||||||
else
|
else
|
||||||
MESSAGE:New( "Loading data from file failed", 25, "ERROR" ):ToAll():ToLog()
|
MESSAGE:New( "Loading data from file failed", 25, "ERROR" ):ToAll():ToLog()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- Check if DCS is desanitized.
|
-- Check if DCS is desanitized.
|
||||||
if lfs and io then
|
if lfs and io then
|
||||||
MESSAGE:New( '*** lfs and io are desanitized = OK ***', 25, "INFO" ):ToAll():ToLog()
|
MESSAGE:New( '*** lfs and io are desanitized = OK ***', 25, "INFO" ):ToAll():ToLog()
|
||||||
|
|
||||||
-- We will use the Mission folder in your DCS Saved Games path.
|
-- We will use the Mission folder in your DCS Saved Games path.
|
||||||
local missionFolderPath = lfs.writedir() .. 'Missions'
|
local missionFolderPath = lfs.writedir() .. 'Missions'
|
||||||
|
|
||||||
-- Add menu entries to execute the functions
|
-- Add menu entries to execute the functions
|
||||||
MENU_MISSION_COMMAND:New( "Show points", nil, ShowPoints )
|
MENU_MISSION_COMMAND:New( "Show points", nil, ShowPoints )
|
||||||
MENU_MISSION_COMMAND:New( "Reset points", nil, ResetPoints )
|
MENU_MISSION_COMMAND:New( "Reset points", nil, ResetPoints )
|
||||||
MENU_MISSION_COMMAND:New( "Give 100 points to RED", nil, AddPoints, 'Red', 100 )
|
MENU_MISSION_COMMAND:New( "Give 100 points to RED", nil, AddPoints, 'Red', 100 )
|
||||||
MENU_MISSION_COMMAND:New( "Give 100 points to BLUE", nil, AddPoints, 'Blue', 100 )
|
MENU_MISSION_COMMAND:New( "Give 100 points to BLUE", nil, AddPoints, 'Blue', 100 )
|
||||||
MENU_MISSION_COMMAND:New( "Save points to file", nil, SavePointsToFile, fileNamePoints, missionFolderPath )
|
MENU_MISSION_COMMAND:New( "Save points to file", nil, SavePointsToFile, fileNamePoints, missionFolderPath )
|
||||||
MENU_MISSION_COMMAND:New( "Load points from file", nil, LoadPointsFromFile, fileNamePoints, missionFolderPath )
|
MENU_MISSION_COMMAND:New( "Load points from file", nil, LoadPointsFromFile, fileNamePoints, missionFolderPath )
|
||||||
else
|
else
|
||||||
MESSAGE:New( '*** Your DCS is not desanitized. MOOSE is unable to use lfs and io! ***', 25, "ERROR" ):ToAll():ToLog()
|
MESSAGE:New( '*** Your DCS is not desanitized. MOOSE is unable to use lfs and io! ***', 25, "ERROR" ):ToAll():ToLog()
|
||||||
end
|
end
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user