Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[-------------------------------------------------------------------------
- Droid Companion / Pet System *SERVERSIDE FILE*
- Written by Derpes (Dan Robinson)
- ---------------------------------------------------------------------------]]
- --Initialize the netmessages for the companion system.
- util.AddNetworkString("Companion_Open")
- util.AddNetworkString("Companion_Buy")
- util.AddNetworkString("Companion_Sell")
- util.AddNetworkString("Companion_Equip")
- --Metafunction for killing a companion
- function ENTITY:killCompanion()
- self:Remove()
- end
- --Metafunction for unlocking the companion when bought/whatever.
- function PLAYER:unlockCompanion(companion)
- self.Companions[companion] = true
- GSDATA.savePlayerCompanions( self:SteamID(), self.Companions )
- jvsNotify(self,jvsCompanions.Cfg.lang_received..jvsCompanions[companion].name)
- end
- --Metafunction for removing a players companion.
- function PLAYER:removeCompanion(companion)
- self.Companions[companion] = nil
- GSDATA.savePlayerCompanions( self:SteamID(), self.Companions )
- end
- --Metafunction to spawn a companion *UNFINISHED*
- function PLAYER:spawnCompanion(companion)
- --Spawn companion entity using companion argument
- end
- --Metafunction for players equipping a new companion
- function PLAYER:equipCompanion(companion)
- self:SetCompanion( companion )
- GSDATA.savePlayerEquippedCompanion( self:SteamID(), self:GetCompanion() )
- end
- --Netmessage metafunction to send and open the menu on the client.
- function PLAYER:openedCompanions()
- net.Start("Companion_Open")
- net.WriteTable(self.Companions)
- net.Send(self)
- end
- --Receive a netmessage to run serverside code once the companion is attempted to be bought.
- net("Companion_Buy",function(len,ply)
- local bought = net.ReadString()
- if( !ply.Companions[bought] )then
- if( ply:checkMoney() >= jvsCompanions[bought].price )then
- ply:takeMoney( jvsCompanions[bought].price )
- ply:unlockCompanion( bought )
- else
- jvsNotify( ply, jvsCompanions.Cfg.lang_nomoney )
- end
- else
- jvsNotify( ply, jvsCompanions.Cfg.lang_alreadyowned )
- end
- end)
- --Receive a netmessage to run serverside code once the companion is attempted to be sold.
- net("Companion_Sell",function(len,ply)
- ply:removeCompanion( net.ReadString() )
- end)
- --Receive a netmessage to run serverside code once the companion is attempted to be equipped.
- net("Companion_Equip",function(len,ply)
- ply:equipCompanion( net.ReadString() )
- end)
- --Hook to increase given damage when a pet makes them do so.
- --Also calculates damage upon pets, killing them when necessary.
- hook("EntityTakeDamage","jvs_doPetDmgChange",function( enemy, dmg )
- if(!IsValid(enemy))then return end
- if(enemy:IsCompanion())then
- enemy:SetHealth(enemy:Health() - dmg)
- if(enemy:Health() - dmg <= 0)then
- enemy:killCompanion()
- return
- end
- end
- local ply = dmg:GetAttacker()
- if(!IsValid(ply) || !ply:IsPlayer() || !ply.petDmgBoost)then return end
- dmg:SetDamage( dmg:GetDamage()*ply.petDmgBoost )
- end)
- --Hook for thinking, counting down and expiring companion abilities.
- local thinkDelay = 0
- hook("Think","jvs_petCooldowns",function()
- if not(thinkDelay>CurTime())then
- thinkDelay=CurTime()+1
- for k,ply in pairs(player.GetAll())do
- if(ply.companionCooldowns)then
- for i,ability in pairs(ply.companionCooldowns)do
- ply.companionCooldowns[ability] = ply.companionCooldowns[ability] - 1
- if(ply.companionCooldowns[ability] <= 0)then
- ply.companionCooldowns[ability] = nil
- end
- end
- end
- end
- end
- end)
- --Hook to kill the players companion when the player dies.
- hook("PlayerDeath","jvs_petPlayerDeath",function(ply)
- if(ply:HasCompanion())then
- for k,v in pairs(ply:GetChildren())do
- if(ply:GetChildren()[k]:GetClass() == "ent_jvs_companion")then
- ply:GetChildren()[k]:killCompanion()
- end
- end
- end
- end)
- --Hook to spawn the players equipped companion if necessary.
- hook("PlayerSpawn","jvs_petPlayerSpawn",function(ply)
- if(ply:HasCompanion())then
- ply:spawnCompanion( ply:GetCompanion() )
- end
- end)
- --[[-------------------------------------------------------------------------
- TEMPORARY CODE
- Opens the menu from the server.
- ---------------------------------------------------------------------------]]
- concommand.Add("companions", function(ply,cnd,args,argStr)
- ply:openedCompanions()
- end)
- ---------------------------------------------------------------------------]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement