First script! and a question about the second one

The place to discuss scripting and game modifications for X³: Terran Conflict and X³: Albion Prelude.

Moderators: Moderators for English X Forum, Scripting / Modding Moderators

Post Reply
kaistern
Posts: 443
Joined: Mon, 30. Jun 14, 13:29
x3ap

First script! and a question about the second one

Post by kaistern » Sat, 8. Nov 14, 06:43

History: Recently in LU I had a friendly pirate base pop up in MY sector... i thought it was cool and decided to keep it. However when I patched it the latest the pirate base was removed. So I decided that it was time to learn how to script (note: I have zero previous history with programming). Any how I successfully manage to creat the Pirate base! or sort of I have not had a chance to investagate it properly all I really managed to do is spawn A pirate base :D What I did was very simple
001 $piratebase = create station: type=2076 owner=pirates addto=<Var/Sector> x=<Var/Number> y=<Var/Number> z=<Var/Number>
Now I want to make it friendly to me, which is a little more complicated being more then a one line script. Can someone tell me if I got it right?

001 $target= get player tracking aim
002 skip if $target -> exists
003 Return Null
004 $target -> set [palyership] to [friend]
my other question is, if when I made the first script if I had thrown in
$piratebase -> set [playership] to [Friend]
would it have made it friendly to begin with?
[ external image ]
Running LU 1.4.7 + XM-O 1.0 + Quick Wings 1.0
Rise of Phanon DiD LUV
Wrath of the Hive DiD XM-O
Try my script: Quick Wings for better wing control in LU!

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Sat, 8. Nov 14, 08:51

In my experience, it's impossible to make all Pirates friendly to you in LU, even when having 10 reputation. However, in LU, you can dock to all Pirate bases, even if you have a bad reputation with them. Turn pirates to "Friend" in your console, and you'll see them in white.

Anyway, a better solution would have been :

Code: Select all

$Station = [THIS] -> get user input: type=[Var/Station], title='Choose a station you want to be friend with'
$Station -> set relation against [PLAYERSHIP] to [Friend]
[PLAYERSHIP] -> set relation against $Station to [Friend]
display subtitle text: text='Done!' duration=0 ms
If the pirate base exists, or to create one from nothing, at a position given by the user :

Code: Select all

$Position = [THIS]-> get user input: type=[Var/Sector Position], title='Choose a position to create the station'
$Sector = $Position[3]
$PosX = $Position[0]
$PosY = $Position[1]
$PosZ = $Position[2]
$Station = create station: type={Pirates Pirate Base (DOCK_PIRATES)} owner=[Pirates] addto=$Sector x=$PosX y=$PosY z=$PosZ
$Station-> add default wares to station/dock
display subtitle text: text='Done!' duration=0 ms
Use X-Studio to script :)

kaistern
Posts: 443
Joined: Mon, 30. Jun 14, 13:29
x3ap

Post by kaistern » Sat, 8. Nov 14, 09:42

THANKS!!!!!! :D :D :D

I'll have to go down load X-studio when I get home :D it looks like it might really help. So far my biggest challenge has been FINDING the button I am looking for lol. Even finding the create station button took forever, though I had just assumed that it was something I would get better at with time.

What is the appropriate ettiqute for changing someone elses mod? I like the look of Cycrow's Wing hotkeys but I don't know if it upto date or if it is LU compatible. There are also some minor changes I would like to make (simlify down to 3 command hotkeys that change effect based on target, add more quick wings). I think this would be a good place to further my scripting skills as I think most of it is just calling other scripts, though I haven't actually opened it up yet.

What I want to do is create a mod that gives you the ability command your wings in the mist of battle without opening a single window. I want you to be able to set hotkeys to each wing. I want three commands bindable to hotkeys:
1)attack (call the attack script if no target; call the attack my target script if I have a target)
2)Protect (call the protect me script if no target; protect my target script if I have a target) and
3)Dock (call the return home script if no target; dock at my target if I have a target).
I also want to make it say the name of the wing you select (push the blue wing hotkey, and betty says "Blue Wing") and I want it to say command accepted after you give it a command. Once I got REALLY good at this I would also like to find a way for it to respect MCLL missle ROE, though I want to try the simpilar stuff first and i dont even know if that is possible.


I know that wing commands has very similar (really almost exactly identical) features but I think that adding my persoanlisation to it will help train my skills to get to where I do some of my more origanal ideas.

