daily pastebin goal
34%
SHARE
TWEET

Server Side

a guest Dec 16th, 2010 40 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. iCounter = 0;
  2.  
  3. function createRandomPed()
  4.         local player = getRandomPlayer();
  5.         if not player then
  6.                 return;
  7.         end
  8.         local x,y,z = getElementPosition(player);
  9.         x = x + math.random(-50,50);
  10.         y = y + math.random(-50,50);
  11.         z = z + 5;
  12.         iCounter = iCounter + 1;
  13.         createPed(iCounter%200,x,y,z);
  14. end
  15.  
  16. function destroyRandomPed()
  17.         for i,ped in ipairs(getElementsByType("ped")) do --this way it destroys less peds when there is not many peds.
  18.                 if math.random(0,5) == 1 then
  19.                         destroyElement(ped);
  20.                         return;
  21.                 end
  22.         end
  23. end
  24.  
  25. function keepPedsBelowHundred()
  26.         local iCount = #getElementsByType("ped");
  27.         if iCount > 99 then
  28.                 for i,ped in ipairs(getElementsByType("ped")) do
  29.                         if math.random(0,1) == 1 then
  30.                                 destroyElement(ped);
  31.                         end
  32.                 end
  33.         end
  34. end
  35.  
  36. function setPedSyncer()
  37.         for i,ped in ipairs(getElementsByType("ped")) do
  38.                   setElementSyncer(ped,getRandomPlayer());
  39.         end
  40. end
  41.  
  42. -- function init()
  43. --      done in onResourceStart
  44. -- end
  45.  
  46. addEventHandler("onResourceStart",getResourceRootElement(),
  47.         function()
  48.                 setTimer(createRandomPed,100,0);
  49.                 setTimer(destroyRandomPed,200,0);
  50.                 setTimer(keepPedsBelowHundred,1000,0);
  51.         end);
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top