Advertisement
Guest User

Untitled

a guest
Dec 15th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.81 KB | None | 0 0
  1. AddCSLuaFile()
  2. DEFINE_BASECLASS( "base_anim" )
  3.  
  4. ENT.Base = "sent_base_gonzo"
  5. ENT.Size = Vector(0,30,30)
  6. ENT.PrintName = "Pot"
  7. ENT.Author = "Gonzo"
  8. ENT.Spawnable = false
  9. ENT.Category = "Drugs"
  10. ENT.AdminOnly = true
  11.  
  12. local function IsLookingAt( a, b, nor, dis, targetVec )
  13. return nor:Dot( (a:GetPos() - b:GetPos()) ) / (a:GetPos() - b:GetPos()):Length() < -1.8
  14. end
  15.  
  16. function ENT:SpawnFunction( ply, tr, ClassName )
  17.  
  18. if ( !tr.Hit ) then return end
  19.  
  20. local SpawnPos = tr.HitPos
  21.  
  22. local ent = ents.Create( ClassName )
  23. ent:SetPos( SpawnPos )
  24. ent:Spawn()
  25. ent:Activate()
  26. ent:SetPersistent()
  27. ent.Owner = ply
  28.  
  29. return ent
  30.  
  31. end
  32.  
  33. function ENT:Initialize()
  34.  
  35. if SERVER then
  36. self:SetModel( "models/gonzo/weedb/pot1.mdl" )
  37. self:PhysicsInit( SOLID_VPHYSICS ) -- Make us work with physics,
  38. self:SetMoveType( MOVETYPE_VPHYSICS ) -- after all, gmod is a physics
  39. self:SetSolid( SOLID_VPHYSICS ) -- Toolbox
  40.  
  41. local phys = self:GetPhysicsObject()
  42. if (phys:IsValid()) then
  43. phys:Wake()
  44. end
  45.  
  46. self:SetHealth(0)
  47. self:SetNWInt("Water",0)
  48. self:SetNWInt("Light",0)
  49. self:SetNWInt("Seed",0)
  50. self:SetNWInt("Level",1)
  51. self:SetNWInt("Percent",0)
  52. self:SetNWInt("Quality",0)
  53.  
  54. end
  55. end
  56.  
  57. function ENT:SetPot(x)
  58.  
  59. self:SetModel( "models/gonzo/weedb/pot"..x..".mdl" )
  60. self:PhysicsInit( SOLID_VPHYSICS )
  61. self:SetMoveType( MOVETYPE_VPHYSICS )
  62. self:SetSolid( SOLID_VPHYSICS )
  63.  
  64. local phys = self:GetPhysicsObject()
  65. if (phys:IsValid()) then
  66. phys:Wake()
  67. end
  68.  
  69. if(x==1) then
  70. self:SetNWInt("MaxWater",90)
  71. self:SetNWInt("Extra",0)
  72. end
  73. if(x==2) then
  74. self:SetNWInt("MaxWater",100)
  75. self:SetNWInt("Extra",1)
  76. end
  77. if(x==3) then
  78. self:SetNWInt("MaxWater",140)
  79. self:SetNWInt("Extra",3)
  80. end
  81. if(x==4) then
  82. self:SetNWInt("MaxWater",100)
  83. self:SetNWInt("Extra",2)
  84. self:SetNWBool("MultiplePot",true)
  85. end
  86.  
  87. end
  88.  
  89. if SERVER then
  90. util.AddNetworkString("ReloadShadow")
  91. end
  92.  
  93. ENT.OldSeed = 0
  94. ENT.SeedWater = 0
  95. ENT.SeedEx = 0
  96. ENT.NSeed = 0
  97.  
  98. function ENT:Touch(entity)
  99. if(self:GetNWInt("Soil",0) > 0 && self:GetNWInt("Seed",0) == 0 && entity:GetClass() == "sent_seed" && !self:GetNWBool("MultiplePot",false)) then
  100. self:SetNWInt("Quality",entity.Quality)
  101. self:SetNWInt("Seed",1)
  102. self:SetNWInt("Water",50)
  103. self:SetHealth(100)
  104. self:SetNWInt("Level",1)
  105. self:SetNWInt("Progress",1)
  106.  
  107. self:SetNWString("seedName", entity:GetNWString("PrintName"));
  108. entity:Remove()
  109.  
  110. local ent = ents.Create("prop_dynamic")
  111. ent:SetModel("models/gonzo/weed_shared.mdl")
  112. ent:SetPos(self:GetPos() + self:GetUp()*16)
  113. ent:SetAngles(self:GetAngles())
  114. ent:Spawn()
  115. ent:SetParent(self)
  116. self:SetNWEntity("WeedGhost",ent)
  117. self.Weed = ent
  118.  
  119. if(entity:GetClass() != "sent_seed") then
  120. self:SetNWInt("MaxWater",self:GetNWInt("MaxWater",100)+entity.Waterizer)
  121. self:SetNWInt("Extra",self:GetNWInt("Extra",100)+entity.Extra)
  122. else
  123. self:SetNWInt("MaxWater",self:GetNWInt("MaxWater",100)+entity.Waterizer)
  124. self:SetNWInt("Extra",self:GetNWInt("Extra",100)+entity.Extra)
  125. self.SeedWater = entity.Waterizer
  126. self.SeedEx = entity.Extra
  127. end
  128. end
  129.  
  130. if(self.NSeed < CurTime() && self:GetNWInt("Soil",0) > 0 && entity:GetClass() == "sent_seed" && self:GetNWBool("MultiplePot",false) && self:GetNWInt("Seed",0) < 3) then
  131. self.NSeed = CurTime()+1
  132. if(self:GetNWInt("Seed",0) == 0) then
  133. self:SetNWInt("Quality",entity.Quality)
  134. self:SetNWInt("MaxWater",self:GetNWInt("MaxWater",100)+entity.Waterizer)
  135. self:SetNWInt("Extra",self:GetNWInt("Extra",100)+entity.Extra)
  136. self.SeedWater = entity.Waterizer
  137. self.SeedEx = entity.Extra
  138. entity:Remove()
  139. self:SetNWInt("Seed",self:GetNWInt("Seed",0)+1)
  140. elseif(entity.Waterizer == self.SeedWater && entity.Extra == self.SeedEx && self:GetNWInt("Seed",0) != 3) then
  141. self:SetNWString("seedName", entity:GetNWString("PrintName"));
  142. entity:Remove()
  143. self:SetNWInt("Seed",self:GetNWInt("Seed",0)+1)
  144. if(self:GetNWInt("Seed",0)==3) then
  145. self:SetNWInt("Water",50)
  146. self:SetNWInt("Level",1)
  147. self:SetNWInt("Progress",1)
  148. self:SetHealth(50)
  149. self.Weed = {}
  150. for k=1,3 do
  151. local ent = ents.Create("prop_dynamic")
  152. ent:SetModel("models/gonzo/weed_shared.mdl")
  153. ent:SetPos(self:GetPos() + self:GetUp()*24 - self:GetRight()*38*2 + self:GetRight()*k*38)
  154. ent:SetAngles(self:GetAngles())
  155. ent:Spawn()
  156. ent:SetParent(self)
  157. self.Weed[k] = ent
  158. end
  159. self:SetNWEntity("WeedGhostA",self.Weed[1])
  160. self:SetNWEntity("WeedGhostB",self.Weed[2])
  161. self:SetNWEntity("WeedGhostC",self.Weed[3])
  162. end
  163. end
  164. end
  165. end
  166.  
  167.  
  168. // XP boost in % depending on seed type.
  169. local seedXPBonus = {
  170. ["Haze Berry"] = 20,
  171. ["Amnesia Haze"] = 40,
  172. ["Bubble Kush"] = 60,
  173. ["O.G. Kush"] = 80
  174. }
  175.  
  176. function ENT:Use(act)
  177. if(self:GetNWInt("Level",0) >= 7) then
  178. self:SetNWInt("Seed",0)
  179. self:SetNWInt("Progress",0)
  180. self:SetNWInt("Level",0)
  181. -- If you change your mind later...
  182. act.notificationType = { "Harvested Weed", ""}
  183.  
  184. if(act.addEXP) then
  185. local xp = Either(self:GetNWBool("MultiplePot",false),5000,1500)
  186. xp = xp * ((seedXPBonus[self:GetNWString("seedName","Quick Seed")] or 20) / 100 + 1) // adds x% based on seed type.
  187. act:addEXP( xp );
  188. end
  189.  
  190. if(!self:GetNWBool("MultiplePot",false)) then
  191. self.Weed:Remove()
  192. local ent = ents.Create("sent_drug_bag")
  193. ent:SetPos(self:GetPos() + Vector(0,0,64))
  194. ent:Spawn()
  195. ent:SetNWInt("Quality",self:GetNWInt("Quality",0))
  196. ent:SetNWString("PrintName","Weed - "..self:GetNWInt("Quality",0).."%")
  197. else
  198. for k,v in pairs(self.Weed) do
  199. local ent = ents.Create("sent_drug_bag")
  200. ent:SetPos(self:GetPos() + Vector(0,0,64) - self:GetRight()*38*2 + self:GetRight()*k*38)
  201. ent:Spawn()
  202. ent:SetNWInt("Quality",self:GetNWInt("Quality",0))
  203. ent:SetNWString("PrintName","Weed - "..self:GetNWInt("Quality",0).."%")
  204. v:Remove()
  205. end
  206. end
  207.  
  208. self:SetNWInt("MaxWater",self:GetNWInt("MaxWater",100)-self.SeedWater)
  209. self:SetNWInt("Extra",self:GetNWInt("Extra",100)-self.SeedEx)
  210. self.SeedWater = 0
  211. self.SeedEx = 0
  212.  
  213. end
  214. end
  215.  
  216. function ENT:Think()
  217. if SERVER then
  218. local a = self:GetNWInt("Seed",0) > 0 && !self:GetNWBool("MultiplePot",false)
  219. local b = self:GetNWBool("MultiplePot",false) && self:GetNWInt("Seed",0)==3
  220. if((a || b)&& self:GetNWInt("Level",0) < 7) then
  221.  
  222. if(!WEED_CONFIG.Demo) then
  223. if(WEED_CONFIG.WaterLossChance >= math.random(1,100) && (self.Watered or 0) <= CurTime()) then
  224. local m = math.random(WEED_CONFIG.WaterLoss[1],WEED_CONFIG.WaterLoss[2])
  225. self:SetNWInt("Water",math.Clamp(self:GetNWInt("Water",0)-m,0,self:GetNWInt("MaxWater",100)))
  226. end
  227.  
  228. if(self:GetNWInt("Water",0) < self:GetNWInt("MaxWater",100)*0.25) then
  229. self:SetHealth(self:Health()-3-(self:GetNWInt("Water",0)/self:GetNWInt("MaxWater",100)*0.25)*3)
  230. end
  231. if(self:GetNWInt("Light",0) < 40) then
  232. self:SetHealth(self:Health()-2-(self:GetNWInt("Light",0)/50)*2.5)
  233. end
  234. end
  235.  
  236. if(WEED_CONFIG.Demo) then
  237. self:SetNWInt("Progress",self:GetNWInt("Progress",0)+50)
  238. else
  239. self:SetNWInt("Progress",self:GetNWInt("Progress",0)+math.random(1,5)+math.max(0,self:GetNWInt("Extra",1)))
  240. end
  241.  
  242. if(self:GetNWInt("Progress",0) >= 100) then
  243. self:SetNWInt("Progress",0)
  244. self:SetNWInt("Level",self:GetNWInt("Level",0)+1)
  245. self:SetNWInt("Water",math.max(self:GetNWInt("Water"),self:GetNWInt("MaxWater",100)*0.5))
  246. if(!istable(self.Weed)) then
  247. self.Weed:SetBodygroup(1,math.Clamp(self:GetNWInt("Level",1),0,7)-1)
  248. else
  249. for k,v in pairs(self.Weed) do
  250. v:SetBodygroup(1,math.Clamp(self:GetNWInt("Level",1),0,7)-1)
  251. end
  252. end
  253.  
  254. end
  255.  
  256. self.Machine = nil
  257.  
  258. for k,v in pairs(ents.FindByClass("sent_light")) do
  259. if(!(v.IsRadial or false)) then
  260. local a = IsLookingAt(v,self,v:GetForward() + v:GetForward(),-172)
  261. if(v:GetPos():Distance(self:GetPos()) < 192 && a && self:GetNWFloat("Light",0) < 100 && v:GetNWInt("Charge",0) > 0 && v:GetNWBool("On",false)) then
  262. self.Machine = v
  263. end
  264. elseif(v:GetPos():Distance(self:GetPos()) < 192/2 && self:GetNWFloat("Light",0) < 100 && v:GetNWInt("Charge",0) > 0 && v:GetNWBool("On",false)) then
  265. self.Machine = v
  266. end
  267. end
  268. //76561197978936716
  269. if(IsValid(self.Machine)) then
  270. self:SetNWInt("Light",math.Clamp(self:GetNWInt("Light",0)+(20-self.Machine:GetPos():Distance(self:GetPos())/14.2),0,100))
  271. else
  272. self:SetNWInt("Light",math.Clamp(self:GetNWInt("Light",0)-10,0,100))
  273. end
  274.  
  275. if(self:Health() <= 0) then
  276. self:SetNWInt("Seed",0)
  277. self:SetNWInt("Progress",0)
  278. self:SetNWInt("Level",0)
  279. if(isentity(self.Weed)) then
  280. self.Weed:Remove()
  281. elseif(istable(self.Weed)) then
  282. for k,v in pairs(self.Weed) do
  283. v:Remove()
  284. end
  285. end
  286.  
  287. MsgN("YOU DIED "..self:GetNWInt("Light",100))
  288.  
  289. self:SetNWInt("MaxWater",self:GetNWInt("MaxWater",100)-self.SeedWater)
  290. self:SetNWInt("Extra",self:GetNWInt("Extra",100)-self.SeedEx)
  291. self.SeedWater = 0
  292. self.SeedEx = 0
  293. end
  294.  
  295. end
  296.  
  297. self:NextThink( CurTime() + math.random(1,3) )
  298.  
  299. return true
  300. end
  301. end
  302.  
  303. if CLIENT then
  304.  
  305. function ENT:PostDraw()
  306. if(!self:GetNWBool("MultiplePot",false) && IsValid(self:GetNWEntity("WeedGhost"))) then
  307. prop = self:GetNWEntity("WeedGhost")
  308. mat = Matrix()
  309. mat:Scale( Vector(1,1,1)*(self:GetNWInt("Level",0)/7+(self:GetNWInt("Progress")/100)*(1/7))*1.2 )
  310. prop:EnableMatrix( "RenderMultiply", mat )
  311. elseif(IsValid(self:GetNWEntity("WeedGhostA"))) then
  312. for k=1,3 do
  313. prop = self:GetNWEntity("WeedGhost"..Either(k==1,"A",Either(k==2,"B","C")))
  314. mat = Matrix()
  315. mat:Scale( Vector(1,1,1)*(self:GetNWInt("Level",0)/7+(self:GetNWInt("Progress")/100)*(1/7))*1.2 )
  316. prop:EnableMatrix( "RenderMultiply", mat )
  317. end
  318. end
  319. end
  320.  
  321. local water = surface.GetTextureID("gui/water")
  322. local light = surface.GetTextureID("gui/light")
  323.  
  324. local emotes = {"dead","bad","neutral","regular","happy"}
  325. local hl = {Color(231, 76, 60),Color(230, 126, 34),Color(241, 196, 15),Color(46, 204, 113)}
  326. local em_tex = {}
  327. for k,v in pairs(emotes) do
  328. em_tex[k] = surface.GetTextureID("gui/"..v)
  329. end
  330.  
  331. local rope = Material("gui/rope")
  332. local triangle = {}
  333. local a,b,c,d,ang
  334.  
  335. function surface.DrawTexturedRectUVRotated(px,py,pw,ph,pu,pv,eu,ev,rot)
  336.  
  337. ang = Angle(0,rot,0)
  338. a = Vector(-pw/2,-ph/2,0)
  339. a:Rotate(ang)
  340. b = Vector(pw/2,-ph/2,0)
  341. b:Rotate(ang)
  342. c = Vector(pw/2,ph/2,0)
  343. c:Rotate(ang)
  344. d = Vector(-pw/2,ph/2,0)
  345. d:Rotate(ang)
  346.  
  347. triangle[1] = {x=px+a.x,y=py+a.y,u=pu,v=pv}
  348. triangle[2] = {x=px+b.x,y=py+b.y,u=eu,v=pv}
  349. triangle[3] = {x=px+c.x,y=py+c.y,u=eu,v=ev}
  350. triangle[4] = {x=px+d.x,y=py+d.y,u=pu,v=ev}
  351.  
  352. surface.DrawPoly(triangle)
  353.  
  354. end
  355.  
  356. function ENT:DoInfo(pos)
  357. surface.SetDrawColor(50,50,50,150)
  358. surface.DrawRect(16,-64,272,128+16)
  359.  
  360. surface.SetTexture(water)
  361. surface.SetDrawColor(hl[math.Clamp(math.ceil((self:GetNWInt("Water",0))/25)+1,1,4)])
  362. surface.DrawTexturedRect(30,0,64,64)
  363.  
  364. surface.SetTexture(light)
  365. surface.SetDrawColor(hl[math.Clamp(math.ceil((self:GetNWInt("Light",0))/33)+1,1,4)])
  366. surface.DrawTexturedRect(214,0,64,64)
  367.  
  368. if((self:GetNWBool("MultiplePot",false) && self:GetNWInt("Seed",0) >= 3) || (!self:GetNWBool("MultiplePot",false) && self:GetNWInt("Seed",0) > 0) && self:GetNWInt("Level",0) < 7) then
  369. for k,v in pairs(em_tex) do
  370. surface.SetTexture(v)
  371. surface.SetDrawColor(255,255,255,Either(math.ceil((self:Health())/25)+1==(k) or (k==1&&self:Health()==0),255,25))
  372. surface.DrawTexturedRect(-20+50*k,-52,48,48)
  373. end
  374. else
  375. if(self:GetNWInt("Level",0) < 7) then
  376. if(self:GetNWInt("Soil",0) > 0) then
  377. draw.SimpleTextOutlined(Either(self:GetNWBool("MultiplePot",false),"("..(3-self:GetNWInt("Seed",0))..") ","").."Seed me","MainWeedFont",152,-28,Color(255,150,50,250),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER,1,Color(75,75,75))
  378. else
  379. draw.SimpleTextOutlined("Soil me","MainWeedFont",152,-28,Color(255,150,50,250),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER,1,Color(75,75,75))
  380. end
  381. else
  382. draw.SimpleTextOutlined("Prepare me","MainWeedFont",152,-28,Color(100,255,50,250),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER,1,Color(75,75,75))
  383. end
  384. end
  385. //76561198044940228
  386. draw.SimpleTextOutlined("%"..self:GetNWInt("Progress",100),"MainWeedFont",152,32,Color(255,255,255,100),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER,1,Color(75,75,75))
  387. //draw.SimpleTextOutlined("HP "..self:Health().." Water "..self:GetNWInt("Water"),"MainWeedFont",152,-128,Color(255,255,255,100),TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER,1,Color(75,75,75))
  388.  
  389. surface.SetMaterial(rope)
  390. surface.SetDrawColor(255,255,255,255)
  391. surface.DrawTexturedRectUV( 14, -64, 8, 128+16, 0, 0, 1, 1 )
  392.  
  393. surface.DrawTexturedRectUVRotated(153, -68, 8, 278, 0, 0, 1, 2 ,90)
  394. surface.DrawTexturedRectUVRotated(14+270+4, 0, 8, 128+16, 0, 0, 1, 1 ,180)
  395. surface.DrawTexturedRectUVRotated(153, 80, 8, 278, 0, 0, 1, 2 ,270)
  396. end
  397.  
  398. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement