Nexus Modding > Scripting
Scripting Issues
Arparso:
... although debug("1",s.this), Debug("2",dev) and Debug("----------------The devices are:", dev) all do the same, more or less ;)
Do you want to enable both devices at the same time? Then the following should suffice:
--- Code: ---SelectEx(s.device & s.owner=M.*ship* & (InSet(s.this,66)| InSet(s.this,42)),
EnableDevice(s.this, 1);
);
--- End code ---
You can leave out the s.owner=M.*ship* part, if you want to enable all such devices on all ships simultaneously or replace it with s.owner:race=#race_whoever, if you're going to enable all such devices only for ships of a specific race.
Mularac:
yes, I do want to enable them, but not when the devices are selected. That code is part of a nice 647 line machine that handles a way to fix a ship's devices (it's one mission exculsive, that's way I set the "ship" parameter in the SelectDevices as only one scene object.
That machine works in a similar way as your warfare mod does it (that's from where I took the idea) a series of dialogs appear, you select the device you want to fix, that goes to a specific rule where the device in question is selected and then a timer appears, and when that timer is done the device is "fixed" (enabled).
The mechanics are: each dialog is connected to their special rule, where the device is selected and the time is set. And then the state is change with this information:
--- Code: ---ChangeState(countdown, dev:=dev; E.time:=p.time);
--- End code ---
that is common to pretty much all devices, where dev is the device and e.time is the time that would take to repair it. In the state "countdown", I give a StartCountdown rule with the time in question and when that is done a rule appears that pretty much all it does is to enable "dev" via the enabledevice command, and then returns to the previous state, so I can't have them enable in the same rule.
As for what old dragon said: yeah, I know that, and the reason while all of them were the same was for the sake of testing what the variable would look like in an out the execlist. However, placing the "changestate" rule inside the execlist wouldn't work either, only one of the devices got fixed.
Well... since there's only one device on the list that actually needs two devices to be fixed I'm gonna have to go with 'Plan B'; a small "if" command in the last rule that would detect that if dev belongs to that devices set, then it must also enable the other device I needed.
The Old Dragon:
How about adding the selected devices into a seperate list via the 'AddItem' command? And using the dev variable to select a command that would 'ExecList' the selected devices?
So the first rule of the new state would be like...
--- Code: ---RULE event In
:action
ChooseFirst(
dev=1,
LocalEvent(RuleOne);
,
dev=2,
LocalEvent(*****************);
):
:end
END
RULE event RuleOne
:action
ExecList(1,
//script whatever to happen here.
);
:end
END
--- End code ---
From those local events you can then dictate what will happen. Is this any use?
Mularac:
I... don't think I understand you.
Here, I'll post a simplified version of my machine (not the 600 lines, as there's a lot of repetetive code I couldn't avoid, but it is still some good 200 lines... perhaps they'll help me make my point):
--- Code: ---Machine "Fixing_Devices"
State Setup
Rule event in
:action
something_is_inside:=1; //this is used to check if all the devices in a given set (military, non-military) are done or not.
if(m.first_time=0,
/*Here I divided the weapons, no use to show this...*/
m.first_time:=1;
LocalEvent(MainMenu);
);
:end
END
Rule event Selected
Condition E.ship=M.ac&m.Dialog_running!=1&Timer_on=0
:action
LocalEvent(mainmenu);
:end
END
Rule event MainMenu
:action
M.Dialog_running:=1;
ChooseFirst(
m.No_More_N_Devs = 1 & m.No_More_M_Devs = 1 & No_More_Devs = 0,
No_more_devs:=1;
Dialog("No_More_Devs",0,0); //this dialog is show in case there're no more devices to fix
, m.No_More_N_Devs = 1 & no_more_devs = 0,
Dialog("First_Choice_military",0,0); //this is the tree of non-military is all done
, m.No_More_M_Devs = 1 & no_more_devs = 0,
Dialog("First_Choice_no_military",0,0); //idem but with the military done
, m.No_More_N_Devs = 0 & m.No_More_M_Devs = 0,
Dialog("First_Choice",0,0); //when they're all incomplete.
);
:end
END
Rule event Cycle_normal
:action
m.military_cycle:=0;
ChooseFirst(
m.eng = 1 | m.eng_sec =1 & m.nav = 1 & m.sens = 1 & m.pgen = 1 & m.hyp = 0 & m.hyp_cycle = 0,
something_is_inside:=1;
Deletependingdialogs(1);
Dialog("fixing_hyp",0,0); //this is the ultimate goal, repair the hyperdrive, and to do so you have to fix all of the above (engine, nav, sensors and pgen)
M.Dialog_running:=1;
, m.eng = 0 & m.eng_cycle = 0,
something_is_inside:=1;
Deletependingdialogs(1);
Dialog("fixing_eng",0,0);
M.Dialog_running:=1;
/*...*/
, m.pgen = 0 & m.pgen_cycle = 0, //this is the part I'm interested in, the power generator
something_is_inside:=1;
Deletependingdialogs(1);
Dialog("fixing_pgen",0,0);
M.Dialog_running:=1;
/*...*/
, m.blank = 0, //in case the player didn't choose anything
Deletependingdialogs(1);
M.Dialog_running:=1;
if(something_is_inside=1,
Dialog("blank_choice",0,0);
,
Dialog("No_More_N_Devs",0,0);
m.No_More_N_Devs:=1;
);
);
:end
END
Rule event Cycle_military
:action
m.military_cycle:=1;
ChooseFirst(
/* Pretty much the same as above, but with weapons and weapons generators */
, m.blank = 0,
Deletependingdialogs(1);
M.Dialog_running:=1;
if(something_is_inside=1,
Dialog("blank_choice",0,0);
,
Dialog("No_More_M_Devs",0,0);
m.No_More_M_Devs:=1;
);
);
:end
END
Rule event Re_Start
:action
LocalEvent(blanc);
LocalEvent(MainMenu);
:end
END
Rule event Blanc
:action
something_is_inside:=1;
M.Dialog_running:=0;
m.eng_cycle:=0;
m.pgen_cycle:=0; //these are the cycle variables, and in here we set them back to 0, as the whole cycle is re-starting.
:end
END
/* and all of these are the output of the player choosing to fix these devices */
Rule event eng
:action
SelectDevices(1, m.ac, s.this:devtype=#eng_b304);
Execlist(1,dev:=s.this);
M.eng:=1;
Debug("e.dev is", e.dev);
ChangeState(countdown, dev:=dev; E.time:=110);
:end
END
Rule event eng_sec
:action
SelectDevices(1, m.ac, s.this:devtype=#eng_b304); //#eng_b304_sec);
Execlist(1, dev:=s.this);
m.eng_sec:=1;
ChangeState(countdown, dev:=dev; E.time:=55;);
:end
END
/*...*/
Rule event pgen ///this is the polemic rule, still not working...
:action
E.time:=250;
SelectDevices(1, m.ac, InSet(s.this,66)| InSet(s.this,42));
Execlist(1,
debug("1",s.this);
Debug("----------------The devices are:", s.this);
ChangeState(countdown, dev:=s.this; E.time:=p.time);
);
:end
END
/*this is the cycle part, the one that enables the rolling of the dialog-options. Basically this works this way, when a dialog is called in the "cycle_***" rule, three options appear: "fix it","next" and "nothing right now", the fix it relates to the above rules, the next to the ones below and the nothing right now to the "blanc" rule. */
/*...*/
Rule event eng_Cycle
:action
//this event means that player didn't choose to repair this device, so we must clear it from the cycle list:
m.eng_cycle:=1;
LocalEvent(Cycle_normal);
:end
END
Rule event eng_sec_cycle
:action
//this event means that player didn't choose to repair this device, so we must clear it from the cycle list:
m.eng_sec_cycle:=1;
LocalEvent(Cycle_normal);
:end
END
/*...*/
Rule event pgen_cycle
:action
//this event means that player didn't choose to repair this device, so we must clear it from the cycle list:
m.pgen_cycle:=1;
LocalEvent(Cycle_normal);
:end
END
Rule event Fix_cycle //this event is only fired if the dialog with the dialog with the options times out.
:action
if(m.military_cycle = 1,
Debug(m.military_cycle);
Delay(0,0.1,LocalEvent(cycle_military);,0);
,
Debug(m.military_cycle);
Delay(0,0.1,LocalEvent(cycle_normal);,0);
);
:end
END
END
State Countdown
Rule event in
:action
//in here we reset the cycle of all devices
M.Dialog_running:=0;
m.eng_cycle:=0;
/*...*/
m.pgen_cycle:=0;
/*...*/
StartCountDown(e.time, Repair);
m.fixing:=1;
Debug("dev is",dev);
:end
END
Rule event Repair
:action
Debug("event Repair", dev);
if(dev!=0 & engineering = 0,
EnableDevice(dev,1);
Debug("repairing", dev);
,
if( engineering = 1,
m.engineering:=1;
);
);
m.fixing:=0;
ChangeState(setup,0);
:end
END
END
END
--- End code ---
The Old Dragon:
I've had a tinker and sent you an email Mularac, fingers crossed it helps.
What I've done is add this line...
--- Code: ---AddItem(TBR,S.this);
--- End code ---
to the execlist section of the 'PGen' rule and set the 'dev' value of the same rule to 999. I also modified the 'Repair' rule to read...
--- Code: ---Rule event Repair
:action
Debug("event Repair", dev);
if(dev!=0 & engineering = 0 & dev!=999,
EnableDevice(dev,1);
Debug("repairing", dev);
,
if( engineering = 1,
m.engineering:=1;
);
);
If(dev=999 & engineering = 0,
ExecList(TBR,
EnableDevice(s.this,1);
Debug("repairing", s.this);
,
if( engineering = 1,
m.engineering:=1;
);
);
);
m.fixing:=0;
ChangeState(setup,0);
:end
END
--- End code ---
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version