Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ------------- NPC zombie test and example script
- // RNPC 0.4 (26.6.2014) - Mauzen
- // Use ConnectZombieBots(playerid, amount)
- // to create <amount> zombie bots that keep following <playerid>
- // They wont attack but can be killed for tests and stuff
- // Either initialize MapAndreas properly, or go to line 78
- // and change the last 1 in MoveRNPC to a 0
- new rnpcZombie[MAX_PLAYERS];
- new rnpcZTimer[MAX_PLAYERS];
- stock ConnectZombieBots(playerid, amount) {
- new name[24];
- new id;
- // spawn the given amount of NPCs
- while(amount-- > 0) {
- format(name, 24, "Zombie_%d", 500-amount);
- id = ConnectRNPC(name);
- // Store their target player
- rnpcZombie[id] = playerid;
- }
- }
- public OnPlayerSpawn(playerid) {
- if (rnpcZombie[playerid] > 0) {
- // Enable RNPC damage management
- RNPC_SetShootable(playerid, 1);
- RNPC_ToggleVehicleCollisionCheck(playerid, 1);
- // Random skin for datz fun
- SetPlayerSkin(playerid, random(299));
- // Change name to avoid name collisions
- new name[24];
- format(name, 24, "Zombie_%d", playerid);
- SetPlayerName(playerid, name);
- // Spawn zombie somewhere in area around player
- new Float:x, Float:y, Float:z;
- GetPlayerPos(rnpcZombie[playerid], x, y, z);
- x = x - 30.0 + random(60);
- y = y - 30.0 + random(60);
- // Set to position on ground
- MapAndreas_FindZ_For2DCoord(x, y, z);
- SetPlayerPos(playerid, x, y, z+0.7);
- // If it was a respawn, kill the old timer
- if (rnpcZTimer[playerid] > 0) KillTimer(rnpcZTimer[playerid]);
- // Make him follow the player
- rnpcZTimer[playerid] = SetTimerEx("RFollowPlayer", 500, 1, "i", playerid);
- }
- #if defined RNPCZ_OnPlayerSpawn
- return RNPCZ_OnPlayerSpawn(playerid);
- #else
- return 1;
- #endif
- }
- #if defined _ALS_OnPlayerSpawn
- #undef OnPlayerSpawn
- #else
- #define _ALS_OnPlayerSpawn
- #endif
- #define OnPlayerSpawn RNPCZ_OnPlayerSpawn
- forward RNPCZ_OnPlayerSpawn(playerid);
- forward RFollowPlayer(npcid);
- public RFollowPlayer(npcid) {
- if (IsPlayerConnected(rnpcZombie[npcid])) {
- new Float:x, Float:y, Float:z;
- GetPlayerPos(rnpcZombie[npcid], x, y, z);
- // Move RNPC to random point in area around target player
- MoveRNPC(npcid, x - 3.0 + random(600) / 100.0,
- y - 3.0 + random(600) / 100.0, z, RNPC_SPEED_RUN, 1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement