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

    1. Red Dead Redemption 2

      1. PC
      2. Gameplay
      3. Missions
      4. Help & Support
    2. Red Dead Online

      1. Gameplay
      2. Find Lobbies & Outlaws
      3. Help & Support
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. Diamond Casino & Resort
      2. DLC
      3. Find Lobbies & Players
      4. Guides & Strategies
      5. Vehicles
      6. Content Creator
      7. Help & Support
    2. Grand Theft Auto Series

    3. GTA 6

    4. GTA V

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

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

    7. GTA Vice City Stories

    8. GTA Liberty City Stories

    9. GTA San Andreas

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

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

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

      1. GTA Advance
      2. GTA 2
      3. GTA
    13. 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. News

    2. Forum Support

    3. 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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.


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

×
×
  • Create New...

Important Information

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