Jump to content
MCERT1

Limiting the number of units available in the battalon chief script

Recommended Posts

Hi all,

I'm working on trying to get the battalion chief commands, so that he can only call one truck from off the map. I've been trying to set limits on the script, but everything I try doesn't work. Either the command doesn't let him create the first vehicle, or lets him create an infinite amount.

Here's my current version;


object PcmdCallUSARSquad : CommandScript
{
PcmdCallUSARSquad()
{
SetIcon("callusarsquad");
SetCursor("callassistance");
SetValidTargets(ACTOR_FLOOR | ACTOR_VIRTUAL);
SetDeselectCaller(false);
SetSelfClickActivation(true);
SetHighlightingEnabled(false);
SetGroupID(CGROUP_GETEQUIPMENT);
SetGroupLeader(true);
}
bool CheckPossible(GameObject *Caller)
{
GameObjectList SelectPer = Game::GetSelectedGameObjects();
if (SelectPer.GetNumObjects() != 1)
return false;
Person p(Caller);
if(p.IsValid() && (p.IsLinkedWithPerson() || p.IsCarryingPerson() || p.IsEquipped() || p.IsPulling() || p.GetFirehoseID()!=0 || p.GetEnteredCarID() != -1))
return false;
if (p.IsCurrentAction("EActionTreatPerson"))
return false;
if (!Caller->IsValid() || Caller->GetType() != ACTOR_PERSON)
return false;
return true;
}
bool CheckTarget(GameObject *Caller, Actor *Target, int childID)
{
if(!Caller->IsValid() || Caller->GetID() == Target->GetID())
return false;
if (Caller->GetType() != ACTOR_PERSON)
return false;
Person p(Caller);
if(p.IsValid() && (p.IsLinkedWithPerson() || p.IsCarryingPerson() || p.IsEquipped() || p.IsPulling() || p.GetFirehoseID()!=0 || p.GetEnteredCarID() != -1))
return false;
if (p.IsCurrentAction("EActionTreatPerson"))
return false;
return true;
}
void PushActions(GameObject *Caller, Actor *Target, int ChildID)
{
Vector CmdPos = Game::GetCommandPos();
Caller->PushActionTurnTo(ACTION_NEWLIST, CmdPos);
Caller->PushActionSwitchAnim(ACTION_APPEND, "talkmike");
Caller->PushActionWait(ACTION_APPEND, 3.5f);
Caller->PushActionSwitchAnim(ACTION_APPEND, "idle");
if(StrCompare(Caller->GetPrototypeFileName(), OBJ_BATTALION_CHIEF) == 0)
Audio::PlaySample3D(SND_BATUSAR, Caller->GetPosition());
else if(StrCompare(Caller->GetPrototypeFileName(), OBJ_EMS_CAPTAIN) == 0)
Audio::PlaySample3D(SND_EMSUSAR, Caller->GetPosition());
Vehicle *theCar = NULL;
float bestCar = 0.;
VehicleList patrolCars(VT_FIREFIGHTERS_RW, VT_FIREFIGHTERS_RW);
for (int i = 0; i < patrolCars.GetNumVehicles(); i++)
{
Vehicle *aCar = patrolCars.GetVehicle(i);
if (StrCompare(aCar->GetPrototypeFileName(), PROTO_USAR) == 0 && aCar->GetPlayerMP() == Caller->GetPlayerMP() && !aCar->HasCommand(DUMMY_VCALLED) && (aCar->HasCommand(CMD_STANDBY_OFF) || aCar->IsCollidingWithVirtualObject(VO_SQUAD01)))
{
float distCurrCar = Math::dist(CmdPos.x, CmdPos.y, aCar->GetPosition().x, aCar->GetPosition().y);
if (distCurrCar < bestCar || bestCar == 0.)
{
theCar = aCar;
bestCar = distCurrCar;
}
}
}
if (theCar)
{
bool VehicleCalled = false;
if (theCar->HasCommand(CMD_STANDBY_OFF))
{
theCar->PushActionWait(ACTION_NEWLIST, 0.3f);
theCar->PushActionMove(ACTION_APPEND, CmdPos);
if (!theCar->HasCommand(DUMMY_HASSIREN) && theCar->HasCommand(CMD_AUTOSIREN_OFF) && !Input::LShiftPressed() && !Input::RShiftPressed())
Game::ExecuteCommand(CMD_SIREN, theCar, theCar);
if (theCar->HasCommand(CMD_STANDBY_OFF))
{
theCar->RemoveCommand(CMD_STANDBY_OFF);
theCar->AssignCommand(CMD_STANDBY_ON);
}
if (theCar->HasCommand(CMD_WARNINGLIGHTS_OFF))
{
theCar->EnableBlinker(BLT_NONE);
theCar->RemoveCommand(CMD_WARNINGLIGHTS_OFF);
theCar->AssignCommand(CMD_WARNINGLIGHTS_ON);
}
if (theCar->HasCommand(CMD_FLOODLIGHTS_OFF))
{
theCar->EnableSpecialLights(false);
theCar->RemoveCommand(CMD_FLOODLIGHTS_OFF);
theCar->AssignCommand(CMD_FLOODLIGHTS_ON);
}
Mission::PlayHint(HINT_DISPATCHED);
return;
}
else if (theCar->IsCollidingWithVirtualObject(VO_SQUAD01))
{
GameObjectList ppc;
Game::CollectObstaclesOnVirtualObject(VO_USAR, ppc, ACTOR_VEHICLE);
for (int i = 0; i < ppc.GetNumObjects(); i++)
{
Vehicle v = ppc.GetObject(i);
if (!v.HasCommand(DUMMY_VCALLED))
{
v.AssignCommand(DUMMY_VCALLED);
VehicleCalled = true;
}
}
}
if (VehicleCalled)
{
if (v.IsBlueLightEnabled() && (Input::LShiftPressed() || Input::RShiftPressed()))
v.EnableBlueLights(false);
else if (!v.IsBlueLightEnabled() && !Input::LShiftPressed() && !Input::RShiftPressed())
v.EnableBlueLights(true);
GameObjectList gate02a = Game::GetGameObjects(OBJ_GATE02A);
for(int i=0; i < gate02a.GetNumObjects(); i++)
GameObject *gate = gate02a.GetObject(i);
PersonList passengers = v.GetPassengers();
if (passengers.GetNumPersons() == 0)
{
v.PushActionExecuteCommand(ACTION_NEWLIST, DUMMY_CALLCREW, Caller, 6, false);
v.PushActionExecuteCommand(ACTION_APPEND, DUMMY_CALLCREW, Caller, 6, false);
v.PushActionWait(ACTION_APPEND, 11.f);
}
if (gate->GetUserData() == 0)
{
v.PushActionExecuteCommand(ACTION_APPEND, DUMMY_GATES, Caller, 5, false);
Vector Move = v.GetPosition();
float r[9];
float childr[9];
v.GetRotation(r[0], r[1], r[2], r[3], r[4], r[5], r[6], r[7], r[8]);
float dx = 750.f, dy = 0.f, dz = 0.f;
Math::RotateVector(dx, dy, dz, r);
Math::EulerToMatrix(0.0f, 0.f, 0.f, childr);
Math::MultiplyMatrices(childr, r);
Move = Move + Vector(dx, dy, 0);
v.PushActionWait(ACTION_APPEND, 1.2f);
if (!v.HasCommand(DUMMY_HASSIREN) && v.HasCommand(CMD_AUTOSIREN_OFF) && !Input::LShiftPressed() && !Input::RShiftPressed())
v.PushActionExecuteCommand(ACTION_APPEND, CMD_SIREN, Caller, 0, false);
v.PushActionMove(ACTION_APPEND, Move);
v.PushActionExecuteCommand(ACTION_APPEND, DUMMY_GATES, Caller, 5, false);
v.PushActionExecuteCommand(ACTION_APPEND, DUMMY_VCALLED, Caller, 0, false);
v.PushActionMove(ACTION_APPEND, CmdPos);
} else
{
if (!v.HasCommand(DUMMY_HASSIREN) && v.HasCommand(CMD_AUTOSIREN_OFF) && !Input::LShiftPressed() && !Input::RShiftPressed())
v.PushActionExecuteCommand(ACTION_APPEND, CMD_SIREN, Caller, 0, false);
v.PushActionExecuteCommand(ACTION_APPEND, DUMMY_VCALLED, Caller, 0, false);
v.PushActionMove(ACTION_APPEND, CmdPos);
}
if (v.HasCommand(CMD_STANDBY_OFF))
{
v.RemoveCommand(CMD_STANDBY_OFF);
v.AssignCommand(CMD_STANDBY_ON);
}
if (v.HasCommand(CMD_WARNINGLIGHTS_OFF))
{
v.EnableBlinker(BLT_NONE);
v.RemoveCommand(CMD_WARNINGLIGHTS_OFF);
v.AssignCommand(CMD_WARNINGLIGHTS_ON);
}
if (v.HasCommand(CMD_FLOODLIGHTS_OFF))
{
v.EnableSpecialLights(false);
v.RemoveCommand(CMD_FLOODLIGHTS_OFF);
v.AssignCommand(CMD_FLOODLIGHTS_ON);
}
Mission::PlayHint(HINT_DISPATCHED);
return;
}
}
Vector Spawn;
Vector Rotate;
ActorList l1 = Game::GetActors(VO_SPAWN_ALL);
ActorList l2 = Game::GetActors(VO_SPAWN_FD);
ActorList l3 = Game::GetActors(VO_SPAWN_ALLR);
ActorList l4 = Game::GetActors(VO_SPAWN_FDR);
ActorList l5 = Game::GetActors(PROTO_USAR);
if (l5.GetNumActors()> 0)
{
Mission::PlayHint(HINT_NOUSAR);
return;
}
else if(l1.GetNumActors() > 0)
{
Spawn = l1.GetActor(0)->GetPosition();
Rotate = l3.GetActor(0)->GetPosition();
}
else if(l2.GetNumActors() > 0)
{
Spawn = l2.GetActor(0)->GetPosition();
Rotate = l4.GetActor(0)->GetPosition();
}
else
{
Mission::PlayHint(HINT_NOUSAR);
return;
}
System::Log("Buy USAR squad");
int Money = Mission::GetMoneyLeft();
if (Money <= 3500)
{
Mission::PlayHint(HINT_NOUSAR);
return;
}
int NewMoney = Money - 3500;
Mission::SetMoney(NewMoney);
Vehicle n;
Person p1;
Person p2;
n = Game::CreateVehicle(PROTO_USAR, UNNAMED);
n.SetSpeed(9.0f);
p1 = Game::CreatePerson(OBJ_USARFF, UNNAMED);
p2 = Game::CreatePerson(OBJ_USARFF, UNNAMED);
n.SetPlayerMP(Caller->GetPlayerMP());
p1.SetPlayerMP(Caller->GetPlayerMP());
p2.SetPlayerMP(Caller->GetPlayerMP());
p1.SetUpgradeLevel(3);
p2.SetUpgradeLevel(3);
n.SetMaxPassengers(4);
n.SetMaxTransports(0);
n.AddPassenger(&p1);
n.AddPassenger(&p2);
n.SetPosition(Spawn);
n.UpdatePlacement();
n.Hide();
n.PushActionTurnTo(ACTION_NEWLIST, Rotate);
n.PushActionWait(ACTION_APPEND, 2.5f);
n.PushActionShowHide(ACTION_APPEND, false);
n.PushActionMove(ACTION_APPEND, CmdPos);
if (Game::IsMission())
n.RemoveCommand("VcmdToFireStation");
if (!n.HasCommand(DUMMY_HASSIREN) && n.HasCommand(CMD_AUTOSIREN_OFF) && !Input::LShiftPressed() && !Input::RShiftPressed())
Game::ExecuteCommand(CMD_SIREN, &n, &n);
Mission::PlayHint(HINT_USARBOUGHT);
}
};

No matter what I do, the script doesn't work. i know that I could change the map boundary and add VO's, but I'd rather not.

Link to comment
Share on other sites

It's been several months since I started this topic, so I thought I'd refresh it. I still have yet to come up with a solution for the problem I'm having.

I realize it may be much easier to spawn the truck off of a virtual object, or something of that nature...I'd just prefer to not limit the size of Hoppah's awesome map. I know asking is a long shot....but if anyone with some scripting skills could consider giving additional guidance or help, please PM me. I'd really like to get the LAFD Realism submod moving again.

Took another crack at it and finally solved the problem

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...