CONNEXION
  • RetourJeux
    • Sorties
    • Hit Parade
    • Les + populaires
    • Les + attendus
    • Soluces
    • Tous les Jeux
    • Gaming
  • RetourActu Gaming
    • News
    • Astuces
    • Tests
    • Previews
    • Toute l'actu gaming
  • RetourBons plans
    • Bons plans
    • Bons plans Smartphone
    • Bons plans Hardware
    • Bons plans Image et Son
    • Bons plans Amazon
    • Bons plans Cdiscount
    • Bons plans Decathlon
    • Bons plans Fnac
    • Tous les Bons plans
  • RetourJVTech
    • Actus High-Tech
    • Intelligence Artificielle
    • Smartphones
    • Mobilité urbaine
    • Hardware
    • Image et son
    • Tutoriels
    • Tests produits High-Tech
    • Guides d'achat High-Tech
    • JVTech
  • RetourCulture
    • Actus Culture
    • Culture
  • RetourVidéos
    • A la une
    • Gaming Live
    • Vidéos Tests
    • Vidéos Previews
    • Gameplay
    • Trailers
    • Chroniques
    • Replay Web TV
    • Toutes les vidéos
  • RetourForums
    • Hardware PC
    • PS5
    • Switch 2
    • Xbox Series
    • Switch
    • Pokemon pocket
    • FC 25 Ultimate Team
    • League of Legends
    • Tous les Forums
  • PC
  • PS5
  • Xbox Series
  • Switch 2
  • PS4
  • One
  • Switch
  • iOS
  • Android
  • MMO
  • RPG
  • FPS
En ce moment Genshin Impact Valhalla Breath of the wild Animal Crossing GTA 5 Red dead 2
Forum
  • Accueil
  • Actus
  • Tests
  • Vidéos
  • Images
  • Soluces
  • Forum
Liste des sujets

Docking Script

hades-wars
hades-wars
Niveau 10
27 février 2015 à 00:11:02

salut a tous.

je vous présente un petit script qui facilite le docking :

steam : http://steamcommunity.com/sharedfiles/filedetails/?id=399326460
démo : https://www.youtube.com/watch?v=z2bTxA88vx8
installation: https://www.youtube.com/watch?v=Gvbu2UFhT_k

principe : ce script permet de géré facilement le docking de vaisseaux a des station / mother ship. dans le cas de la démo c est un drone soudeur. la première exécution active l antenne. la 2eme déconnecte le drone et active les propulseur. exécuter de nouveau le script permet d activer le connecteur. si celui ci est activer et qu il ne peut pas ce connecter a un vaisseau. si au contraire il peut ce connecter le connecteur est verrouiller et l antenne et propulseur son couper.

aucun groupe n est requis. seul le nom du bloque qui exécute le script doit être spécifique. ce nom lui est donner a l installation.

installation: (première exécution)

le vaisseau ne doit pas être connecté à un autre.
à l'installation du script on doit lui donner un ID Unique.
à la première exécution le bloc de programmation va être renommé. Ne pas le modifier ce nom par la suite.

code:

void Main()
{
//////////////////////////////////////////////////////////////////////////////////////////////
//******************************************************************************************//
int id_Drone = 0; //<==== Ne peux pas etre = a 0 et doit etre unique !!!!!//
//******************************************************************************************//
//////////////////////////////////////////////////////////////////////////////////////////////

string debug = "";
string info_Grid = ""; // info de la grille du vaissaux

bool is_connected = false; // vrais si le vaissaux est connecter a un autre.

if (id_Drone == 0)
throw new Exception("l'ID du drone ne peux etre 0. merci de mettre une ID unique");

//on cherche le prog de prog pour recuperer l id de la grid.
List<IMyTerminalBlock> liste_blocks = Get_Block_Programmable(id_Drone);

if (!(liste_blocks.Count == 1 && liste_blocks[0].CustomName == "IA Docking [N°" + id_Drone + "]"))
{
throw new Exception("Block IA non trouver,executez le script sans etre connecter un vaissaux");
}
else
{
// on a trouver le block de prog. on recuperer les information de grid pour ne toucher que les equipement du vaissaux.
info_Grid = liste_blocks[0].CubeGrid + "";

// recherche de l antenne pour savoir si elle est connecter.

IMyRadioAntenna ant = null;

liste_blocks = Get_Liste_Antenne();

for (int cpt = 0; cpt < liste_blocks.Count; cpt++)
{
if (liste_blocks[cpt].CubeGrid + "" == info_Grid)
{
ant = liste_blocks[cpt] as IMyRadioAntenna;

}
}

if (!ant.IsWorking) // si l antenne n est pas allumer on l active.
{
ant.GetActionWithName("OnOff_On").Apply(ant);
}
else // si l antenne est allumer on regarde pour executer une maneuvre de docking
{

// recherche du connecteur

liste_blocks = Get_Liste_Connecteur();

IMyShipConnector connec = null;

bool trouver = false;

for (int cpt = 0; cpt < liste_blocks.Count; cpt++)
{
if (liste_blocks[cpt].CubeGrid + "" == info_Grid)
{
trouver = true;
connec = liste_blocks[cpt] as IMyShipConnector;
}
else
{
is_connected = true;

if (trouver)
{
break;
}
}
}

if (connec == null) // si le connecteur n'a pas ete trouver
{
throw new Exception("le connecteur du vaissaux n a pas ete trouver");
}
else
{

if (connec.IsWorking && is_connected) // si le block est allimenter et connecter a un autre vaissaux
{
// activation des propulsseur
this.Activation_Propulsseur(info_Grid);

// activation de la camera
this.Activation_Camera_Avant(info_Grid);

// deconnection du vaissaux et extinction du connecteur
connec.GetActionWithName("SwitchLock").Apply(connec);
connec.GetActionWithName("OnOff_Off").Apply(connec);

}
else if (connec.IsWorking && connec.IsLocked && !is_connected) // si le drone peut ce connecter mais ne l ai pas encore
{
// deactivation de l antenne
this.Deactivation_Antenne(info_Grid);
// desactivation des propulsseur
this.Deactivation_Propulsseur(info_Grid);
// connection aux vaissaux
connec.GetActionWithName("SwitchLock").Apply(connec);
}
else if (!connec.IsWorking) // si le connecteur n est pas allimenter
{
connec.GetActionWithName("OnOff_On").Apply(connec);
}
else // si le connecteur est allimenter mais qu on ne peux pas ce connecter
{
connec.GetActionWithName("OnOff_Off").Apply(connec);
}
}
}
}

if (debug != "")
Set_debug(debug);

}

