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
      4. Frontier Pursuits
    1. Crews & Posses

      1. Recruitment
    2. Events

    1. GTA Online

      1. DLC
      2. Find Lobbies & Players
      3. Guides & Strategies
      4. Vehicles
      5. Content Creator
      6. Help & Support
      7. The Diamond Casino Heist
    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 IV 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 SA Mods
    10. GTA Vice City

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

      1. Guides & Strategies
      2. Help & Support
      3. GTA III 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

ClareXoBearrx3R9

Can't Spawn Attacking Peds

Recommended Posts

ClareXoBearrx3R9

Hello,

I'm trying to write a function to spawn a cop car with two cops and send them to attack me. But somehow even though the car spawns and cops do too, they spawn far away and stay there, not doing anything :panic:

Aiming at them will yield a wanted level but they will literally just be still, no movement whatsoever. One cop spawns inside the car and the other spawns next to it, and sometimes the car will spawn too close and crush the outside cop.

Once I unload the script, (CTRL+R) the cops "unfreeze" and act like normal cops and walk away etc. Is there something I'm doing wrong?

The function:

void send_attackers(Ped target_ped, Hash phash1, Hash phash2, Hash vhash1){    string security_police_plate_template = "POLICE";    STREAMING::REQUEST_MODEL(phash1); STREAMING::REQUEST_MODEL(phash2); STREAMING::REQUEST_MODEL(vhash1);    Vector3 Pos = ENTITY::GET_OFFSET_FROM_ENTITY_IN_WORLD_COORDS(target_ped, GAMEPLAY::GET_RANDOM_FLOAT_IN_RANGE(-10, 15), GAMEPLAY::GET_RANDOM_FLOAT_IN_RANGE(-10, 15), 1.0f);    Ped ped2 = PED::CREATE_PED(26, phash2, Pos.x, Pos.y, Pos.z + 1.5f, 0.0f, 1, 1);    Vehicle vehicle1 = VEHICLE::CREATE_VEHICLE(vhash1, Pos.x, Pos.y, Pos.z + 1.3f, 0.0f, 1, 1);    Ped    ped1 = PED::CREATE_PED_INSIDE_VEHICLE(vehicle1, 5, phash1, -1, 1, 1);    ENTITY::SET_ENTITY_AS_MISSION_ENTITY(ped1, 1, 1);    ENTITY::SET_ENTITY_AS_MISSION_ENTITY(ped2, 1, 1);    ENTITY::SET_ENTITY_AS_MISSION_ENTITY(vehicle1, 1, 1);    Blip b = UI::ADD_BLIP_FOR_ENTITY(vehicle1);    UI::SET_BLIP_COLOUR(b, 20);    UI::SET_BLIP_SPRITE(b, 56); // 56 = police car; 225 = personal vehicle        // This part is not important; it just sets the car's plate text and type (works fine).    /*    security_police_unit++;    string security_police_plate_number = std::to_string(security_police_unit);    security_police_plate_template += security_police_plate_number;    VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT(vehicle1, security_police_plate_template.c_str());    VEHICLE::SET_VEHICLE_NUMBER_PLATE_TEXT_INDEX(vehicle1, 1);    */    PED::SET_BLOCKING_OF_NON_TEMPORARY_EVENTS(ped1, 1);    PED::SET_BLOCKING_OF_NON_TEMPORARY_EVENTS(ped2, 1);    PED::SET_PED_COMBAT_ATTRIBUTES(ped1, 37, 1);    PED::SET_PED_COMBAT_ATTRIBUTES(ped2, 37, 1);    AI::SET_PED_PATH_CAN_USE_CLIMBOVERS(ped1, 1);    AI::SET_PED_PATH_CAN_USE_CLIMBOVERS(ped2, 1);    AI::SET_PED_PATH_CAN_USE_LADDERS(ped1, 1);    AI::SET_PED_PATH_CAN_USE_LADDERS(ped2, 1);    AI::SET_PED_PATH_CAN_DROP_FROM_HEIGHT(ped1, 1);    AI::SET_PED_PATH_CAN_DROP_FROM_HEIGHT(ped2, 1);    AI::SET_PED_PATH_PREFER_TO_AVOID_WATER(ped1, 1);    AI::SET_PED_PATH_PREFER_TO_AVOID_WATER(ped2, 1);    AI::SET_PED_PATH_AVOID_FIRE(ped1, 1);    AI::SET_PED_PATH_AVOID_FIRE(ped2, 1);    PED::SET_PED_COMBAT_ABILITY(ped1, 100);    PED::SET_PED_COMBAT_ABILITY(ped2, 100);        /*    WEAPON_CARBINERIFLE = 0x83BF0278,2210333304    WEAPON_ADVANCEDRIFLE = 0xAF113F99,2937143193    WEAPON_MG = 0x9D07F764,2634544996    WEAPON_COMBATMG = 0x7FD62962,2144741730    WEAPON_PUMPSHOTGUN = 0x1D073A89,487013001    WEAPON_SAWNOFFSHOTGUN = 0x7846A318,2017895192    WEAPON_ASSAULTSHOTGUN = 0xE284C527,3800352039    WEAPON_BULLPUPSHOTGUN = 0x9D61E50F,2640438543    WEAPON_STUNGUN = 0x3656C8C1,911657153    */        WEAPON::GIVE_DELAYED_WEAPON_TO_PED(ped1, 0x3656C8C1, 99, 1);    WEAPON::SET_CURRENT_PED_WEAPON(ped1, 0x3656C8C1, 0);    WEAPON::SET_PED_CURRENT_WEAPON_VISIBLE(ped1, 1, 1, 1, 0);    WEAPON::GIVE_DELAYED_WEAPON_TO_PED(ped2, 0x83BF0278, 99, 1);    WEAPON::SET_CURRENT_PED_WEAPON(ped2, 0x83BF0278, 0);    WEAPON::SET_PED_CURRENT_WEAPON_VISIBLE(ped2, 1, 1, 1, 0);    //WEAPON::SET_PED_CURRENT_WEAPON_VISIBLE(ped2, 1, 1, 1);    PED::SET_PED_AS_COP(ped1, 1); PED::SET_PED_AS_COP(ped2, 1);    WAIT(5);    //      SET_PED_INTO_VEHICLE(ped1, vehicle1, FindFreeCarSeat(vehicle1));    //      SET_PED_INTO_VEHICLE(ped2, vehicle1, FindFreeCarSeat(vehicle1));    WAIT(2);    VEHICLE::SET_VEHICLE_ON_GROUND_PROPERLY(vehicle1);    int CarType = 64;    CarType |= 2710;    CarType |= 2048;    CarType |= 1;    CarType |= 2;    CarType |= 4;    CarType |= 32;    CarType |= 16;    CarType |= 8;        Vehicle closestVeh = VEHICLE::GET_CLOSEST_VEHICLE(Pos.x, Pos.y, Pos.z, 220.0f, 0, CarType);    if (ENTITY::DOES_ENTITY_EXIST(closestVeh)){                Pos = ENTITY::GET_ENTITY_COORDS(closestVeh, 1);        ENTITY::SET_ENTITY_COORDS(vehicle1, Pos.x, Pos.y + 5.0f, Pos.z + 2.0f, 0, 0, 0, 1);    }    Vector3 targPos = ENTITY::GET_ENTITY_COORDS(target_ped, 1);    TaskSequence tempSeq;    AI::OPEN_SEQUENCE_TASK(&tempSeq);    if (VEHICLE::IS_THIS_MODEL_A_PLANE(vhash1)) AI::TASK_PLANE_MISSION(ped1, vehicle1, 0, 0, targPos.x, targPos.y, targPos.z, 4, 20.0, -1.0, -1.0, 100, 100);    else if (VEHICLE::IS_THIS_MODEL_A_HELI(vhash1)) AI::TASK_HELI_MISSION(ped1, vehicle1, 0, 0, targPos.x, targPos.y, targPos.z, 4, 20.0, -1.0, -1.0, 100, 100, 0xbf800000, 0);    else AI::TASK_VEHICLE_MISSION_PED_TARGET(0, vehicle1, target_ped, 7, 15.0f, 786469, 15.0f, -1, 1);    AI::TASK_VEHICLE_SHOOT_AT_PED(0, target_ped, 5.0f);    AI::TASK_LEAVE_ANY_VEHICLE(0, 0, 0);    AI::TASK_COMBAT_PED_TIMED(0, target_ped, 2000, 0);    AI::TASK_SHOOT_AT_ENTITY(0, target_ped, -1, 0);    AI::CLOSE_SEQUENCE_TASK(tempSeq);    AI::TASK_PERFORM_SEQUENCE(ped1, tempSeq); AI::CLEAR_SEQUENCE_TASK(&tempSeq);    AI::OPEN_SEQUENCE_TASK(&tempSeq);    //      TASK_VEHICLE_SHOOT_AT_PED(0, target_ped, 5.0f);    //      TASK_LEAVE_ANY_VEHICLE(0, 0, 0);    AI::TASK_SET_BLOCKING_OF_NON_TEMPORARY_EVENTS(0, 1);    //      TASK_COMBAT_PED_TIMED(0, target_ped, 100, 0);    //      TASK_GO_TO_ENTITY_WHILE_AIMING_AT_ENTITY(0, target_ped, target_ped, 1.0f, 0, 3.0f, 1082130432, 1, 0, -957453492);    AI::TASK_SHOOT_AT_ENTITY(0, target_ped, -1, 0);    AI::CLOSE_SEQUENCE_TASK(tempSeq);    AI::TASK_PERFORM_SEQUENCE(ped2, tempSeq);    AI::CLEAR_SEQUENCE_TASK(&tempSeq);    AI::TASK_COMBAT_HATED_TARGETS_AROUND_PED(ped1, 400.f, 0);    AI::TASK_COMBAT_PED(ped1, target_ped, 0, 16);    AI::TASK_COMBAT_PED(ped2, target_ped, 0, 16);    //      TASK_COMBAT_HATED_TARGETS_AROUND_PED(ped2, 400.f, 0);    PED::SET_PED_KEEP_TASK(ped1, 1);     PED::SET_PED_KEEP_TASK(ped2, 1);    if (VEHICLE::DOES_VEHICLE_HAVE_WEAPONS(vehicle1)){                //SET_CURRENT_PED_VEHICLE_WEAPON(ped1, GET_HASH_KEY("VEHICLE_WEAPON_TANK"));        VEHICLE::SET_VEHICLE_SHOOT_AT_TARGET(ped1, target_ped, targPos.x, targPos.y, targPos.z);    }    STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(phash1); STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(phash2); STREAMING::SET_MODEL_AS_NO_LONGER_NEEDED(vhash1);    //      SET_PED_AS_NO_LONGER_NEEDED(&ped1); SET_PED_AS_NO_LONGER_NEEDED(&ped2);    ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&vehicle1);    set_status_text("Police dispatched");}

What I use to call the function (works fine):

(Note: 0x5E3DA4A4 is the hash for a cop ped and 0x79FBB0C5 is the hash for a cop car)

SHORT key_sendPolice = GetAsyncKeyState(VkKeyScan('j'));if ((GetAsyncKeyState(VK_LCONTROL)) && (key_sendPolice & 0x8000)){        send_attackers(PLAYER::GET_PLAYER_PED(PLAYER::PLAYER_PED_ID()), 0x5E3DA4A4, 0x5E3DA4A4, 0x79FBB0C5);}

I desperately want to get this working. :( Any ideas? :D

Edited by ClareXoBearrx3

Share this post


Link to post
Share on other sites
ClareXoBearrx3R9

Anyone? :(

Share this post


Link to post
Share on other sites
ClareXoBearrx3R9

I got it working. Had to use PLAYER::PLAYER_PED_ID() instead. :facedesk:

  • Like 1

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.