ADDED: Maybe also a hotkey for ALL wings.... that would be usefull to :D

ADDED2: Also the attack hotkey should NOT attack non-enemies.... I HATE it when I accidentally declare ware on the argons :lol:
[ external image ]
Running LU 1.4.7 + XM-O 1.0 + Quick Wings 1.0
Rise of Phanon DiD LUV
Wrath of the Hive DiD XM-O
Try my script: Quick Wings for better wing control in LU!

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Sat, 8. Nov 14, 09:56

Well... That's not going to be easy if you have no experience in scripting. Modifying the code of other people, in programming, is hard in general, even when it's well commented. And make a mod compatible with LU can be very very hard, if you don't have a perfect knowledge of the mod, and of LU's specifics. I'm pretty sure it would be easier to develop such a mod from scratch. That way, you'd be 100% sure that it is compatible with LU.

You should take a look at these tutorials Cycrow made. Among other things, he explains how to setup a hotkey and run a script via the AL menu (you don't want to have to go by the IG Script Editor every time you want to run your script...).

(and I can assure you that Cycrow's Wing hotkeys do more than just calling other scripts :) )

EDIT : redo such a script is in my TODO list ; I'd also want to have hotkeys for my wings, but go ahead, make us a nice powerful Wing Manager for LU :) A nice small project to start scripting.

kaistern
Posts: 443
Joined: Mon, 30. Jun 14, 13:29
x3ap

Post by kaistern » Sat, 8. Nov 14, 10:18

:D I have that link bookmarked. I have read it 4 or 5 times so far. it is the only guide that makes 100% since to me. all of the other guides blow my mind, I think they assume I should know what arrays and arguments are from the get go lol. My background is in medicine not programming :D

I'll do as you suggest and start from scratch... though I think I am going to end up with a LOT of questions lol. I understand how to assign hotkeys. I think I understand how to make all of the command that I want except the select wing without targeting wing command. I know it can be done because cycrow did it, but I have no idea HOW he did it. When I get home if I get time before i pass out I'll open hs script up and see if I can figure it out...... which I very well might not beable to for the reasons you stated. But if all else fails I'll just ask :D
[ external image ]
Running LU 1.4.7 + XM-O 1.0 + Quick Wings 1.0
Rise of Phanon DiD LUV
Wrath of the Hive DiD XM-O
Try my script: Quick Wings for better wing control in LU!

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Sat, 8. Nov 14, 10:32

Code: Select all

$Wing = get predefined wing: wing=[Wing.Blue]
There's a very useful feature in X-Studio : you right click on a command and then you can "Find usage in other scripts". It will browse all scripts and return them in a list.

An array is a variable that can contain multiple other variables. Indeed an important thing to understand :) The X-Script engine uses them a lot.

Code: Select all

MyVar = 1

MyArray = array alloc: size=2
MyArray[0] = 1
MyArray[1] = 2

MyVar = MyArray[1]
* MyVar now returns 2
In my previous example, $Position is an array.

kaistern
Posts: 443
Joined: Mon, 30. Jun 14, 13:29
x3ap

Post by kaistern » Sat, 8. Nov 14, 10:57

Joubarbe wrote:

Code: Select all

$Wing = get predefined wing: wing=[Wing.Blue]
That is awesome, and now I think I have an idea of how to do the quick wing commands. well shoot... ok I am thinking that when you press the blue wing button it has to change something that the command buttons can referance to know what wing to give orders to. But I am not sure about what I would use as a flag. Am I going to have to make a global script where I can store the flag? (what I mean is simpily a script that changes whenever you press the wing selection button, and then when a wing command is pressed it referancs that script to decide which wing is selected?
There's a very useful feature in X-Studio : you right click on a command and then you can "Find usage in other scripts". It will browse all scripts and return them in a list.
This looks very usefull and I will probably be using it a lot.
An array is a variable that can contain multiple other variables. Indeed an important thing to understand :) The X-Script engine uses them a lot.

Code: Select all

MyVar = 1

Code: Select all

MyArray = array alloc: size=2
MyArray[0] = 1
MyArray[1] = 2

MyVar = MyArray[1]
* MyVar now returns 2
In my previous example, $Position is an array.
I kind of understand how to write the code for arrays I'm just not sure what they are useful for. The bad part is I think this is probably one of the foundation stone that all of this is based off of and it irritates me that my head has not automatically wrapped it's self around it lol
[ external image ]
Running LU 1.4.7 + XM-O 1.0 + Quick Wings 1.0
Rise of Phanon DiD LUV
Wrath of the Hive DiD XM-O
Try my script: Quick Wings for better wing control in LU!

kaistern
Posts: 443
Joined: Mon, 30. Jun 14, 13:29
x3ap

Post by kaistern » Sat, 8. Nov 14, 11:00

kaistern wrote: Am I going to have to make a global script where I can store the flag? (what I mean is simpily a script that changes whenever you press the wing selection button, and then when a wing command is pressed it referancs that script to decide which wing is selected?
actually I don't think that would work... back to the drawing board
[ external image ]
Running LU 1.4.7 + XM-O 1.0 + Quick Wings 1.0
Rise of Phanon DiD LUV
Wrath of the Hive DiD XM-O
Try my script: Quick Wings for better wing control in LU!

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Sat, 8. Nov 14, 11:09

When I first start programming (array is a crucial notion in every language), I too didn't understand the use for arrays, so I think it's pretty common :)

Programming is the handling of data. You need some tools to do that properly. Modding X3 is a pretty good way to start learning that, because it gives you a purpose and a motivation.

Say you want to create a Pirate Base in multiple sectors.
You could do :

Code: Select all

$Station = create station: type={Pirates Pirate Base (DOCK_PIRATES)} owner=[Pirates] addto=[Argon Prime] x=$PosX y=$PosY z=$PosZ
$Station = create station: type={Pirates Pirate Base (DOCK_PIRATES)} owner=[Pirates] addto=[Home Of Light] x=$PosX y=$PosY z=$PosZ
$Station = create station: type={Pirates Pirate Base (DOCK_PIRATES)} owner=[Pirates] addto=[Power Circle] x=$PosX y=$PosY z=$PosZ
$Station = create station: type={Pirates Pirate Base (DOCK_PIRATES)} owner=[Pirates] addto=[Elena's Fortune] x=$PosX y=$PosY z=$PosZ
Or you could use an array and a loop (an other crucial tool) :

Code: Select all

dim $AllSectors = [Argon Prime], [Home Of Light], [Power Circle], [Elena's Fortune]

for each $Sector in array $AllSectors
  $Station = create station: type={Pirates Pirate Base (DOCK_PIRATES)} owner=[Pirates] addto=$Sector x=$PosX y=$PosY z=$PosZ
end
This code goes through each element of your array, assign them to the variable $Sector, then create the Pirate Base. "dim" is a macro in X-Studio that let you create arrays very easily. Having only four sectors is not very relevant, but if you imagine 200 of them (several commands return an array of sectors), you can see how convenient arrays are.


EDIT : The MSCI Handbook for X2 is not obsolete. There's a section for beginners in it.

kaistern
Posts: 443
Joined: Mon, 30. Jun 14, 13:29
x3ap

Post by kaistern » Sat, 8. Nov 14, 11:16

ok so in short the purpose of an array is to save time, and possible a LOT of time, as well as making the script easier to read. And waht I mean by this is that you could get to the same result by writing the code for each individual part of the array but it is easier to write an array.

Or simply put..... array=wing (of codes) ;)

added:to clairy id do not mean that array is only used for wings, but rather that array serve the same function for programming that wings serve in the game... to give the same order to multiple targets (or what ever your array is made of)

Added2:
EDIT : The MSCI Handbook for X2 is not obsolete. There's a section for beginners in it.
I have read this 2 or 3 times. It was very usefull but I feel like it could use improvement. For example it tells you how to make an array but not why to make an array. It tells you how to make an argument but not why to make an argument. It touches on what they are good for but it could go much more in depth, IMHO
[ external image ]
Running LU 1.4.7 + XM-O 1.0 + Quick Wings 1.0
Rise of Phanon DiD LUV
Wrath of the Hive DiD XM-O
Try my script: Quick Wings for better wing control in LU!

User avatar
Joubarbe
Posts: 4796
Joined: Tue, 31. Oct 06, 12:11
xr

Post by Joubarbe » Sat, 8. Nov 14, 11:26

Yep, again, I had the same reaction when I read my first coding books. The problem is that you must have a project in mind to understand it. When you'll start to code, you'll understand why all these things are important, after trying to make things your way and seeing that it doesn't work well :)

Post Reply

Return to “X³: Terran Conflict / Albion Prelude - Scripts and Modding”