Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.54 KB | None | 0 0
  1. --[[-------------------------------------------------------------------------
  2. Droid Companion / Pet System *SERVERSIDE FILE*
  3. Written by Derpes (Dan Robinson)
  4. ---------------------------------------------------------------------------]]
  5.  
  6. --Initialize the netmessages for the companion system.
  7. util.AddNetworkString("Companion_Open")
  8. util.AddNetworkString("Companion_Buy")
  9. util.AddNetworkString("Companion_Sell")
  10. util.AddNetworkString("Companion_Equip")
  11.  
  12. --Metafunction for killing a companion
  13. function ENTITY:killCompanion()
  14.  
  15. self:Remove()
  16.  
  17. end
  18.  
  19. --Metafunction for unlocking the companion when bought/whatever.
  20. function PLAYER:unlockCompanion(companion)
  21.  
  22. self.Companions[companion] = true
  23.  
  24. GSDATA.savePlayerCompanions( self:SteamID(), self.Companions )
  25.  
  26. jvsNotify(self,jvsCompanions.Cfg.lang_received..jvsCompanions[companion].name)
  27.  
  28. end
  29.  
  30. --Metafunction for removing a players companion.
  31. function PLAYER:removeCompanion(companion)
  32.  
  33. self.Companions[companion] = nil
  34.  
  35. GSDATA.savePlayerCompanions( self:SteamID(), self.Companions )
  36.  
  37. end
  38.  
  39. --Metafunction to spawn a companion *UNFINISHED*
  40. function PLAYER:spawnCompanion(companion)
  41.  
  42. --Spawn companion entity using companion argument
  43.  
  44. end
  45.  
  46. --Metafunction for players equipping a new companion
  47. function PLAYER:equipCompanion(companion)
  48.  
  49. self:SetCompanion( companion )
  50.  
  51. GSDATA.savePlayerEquippedCompanion( self:SteamID(), self:GetCompanion() )
  52.  
  53. end
  54.  
  55. --Netmessage metafunction to send and open the menu on the client.
  56. function PLAYER:openedCompanions()
  57.  
  58. net.Start("Companion_Open")
  59.  
  60. net.WriteTable(self.Companions)
  61.  
  62. net.Send(self)
  63.  
  64. end
  65.  
  66. --Receive a netmessage to run serverside code once the companion is attempted to be bought.
  67. net("Companion_Buy",function(len,ply)
  68.  
  69. local bought = net.ReadString()
  70.  
  71. if( !ply.Companions[bought] )then
  72.  
  73. if( ply:checkMoney() >= jvsCompanions[bought].price )then
  74.  
  75. ply:takeMoney( jvsCompanions[bought].price )
  76.  
  77. ply:unlockCompanion( bought )
  78.  
  79. else
  80.  
  81. jvsNotify( ply, jvsCompanions.Cfg.lang_nomoney )
  82.  
  83. end
  84.  
  85. else
  86.  
  87. jvsNotify( ply, jvsCompanions.Cfg.lang_alreadyowned )
  88.  
  89. end
  90.  
  91. end)
  92.  
  93. --Receive a netmessage to run serverside code once the companion is attempted to be sold.
  94. net("Companion_Sell",function(len,ply)
  95.  
  96. ply:removeCompanion( net.ReadString() )
  97.  
  98. end)
  99.  
  100. --Receive a netmessage to run serverside code once the companion is attempted to be equipped.
  101. net("Companion_Equip",function(len,ply)
  102.  
  103. ply:equipCompanion( net.ReadString() )
  104.  
  105. end)
  106.  
  107. --Hook to increase given damage when a pet makes them do so.
  108. --Also calculates damage upon pets, killing them when necessary.
  109. hook("EntityTakeDamage","jvs_doPetDmgChange",function( enemy, dmg )
  110.  
  111. if(!IsValid(enemy))then return end
  112.  
  113. if(enemy:IsCompanion())then
  114.  
  115. enemy:SetHealth(enemy:Health() - dmg)
  116.  
  117. if(enemy:Health() - dmg <= 0)then
  118.  
  119. enemy:killCompanion()
  120.  
  121. return
  122.  
  123. end
  124.  
  125. end
  126.  
  127. local ply = dmg:GetAttacker()
  128.  
  129. if(!IsValid(ply) || !ply:IsPlayer() || !ply.petDmgBoost)then return end
  130.  
  131. dmg:SetDamage( dmg:GetDamage()*ply.petDmgBoost )
  132.  
  133. end)
  134.  
  135. --Hook for thinking, counting down and expiring companion abilities.
  136. local thinkDelay = 0
  137. hook("Think","jvs_petCooldowns",function()
  138.  
  139. if not(thinkDelay>CurTime())then
  140.  
  141. thinkDelay=CurTime()+1
  142.  
  143. for k,ply in pairs(player.GetAll())do
  144.  
  145. if(ply.companionCooldowns)then
  146.  
  147. for i,ability in pairs(ply.companionCooldowns)do
  148.  
  149. ply.companionCooldowns[ability] = ply.companionCooldowns[ability] - 1
  150.  
  151. if(ply.companionCooldowns[ability] <= 0)then
  152.  
  153. ply.companionCooldowns[ability] = nil
  154.  
  155. end
  156.  
  157. end
  158.  
  159. end
  160.  
  161. end
  162.  
  163. end
  164.  
  165. end)
  166.  
  167. --Hook to kill the players companion when the player dies.
  168. hook("PlayerDeath","jvs_petPlayerDeath",function(ply)
  169.  
  170. if(ply:HasCompanion())then
  171.  
  172. for k,v in pairs(ply:GetChildren())do
  173.  
  174. if(ply:GetChildren()[k]:GetClass() == "ent_jvs_companion")then
  175.  
  176. ply:GetChildren()[k]:killCompanion()
  177.  
  178. end
  179.  
  180. end
  181.  
  182. end
  183.  
  184. end)
  185.  
  186. --Hook to spawn the players equipped companion if necessary.
  187. hook("PlayerSpawn","jvs_petPlayerSpawn",function(ply)
  188.  
  189. if(ply:HasCompanion())then
  190.  
  191. ply:spawnCompanion( ply:GetCompanion() )
  192.  
  193. end
  194.  
  195. end)
  196.  
  197. --[[-------------------------------------------------------------------------
  198. TEMPORARY CODE
  199. Opens the menu from the server.
  200. ---------------------------------------------------------------------------]]
  201. concommand.Add("companions", function(ply,cnd,args,argStr)
  202. ply:openedCompanions()
  203. end)
  204. ---------------------------------------------------------------------------]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement