Advertisement
Guest User

Untitled

a guest
Jan 20th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.28 KB | None | 0 0
  1. AddCSLuaFile("cl_init.lua");
  2. AddCSLuaFile("shared.lua");
  3. include("shared.lua");
  4.  
  5. function ENT:Initialize()
  6.     self:SetModel("models/props_junk/wood_crate002a.mdl");
  7.     self:PhysicsInit(SOLID_VPHYSICS);
  8.    
  9.     self:SetMoveType(MOVETYPE_VPHYSICS);
  10.     self:SetSolid(SOLID_VPHYSICS);
  11.    
  12.     self:SetHealth(FS_Box_Health);
  13.    
  14.     self:SetDTInt(1, 0);
  15.     self:SetDTInt(2, 0);
  16.     self:SetDTInt(3, 0);
  17.     self:SetDTInt(4, 0);
  18.     self:SetDTInt(5, 0);
  19.     self:SetDTInt(6, 0);
  20.     self:SetDTInt(7, 0);
  21.     self:SetDTInt(8, 0);
  22.     self:SetDTString(1, "none");
  23.     self:GetPhysicsObject():SetMass(105);
  24.    
  25.     self:SetPos(self:GetPos()+self:GetUp()*32);
  26. end;
  27.  
  28. function ENT:SpawnFunction(ply, trace)
  29.     local ent = ents.Create("fs_box");
  30.     ent:SetPos(trace.HitPos + trace.HitNormal * 8);
  31.     ent:Spawn();
  32.     ent:Activate();    
  33.     return ent;
  34. end;
  35.  
  36. function ENT:OnTakeDamage(dmginfo)
  37.     if FS_Box_CanBeDestroyed then
  38.         self:SetHealth(self:Health()-dmginfo:GetDamage());
  39.        
  40.         local effectData = EffectData();   
  41.         effectData:SetStart(dmginfo:GetDamagePosition());
  42.         effectData:SetOrigin(dmginfo:GetDamagePosition());
  43.         effectData:SetScale(8);
  44.         util.Effect("BloodImpact", effectData, true, true);
  45.    
  46.         if (self:Health()<=0) then
  47.             for i=1, math.Round(self:GetDTInt(1)*FS_Box_ContentScaleOnDestroyed) do
  48.                 local content = ents.Create("fs_melon")
  49.                 content:SetAngles(Angle(0,math.random(0, 360),0));
  50.                 content:SetPos(self:GetPos()+(self:GetUp()*math.random(0, 25))+(self:GetRight()*math.random(-40, 40))+(self:GetForward()*math.random(-20, 20)));                       
  51.                 content:Spawn();       
  52.                 content:GetPhysicsObject():SetVelocity(Vector(math.random(-8, 8), math.random(-8, 8), math.random(0, 32)));        
  53.             end;
  54.             for i=1, math.Round(self:GetDTInt(2)*FS_Box_ContentScaleOnDestroyed) do
  55.                 local content = ents.Create("fs_cabbage")
  56.                 content:SetAngles(Angle(0,math.random(0, 360),0));
  57.                 content:SetPos(self:GetPos()+(self:GetUp()*math.random(0, 25))+(self:GetRight()*math.random(-40, 40))+(self:GetForward()*math.random(-20, 20)));                       
  58.                 content:Spawn();           
  59.                 content:GetPhysicsObject():SetVelocity(Vector(math.random(-8, 8), math.random(-8, 8), math.random(0, 32)));        
  60.             end;
  61.             for i=1, math.Round(self:GetDTInt(3)*FS_Box_ContentScaleOnDestroyed) do
  62.                 local content = ents.Create("fs_watermelon")
  63.                 content:SetAngles(Angle(0,math.random(0, 360),0));
  64.                 content:SetPos(self:GetPos()+(self:GetUp()*math.random(0, 25))+(self:GetRight()*math.random(-40, 40))+(self:GetForward()*math.random(-20, 20)));                       
  65.                 content:Spawn();       
  66.                 content:GetPhysicsObject():SetVelocity(Vector(math.random(-8, 8), math.random(-8, 8), math.random(0, 32)));        
  67.             end;
  68.             for i=1, math.Round(self:GetDTInt(4)*FS_Box_ContentScaleOnDestroyed) do
  69.                 local content = ents.Create("fs_tomato")
  70.                 content:SetAngles(Angle(0,math.random(0, 360),0));
  71.                 content:SetPos(self:GetPos()+(self:GetUp()*math.random(0, 25))+(self:GetRight()*math.random(-40, 40))+(self:GetForward()*math.random(-20, 20)));                       
  72.                 content:Spawn();           
  73.                 content:GetPhysicsObject():SetVelocity(Vector(math.random(-8, 8), math.random(-8, 8), math.random(0, 32)));        
  74.             end;
  75.             for i=1, math.Round(self:GetDTInt(5)*FS_Box_ContentScaleOnDestroyed) do
  76.                 local content = ents.Create("fs_orange")
  77.                 content:SetAngles(Angle(0,math.random(0, 360),0));
  78.                 content:SetPos(self:GetPos()+(self:GetUp()*math.random(0, 25))+(self:GetRight()*math.random(-40, 40))+(self:GetForward()*math.random(-20, 20)));                       
  79.                 content:Spawn();       
  80.                 content:GetPhysicsObject():SetVelocity(Vector(math.random(-8, 8), math.random(-8, 8), math.random(0, 32)));        
  81.             end;   
  82.             for i=1, math.Round(self:GetDTInt(6)*FS_Box_ContentScaleOnDestroyed) do
  83.                 local content = ents.Create("fs_apple")
  84.                 content:SetAngles(Angle(0,math.random(0, 360),0));
  85.                 content:SetPos(self:GetPos()+(self:GetUp()*math.random(0, 25))+(self:GetRight()*math.random(-40, 40))+(self:GetForward()*math.random(-20, 20)));                       
  86.                 content:Spawn();       
  87.                 content:GetPhysicsObject():SetVelocity(Vector(math.random(-8, 8), math.random(-8, 8), math.random(0, 32)));        
  88.             end;
  89.             for i=1, math.Round(self:GetDTInt(7)*FS_Box_ContentScaleOnDestroyed) do
  90.                 local content = ents.Create("fs_lemon")
  91.                 content:SetAngles(Angle(0,math.random(0, 360),0));
  92.                 content:SetPos(self:GetPos()+(self:GetUp()*math.random(0, 25))+(self:GetRight()*math.random(-40, 40))+(self:GetForward()*math.random(-20, 20)));                       
  93.                 content:Spawn();       
  94.                 content:GetPhysicsObject():SetVelocity(Vector(math.random(-8, 8), math.random(-8, 8), math.random(0, 32)));        
  95.             end;
  96.             for i=1, math.Round(self:GetDTInt(8)*FS_Box_ContentScaleOnDestroyed) do
  97.                 local content = ents.Create("fs_potato")
  98.                 content:SetAngles(Angle(0,math.random(0, 360),0));
  99.                 content:SetPos(self:GetPos()+(self:GetUp()*math.random(0, 25))+(self:GetRight()*math.random(-40, 40))+(self:GetForward()*math.random(-20, 20)));                       
  100.                 content:Spawn();       
  101.                 content:GetPhysicsObject():SetVelocity(Vector(math.random(-8, 8), math.random(-8, 8), math.random(0, 32)));        
  102.             end;               
  103.             self:Remove();
  104.         end;
  105.     end;
  106. end;
  107.  
  108. function ENT:Use(activator, caller)
  109.     if (!self.nextUse or CurTime() >= self.nextUse) then
  110.         if (activator:GetEyeTrace().Entity == self) and (activator:GetPos():Distance(self:GetPos())<FS_Use_Distance) then          
  111.             if (self:GetDTString(1) == activator:Nick()) then
  112.                 for k, v in pairs(ents.FindInSphere(self:GetPos(), 128)) do
  113.                     if (v:GetClass() == "fs_salesman") then
  114.                         if (self:GetDTInt(1)>0) or (self:GetDTInt(2)>0) or (self:GetDTInt(3)>0) or (self:GetDTInt(4)>0) or (self:GetDTInt(5)>0) or
  115.                         (self:GetDTInt(6)>0) or (self:GetDTInt(7)>0) or (self:GetDTInt(8)>0) then
  116.                             self.owner:SendLua("local tab={Color(255,255,255),[[Hello ]],Color(0,75,255),[["..self.owner:Nick().."]],Color(255,255,255),[[!]]}chat.AddText(unpack(tab))");
  117.                             v:EmitSound("vo/npc/male01/nice.wav", 70, 100);
  118.                             local totalAmount = 0;                     
  119.                             if (self:GetDTInt(1)>0) then
  120.                                 local money = math.Round(self:GetDTInt(1)*FS_Melon_Price);
  121.                                 totalAmount = totalAmount + money;
  122.                                 if (GAMEMODE.Version == "2.4.3") then  
  123.                                     self.owner:AddMoney(money);
  124.                                 else
  125.                                     self.owner:addMoney(money);
  126.                                 end;
  127.                                 if (self:GetDTInt(1) > 1) then
  128.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(213,213,25),[["..self:GetDTInt(1).." Melons]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");
  129.                                 elseif (self:GetDTInt(1) == 1) then
  130.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(213,213,25),[["..self:GetDTInt(1).." Melon]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");             
  131.                                 end;
  132.                                 self:SetDTInt(1, 0);
  133.                             end;
  134.                             if (self:GetDTInt(2)>0) then
  135.                                 local money = math.Round(self:GetDTInt(2)*FS_Cabbage_Price);
  136.                                 totalAmount = totalAmount + money;
  137.                                 if (GAMEMODE.Version == "2.4.3") then  
  138.                                     self.owner:AddMoney(money);
  139.                                 else
  140.                                     self.owner:addMoney(money);
  141.                                 end;
  142.                                 if (self:GetDTInt(2) > 1) then
  143.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(177,222,160),[["..self:GetDTInt(2).." Cabbages]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");
  144.                                 elseif (self:GetDTInt(2) == 1) then
  145.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(177,222,160),[["..self:GetDTInt(2).." Cabbage]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");              
  146.                                 end;
  147.                                 self:SetDTInt(2, 0);
  148.                             end;
  149.                             if (self:GetDTInt(3)>0) then
  150.                                 local money = math.Round(self:GetDTInt(3)*FS_Watermelon_Price);
  151.                                 totalAmount = totalAmount + money;
  152.                                 if (GAMEMODE.Version == "2.4.3") then  
  153.                                     self.owner:AddMoney(money);
  154.                                 else
  155.                                     self.owner:addMoney(money);
  156.                                 end;
  157.                                 if (self:GetDTInt(3) > 1) then
  158.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(119,214,25),[["..self:GetDTInt(3).." Watermelons]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");
  159.                                 elseif (self:GetDTInt(3) == 1) then
  160.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(119,214,25),[["..self:GetDTInt(3).." Watermelon]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");            
  161.                                 end;
  162.                                 self:SetDTInt(3, 0);
  163.                             end;
  164.                             if (self:GetDTInt(4)>0) then
  165.                                 local money = math.Round(self:GetDTInt(4)*FS_Tomato_Price);
  166.                                 totalAmount = totalAmount + money;
  167.                                 if (GAMEMODE.Version == "2.4.3") then  
  168.                                     self.owner:AddMoney(money);
  169.                                 else
  170.                                     self.owner:addMoney(money);
  171.                                 end;
  172.                                 if (self:GetDTInt(4) > 1) then
  173.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(175,0,0),[["..self:GetDTInt(4).." Tomatoes]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");
  174.                                 elseif (self:GetDTInt(4) == 1) then
  175.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(175,0,0),[["..self:GetDTInt(4).." Tomato]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");               
  176.                                 end;
  177.                                 self:SetDTInt(4, 0);
  178.                             end;
  179.                             if (self:GetDTInt(5)>0) then
  180.                                 local money = math.Round(self:GetDTInt(5)*FS_Orange_Price);
  181.                                 totalAmount = totalAmount + money;
  182.                                 if (GAMEMODE.Version == "2.4.3") then  
  183.                                     self.owner:AddMoney(money);
  184.                                 else
  185.                                     self.owner:addMoney(money);
  186.                                 end;
  187.                                 if (self:GetDTInt(5) > 1) then
  188.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(246,165,42),[["..self:GetDTInt(5).." Oranges]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");
  189.                                 elseif (self:GetDTInt(5) == 1) then
  190.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(246,165,42),[["..self:GetDTInt(5).." Orange]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");            
  191.                                 end;
  192.                                 self:SetDTInt(5, 0);
  193.                             end;
  194.                             if (self:GetDTInt(6)>0) then
  195.                                 local money = math.Round(self:GetDTInt(6)*FS_Apple_Price);
  196.                                 totalAmount = totalAmount + money;
  197.                                 if (GAMEMODE.Version == "2.4.3") then  
  198.                                     self.owner:AddMoney(money);
  199.                                 else
  200.                                     self.owner:addMoney(money);
  201.                                 end;
  202.                                 if (self:GetDTInt(6) > 1) then
  203.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(138,239,95),[["..self:GetDTInt(6).." Apples]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");
  204.                                 elseif (self:GetDTInt(6) == 1) then
  205.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(138,239,95),[["..self:GetDTInt(6).." Apple]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");             
  206.                                 end;
  207.                                 self:SetDTInt(6, 0);
  208.                             end;
  209.                             if (self:GetDTInt(7)>0) then
  210.                                 local money = math.Round(self:GetDTInt(7)*FS_Lemon_Price);
  211.                                 totalAmount = totalAmount + money;
  212.                                 if (GAMEMODE.Version == "2.4.3") then  
  213.                                     self.owner:AddMoney(money);
  214.                                 else
  215.                                     self.owner:addMoney(money);
  216.                                 end;
  217.                                 if (self:GetDTInt(7) > 1) then
  218.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(225,255,0),[["..self:GetDTInt(7).." Lemons]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");
  219.                                 elseif (self:GetDTInt(7) == 1) then
  220.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(225,255,0),[["..self:GetDTInt(7).." Lemon]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");              
  221.                                 end;
  222.                                 self:SetDTInt(7, 0);
  223.                             end;
  224.                             if (self:GetDTInt(8)>0) then
  225.                                 local money = math.Round(self:GetDTInt(8)*FS_Potato_Price);
  226.                                 totalAmount = totalAmount + money;
  227.                                 if (GAMEMODE.Version == "2.4.3") then  
  228.                                     self.owner:AddMoney(money);
  229.                                 else
  230.                                     self.owner:addMoney(money);
  231.                                 end;
  232.                                 if (self:GetDTInt(8) > 1) then
  233.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(125,82,17),[["..self:GetDTInt(8).." Potatoes]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");
  234.                                 elseif (self:GetDTInt(8) == 1) then
  235.                                     self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..money.."$]],Color(255,255,255),[[ for selling ]],Color(125,82,17),[["..self:GetDTInt(8).." Potato]],Color(255,255,255),[[.]]}chat.AddText(unpack(tab))");             
  236.                                 end;
  237.                                 self:SetDTInt(8, 0);
  238.                             end;                       
  239.                             self.owner:SendLua("local tab={Color(255,255,255),[[You got ]],Color(25,255,25),[["..totalAmount.."$ ]],Color(255,255,255),[[total.]]}chat.AddText(unpack(tab))");         
  240.                             self:EmitSound("vehicles/atv_ammo_open.wav");      
  241.                         else
  242.                             v:EmitSound("vo/npc/male01/sorry0"..math.random(1, 3)..".wav", 70, 100);
  243.                             self.owner:SendLua("local tab={Color(255,255,255),[[You don't have anything to sell!]]}chat.AddText(unpack(tab))");                    
  244.                         end;
  245.                     end;                   
  246.                 end;
  247.                 self.nextUse = CurTime() + 0.5;
  248.             end;       
  249.             if (self:GetDTString(1) == "none") then
  250.                 self:EmitSound("vehicles/atv_ammo_close.wav");
  251.                 self:SetDTString(1, activator:Nick());
  252.                 self.owner = activator;
  253.             end;           
  254.         end;
  255.     end;
  256. end;
  257.  
  258. function ENT:PhysicsCollide(data, phys)
  259. local curTime = CurTime();
  260.     if (data.DeltaTime > 0.1) then
  261.         timer.Simple(0, function()
  262.             if ((data.HitEntity:GetClass() == "fs_melon") and self:GetDTInt(1)<FS_Box_MaxHold_Melon) then
  263.                 self:SetDTInt(1, self:GetDTInt(1)+1);
  264.                 self:EmitSound("physics/wood/wood_box_impact_soft"..math.random(1, 3)..".wav");
  265.                 data.HitEntity:VisualEffect();         
  266.             end;
  267.             if ((data.HitEntity:GetClass() == "fs_cabbage") and self:GetDTInt(2)<FS_Box_MaxHold_Cabbage) then
  268.                 self:SetDTInt(2, self:GetDTInt(2)+1);
  269.                 self:EmitSound("physics/wood/wood_box_impact_soft"..math.random(1, 3)..".wav");
  270.                 data.HitEntity:VisualEffect();         
  271.             end;   
  272.             if ((data.HitEntity:GetClass() == "fs_watermelon") and self:GetDTInt(3)<FS_Box_MaxHold_Watermelon) then
  273.                 self:SetDTInt(3, self:GetDTInt(3)+1);
  274.                 self:EmitSound("physics/wood/wood_box_impact_soft"..math.random(1, 3)..".wav");
  275.                 data.HitEntity:VisualEffect();         
  276.             end;
  277.             if ((data.HitEntity:GetClass() == "fs_tomato") and self:GetDTInt(4)<FS_Box_MaxHold_Tomato) then
  278.                 self:SetDTInt(4, self:GetDTInt(4)+1);
  279.                 self:EmitSound("physics/wood/wood_box_impact_soft"..math.random(1, 3)..".wav");
  280.                 data.HitEntity:VisualEffect();         
  281.             end;
  282.             if ((data.HitEntity:GetClass() == "fs_orange") and self:GetDTInt(5)<FS_Box_MaxHold_Orange) then
  283.                 self:SetDTInt(5, self:GetDTInt(5)+1);
  284.                 self:EmitSound("physics/wood/wood_box_impact_soft"..math.random(1, 3)..".wav");
  285.                 data.HitEntity:VisualEffect();         
  286.             end;
  287.             if ((data.HitEntity:GetClass() == "fs_apple") and self:GetDTInt(6)<FS_Box_MaxHold_Apple) then
  288.                 self:SetDTInt(6, self:GetDTInt(6)+1);
  289.                 self:EmitSound("physics/wood/wood_box_impact_soft"..math.random(1, 3)..".wav");
  290.                 data.HitEntity:VisualEffect();         
  291.             end;
  292.             if ((data.HitEntity:GetClass() == "fs_lemon") and self:GetDTInt(7)<FS_Box_MaxHold_Lemon) then
  293.                 self:SetDTInt(7, self:GetDTInt(7)+1);
  294.                 self:EmitSound("physics/wood/wood_box_impact_soft"..math.random(1, 3)..".wav");
  295.                 data.HitEntity:VisualEffect();         
  296.             end;
  297.             if ((data.HitEntity:GetClass() == "fs_potato") and self:GetDTInt(8)<FS_Box_MaxHold_Potato) then
  298.                 self:SetDTInt(8, self:GetDTInt(8)+1);
  299.                 self:EmitSound("physics/wood/wood_box_impact_soft"..math.random(1, 3)..".wav");
  300.                 data.HitEntity:VisualEffect();         
  301.             end;
  302.         end)
  303.     end;
  304. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement