Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <FCNPC>
- #include <LocalPlugin>
- #include <ColAndreas>
- #define NPC_NUM 25
- new NPC[NPC_NUM] = {-1};
- new LocalPlayer = -1, formation = 0, forming = 0, specid = -1, bool:moveall = false;
- #define fornpcs(%1) for(new %1 = 0; %1 < sizeof(NPC); %1 ++)
- new weaps[] =
- {
- WEAPON_DEAGLE,
- WEAPON_RIFLE,
- WEAPON_SHOTGSPA,
- WEAPON_SHOTGUN,
- WEAPON_M4,
- WEAPON_AK47,
- WEAPON_SILENCED,
- WEAPON_MP5,
- WEAPON_SNIPER,
- WEAPON_MINIGUN,
- WEAPON_FLAMETHROWER
- };
- main()
- {
- }
- public OnGameModeInit()
- {
- // Direct Control
- ToggleKey(VK_C); // Crouch
- ToggleKey(VK_J); // Jetpack
- ToggleKey(VK_Q); // Prev Weapon
- ToggleKey(VK_E); // Next Weapon
- // Management
- ToggleKey(VK_P);
- ToggleKey(VK_O);
- ToggleKey(VK_I);
- ToggleKey(VK_U);
- ToggleKey(VK_KEYB0);
- ToggleKey(VK_KEYB1);
- ToggleKey(VK_KEYB2);
- ToggleKey(VK_KEYB3);
- ToggleKey(VK_KEYB4);
- ToggleKey(VK_KEYB5);
- ToggleKey(VK_KEYB6);
- ToggleKey(VK_KEYB7);
- ToggleKey(VK_KEYB8);
- ToggleKey(VK_KEYB9);
- // Modifiers
- ToggleKey(VK_LCONTROL);
- // Help/Meta
- ToggleKey(VK_F2);
- CA_Init();
- FCNPC_SetUpdateRate(40);
- new Float:sx, Float:sy, Float:sz, ret, Float:x, Float:y, Float:z;
- do
- {
- sx = (random(60000)-30000)/10.0;
- sy = (random(60000)-30000)/10.0;
- ret = CA_RayCastLine(sx, sy, 700.0, sx, sy, -5.0, sx, sy, sz);
- } while(ret == 0 || ret == WATER_OBJECT);
- AddPlayerClass(0, sx, sy, sz+1.0, 0.0, WEAPON_DEAGLE, 9999, WEAPON_M4, 9999, WEAPON_MINIGUN, 9999);
- fornpcs(i)
- {
- new name[10] = {0, ...};
- for(new j = 0; j < sizeof(name)-1; j ++) name[j] = (random(2) == 0 ? 'a' + random(26) : 'A' + random(26));
- NPC[i] = FCNPC_Create(name);
- x = sx + random(sizeof(NPC)) * 1.3, y = sy + (random(sizeof(NPC))+random(5)) * 0.8;
- CA_RayCastLine(x, y, 700.0, x, y, -5.0, x, y, z);
- FCNPC_Spawn(NPC[i], random(311), x, y, z+1.0);
- FCNPC_SetWeapon(NPC[i], weaps[0]);
- FCNPC_SetAmmo(NPC[i], 9000);
- for(new j = 0; j < sizeof(weaps); j ++) FCNPC_SetWeaponSkillLevel(NPC[i], weaps[j], 1000);
- }
- SetTimer("ControlTimer", 100, 1);
- return 1;
- }
- public OnGameModeExit()
- {
- fornpcs(i) if(FCNPC_IsValid(NPC[i])) FCNPC_Destroy(NPC[i]);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- if(IsPlayerNPC(playerid)) return 1;
- if(LocalPlayer != -1) return 1;
- new IP[16];
- GetPlayerIp(playerid, IP, 16);
- if(strlen(IP) != 9) return 1;
- if(strcmp(IP, "127.0.0.1") != 0) return 1;
- LocalPlayer = playerid;
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- if(IsPlayerNPC(playerid)) return 1;
- return 1;
- }
- public OnLocalKeyStateChange(key, newstate)
- {
- //printf("%d", key);
- if((LocalPlayer == -1 || !IsSAMPFocused()) && newstate) return 1;
- if(key == VK_F2 && newstate)
- {
- SendClientMessage(LocalPlayer, -1, "--- HNPC Controls ---");
- SendClientMessage(LocalPlayer, -1, " W/A/S/D - Move");
- SendClientMessage(LocalPlayer, -1, " C - Crouch");
- SendClientMessage(LocalPlayer, -1, " Q - Previous Weapon");
- SendClientMessage(LocalPlayer, -1, " E - Next Weapon");
- SendClientMessage(LocalPlayer, -1, " J - Toggle Jetpack");
- SendClientMessage(LocalPlayer, -1, " LCTRL + [0-8] - Build Formation");
- SendClientMessage(LocalPlayer, -1, " LCTRL + P - Switich to next NPC");
- SendClientMessage(LocalPlayer, -1, " LCTRL + O - Go Back to CJ");
- SendClientMessage(LocalPlayer, -1, " LCTRL + I - Reset");
- SendClientMessage(LocalPlayer, -1, " LCTRL + U - Toggle Move All");
- SendClientMessage(LocalPlayer, -1, "---");
- return 1;
- }
- fornpcs(i) if(NPC[i] == -1) return 1;
- if(key == VK_I && newstate && IsLocalKeyDown(VK_LCONTROL))
- {
- fornpcs(i)
- {
- FCNPC_SetPosition(NPC[i], 0.0, 0.0, 0.0);
- FCNPC_Respawn(NPC[i]);
- }
- return 1;
- }
- if(key == VK_P && newstate && IsLocalKeyDown(VK_LCONTROL))
- {
- if(specid == -1) TogglePlayerSpectating(LocalPlayer, 1);
- specid ++;
- if(specid == NPC_NUM) specid = 0;
- if(GetPlayerState(NPC[specid]) == PLAYER_STATE_ONFOOT) PlayerSpectatePlayer(LocalPlayer, NPC[specid]);
- else PlayerSpectateVehicle(LocalPlayer, 1);
- return 1;
- }
- if(key == VK_O && newstate && IsLocalKeyDown(VK_LCONTROL) && specid != -1)
- {
- TogglePlayerSpectating(LocalPlayer, 0);
- specid = -1;
- return 1;
- }
- if(key == VK_U && newstate && IsLocalKeyDown(VK_LCONTROL))
- {
- moveall = !moveall;
- if(moveall) SendClientMessage(LocalPlayer, -1, "Moving all NPCs.");
- else
- {
- SendClientMessage(LocalPlayer, -1, "Moving selected NPC only.");
- fornpcs(i)
- {
- if(FCNPC_IsMoving(NPC[i])) FCNPC_Stop(NPC[i]);
- if(FCNPC_IsAiming(NPC[i])) FCNPC_StopAim(NPC[i]);
- FCNPC_SetKeys(NPC[i], 0, 0, 0);
- }
- }
- forming = 0;
- return 1;
- }
- if(specid == -1 && newstate) return 1;
- if(key == VK_C && newstate)
- {
- fornpcs(i)
- {
- if(!moveall) i = specid;
- new cursact = FCNPC_GetSpecialAction(NPC[i]);
- if(cursact == 2) continue;
- if(cursact == 0) FCNPC_SetSpecialAction(NPC[i], 1);
- else if(cursact == 1) FCNPC_SetSpecialAction(NPC[i], 0);
- if(!moveall) break;
- }
- return 1;
- }
- if(key == VK_J && newstate)
- {
- fornpcs(i)
- {
- if(!moveall) i = specid;
- new cursact = FCNPC_GetSpecialAction(NPC[i]);
- if(cursact == 1) continue;
- if(cursact == 0) FCNPC_SetSpecialAction(NPC[i], 2);
- else if(cursact == 2)
- {
- FCNPC_SetSpecialAction(NPC[i], 0);
- FCNPC_SetWeapon(NPC[i], FCNPC_GetWeapon(NPC[i]));
- }
- if(!moveall) break;
- }
- return 1;
- }
- if(key == VK_Q && newstate && !moveall)
- {
- new slot = -1, wid = FCNPC_GetWeapon(NPC[specid]);
- for(new i = 0; i < sizeof(weaps); i ++) if(weaps[i] == wid)
- {
- slot = i;
- break;
- }
- if(slot == -1) return 1;
- slot --;
- if(slot < 0) slot = sizeof(weaps)-1;
- FCNPC_SetWeapon(NPC[specid], weaps[slot]);
- FCNPC_SetAmmo(NPC[specid], 10000);
- return 1;
- }
- if(key == VK_E && newstate && !moveall)
- {
- new slot = -1, wid = FCNPC_GetWeapon(NPC[specid]);
- for(new i = 0; i < sizeof(weaps); i ++) if(weaps[i] == wid)
- {
- slot = i;
- break;
- }
- if(slot == -1) return 1;
- slot ++;
- if(slot == sizeof(weaps)) slot = 0;
- FCNPC_SetWeapon(NPC[specid], weaps[slot]);
- FCNPC_SetAmmo(NPC[specid], 10000);
- return 1;
- }
- if(key == VK_LCONTROL && newstate) return 1;
- new movingnpcs = 0;
- fornpcs(i)
- {
- if(!moveall && i == specid) continue;
- if(FCNPC_IsMoving(NPC[i])) movingnpcs ++;
- }
- if(key >= VK_KEYB0 && key <= VK_KEYB9 && newstate && IsLocalKeyDown(VK_LCONTROL) && (forming == 0 || movingnpcs == 0))
- {
- formation = key - VK_KEYB0;
- forming = 0;
- new Float:bx, Float:by, Float:bz, Float:tx, Float:ty, Float:tz;
- if(formation == 0)
- {
- SendClientMessageToAll(-1, "Building Random Group");
- if(moveall) FCNPC_GetPosition(NPC[0], bx, by, bz);
- else FCNPC_GetPosition(NPC[specid], bx, by, bz);
- fornpcs(i)
- {
- tx = bx + random(sizeof(NPC)) * 1.3;
- ty = by + (random(sizeof(NPC))+random(5));
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 1)
- {
- SendClientMessageToAll(-1, "Building Formation 1 - Line X");
- if(moveall) FCNPC_GetPosition(NPC[0], bx, by, bz);
- else FCNPC_GetPosition(NPC[specid], bx, by, bz);
- fornpcs(i)
- {
- tx = bx + (i) * 2.0;
- ty = by;
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 2)
- {
- SendClientMessageToAll(-1, "Building Formation 2 - Line Y");
- if(moveall) FCNPC_GetPosition(NPC[0], bx, by, bz);
- else FCNPC_GetPosition(NPC[specid], bx, by, bz);
- fornpcs(i)
- {
- tx = bx;
- ty = by + (i) * 2.0;
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 3)
- {
- SendClientMessageToAll(-1, "Building Formation 3 - Circle");
- FCNPC_GetPosition(NPC[specid], bx, by, bz);
- new num = sizeof(NPC);
- fornpcs(i)
- {
- tx = bx + (num * 0.4)*floatsin((360.0 / num) * i, degrees);
- ty = by + (num * 0.4)*floatcos((360.0 / num) * i, degrees);
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 4)
- {
- SendClientMessageToAll(-1, "Building Formation 4 - Circle Around");
- FCNPC_GetPosition(NPC[specid], bx, by, bz);
- new num = sizeof(NPC) - 1, idx = 0;
- fornpcs(i)
- {
- if(i != specid)
- {
- tx = bx + (num * 0.4)*floatsin((360.0 / num) * idx, degrees);
- ty = by + (num * 0.4)*floatcos((360.0 / num) * idx, degrees);
- idx ++;
- }
- else
- {
- tx = bx;
- ty = by;
- }
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 5)
- {
- SendClientMessageToAll(-1, "Building Formation 5 - Pair");
- if(moveall) FCNPC_GetPosition(NPC[0], bx, by, bz);
- else FCNPC_GetPosition(NPC[specid], bx, by, bz);
- fornpcs(i)
- {
- if(i % 2 == 0)
- {
- tx = bx;
- ty = by + i;
- }
- else
- {
- tx = bx + 2.0;
- ty = by + i-1;
- }
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 6)
- {
- SendClientMessageToAll(-1, "Building Formation 6 - Trio");
- if(moveall) FCNPC_GetPosition(NPC[0], bx, by, bz);
- else FCNPC_GetPosition(NPC[specid], bx, by, bz);
- fornpcs(i)
- {
- if(i % 3 == 0)
- {
- tx = bx;
- ty = by + (i);
- }
- else if(i % 3 == 1)
- {
- tx = bx + 2.0;
- ty = by + (i-1);
- }
- else
- {
- tx = bx + 4.0;
- ty = by + (i-2);
- }
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 7)
- {
- SendClientMessageToAll(-1, "Building Formation 7 - Stuffed");
- FCNPC_GetPosition(NPC[specid], tx, ty, bz);
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- fornpcs(i)
- {
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 8)
- {
- SendClientMessageToAll(-1, "Building Formation 8 - Random Row");
- new Float:a = random(360000)/1000.0, adir = random(2);
- FCNPC_GetPosition(NPC[specid], tx, ty, bz);
- fornpcs(i)
- {
- tx += 1.5 * floatsin(a, degrees);
- ty += 1.5 * floatcos(a, degrees);
- if(adir) a += random(14000)/1000.0;
- else a -= random(14000)/1000.0;
- if(!random(25)) adir = (adir == 1 ? 0 : 1);
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- if(formation == 9)
- {
- SendClientMessageToAll(-1, "Building Formation 9 - Spiral");
- new Float:a = 14.0;
- FCNPC_GetPosition(NPC[specid], bx, by, bz);
- fornpcs(i)
- {
- new Float:rad = (3.5 + i * 0.085);
- tx = bx + rad * floatsin(i*a, degrees);
- ty = by + rad * floatcos(i*a, degrees);
- if(CA_RayCastLine(tx, ty, 700.0, tx, ty, -5.0, tx, ty, tz) == WATER_OBJECT) tz -= 1.6;
- FCNPC_GoTo(NPC[i], tx, ty, tz + 1.0, MOVE_TYPE_SPRINT, 0.5, false, 0.0, true);
- if(moveall || (!moveall && i != specid)) forming ++;
- }
- }
- return 1;
- }
- return 1;
- }
- public FCNPC_OnReachDestination(npcid)
- {
- if(forming > 0)
- {
- forming --;
- FCNPC_SetKeys(npcid, 0, 0, 0);
- }
- return 1;
- }
- forward ControlTimer();
- public ControlTimer()
- {
- if(LocalPlayer == -1 || NPC[0] == -1 || (forming > 0 && moveall) || specid == -1) return 1;
- new ud, lr;
- if(IsLocalKeyDown(VK_W) && !IsLocalKeyDown(VK_S)) ud = 1;
- else if(!IsLocalKeyDown(VK_W) && IsLocalKeyDown(VK_S)) ud = -1;
- if(IsLocalKeyDown(VK_D) && !IsLocalKeyDown(VK_A)) lr = 1;
- else if(!IsLocalKeyDown(VK_D) && IsLocalKeyDown(VK_A)) lr = -1;
- new Float:cx, Float:cy, Float:cz, Float:aorg, Float:a, Float:xo, Float:yo;
- GetPlayerCameraFrontVector(LocalPlayer, cx, cy, cz);
- cx *= 5.0, cy *= 5.0, cz *= 5.0;
- aorg = atan2(cx, cy);
- a = aorg;
- if(ud > 0)
- {
- if(lr > 0) a += 45.0;
- else if(lr < 0) a -= 45.0;
- }
- else if(ud < 0)
- {
- if(lr > 0) a += 135.0;
- else if(lr < 0) a -= 135.0;
- else a += 180.0;
- }
- else
- {
- if(lr > 0) a += 90.0;
- else if(lr < 0) a -= 90.0;
- }
- xo = 5.0 * floatsin(a, degrees);
- yo = 5.0 * floatcos(a, degrees);
- fornpcs(i)
- {
- if(!moveall) i = specid;
- new Float:x, Float:y, Float:z;
- FCNPC_GetPosition(NPC[i], x, y, z);
- if(ud == 0 && lr == 0)
- {
- if(FCNPC_IsMoving(NPC[i])) FCNPC_Stop(NPC[i]);
- FCNPC_SetKeys(NPC[i], 0, 0, 0);
- }
- else
- {
- x += xo;
- y += yo;
- }
- new special = FCNPC_GetSpecialAction(NPC[i]);
- if(special != 2)
- {
- new Float:speed, movetype, aim;
- if(IsLocalKeyDown(VK_RMB))
- {
- FCNPC_AimAt(NPC[i], x + (cx*100.0), y + (cy*100.0), z + (cz*100.0), (IsLocalKeyDown(VK_LMB) ? true : false), 0, true);
- aim = 1;
- if(IsLocalKeyDown(VK_LMB)) FCNPC_SetKeys(NPC[i], 0, 0, 128 | KEY_FIRE);
- else FCNPC_SetKeys(NPC[i], 0, 0, 128);
- speed = 0.005;
- movetype = MOVE_TYPE_WALK;
- }
- else if(IsLocalKeyDown(VK_LSHIFT) && special != 1)
- {
- FCNPC_SetKeys(NPC[i], 0, 0, KEY_SPRINT);
- speed = 0.5;
- movetype = MOVE_TYPE_SPRINT;
- }
- else if(IsLocalKeyDown(VK_ALT) && special != 1)
- {
- FCNPC_SetKeys(NPC[i], 0, 0, KEY_WALK);
- speed = 0.005;
- movetype = MOVE_TYPE_WALK;
- }
- else
- {
- FCNPC_SetKeys(NPC[i], 0, 0, 0);
- speed = 0.05;
- movetype = MOVE_TYPE_RUN;
- }
- if(!aim && FCNPC_IsAiming(NPC[i])) FCNPC_StopAim(NPC[i]);
- new ret = CA_RayCastLine(x, y, z + 700.0, x, y, -5.0, x, y, z);
- if(ret != WATER_OBJECT) z += 1.0;
- else z = -0.6;
- if(aim) FCNPC_SetAngle(NPC[i], -aorg);
- if(ud != 0 || lr != 0)
- {
- FCNPC_GoTo(NPC[i], x, y, z, movetype, speed, false, 0.0, false);
- if(!aim) FCNPC_SetAngle(NPC[i], -a);
- }
- }
- else
- {
- new move;
- if(IsLocalKeyDown(VK_RMB))
- {
- FCNPC_AimAt(NPC[i], x + (cx*100.0), y + (cy*100.0), z + (cz*100.0), (IsLocalKeyDown(VK_LMB) ? true : false), 0, true);
- if(IsLocalKeyDown(VK_LMB)) FCNPC_SetKeys(NPC[i], 0, 0, 128 | KEY_FIRE);
- else FCNPC_SetKeys(NPC[i], 0, 0, 128);
- }
- else
- {
- FCNPC_SetKeys(NPC[i], 0, 0, 0);
- if(FCNPC_IsAiming(NPC[i])) FCNPC_StopAim(NPC[i]);
- }
- if(IsLocalKeyDown(VK_SPACE) && !IsLocalKeyDown(VK_LSHIFT)) { z -= 1.7; move = 1; }
- else if(!IsLocalKeyDown(VK_SPACE) && IsLocalKeyDown(VK_LSHIFT)) { z += 1.7; move = 1; }
- FCNPC_SetAngle(NPC[i], -aorg);
- if(move || ud != 0 || lr != 0)
- {
- FCNPC_GoTo(NPC[i], x, y, z, MOVE_TYPE_RUN, 0.1, false, 0.0, false);
- }
- }
- if(!moveall) break;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement