Playability

All discussions & material related to Command's Lua interface

Moderators: angster, RoryAndersonCDT, michaelm75au, MOD_Command

Post Reply
User avatar
andytm956
Posts: 7
Joined: Fri Apr 08, 2016 5:11 am
Location: Portsmouth, England

Playability

Post by andytm956 »

I wanted to make my scenario's have playabilty, therefore the fleets of one side would appear in different locations
I used reference points called Zone1, Zone2, and Zone3, (South of Japan) where i wanted the choices for the fleets to position. Also a reference point called Test. This Test Reference Point is the one that would move to a Zone and the units would gather around the reference point test. The side was Blue. The units used were
"CVN 70 Carl Vinson [Nimitz Class]",
"CG 52 Bunker Hill [Ticonderoga Baseline 2, VLS]",
"CG 54 Antietam [Ticonderoga Baseline 3, VLS]"
Here is the code I used.

-- Seed the random number generator
math.randomseed(os.time())

-- Define the zones with their coordinates
local zones = {
{name = "Zone1", latitude = 32, longitude = 133},
{name = "Zone2", latitude = 28, longitude = 133},
{name = "Zone3", latitude = 24, longitude = 133}
}

-- Randomly select one of the zones
local selectedZone = zones[math.random(#zones)]
-- Print the selected zone's details
print("Selected Zone: " .. selectedZone.name)
print("Latitude: " .. selectedZone.latitude)
print("Longitude: " .. selectedZone.longitude)

-- Example of setting a reference point to the selected zone's coordinates
local refPointName = "Test"
local sideName = "Blue" -- Replace with the actual side name
ScenEdit_SetReferencePoint({side="Blue", name=refPointName, latitude=selectedZone.latitude, longitude=selectedZone.longitude})

----- Move Units to Reference Point
-- Seed the random number generator
math.randomseed(os.time())

-- Define the reference point name and side
local refPointName = "Test"
local sideName = "Blue" -- Replace with the actual side name

-- Get the current position of the reference point
local refPoint = ScenEdit_GetReferencePoint({side=sideName, name=refPointName})

-- Define the units to be teleported
local units = {"CVN 70 Carl Vinson [Nimitz Class]", "CG 52 Bunker Hill [Ticonderoga Baseline 2, VLS]", "CG 54 Antietam [Ticonderoga Baseline 3, VLS]"} -- Replace with the actual unit names

-- Function to teleport a unit near the reference point
local function teleportUnitNearRefPoint(units, refPointName)
-- Generate random offsets (in degrees)
local randomLatOffset = (math.random() - 0.5) * 0.1 -- Random offset between -0.05 and 0.05 degrees
local randomLonOffset = (math.random() - 0.5) * 0.1 -- Random offset between -0.05 and 0.05 degrees

-- Calculate new position near the reference point
local newLat = refPoint.latitude + randomLatOffset
local newLon = refPoint.longitude + randomLonOffset

-- Teleport the unit to the new position
ScenEdit_SetUnit({side=sideName, name=unitName, latitude=newLat, longitude=newLon})
end

-- Loop through each unit and teleport it near the reference point
for _, unitName in ipairs(units) do
teleportUnitNearRefPoint(unitName, refPointName)
end

No I do not know code, I have rudimentary understanding, but boy did Co-Pilot help me.
Post Reply

Return to “Lua Legion”