void Set_Block_Prog(int Id) // initialisation du vaissaux par changement de nom du block de prog.
{

List<IMyTerminalBlock> liste_Conn = Get_Liste_Block_Programmable();

if (liste_Conn.Count == 1)
{
Renam_Block(liste_Conn[0], "IA Docking [N°" + Id + "]");
}

}

void Activation_Antenne(string Info_Grid)
{
IMyRadioAntenna ant = null;

List<IMyTerminalBlock> liste_blocks = Get_Liste_Antenne();

for (int cpt = 0; cpt < liste_blocks.Count; cpt++)
{
if (liste_blocks[cpt].CubeGrid + "" == Info_Grid)
{
ant = liste_blocks[cpt] as IMyRadioAntenna;
ant.GetActionWithName("OnOff_On").Apply(ant);
}
}
}
void Deactivation_Antenne(string Info_Grid)
{
List<IMyTerminalBlock> liste_blocks = Get_Liste_Antenne();

IMyRadioAntenna ant = null;

for (int cpt = 0; cpt < liste_blocks.Count; cpt++)
{

if (liste_blocks[cpt].CubeGrid + "" == Info_Grid)
{
ant = liste_blocks[cpt] as IMyRadioAntenna;
ant.GetActionWithName("OnOff_Off").Apply(ant);
}
}
}

void Activation_Camera_Avant(string Info_Grid) // desactiver pour bug
{
//IMyCameraBlock cam = null;

//List<IMyTerminalBlock> liste_blocks = Get_Liste_Camera();

//for (int cpt = 0; cpt < liste_blocks.Count; cpt++)
//{
// if (liste_blocks[cpt].CubeGrid + "" == Info_Grid)
// {
// cam = liste_blocks[cpt] as IMyCameraBlock;

// if (cam.CustomName.Contains("AV"))
// {
// cam.GetActionWithName("View").Apply(cam);
// break;
// }
// }
//}
}

void Activation_Propulsseur(string Info_Grid)
{
IMyThrust propu = null;

List<IMyTerminalBlock> liste_blocks = Get_Liste_Propulsseur();

for (int cpt = 0; cpt < liste_blocks.Count; cpt++)
{
if (liste_blocks[cpt].CubeGrid + "" == Info_Grid)
{
propu = liste_blocks[cpt] as IMyThrust;
propu.GetActionWithName("OnOff_On").Apply(propu);
}
}
}
void Deactivation_Propulsseur(string Info_Grid)
{
IMyThrust propu = null;

List<IMyTerminalBlock> liste_blocks = Get_Liste_Propulsseur();

for (int cpt = 0; cpt < liste_blocks.Count; cpt++)
{
if (liste_blocks[cpt].CubeGrid + "" == Info_Grid)
{
propu = liste_blocks[cpt] as IMyThrust;
propu.GetActionWithName("OnOff_Off").Apply(propu);
}
}
}

List<IMyTerminalBlock> Get_Liste_Connecteur()
{
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyShipConnector>(blocks);
return blocks;
}
List<IMyTerminalBlock> Get_Liste_Antenne()
{
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(blocks);
return blocks;
}
List<IMyTerminalBlock> Get_Liste_Propulsseur()
{
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyThrust>(blocks);
return blocks;
}
List<IMyTerminalBlock> Get_Liste_Camera()
{
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyCameraBlock>(blocks);
return blocks;
}
List<IMyTerminalBlock> Get_Liste_Block_Programmable()
{
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyProgrammableBlock>(blocks);
return blocks;
}
List<IMyTerminalBlock> Get_Block_Programmable(int id)
{
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.SearchBlocksOfName("IA Docking [N°" + id + "]", blocks); // recherche du block de prog

if (blocks.Count == 0) // si le block de prog n a pas etre trouver on tante d inisatiliser le vaissaux.
{
this.Set_Block_Prog(id);
GridTerminalSystem.SearchBlocksOfName("IA Docking [N°" + id + "]", blocks); // on cherche si un block de prog a ete ini
}

return blocks;
}

void Set_debug(string texte)
{
List<IMyTerminalBlock> blocks = new List<IMyTerminalBlock>();
GridTerminalSystem.GetBlocksOfType<IMyRadioAntenna>(blocks);
Renam_Block(blocks[0], "IA debug " + texte);
}
void Renam_Block(IMyTerminalBlock Block, string name)
{
Block.SetCustomName(name);
}

si vous avez des question/ suggestion sur le fonctionnement du script n hésiter pas.
ou des question sur du code en général. je pourrais p-t vous aider.