Bernt Posted March 4, 2012 Report Share Posted March 4, 2012 Hello Scripters,I have a problem with this script, this script call the nearst car on the map.But i can only use this one time at the same point.If i want a second car on the emergency, then must i call this one on the another side of the map...//Version 1.2 ////Frei verwendbar, solang diese Kommentare erhalten bleiben ////und per PN oder E-Mail eine schriftliche Erlaubniss vorliegt ////Version 1.0 ////©Gerrit & Bernt van Dongen //const char IMG_ICON[] = "A1";const char IMG_CURSOR[] = "send";object Alarmambu : CommandScript{Alarmambu(){SetIcon(IMG_ICON);SetCursor(IMG_CURSOR);SetValidTargets(ACTOR_FLOOR | ACTOR_STREET);}bool CheckPossible(GameObject *Caller){return true;}bool CheckTarget(GameObject *Caller, Actor *Target, int childID){Person p(Caller);if (!Game::IsFreeplay())return false;if (Caller->GetID() == Target->GetID())return false;return true;}void PushActions(GameObject *Caller, Actor *Target, int ChildID){VehicleList vl_rtw1("ambu");VehicleList vl_rtw2("ambu2");VehicleList vl_rtw3("ambu3");Vehicle v_rtw1 = vl_rtw1.GetVehicle(0);Vehicle v_rtw2 = vl_rtw2.GetVehicle(0);Vehicle v_rtw3 = vl_rtw3.GetVehicle(0);Vector v_est = Game::GetCommandPos();float f_est_x = v_est.x; //x, y und z der ESTfloat f_est_y = v_est.y;float f_est_z = v_est.z;float f_rtw1d = v_rtw1.Distance(f_est_x, f_est_y, f_est_z); //distanzen jeden NEFs zur ESTfloat f_rtw2d = v_rtw2.Distance(f_est_x, f_est_y, f_est_z);float f_rtw3d = v_rtw3.Distance(f_est_x, f_est_y, f_est_z);if(v_rtw1.HasCommand("ich_bin_nicht_frei")) //Wenn ich nicht frei bin bin ich gaaaanz weit wegf_rtw1d = 99999.9;if(v_rtw2.HasCommand("ich_bin_nicht_frei"))f_rtw2d = 99999.9;if(v_rtw3.HasCommand("ich_bin_nicht_frei"))f_rtw3d = 99999.7;if(f_rtw1d < f_rtw2d && f_rtw1d < f_rtw3d)Game::ExecuteCommand("PCmdFPAlarmambu",Caller,Target);if(f_rtw2d < f_rtw1d && f_rtw2d < f_rtw3d)Game::ExecuteCommand("PCmdFPAlarmambu2",Caller,Target);if(f_rtw3d < f_rtw1d && f_rtw3d < f_rtw2d)Game::ExecuteCommand("PCmdFPAlarmambu3",Caller,Target);}};//////////////////////////////////////////////////////////////////////////////////////////////////////////// A-Rescue Mod - Freeplay Alarm RTW1 - Script v1.7 //// ************************************************ //// //// 1.0| PCmdFPAlarmRTW1 //// //// _____________________ //// Skript frei fuer alle ////////////////////////////////////////////////////////////////////////////////////////////////////////////const char IMG_ICON[] = "heal";const char IMG_CURSOR[] = "send";const char COMMANDABLE_TRUE[] = "DUMMYSetCommandableTrue";const char COMMANDABLE_FALSE[] = "DUMMYSetCommandableFalse";const char FREEFORALERT_TRUE[] = "DUMMYFPSetFreeForAlertTrue";const char FREEFORALERT_FALSE[] = "DUMMYFPSetFreeForAlertFalse";const char FREEFORALERT[] = "DUMMYFPIsFreeForAlert";const char INBASE_TRUE[] = "DUMMYFPSetInBaseTrue";const char INBASE_FALSE[] = "DUMMYFPSetInBaseFalse";const char INBASE[] = "DUMMYFPIsInBase";// 1.0object PCmdFPAlarmambu : CommandScript{PCmdFPAlarmambu(){SetIcon(IMG_ICON);SetCursor(IMG_CURSOR);SetValidTargets(ACTOR_FLOOR | ACTOR_STREET);}bool CheckPossible(GameObject *Caller){GameObjectList ol;GameObject *o;ol = Game::GetGameObjects("ambu");o = *ol.GetObject(0);Vehicle v(o);// nicht einsatzbereitif (!v.HasCommand(FREEFORALERT))return false;return true;}bool CheckTarget(GameObject *Caller, Actor *Target, int childID){Person p(Caller);if (!Game::IsFreeplay())return false;if (p.HasName("LeitstellePerson"))return true;if (Caller->GetID() == Target->GetID())return false;return false;}void PushActions(GameObject *Caller, Actor *Target, int childID){GameObjectList ol;GameObject *o;ActorList al;Actor spawnpoint;Vector spawnpos;Person p;float rot[9];float childRot[9];Vector tpos;PersonList pl;// fahrzeug findenol = Game::GetGameObjects("ambu");// fahrzeug anwaehleno = *ol.GetObject(0);Vehicle v(o);// ersatzfahrzeug?if (v.IsDestroyed()){// spaeter wird hier ersatzfahrzeug gefordertMission::PlayHint("RTW1 wurde zerstoert und steht deshalb nicht mehr zur Verfuegung.");return; // abbrechen}// frei fuer einsatz?if (!v.HasCommand(FREEFORALERT)){ Game::ExecuteCommand("PCmdFPAlarmambu2",Caller,Target);return;}else{// alarm-meldung ausgebenMission::PlayHint("A1 Inzet 21-101");// fahrzeug auf "im einsatz" setzenv.PushActionExecuteCommand(ACTION_NEWLIST, FREEFORALERT_FALSE, &v, 1, true);// wache-eingang findenal=Game::GetActors("ambue");if(al.GetNumActors() > 0){spawnpoint = *al.GetActor(0);spawnpos = spawnpoint.GetPosition();}else{Mission::PlayHint("Kann Rettungswache1-Eingang nicht finden!");return;}// besatzung erzeugen?bool ob_ra1 = false;bool ob_ra2 = false;pl = v.GetPassengers();for(int i=0; i < pl.GetNumPersons(); i++){//Mission::PlayHint(v.GetName());if (pl.GetPerson(i)->HasCommand("PcmdStabilize")){if(ob_ra1){ob_ra2 = true;//Mission::PlayHint("Test... Habe Sani 2 an Board");}else{ob_ra1 = true;//Mission::PlayHint("Test... Habe Sani 1 an Board");}}if (pl.GetPerson(i)->IsParamedicTeam()){ob_ra1 = true;ob_ra2 = true;//Mission::PlayHint("Test... Habe Sani-Team an Board");}}bool vinbase = false;if (v.HasCommand(INBASE)){vinbase = true;Mission::PlayHint("Ambulance 22-201 Status 1!");}// Sanitaeter 1 // besatzung erzeugen (1/2)if (!ob_ra1 && vinbase){p = Game::CreatePerson("mod:Prototypes/Persons/01Ambulance/sani.e4p","Verpleeg");p.GetRotation(rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]);Math::EulerToMatrix(0.f, 0.f, 0.f, childRot);Math::MultiplyMatrices(childRot, rot);p.SetRotation(childRot[0], childRot[1], childRot[2], childRot[3], childRot[4], childRot[5], childRot[6], childRot[7], childRot[8]);// " an wache-eingang spawnenGameObject *px(p);Game::FindFreePosition(px, spawnpos, 100);p.SetPosition(spawnpos);// " set commandable falsep.PushActionExecuteCommand(ACTION_NEWLIST, COMMANDABLE_FALSE, &p, 1, true);// " set commandable truep.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &p, 1, true);// " in fahrzeug einsteigenp.PushActionExecuteCommand(ACTION_APPEND, "entercar", o, 0, false);}// Sanitaeter 2 // besatzung erzeugen (2/2)if (!ob_ra2 && vinbase){p = Game::CreatePerson("mod:Prototypes/Persons/01Ambulance/sani.e4p","Verpleeg");p.GetRotation(rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]);Math::EulerToMatrix(0.f, 0.f, 0.f, childRot);Math::MultiplyMatrices(childRot, rot);p.SetRotation(childRot[0], childRot[1], childRot[2], childRot[3], childRot[4], childRot[5], childRot[6], childRot[7], childRot[8]);// " an wache-eingang spawnenGameObject *px(p);Game::FindFreePosition(px, spawnpos, 100);p.SetPosition(spawnpos);// " set commandable falsep.PushActionExecuteCommand(ACTION_NEWLIST, COMMANDABLE_FALSE, &p, 1, true);// " set commandable truep.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &p, 1, true);// " in fahrzeug einsteigenp.PushActionExecuteCommand(ACTION_APPEND, "entercar", o, 0, false);}//// besatzung einsatzbereit?bool ready = false;if (ob_ra1 && ob_ra2){ready= true;}// in basisif (vinbase){v.PushActionWait(ACTION_APPEND, 4.0); //Zeit bevor Tor aufgeht v.PushActionExecuteCommand(ACTION_APPEND, "OpenGate", &v, 1, true); v.PushActionWait(ACTION_APPEND, 3.0); //Zeit bis Fahrzeug fŠhrt nachdem das Tor offen ist//Mission::PlayHint(v.GetName());}// nicht in basis und nicht einsatzbereit?if (!ready && !vinbase)){Mission::PlayHint(v.GetName());Mission::PlayHint("Ohne zwei Sani. oder einem Sani.-Team, Einsatz nicht moeglich!");v.PushActionExecuteCommand(ACTION_APPEND, "VCmdFPGoHome", &v, 1, true);return;}// fahrzeug set commandable truev.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &v, 1, true);// bl und sosi anif(!v.HasCommand("DUMMYHasSiren")){v.PushActionExecuteCommand(ACTION_APPEND, "VCmdSiren", o, 0, false);}// verlaesst basisv.PushActionExecuteCommand(ACTION_APPEND, INBASE_FALSE, &v, 1, true);if (!vinbase){// warnleuchten ausv.PushActionExecuteCommand(ACTION_APPEND, "VCmdWarningLightsOff", &v, 1, true);// sl aus (beleuchtung)v.PushActionExecuteCommand(ACTION_APPEND, "VCmdSpecialLightsOff", &v, 1, true);}// losfahren zum einsatzorttpos = Game::GetCommandPos();v.PushActionMove(ACTION_APPEND, tpos);}}};// 1.0object PCmdFPAlarmambu2 : CommandScript{PCmdFPAlarmambu2(){SetIcon(IMG_ICON);SetCursor(IMG_CURSOR);SetValidTargets(ACTOR_FLOOR | ACTOR_STREET);}bool CheckPossible(GameObject *Caller){GameObjectList ol;GameObject *o;ol = Game::GetGameObjects("ambu2");o = *ol.GetObject(0);Vehicle v(o);// nicht einsatzbereitif (!v.HasCommand(FREEFORALERT))return false;return true;}bool CheckTarget(GameObject *Caller, Actor *Target, int childID){Person p(Caller);if (!Game::IsFreeplay())return false;if (p.HasName("LeitstellePerson"))return true;if (Caller->GetID() == Target->GetID())return false;return false;}void PushActions(GameObject *Caller, Actor *Target, int childID){GameObjectList ol;GameObject *o;ActorList al;Actor spawnpoint;Vector spawnpos;Person p;float rot[9];float childRot[9];Vector tpos;PersonList pl;// fahrzeug findenol = Game::GetGameObjects("ambu2");// fahrzeug anwaehleno = *ol.GetObject(0);Vehicle v(o);// ersatzfahrzeug?if (v.IsDestroyed()){// spaeter wird hier ersatzfahrzeug gefordertMission::PlayHint("RTW1 wurde zerstoert und steht deshalb nicht mehr zur Verfuegung.");return; // abbrechen}// frei fuer einsatz?if (!v.HasCommand(FREEFORALERT)){ Game::ExecuteCommand("PCmdFPAlarmambu3",Caller,Target);return;}else{// alarm-meldung ausgebenMission::PlayHint("A1 inzet 21-106");// fahrzeug auf "im einsatz" setzenv.PushActionExecuteCommand(ACTION_NEWLIST, FREEFORALERT_FALSE, &v, 1, true);// wache-eingang findenal=Game::GetActors("ambue");if(al.GetNumActors() > 0){spawnpoint = *al.GetActor(0);spawnpos = spawnpoint.GetPosition();}else{Mission::PlayHint("Kann Rettungswache1-Eingang nicht finden!");return;}// besatzung erzeugen?bool ob_ra1 = false;bool ob_ra2 = false;pl = v.GetPassengers();for(int i=0; i < pl.GetNumPersons(); i++){//Mission::PlayHint(v.GetName());if (pl.GetPerson(i)->HasCommand("PcmdStabilize")){if(ob_ra1){ob_ra2 = true;//Mission::PlayHint("Test... Habe Sani 2 an Board");}else{ob_ra1 = true;//Mission::PlayHint("Test... Habe Sani 1 an Board");}}if (pl.GetPerson(i)->IsParamedicTeam()){ob_ra1 = true;ob_ra2 = true;//Mission::PlayHint("Test... Habe Sani-Team an Board");}}bool vinbase = false;if (v.HasCommand(INBASE)){vinbase = true;//Mission::PlayHint("Test... Fahrzeug ist auf seinem Stellplatz");}// Sanitaeter 1 // besatzung erzeugen (1/2)if (!ob_ra1 && vinbase){p = Game::CreatePerson("mod:Prototypes/Persons/01Ambulance/sani.e4p","Verpleeg");p.GetRotation(rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]);Math::EulerToMatrix(0.f, 0.f, 0.f, childRot);Math::MultiplyMatrices(childRot, rot);p.SetRotation(childRot[0], childRot[1], childRot[2], childRot[3], childRot[4], childRot[5], childRot[6], childRot[7], childRot[8]);// " an wache-eingang spawnenGameObject *px(p);Game::FindFreePosition(px, spawnpos, 100);p.SetPosition(spawnpos);// " set commandable falsep.PushActionExecuteCommand(ACTION_NEWLIST, COMMANDABLE_FALSE, &p, 1, true);// " set commandable truep.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &p, 1, true);// " in fahrzeug einsteigenp.PushActionExecuteCommand(ACTION_APPEND, "entercar", o, 0, false);}// Sanitaeter 2 // besatzung erzeugen (2/2)if (!ob_ra2 && vinbase){p = Game::CreatePerson("mod:Prototypes/Persons/01Ambulance/sani.e4p","Verpleeg");p.GetRotation(rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]);Math::EulerToMatrix(0.f, 0.f, 0.f, childRot);Math::MultiplyMatrices(childRot, rot);p.SetRotation(childRot[0], childRot[1], childRot[2], childRot[3], childRot[4], childRot[5], childRot[6], childRot[7], childRot[8]);// " an wache-eingang spawnenGameObject *px(p);Game::FindFreePosition(px, spawnpos, 100);p.SetPosition(spawnpos);// " set commandable falsep.PushActionExecuteCommand(ACTION_NEWLIST, COMMANDABLE_FALSE, &p, 1, true);// " set commandable truep.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &p, 1, true);// " in fahrzeug einsteigenp.PushActionExecuteCommand(ACTION_APPEND, "entercar", o, 0, false);}//// besatzung einsatzbereit?bool ready = false;if (ob_ra1 && ob_ra2){ready= true;}// in basisif (vinbase){v.PushActionWait(ACTION_APPEND, 4.0); //Zeit bevor Tor aufgeht v.PushActionExecuteCommand(ACTION_APPEND, "OpenGate", &v, 1, true); v.PushActionWait(ACTION_APPEND, 3.0); //Zeit bis Fahrzeug fŠhrt nachdem das Tor offen ist//Mission::PlayHint(v.GetName());}// nicht in basis und nicht einsatzbereit?if (!ready && !vinbase)){Mission::PlayHint(v.GetName());Mission::PlayHint("Ohne zwei Sani. oder einem Sani.-Team, Einsatz nicht moeglich!");v.PushActionExecuteCommand(ACTION_APPEND, "VCmdFPGoHome", &v, 1, true);return;}// fahrzeug set commandable truev.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &v, 1, true);// bl und sosi anif(!v.HasCommand("DUMMYHasSiren")){v.PushActionExecuteCommand(ACTION_APPEND, "VCmdSiren", o, 0, false);}// verlaesst basisv.PushActionExecuteCommand(ACTION_APPEND, INBASE_FALSE, &v, 1, true);if (!vinbase){// warnleuchten ausv.PushActionExecuteCommand(ACTION_APPEND, "VCmdWarningLightsOff", &v, 1, true);// sl aus (beleuchtung)v.PushActionExecuteCommand(ACTION_APPEND, "VCmdSpecialLightsOff", &v, 1, true);}// losfahren zum einsatzorttpos = Game::GetCommandPos();v.PushActionMove(ACTION_APPEND, tpos);}}};// 1.0object PCmdFPAlarmambu3 : CommandScript{PCmdFPAlarmambu3(){SetIcon(IMG_ICON);SetCursor(IMG_CURSOR);SetValidTargets(ACTOR_FLOOR | ACTOR_STREET);}bool CheckPossible(GameObject *Caller){GameObjectList ol;GameObject *o;ol = Game::GetGameObjects("ambu3");o = *ol.GetObject(0);Vehicle v(o);// nicht einsatzbereitif (!v.HasCommand(FREEFORALERT))return false;return true;}bool CheckTarget(GameObject *Caller, Actor *Target, int childID){Person p(Caller);if (!Game::IsFreeplay())return false;if (p.HasName("LeitstellePerson"))return true;if (Caller->GetID() == Target->GetID())return false;return false;}void PushActions(GameObject *Caller, Actor *Target, int childID){GameObjectList ol;GameObject *o;ActorList al;Actor spawnpoint;Vector spawnpos;Person p;float rot[9];float childRot[9];Vector tpos;PersonList pl;// fahrzeug findenol = Game::GetGameObjects("ambu3");// fahrzeug anwaehleno = *ol.GetObject(0);Vehicle v(o);// ersatzfahrzeug?if (v.IsDestroyed()){// spaeter wird hier ersatzfahrzeug gefordertMission::PlayHint("RTW1 wurde zerstoert und steht deshalb nicht mehr zur Verfuegung.");return; // abbrechen}// frei fuer einsatz?if (!v.HasCommand(FREEFORALERT)){ Game::ExecuteCommand("PCmdFPAlarmambu5",Caller,Target);return;}else{// alarm-meldung ausgebenMission::PlayHint("A1 inzet 21-107");// fahrzeug auf "im einsatz" setzenv.PushActionExecuteCommand(ACTION_NEWLIST, FREEFORALERT_FALSE, &v, 1, true);// wache-eingang findenal=Game::GetActors("ambue");if(al.GetNumActors() > 0){spawnpoint = *al.GetActor(0);spawnpos = spawnpoint.GetPosition();}else{Mission::PlayHint("Kann Rettungswache1-Eingang nicht finden!");return;}// besatzung erzeugen?bool ob_ra1 = false;bool ob_ra2 = false;pl = v.GetPassengers();for(int i=0; i < pl.GetNumPersons(); i++){//Mission::PlayHint(v.GetName());if (pl.GetPerson(i)->HasCommand("PcmdStabilize")){if(ob_ra1){ob_ra2 = true;//Mission::PlayHint("Test... Habe Sani 2 an Board");}else{ob_ra1 = true;//Mission::PlayHint("Test... Habe Sani 1 an Board");}}if (pl.GetPerson(i)->IsParamedicTeam()){ob_ra1 = true;ob_ra2 = true;//Mission::PlayHint("Test... Habe Sani-Team an Board");}}bool vinbase = false;if (v.HasCommand(INBASE)){vinbase = true;//Mission::PlayHint("Test... Fahrzeug ist auf seinem Stellplatz");}// Sanitaeter 1 // besatzung erzeugen (1/2)if (!ob_ra1 && vinbase){p = Game::CreatePerson("mod:Prototypes/Persons/01Ambulance/sani.e4p","Verpleeg");p.GetRotation(rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]);Math::EulerToMatrix(0.f, 0.f, 0.f, childRot);Math::MultiplyMatrices(childRot, rot);p.SetRotation(childRot[0], childRot[1], childRot[2], childRot[3], childRot[4], childRot[5], childRot[6], childRot[7], childRot[8]);// " an wache-eingang spawnenGameObject *px(p);Game::FindFreePosition(px, spawnpos, 100);p.SetPosition(spawnpos);// " set commandable falsep.PushActionExecuteCommand(ACTION_NEWLIST, COMMANDABLE_FALSE, &p, 1, true);// " set commandable truep.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &p, 1, true);// " in fahrzeug einsteigenp.PushActionExecuteCommand(ACTION_APPEND, "entercar", o, 0, false);}// Sanitaeter 2 // besatzung erzeugen (2/2)if (!ob_ra2 && vinbase){p = Game::CreatePerson("mod:Prototypes/Persons/01Ambulance/sani.e4p","Verpleeg");p.GetRotation(rot[0], rot[1], rot[2], rot[3], rot[4], rot[5], rot[6], rot[7], rot[8]);Math::EulerToMatrix(0.f, 0.f, 0.f, childRot);Math::MultiplyMatrices(childRot, rot);p.SetRotation(childRot[0], childRot[1], childRot[2], childRot[3], childRot[4], childRot[5], childRot[6], childRot[7], childRot[8]);// " an wache-eingang spawnenGameObject *px(p);Game::FindFreePosition(px, spawnpos, 100);p.SetPosition(spawnpos);// " set commandable falsep.PushActionExecuteCommand(ACTION_NEWLIST, COMMANDABLE_FALSE, &p, 1, true);// " set commandable truep.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &p, 1, true);// " in fahrzeug einsteigenp.PushActionExecuteCommand(ACTION_APPEND, "entercar", o, 0, false);}//// besatzung einsatzbereit?bool ready = false;if (ob_ra1 && ob_ra2){ready= true;}// in basisif (vinbase){v.PushActionWait(ACTION_APPEND, 4.0); //Zeit bevor Tor aufgeht v.PushActionExecuteCommand(ACTION_APPEND, "OpenGate", &v, 1, true); v.PushActionWait(ACTION_APPEND, 3.0); //Zeit bis Fahrzeug fŠhrt nachdem das Tor offen ist//Mission::PlayHint(v.GetName());}// nicht in basis und nicht einsatzbereit?if (!ready && !vinbase)){Mission::PlayHint(v.GetName());Mission::PlayHint("Ohne zwei Sani. oder einem Sani.-Team, Einsatz nicht moeglich!");v.PushActionExecuteCommand(ACTION_APPEND, "VCmdFPGoHome", &v, 1, true);return;}// fahrzeug set commandable truev.PushActionExecuteCommand(ACTION_APPEND, COMMANDABLE_TRUE, &v, 1, true);// bl und sosi anif(!v.HasCommand("DUMMYHasSiren")){v.PushActionExecuteCommand(ACTION_APPEND, "VCmdSiren", o, 0, false);}// verlaesst basisv.PushActionExecuteCommand(ACTION_APPEND, INBASE_FALSE, &v, 1, true);if (!vinbase){// warnleuchten ausv.PushActionExecuteCommand(ACTION_APPEND, "VCmdWarningLightsOff", &v, 1, true);// sl aus (beleuchtung)v.PushActionExecuteCommand(ACTION_APPEND, "VCmdSpecialLightsOff", &v, 1, true);}// losfahren zum einsatzorttpos = Game::GetCommandPos();v.PushActionMove(ACTION_APPEND, tpos);}}};Thx,Bernt Quote Link to comment Share on other sites More sharing options...