Quantcast
Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
    1. Welcome to GTAForums!

    2. News

    1. Red Dead Redemption 2

      1. News
      2. Red Dead Online
      3. The Armadillo Inn *Spoilers*
    1. GTA Online

      1. After Hours
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
    2. Crews

      1. Events
      2. Recruitment
    1. Grand Theft Auto Series

    2. GTA Next

    3. GTA V

      1. PC
      2. Guides & Strategies
      3. Help & Support
    4. GTA IV

      1. Episodes from Liberty City
      2. Multiplayer
      3. Guides & Strategies
      4. Help & Support
      5. GTA Mods
    5. GTA Chinatown Wars

    6. GTA Vice City Stories

    7. GTA Liberty City Stories

    8. GTA San Andreas

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    9. GTA Vice City

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    10. GTA III

      1. Guides & Strategies
      2. Help & Support
      3. GTA Mods
    11. Top Down Games

      1. GTA Advance
      2. GTA 2
      3. GTA
    12. Wiki

      1. Merchandising
    1. GTA Modding

      1. GTA V
      2. GTA IV
      3. GTA III, VC & SA
      4. Tutorials
    2. Mod Showroom

      1. Scripts & Plugins
      2. Maps
      3. Total Conversions
      4. Vehicles
      5. Textures
      6. Characters
      7. Tools
      8. Other
      9. Workshop
    3. Featured Mods

      1. DYOM
      2. OpenIV
      3. GTA: Underground
      4. GTA: Liberty City
      5. GTA: State of Liberty
    1. Red Dead Redemption

    2. Rockstar Games

    1. Off-Topic

      1. General Chat
      2. Gaming
      3. Technology
      4. Programming
      5. Movies & TV
      6. Music
      7. Sports
      8. Vehicles
    2. Expression

      1. Graphics / Visual Arts
      2. GFX Requests & Tutorials
      3. Writers' Discussion
      4. Debates & Discussion
    1. Forum Support

    2. Site Suggestions

XboxHaxorZ

Custom GTA Bodyguard script.. please help.

Recommended Posts

XboxHaxorZ

I'm using the .NET script hook, C++/CLI. In need of some advice as to why the bodyguards run back and forth between the player's vehicle and a randomly chosen vehicle. Why won't they stay inside of the chosen vehicle? If there is only one guard with you it works fine, but as soon as you spawn more than 1 in messes up.

 

 

