Advertisement
Guest User

Chalua Example

a guest
Feb 23rd, 2020
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.13 KB | None | 0 0
  1. local PrintMore
  2. function ENT:Initialize() -- This is a function that is called when the printer is created.
  3.         self:SetModel("models/props_c17/consolebox01a.mdl") -- Here we set the model. This is a model you can find in the Q menu ingame.
  4.         self:PhysicsInit(SOLID_VPHYSICS) -- We want the money printer to be affected by physics, such as gravity. This is automatically taken care of by the engine when we set this.
  5.         self:SetMoveType(MOVETYPE_VPHYSICS) -- This defines how the money printer reacts to movement.
  6.         self:SetSolid(SOLID_VPHYSICS) -- Here we set whether or not the printer is solid or not.
  7.         local phys = self:GetPhysicsObject() -- PhysicsInit above gave the printer a physic object, which we retrieve here.
  8.         if phys:IsValid() then phys:Wake() end -- We check that everything went according to plan, then we wake the physic object up (it'll fly midair unless we do this).
  9.         self.sparking = false -- This is a variable we'll be using later.
  10.         self.damage = 100 -- This is the health of the printer.
  11.         self.IsMoneyPrinter = true
  12.         timer.Simple(27, PrintMore, self) -- We start the first print cycle. Notice that it's set to 27 seconds.
  13. end
  14.  
  15. function ENT:OnTakeDamage(dmg) -- This function is called when the printer takes damage.
  16.         if self.burningup then return end -- If the printer is already burning, we "return", meaning we interrupt the script, thus disallowing damage to the printer.
  17.  
  18.         self.damage = (self.damage or 100) - dmg:GetDamage() -- Here we use the variable `.damage` that was set in Initialize, then apply the received damage.
  19.         if self.damage <= 0 then -- if the health of our printer is equal to or less than 0...
  20.                 local rnd = math.random(1, 10) -- pick a random number between 1 and 10, and store it in the "rnd" variable
  21.                 if rnd < 3 then -- if the random number we picked is less than 3 then we...
  22.                         self:BurstIntoFlames() -- put it on fire!
  23.                 else -- but if the number was 3 or higher then we..
  24.                         self:Destruct() -- explode it
  25.                         self:Remove() -- and remove it!
  26.                 end
  27.         end
  28. end
  29.  
  30. function ENT:Destruct() -- This is a custom function that is called when we want to blow the printer up.
  31.         -- We'll create a custom effect of an explosion.
  32.         local vPoint = self:GetPos() -- First, we get the position of our printer, and store that in vPoint for later use
  33.         local effectdata = EffectData() -- Then we create the effect...
  34.         effectdata:SetStart(vPoint) -- set its position using vPoint
  35.         effectdata:SetOrigin(vPoint) -- this is also setting its position
  36.         effectdata:SetScale(1) -- this is how big the explosion will appear
  37.         util.Effect("Explosion", effectdata) -- We've finished defining our explosion, time to put it into action. util.Effect(effect-type, settings)
  38.         Notify(self.dt.owning_ent, 1, 4, "Your money printer has exploded!") -- we give the player a heads up, that their printer has blown up.
  39. end
  40.  
  41. function ENT:BurstIntoFlames() -- This is a custom function that is called when we want to put the printer on fire.
  42.         Notify(self.dt.owning_ent, 1, 4, "Your money printer is overheating!") -- we start off by giving the player a heads up that their printer is on fire!
  43.         self.burningup = true -- We prevent the printer from taking more damage, so it can burn in peace (see ENT:OnTakeDamage())
  44.         local burntime = math.random(8, 18) -- we pick a random number between 8 and 18, which will be how long it will burn
  45.         self:Ignite(burntime, 0) -- we put the printer on fire..
  46.         timer.Simple(burntime, self.Fireball, self) -- .. and after that duration we call the ENT:Fireball() function, which will blow the printer up.
  47. end
  48.  
  49. function ENT:Fireball() -- This is a custom function that is called after the printer has been burning for a while
  50.         if not self:IsOnFire() then return end -- If the printer isn't on fire, this must have been called by a mistake. Abort abort!
  51.         local dist = math.random(20, 280) -- Explosion radius.
  52.         self:Destruct() -- We call the ENT:Destruct() function to create the explosion effect.
  53.         for k, v in pairs(ents.FindInSphere(self:GetPos(), dist)) do -- We search the surrounding vicinity of the printer, and for each item we find we..
  54.                 if not v:IsPlayer() and not v.IsMoneyPrinter then v:Ignite(math.random(5, 22), 0) end -- check that the item is not a player or another printer, then we put it on fire for a random duration between 5 and 22 seconds.
  55.         end
  56.         self:Remove() -- All done! The printer has gone KABOOM and ignited other random things in the area. Now we can remove the printer.
  57. end
  58.  
  59. PrintMore = function(ent) -- This is an alternative version of creating a function. Don't be alarmed, it works exactly the same.
  60.         if ValidEntity(ent) then -- if the printer still exists..
  61.                 ent.sparking = true -- we make the printer spark, like it does when its about to print money
  62.                 timer.Simple(3, ent.CreateMoneybag, ent) -- after 3 seconds it will attempt to create money. Notice: 27 seconds first time + 3 seconds - 30 seconds from spawn. Always.
  63.         end
  64. end
  65.  
  66. function ENT:CreateMoneybag() -- This is a custom function that we call when we want the printer to attempt printing money
  67.         if not ValidEntity(self) then return end -- Printer no longer exist! Abort abort!
  68.         if self:IsOnFire() then return end -- Printer is burning! Abort abort!
  69.         local MoneyPos = self:GetPos() -- All is well, we proceed to figure out where the money should be spawned. We use the location of the printer.
  70.  
  71.         if math.random(1, 22) == 3 then self:BurstIntoFlames() end -- We make a random number between 1, and 22. And if that number is 3 exactly, we put the printer on fire! >:3
  72.  
  73.         local amount = GetConVarNumber("mprintamount") -- We check the server CVAR for how much money we should print
  74.         if amount == 0 then -- if server cvar is somehow set to 0 (probably broken), we default to 250
  75.                 amount = 250
  76.         end
  77.  
  78.         DarkRPCreateMoneyBag(Vector(MoneyPos.x + 15, MoneyPos.y, MoneyPos.z + 15), amount) -- We actually create the money.
  79.         self.sparking = false -- we are done creating money. No need to spark anymore.
  80.         timer.Simple(math.random(100, 350), PrintMore, self) -- We start the next print cycle, between 100-350 seconds from now.
  81. end
  82.  
  83. function ENT:Think() -- This is an engine function, which is called every "frame" or FPS that the server is alive on (i.e extremely often)
  84.         if not self.sparking then return end -- if we aren't busy printing money, we have no further business here. We stop the script.
  85.  
  86.         -- the following is creating the spark effect the printer makes when its about to print money. As defined in PrintMore, it'll continue to do so for 3 whole seconds.
  87.         local effectdata = EffectData()
  88.         effectdata:SetOrigin(self:GetPos())
  89.         effectdata:SetMagnitude(1)
  90.         effectdata:SetScale(1)
  91.         effectdata:SetRadius(2)
  92.         util.Effect("Sparks", effectdata)
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement