custom LUA functions
4 posters
Operation Flashpoint Dragon Rising OFDR Forums :: OPERATION FLASHPOINT: DRAGON RISING :: OFDR EDITING
Page 1 of 1
custom LUA functions
Here are a bunch of functions I use regularly that people may find helpful
Gets a new position using direction and distance values
gets the direction between two points
Gets the distance between two points
Gets a random position around the initial position within specified distances
Limits a value to specified min and max, with looping ability (for angles)
checks to see if the terrain is blocking the line of sight between two entities
attempts to merge units of one echelon into another if there is space
Gets a new position using direction and distance values
- Code:
--originalPosition = table containing x,y,z coordinates. use OFP:getPosition
--distance = distance in units from the starting position
--direction = direction in degrees from the starting position
--returns table containing new x,y,z coordinates of position
function positionByDirection(originalPosition, distance, direction)
origx = originalPosition[1]
origz = originalPosition[3]
newx = origx + math.cos(direction*3.14/180) * distance
newz = origz + math.sin(direction*3.14/180) * distance
newy = OFP:getTerrainHeight(newx, newz)
return {newx, newy, newz}
end
gets the direction between two points
- Code:
--radians = angle in radians to be converted to degrees (for use with atan2 function)
--returns angle in degrees
function radiansToDegrees(radians)
return radians*(180/3.14)
end
--startPosition = table containing x,y,z position of start point
--endPosition = table containing x,y,z position of end point
--returns the angle in degrees from the start position to end position
function pointDirection(startPosition, endPosition)
return radiansToDegrees(math.atan2(endPosition[3]-startPosition[3], endPosition[1]-startPosition[1]))
end
Gets the distance between two points
- Code:
--startPosition = table containing x,y,z position of start point
--endPosition = table containing x,y,z position of end point
returns the distance in units between the two positions (like OFP:getDistance)
function pointDistance (startPosition, endPosition)
local result_position = {endPosition[1] - startPosition[1], endPosition[2] - startPosition[2], endPosition[3] - startPosition[3]}
return math.sqrt(result_position[1] * result_position[1] + result_position[2] * result_position[2] + result_position[3] * result_position[3])
end
Gets a random position around the initial position within specified distances
- Code:
--startPosition = table containing x,y,z position of start point
--minDistance = minimum distance new position can be from start position
--maxDistance = maximum distance new position can be from start position
returns table containing new x,y,z position
function getRandomPosition(startPosition, minDistance, maxDistance)
distance = math.random(mindDistance, maxDistance)
direction = math.random(0, 359)
return positionByDirection(startPosition, distance, direction)
end
Limits a value to specified min and max, with looping ability (for angles)
- Code:
--inputValue = the value to limit
--minValue = minimum value input can be
--maxValue = maximum value input can be
--loop = if true, inputValue will be adjusted by maxValue until it fits inside min and max (useful for angle calculations in degrees or radians)
--loop = if false, returns minValue or maxValue if input outside of limit
--returns the limited value
function limitValue(inputValue, minValue, maxValue, loop)
if loop == false then
if inputValue < minValue then
inputValue = minValue
end
if inputValue > maxValue then
inputValue = maxValue
end
return inputValue
else
while inputValue > maxValue do
inputValue = inputValue - maxValue
end
while inputValue < minValue do
inputValue = inputValue + maxValue
end
end
end
checks to see if the terrain is blocking the line of sight between two entities
- Code:
--viewingEntity = the entity that is doing the looking
--targetEntity = the entity that the viewer is trying to look at
--entityHeight = how tall the viewing entity is (1.5 for soldiers is good)
--stepSize = amount of distance in units to check for blocking terrain
--returns true if the terrain is not blocking the line of site or false if it is
function canSee(viewingEntity, targetEntity, entityHeight, stepSize)
start_pos = OFP:getPosition(viewingEntity)
start_height = OFP:getTerrainHeight(viewingEntity)
end_pos = OFP:getPosition(targetEntity)
direction = pointDirection(start_pos, end_pos)
distance = OFP:getDistance(viewingEntity, targetEntity)
steps = distance / stepSize
can_see = true
for i=1, steps do
test_distance = stepSize * i
if test_distance > distance then
test_distance = distance
i = steps + 1
end
new_position = positionByDirection(start_pos, direction, test_distance)
if new_position[2] > start_height + entityHeight then
can_see = false
end
end
return can_see
end
attempts to merge units of one echelon into another if there is space
- Code:
--echelonName = the echelon we want to merge with another
--tableOfEchelons = table containing names of echelons we want to try and merge with
--maxDistance = the maximum distance any of the merging echelons can be
--returns true if the members of echelonName have been attached to another echelon and false if not
function mergeEchelons(echelonName, tableOfEchelons, maxDistance)
echelon_size = OFP:getEchelonSize(echelonName)
members = {}
for i=0, echelon_size do
table.insert(members, OFP:getEchelonMember(echelonName, i))
end
chosen_echelon = ""
for i=1, #tableOfEchelons do
if tableOfEchelons[i] ~= echelonName then
index_size = OFP:getEchelonSize(tableOfEchelons[i])
if squad_max_size - index_size >= echelon_size and OFP:getDistance(echelonName, tableOfEchelons[i]) < maxDistance then
chosen_echelon = tableOfEchelons[i]
break
end
end
end
if chosen_echelon ~= "" then
for i=1, #members do
OFP:attach(members[i], chosen_echelon)
end
return true
end
return false
end
TemplarGFX- Veteran
- Points : 159
Reputation : 18
Join date : 2013-02-20
Re: custom LUA functions
Hello MDog!
I'm back on OFDR for a while, just can't find anything to replace it. ARMA just doesn't feel the same for me!
I'm back on OFDR for a while, just can't find anything to replace it. ARMA just doesn't feel the same for me!
TemplarGFX- Veteran
- Points : 159
Reputation : 18
Join date : 2013-02-20
Re: custom LUA functions
I know what you mean dude. I do like the sim/immersion side in Arma though. Which I only came close to creating in DR with Tjdagger when we made nightshade.
I've just started a udemy course so I might end back to it as well. It's been a while.
I've just started a udemy course so I might end back to it as well. It's been a while.
Re: custom LUA functions
TemplarGFX wrote:
I'm back on OFDR for a while, just can't find anything to replace it. ARMA just doesn't feel the same for me!
Excellent news there are a handfull of people who can really make this game sing, awaiting new orders Sir, ssshhh whisper it Island War 3.
Last edited by dewi316 on Wed 09 Dec 2015, 21:43; edited 1 time in total
dewi316- Veteran
- Location : swansea
Points : 179
Reputation : 22
Join date : 2012-12-19
Re: custom LUA functions
I'd say you are in no way alone in that assertion. I'm frankly not sure that I'll ever find anything that replaces this game. Welcome back!TemplarGFX wrote:Hello MDog!
I'm back on OFDR for a while, just can't find anything to replace it. ARMA just doesn't feel the same for me!
tvig
Re: custom LUA functions
tvig0r0us wrote:I'd say you are in no way alone in that assertion. I'm frankly not sure that I'll ever find anything that replaces this game. Welcome back!TemplarGFX wrote:Hello MDog!
I'm back on OFDR for a while, just can't find anything to replace it. ARMA just doesn't feel the same for me!
tvig
Im glad to see so many "old" names still around!
Im currently working on a little present for the community (no its not IW 3 LOL)!
It really annoyed me returning to OFDR this time around that the help file was so unhelpful, didn't contain any basic lua functions, and was missing alot of information.
So I came up with a way to integrate command and function help directly into the LUA Editor! So I have been going over EVERY command (both from OFP, and LUA core functions) putting concise and detailed help information into it!
I have completed the LUA string, IO, OS, table, math and core libraries and just on the final leg of fixing the help information for the OFP, debug and waypoint commands (which is going to take a few days at least LOL).
Im doing a "dump" of my knowledge into this on each command so that everyone has immediate access to a fully comprehensive help system (that's accurate!) that contains practically everything including EVERY OFP specific command! and all the LUA commands we use on a regular basis!
TemplarGFX- Veteran
- Points : 159
Reputation : 18
Join date : 2013-02-20
Re: custom LUA functions
Wow am I going overboard with this LOL
Any information missing from the ME that you can think of including? Nothing too huge character-count wise!
So far I've got all the stuff with the AI commands, tables of all the predefined strings, some handy custom functions and a contextual and paged help system!
Any information missing from the ME that you can think of including? Nothing too huge character-count wise!
So far I've got all the stuff with the AI commands, tables of all the predefined strings, some handy custom functions and a contextual and paged help system!
TemplarGFX- Veteran
- Points : 159
Reputation : 18
Join date : 2013-02-20
Similar topics
» OWP: Custom Sound App
» Using custom timers
» custom sounds and ambient lighting
» User made Custom Sounds
» Using custom timers
» custom sounds and ambient lighting
» User made Custom Sounds
Operation Flashpoint Dragon Rising OFDR Forums :: OPERATION FLASHPOINT: DRAGON RISING :: OFDR EDITING
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|