// PS_BodyGuards.h// Description: Simple Bodyguard script...// Coded in C++/CLI (Managed C++)#pragma onceusing namespace System;using namespace System::Windows::Forms;using namespace GTA;namespace PS_BodyGuards {    public ref class BodyGuards : Script {    private:        Group ^group;        Model PedModel = Model::FromString("M_Y_BOUNCER_02");        Ped ^target;        Ped ^looker;        bool bJustLeftVehicle;        bool bVehicleFound;    public:        BodyGuards() {            group = Player->Group;            target = nullptr;            looker = nullptr;            bJustLeftVehicle = true;            bVehicleFound = false;            Interval = 250;            this->KeyDown += gcnew GTA::KeyEventHandler(this, &BodyGuards::BodyGuards_KeyDown);            this->Tick += gcnew EventHandler(this, &BodyGuards::BodyGuards_OnTick);        }    private:        void BodyGuards_KeyDown(Object^ sender, GTA::KeyEventArgs^ e) {            switch (e->Key) {                            case Keys::Insert:                if (group->MemberCount < 3) { // limit to 3 friends, so they all fit in a 4-door vehicle                    Ped^ p = World::CreatePed(PedModel, Player->Character->Position.Around(3.0f), RelationshipGroup::Player);                    AddToGroup(p);                    // Set the looker                    if (group->MemberCount == 1 && looker == nullptr)                        looker = p;                }                break;            case Keys::Delete:                for each(Ped ^member in group) {                    member->Weapons->RemoveAll();                    member->Die();                    member->NoLongerNeeded();                }                group->RemoveAllMembers();                if (looker != nullptr)                    looker = nullptr;                break;            case Keys::T:                for each(Ped ^member in group) {                    if (Exists(member)) {                        target = Player->GetTargetedPed();                        if (Exists(target)) {                            member->Task->ClearAll();                            member->Task->AlwaysKeepTask = true;                            member->Task->FightAgainst(target);                        }                    }                }                break;            }        }        /*         * Function that controls, the dudes.         */        void BodyGuards_OnTick(Object^ sender, EventArgs ^e) {            if (Player->Character->isInVehicle())                bJustLeftVehicle = false;            else                bJustLeftVehicle = true;            // TODO : Fix this!            // handles the vehicle searching member            if (Exists(looker) && looker != nullptr && group->MemberCount > 1 && group->MemberCount < 3 && !bVehicleFound) {                if (!bJustLeftVehicle && Player->Character->isInVehicle() && !Player->Character->CurrentVehicle->isSeatFree(VehicleSeat::AnyPassengerSeat)) {                    array<Vehicle^> ^vehArrRef = World::GetVehicles(looker->Position, 15.0f);                    for each(Vehicle ^veh in vehArrRef) {                        if (Exists(veh) && veh != nullptr && Exists(Player->Character->CurrentVehicle)) {                            if (veh != Player->Character->CurrentVehicle) {                                looker->Task->EnterVehicle(veh, VehicleSeat::Driver);                                bVehicleFound = true;                                break;                            }                        }                        else                            bVehicleFound = false;                    }                }            }                        // TODO: Fix this!            // handles all other group members            for each(Ped ^member in group) {                if (Exists(member) && Exists(looker)) {                    if (Player->Character->isInVehicle() && bVehicleFound) {                        if (member != looker && Exists(looker->CurrentVehicle) && looker->CurrentVehicle->isSeatFree(VehicleSeat::AnyPassengerSeat) && !bJustLeftVehicle) {                            member->Task->ClearAll();                            member->Task->EnterVehicle(looker->CurrentVehicle, VehicleSeat::AnyPassengerSeat);                        }                    }                }            }            // My Targetting Mess            if (Exists(target) && target != nullptr) {                if (!target->isAlive) {                    for each(Ped ^member in group) {                        member->Task->AlwaysKeepTask = false;                        member->Task->ClearAll();                    }                    target = nullptr;                }            }        }        void AddToGroup(Ped ^p) {            if (!Exists(p)) return;  // won't cause an exception this way            // Setup normal npc crap that I want            p->CurrentRoom = Player->Character->CurrentRoom;            p->WillDoDrivebys = true;            p->PriorityTargetForEnemies = true;            p->DuckWhenAimedAtByGroupMember = false;            p->AlwaysDiesOnLowHealth = false;            p->SetPathfinding(true, true, true);            // Setup what kind of guns they have            if (Game::CurrentEpisode == GameEpisode::TLAD) {                p->Weapons->FromType(Weapon::TLAD_Automatic9mm)->Ammo = 30000;                p->Weapons->FromType(Weapon::TLAD_AssaultShotgun)->Ammo = 30000;            }            else {                p->Weapons->FromType(Weapon::Rifle_AK47)->Ammo = 30000;                p->Weapons->FromType(Weapon::Handgun_DesertEagle)->Ammo = 30000;            }            p->Weapons->Select(Weapon::Misc_AnyWeapon);            // Setup the group to player            p->RelationshipGroup = RelationshipGroup::Player;            p->ChangeRelationship(RelationshipGroup::Player, Relationship::Companion);            p->CantBeDamagedByRelationshipGroup(RelationshipGroup::Player, true);            group->AddMember(p);            Game::DisplayText(group->MemberCount.ToString() + " members in gang");        }    };}

 

Any help at all leading to a solution to this problem will be greatly appreciated. Thanks in advance.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • 1 User Currently Viewing
    0 Members, 0 Anonymous, 1 Guest

×

Important Information

By using GTAForums.com, you agree to our Terms of Use and Privacy Policy.