Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Zombies become very active at night, scattering and moving around often
- TwoHoursOfTerrorUse: from midnight to 2am zombies gain a speed boost
- By Nolan Ritchie
- Modified by cerastes
- Changed the roaming algorithm:
- 1) A random number ("target"), a random increment, and a random location to roam to are picked for each zombie.
- 2) During every iteration of the roaming function, each zombie's target is reduced by the increment.
- 3) If the target reaches zero, steps 1 is repeated and the cycle restarts.
- This approach makes zombie roaming look more random - zombies do not all change direction at the same time.
- Finally, there's a "pullback" function. This roaming algorithm's downside is that the zombies might be directed
- to leave the player's cell. Once they leave, they can't be recalled easily. This means that this algorithm
- may actually push zombies away from the player, which is pretty much the exact opposite of the intended effect.
- So, a pullback function is needed to force the zombies to come towards the player if they get too close to the cell's edge.
- ]]
- local interval = 400;
- local PUCount = 0;
- local TwoHoursOfTerrorUse = false;
- local tempx;
- local tempy;
- local diffX;
- local diffY;
- local playerX;
- local playerY;
- local playerZ;
- local distanceFromPlayer;
- local target;
- function updateZombie( currentZombie )
- tempx = currentZombie:getX() + ZombRand(-100.0,100.0);
- tempy = currentZombie:getY() + ZombRand(-100.0,100.0);
- currentZombie:pathToLocation(tempx,tempy,currentZombie:getZ());
- currentZombie:getModData().increment = ZombRand(100, 400);
- currentZombie:getModData().target = ZombRand(interval, interval * 3 );
- currentZombie:getModData().doNotDisturb = false;
- end
- function ScatterZombies()
- local hour = getGameTime():getTimeOfDay();
- if( hour < 5.0 ) or ( hour >= 22.0) then
- if(TwoHoursOfTerrorUse) then sendClientCommand(getPlayer(), "NocturnalZombies", "ScatterZombies", {TwoHoursOfTerror= "true"});
- else sendClientCommand(getPlayer(), "NocturnalZombies", "ScatterZombies", {TwoHoursOfTerror= "false"}) end
- local zlist = getPlayer():getCell():getZombieList();
- if(zlist ~= nil) then
- playerX = getPlayer():getX();
- playerY = getPlayer():getY();
- playerZ = getPlayer():getZ();
- --debug - see how many zombies are nearby
- --print( zlist:size() );
- for i=0, zlist:size()-1 do
- local currentZombie = zlist:get(i);
- if(currentZombie:getModData() ~= nil) then
- if( currentZombie:getModData().target ~= nil ) and ( currentZombie:getModData().doNotDisturb == false ) then
- target = currentZombie:getModData().target;
- target = target - currentZombie:getModData().increment;
- if( target <= 0 ) then
- --- calculate new position and send the zombie there
- updateZombie(currentZombie);
- else
- currentZombie:getModData().target = target;
- end
- else
- updateZombie(currentZombie);
- end
- else
- updateZombie(currentZombie);
- end
- -- calculate the current zombie's distance from the player
- diffX = playerX - currentZombie:getX();
- diffY = playerY - currentZombie:getY();
- distanceFromPlayer = math.sqrt( ( diffX * diffX ) + ( diffY * diffY ) );
- --print( distanceFromPlayer );
- -- pullback (see description above)
- if( distanceFromPlayer > 90 ) then
- currentZombie:pathToLocation( playerX, playerY, playerZ );
- currentZombie:getModData().doNotDisturb = true;
- currentZombie:getModData().increment = interval;
- currentZombie:getModData().target = interval * 2;
- else
- -- reset the do not disturb flag so that the zombie can path normally
- currentZombie:getModData().doNotDisturb = false;
- end
- end
- end
- end
- end
- function NZInit()
- PUCount = 0;
- if (TwoHoursOfTerror ~= nil) then
- TwoHoursOfTerrorUse = TwoHoursOfTerror;
- else
- TwoHoursOfTerrorUse = false;
- end
- end
- function NZPlayerUpdateHandle(player)
- PUCount = PUCount + 1;
- --player:Say(tostring(TwoHoursOfTerrorUse))
- if(PUCount == interval) then
- --player:Say("working");
- ScatterZombies();
- PUCount = 0;
- end
- end
- Events.OnGameStart.Add(NZInit);
- Events.OnPlayerUpdate.Add(NZPlayerUpdateHandle);
Advertisement
Add Comment
Please, Sign In to add comment