Advertisement
Guest User

Untitled

a guest
Feb 19th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.85 KB | None | 0 0
  1. AddCSLuaFile("cl_init.lua")
  2. AddCSLuaFile("shared.lua")
  3. AddCSLuaFile("storerob_core/config/sh_config.lua")
  4. include("shared.lua")
  5. include("storerob_core/config/sh_config.lua")
  6.  
  7. local joballow = false
  8.  
  9. function ENT:Initialize()
  10. self:SetModel(NPCRobSystem.Config.NPCModel)
  11. self:SetHullType(HULL_HUMAN);
  12. self:SetHullSizeNormal();
  13. self:SetNPCState(NPC_STATE_SCRIPT)
  14. self:SetSolid(SOLID_BBOX)
  15. self:SetUseType(SIMPLE_USE)
  16. self:DropToFloor()
  17. self.data = {}
  18. self.data.canrob = true
  19. self.data.robber = nil
  20.  
  21. local sequence = self:LookupSequence( "cower" )
  22. self:SetSequence( sequence )
  23.  
  24. end
  25.  
  26. function ENT:AcceptInput(name, activator, caller)
  27.  
  28. if activator:IsPlayer() == false then return end
  29.  
  30. if timer.Exists("npcrobid"..self:EntIndex()) then
  31. net.Start("ncprobmsg")
  32. net.WriteString("Braquage en cours ! Plus que "..math.Round(timer.TimeLeft( "npcrobid"..self:EntIndex() ) ).." secondes !")
  33. net.Send(activator)
  34. else
  35. net.Start("npcstoreui")
  36. net.Send(activator)
  37. end
  38.  
  39. net.Receive("ncprobdoact", function(name, activator, caller)
  40. if activator:GetPos():Distance( self:GetPos() ) > 100 then
  41. net.Start("ncprobmsg")
  42. net.WriteString("Vous êtes trop loin pour braquer !")
  43. net.Send(activator)
  44. return
  45. end
  46.  
  47. if !(activator:Alive()) then
  48. net.Start("ncprobmsg")
  49. net.WriteString("Vous êtes mort !")
  50. net.Send(activator)
  51. return
  52. end
  53.  
  54. local joballow = false
  55. for _, job in pairs(NPCRobSystem.Config.CanRobJobs) do
  56. if activator:Team() == job then
  57. joballow = true
  58. break
  59. end
  60. end
  61.  
  62. local cops = 0
  63. for _, job in pairs(NPCRobSystem.Config.ConsideredCops) do
  64. cops = cops + #team.GetPlayers(job)
  65. end
  66.  
  67. if self.data.canrob == true then
  68. if joballow == true then
  69. if ( #player.GetAll() * NPCRobSystem.Config.RobGovernmentAmount ) > cops then
  70. net.Start("ncprobmsg")
  71. net.WriteString("Pas assez de policiers")
  72. net.Send(activator)
  73. elseif ( #player.GetAll() * NPCRobSystem.Config.RobGovernmentAmount ) <= cops then
  74. if (#player.GetAll() >= NPCRobSystem.Config.RobPlayerAmount) then
  75. self.data.canrob = false
  76. self.data.robber = activator
  77. sound.Add( {
  78. name = "alarmnoise",
  79. channel = CHAN_STREAM,
  80. volume = 1.0,
  81. level = 80,
  82. pitch = { 95, 110 },
  83. sound = NPCRobSystem.Config.RobAlarmDir
  84. } )
  85.  
  86. if NPCRobSystem.Config.RobAlarmActive then
  87. self:EmitSound("alarmnoise")
  88. end
  89.  
  90. net.Start("ncprobdoani")
  91. net.WriteEntity(self)
  92. net.Broadcast()
  93.  
  94. net.Start( "ncprobmsg" )
  95. net.WriteString( string.format( activator:Nick().." est en train de braquer le vendeur d'arme illégal pour "..NPCRobSystem.Config.RobAmount.."€. Fin du braquage dans "..NPCRobSystem.Config.RobTime.."s" ) )
  96. net.Broadcast()
  97.  
  98. self:EmitSound("vo/npc/male01/help01.wav")
  99. timer.Create("npcscream"..self:EntIndex(), math.random(1,NPCRobSystem.Config.RobShouttime), 0, function()
  100. local ranscream = math.random(1,2)
  101. if ranscream == 1 then
  102. self:EmitSound("vo/npc/male01/help01.wav")
  103. elseif ranscream == 2 then
  104. self:EmitSound("ambient/voices/m_scream1.wav")
  105. end
  106. end)
  107.  
  108. for _, v in pairs(player.GetAll()) do
  109. for _, n in pairs(NPCRobSystem.Config.ConsideredCops) do
  110. if v:Team() == n then
  111. net.Start( "ncprobpolicecall" )
  112. net.WriteEntity(self)
  113. net.Send(v)
  114. end
  115. end
  116. end
  117.  
  118.  
  119. timer.Create("npcrobid"..self:EntIndex(), NPCRobSystem.Config.RobTime, 1, function()
  120.  
  121. self:StopSound("alarmnoise" )
  122.  
  123. net.Start("ncprobdoanires")
  124. net.WriteEntity(self)
  125. net.Broadcast()
  126.  
  127. self.data.canrob = false
  128. for _, v in pairs(player.GetAll()) do
  129. for _, n in pairs(NPCRobSystem.Config.ConsideredCops) do
  130. if v:Team() == n then
  131. net.Start( "ncprobpolicecallend" )
  132. net.Send(v)
  133. end
  134. end
  135. end
  136.  
  137. timer.Destroy("npcscream"..self:EntIndex())
  138. self.data.robber = nil
  139. local cops = nil
  140. if activator:IsValid() then
  141. net.Start( "ncprobmsg" )
  142. net.WriteString( string.format( activator:Nick().." a braqué le vendeur d'arme illégal pour €"..NPCRobSystem.Config.RobAmount ) )
  143. net.Broadcast()
  144. end
  145. if NPCRobSystem.Config.RobMoneybagSystem == true then
  146. local entity = ents.Create( "storerob_moneybag" )
  147. if ( !IsValid( entity ) ) then return end
  148. entity:SetPos( self:GetPos() + Vector(-20,0,60) )
  149. entity:Spawn()
  150. elseif NPCRobSystem.Config.RobMoneybagSystem == false then
  151. activator:addMoney( NPCRobSystem.Config.RobAmount )
  152. end
  153. timer.Create("npccooldown"..self:EntIndex(), NPCRobSystem.Config.RobCoodownTime, 1, function()
  154. if IsValid(self) then
  155. self.data.canrob = true
  156. end
  157.  
  158. end)
  159. end)
  160.  
  161. elseif (#player.GetAll() < NPCRobSystem.Config.RobPlayerAmount) then
  162. net.Start("ncprobmsg")
  163. net.WriteString("Pas assez de joueurs")
  164. net.Send(activator)
  165. end
  166. else
  167. net.Start("ncprobmsg")
  168. net.WriteString("Pas assez de policiers")
  169. net.Send(activator)
  170. end
  171.  
  172. elseif joballow == false then
  173. net.Start("ncprobmsg")
  174. net.WriteString("Vous n'avez pas le bon métier pour braquer")
  175. net.Send(activator)
  176. end
  177.  
  178. elseif self.data.canrob == false then
  179. if timer.Exists("npcrobid"..self:EntIndex()) then
  180. net.Start("ncprobmsg")
  181. net.WriteString("Braquage en cours ! Fin du braquage dans "..math.Round(timer.TimeLeft( "npcrobid"..self:EntIndex() ) ).." secondes.")
  182. net.Send(activator)
  183. elseif timer.Exists("npccooldown"..self:EntIndex()) then
  184. net.Start("ncprobmsg")
  185. net.WriteString("Il y a déja eu un braquage ! Revenez dans "..math.Round(timer.TimeLeft( "npccooldown"..self:EntIndex() )).."secondes !")
  186. net.Send(activator)
  187. else
  188. self.data.canrob = true
  189. end
  190. end
  191.  
  192. end)
  193.  
  194. end
  195.  
  196.  
  197. function ENT:RobAbort()
  198. net.Start("ncprobdoanires")
  199. net.WriteEntity(self)
  200. net.Broadcast()
  201. self:StopSound("alarmnoise" )
  202. if !IsValid(self.data.robber) then return end
  203.  
  204. timer.Destroy("npcrobid"..self:EntIndex())
  205. timer.Destroy("npcscream"..self:EntIndex())
  206. self.data.canrob = false
  207. for _, v in pairs(player.GetAll()) do
  208. for _, n in pairs(NPCRobSystem.Config.ConsideredCops) do
  209. if v:Team() == n then
  210. net.Start( "ncprobpolicecallend" )
  211. net.Send(v)
  212. end
  213. end
  214. end
  215. timer.Create("npccooldown"..self:EntIndex(), NPCRobSystem.Config.RobCoodownTime, 1, function()
  216. if IsValid(self) then
  217. self.data.canrob = true
  218. end
  219. end)
  220.  
  221. net.Start( "ncprobmsg" )
  222. net.WriteString( self.data.robber:Nick().." a raté son braquage de €"..NPCRobSystem.Config.RobAmount )
  223. net.Broadcast()
  224. self.data.robber = nil
  225. local cops = nil
  226.  
  227. end
  228.  
  229. function ENT:Think()
  230. if not IsValid( self.data.robber ) then return end
  231.  
  232. if self.data.robber:GetPos():Distance( self:GetPos() ) > NPCRobSystem.Config.RobMaxDistance then
  233. self:RobAbort()
  234. end
  235. end
  236.  
  237. function ENT:OnRemove()
  238. if timer.Exists("npcrobid"..self:EntIndex()) then
  239. self:RobAbort()
  240. timer.Destroy("npccooldown"..self:EntIndex())
  241. end
  242. end
  243.  
  244.  
  245. --
  246. -- Hooks
  247. --
  248.  
  249.  
  250. hook.Add( "PlayerDeath", "rob_robberkilled", function( victim, inflictor, attacker )
  251. for _, npctorob in pairs( ents.FindByClass( "storerob_corenpc" ) ) do
  252. if npctorob.data.robber == victim then
  253. npctorob:RobAbort()
  254. end
  255. end
  256.  
  257. end)
  258.  
  259. hook.Add( "PlayerDisconnected", "rob_robberkilled", function( ply )
  260. for _, npctorob in pairs( ents.FindByClass( "storerob_corenpc" ) ) do
  261. if npctorob.data.robber == ply then
  262. npctorob:RobAbort()
  263. end
  264. end
  265.  
  266. end)
  267.  
  268. hook.Add("OnPlayerChangedTeam", "rob_robberchangejob", function( ply )
  269. for _, npctorob in pairs( ents.FindByClass( "storerob_corenpc" ) ) do
  270. if npctorob.data.robber == ply then
  271. npctorob:RobAbort()
  272. end
  273. end
  274. end)
  275.  
  276. concommand.Add( "savestorerob", function(ply)
  277.  
  278. if !NPCRobSystem.Config.SaveComGroup[ply:GetUserGroup()] then
  279. net.Start("ncprobmsg")
  280. net.WriteString("You do not have access to that command!")
  281. net.Send(ply)
  282. return
  283. end
  284.  
  285. savedStores = {}
  286. for i, store in pairs( ents.FindByClass( "storerob_corenpc" ) ) do
  287. savedStores[ i ] = { pos = store:GetPos(), ang = store:GetAngles() }
  288. file.Write( "stores/storefile.txt", util.TableToJSON( savedStores ) )
  289. end
  290.  
  291. net.Start("ncprobmsg")
  292. net.WriteString("NPC's saved")
  293. net.Send(ply)
  294.  
  295. end )
  296.  
  297.  
  298. function ENT:AcceptInput( Name, Activator, Caller )
  299.  
  300. for k,v in pairs(player.GetAll() ) do
  301.  
  302. if team.NumPlayers( TEAM_GUN ) >= 1 then
  303.  
  304. Activator:ChatPrint("Il y a déjà un vendeur d'armes en ville !")
  305. return false
  306.  
  307. else
  308.  
  309. if Name == "Use" and Caller:IsPlayer() then
  310.  
  311. net.Start("npcstoreui")
  312. net.Send(Activator)
  313.  
  314. end
  315.  
  316. end
  317.  
  318. end
  319.  
  320. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement