Tutorial: Introduction to Lua scripting - Page 10 - ED Forums
 


Notices

Reply
 
Thread Tools Display Modes
Old 10-29-2018, 09:21 PM   #91
funkyfranky
Senior Member
 
funkyfranky's Avatar
 
Join Date: Sep 2015
Location: Asgård
Posts: 2,213
Default

Quote:
Originally Posted by Tiramisu View Post
A very simple example for a dynamic spawning behaviour is spawning an enemy unit around an airplane on a random heading between 90° and 140° on a random distance between 20nm and 30nm. If I wanted to imitate such a spawning behaviour using only the MOOSE in predefined trigger zones, then it would be very hard.
Also if MOOSE is only using uniform probability distributions, then I could not use custom distributions like the Gaussian one.
Code:
local spawn=SPAWN:New("Spawn Template")
local rho=UTILS.RandomGaussian(UTILS.NMToMeters(25), UTILS.NMToMeters(2), UTILS.NMToMeters(20), UTILS.NMToMeters(30))
local theta=UTILS.RandomGaussian(120, 5, 90, 140)
local zone=ZONE_UNIT:New("Zone Unit", UNIT:FindByName("Spawn Relative"), 100, {rho=rho, theta=theta, relative_to_unit=true})
spawn:SpawnInZone(zone)
__________________
Multiple exclamation marks, are a sure sign of a diseased mind.
i7-8700K | Asus RTX 2080Ti Strix OC | 32 GB Ram 3200 MHz DDR-4 | Asus Maximus Hero X | Samung EVO 960 Pro SSD | VKB Gunfighter Pro | MFG Crosswind | Rift S
RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss

Last edited by funkyfranky; 10-29-2018 at 09:24 PM.
funkyfranky is offline   Reply With Quote
Old 10-30-2018, 02:22 AM   #92
Tiramisu
Member
 
Join Date: Oct 2018
Location: Germany
Posts: 369
Default

Ok, that kind of impresses me. I guess I should ask my further questions in the MOOSE threads then.

Edit: So I have tried your code and it works well. Something I noticed is that I had to load my own Lua file in the "Do Script"-trigger-option again each time I edited it with Notepad++. That seems like a small issue in the mission editor, which does not load changed Lua files automatically. Other than that MOOSE worked perfectly for me. So thx!

Btw. I wonder if it is possible to set the settings of the DDIs, weapons, flairs and the radar of the player's airplane before the mission start. It would be nice for training missions, that are frequently repeated. For example in bombing training missions I do not want to set the counter measures and bomb settings myself every time I start that mission.

Last edited by Tiramisu; 10-30-2018 at 03:49 AM.
Tiramisu is offline   Reply With Quote
Old 10-30-2018, 06:32 AM   #93
funkyfranky
Senior Member
 
funkyfranky's Avatar
 
Join Date: Sep 2015
Location: Asgård
Posts: 2,213
Default

Quote:
Originally Posted by Tiramisu View Post
Edit: So I have tried your code and it works well.
Great, and sorry for just giving you the plain code above. I was about to go to bed and just had a few minutes
__________________
Multiple exclamation marks, are a sure sign of a diseased mind.
i7-8700K | Asus RTX 2080Ti Strix OC | 32 GB Ram 3200 MHz DDR-4 | Asus Maximus Hero X | Samung EVO 960 Pro SSD | VKB Gunfighter Pro | MFG Crosswind | Rift S
RAT - On the Range - Rescue Helo - Recovery Tanker - Warehouse - Airboss
funkyfranky is offline   Reply With Quote
Old 10-30-2018, 01:16 PM   #94
Tiramisu
Member
 
Join Date: Oct 2018
Location: Germany
Posts: 369
Default

No problem! Your documentation was already clear enough for me.
Tiramisu is offline   Reply With Quote
Old 04-12-2019, 12:05 PM   #95
colubridae
Member
 
Join Date: Aug 2006
Location: cheshire, england
Posts: 223
Default problem

my bad


I found my problem


sorry to waste time

Last edited by colubridae; 04-12-2019 at 12:15 PM.
colubridae is offline   Reply With Quote
Old 04-12-2019, 06:44 PM   #96
colubridae
Member
 
Join Date: Aug 2006
Location: cheshire, england
Posts: 223
Default dabbling

I've trying to get ti grips with scripting...


so I have a mission with a group called "tanks" consisting of two tanks (tank 01 and tank 02)


This code works (taken from an example)

myUnit = Group.getByName("tanks"):getUnit(2)



but this code does not (error message says 'param self missing')

myGroup = Group.getByName("tanks")
myUnit = myGroup.getUnit(2)





can anyone please explain where i'm going wrong (other than being out of my depth tee hee)
colubridae is offline   Reply With Quote
Old 04-12-2019, 06:47 PM   #97
Tiramisu
Member
 
Join Date: Oct 2018
Location: Germany
Posts: 369
Default

lol. You forgot the colon in the 2nd example.


myGroup = Group.getByName("tanks")
myUnit = myGroup:getUnit(2)
Tiramisu is offline   Reply With Quote
Old 04-12-2019, 07:54 PM   #98
colubridae
Member
 
Join Date: Aug 2006
Location: cheshire, england
Posts: 223
Default

Quote:
Originally Posted by Tiramisu View Post
lol. You forgot the colon in the 2nd example.


myGroup = Group.getByName("tanks")
myUnit = myGroup:getUnit(2)

thanks tiramisu, worked a treat.


It's a tough job, but do you have an explanation for the difference of using a period in the first statement and a colon in the second?
colubridae is offline   Reply With Quote
Old 04-12-2019, 08:27 PM   #99
Tiramisu
Member
 
Join Date: Oct 2018
Location: Germany
Posts: 369
Default

It is quite easy. In Lua a colon automatically inserts the class itself into the first argument of the function.
So myGroup:getUnit(2) should be the same as myGroup.getUnit( myGroup, 2) if I am not mistaken. In this case imagine myGroup.getUnit as a function with actually two arguments, which needs the object in the first and the number in the second argument.
Tiramisu is offline   Reply With Quote
Old 04-24-2019, 12:34 PM   #100
Tiramisu
Member
 
Join Date: Oct 2018
Location: Germany
Posts: 369
Default

Is there any method for the player to send coordinates to a Lua script during a running mission?

What I have already tried is to get the coordinates of the waypoints of a unit with the _DATABASE method and then change its waypoints with the Combined Arms module. Sadly the waypoint data from _DATABASE is not updated, so it only contains informations of the preset waypoint coordinates set in the mission editor.
I was wondering if a script could read the coordinates of markers, that can be placed by the player in the F-10 map.
Tiramisu is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT. The time now is 03:01 AM. vBulletin Skin by ForumMonkeys. Powered by vBulletin®.
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.