Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.35 KB | None | 0 0
  1. hatemap = { }
  2.  
  3. local function OnNPCKilled( npc, attacker, inflictor )
  4.     local a, b, k, v, d
  5.    
  6.     a = npc:GetClass( )
  7.     b = attacker:GetClass( )
  8.    
  9.     hatemap[ a ] = hatemap[ a ] or { }
  10.     hatemap[ a ][ b ] = hatemap[ a ][ b ] or 0
  11.    
  12.     hatemap[ b ] = hatemap[ b ] or { }
  13.     hatemap[ b ][ a ] = hatemap[ b ][ a ] or 0
  14.    
  15.     hatemap[ a ][ b ] = hatemap[ a ][ b ] - 100
  16.     hatemap[ b ][ a ] = hatemap[ b ][ a ] + 100
  17.    
  18.     d = hatemap[ a ][ b ]
  19.    
  20.     for k, v in ents.FindByClass( a ) do
  21.         v:AddRelationship( string.format( "%s %s %d", b, d > 0 and "D_LI" or "D_HT", math.abs( d ) ) )
  22.         if d > 0 then
  23.             v:AddRelationship( string.format( "%s D_HT 0", b ) )
  24.         end
  25.     end
  26.    
  27.     d = hatemap[ b ][ a ]
  28.    
  29.     for k, v in ents.FindByClass( b ) do
  30.         v:AddRelationship( string.format( "%s %s %d", b, d > 0 and "D_LI" or "D_HT", math.abs( d ) )
  31.         if d > 0 then
  32.             v:AddRelationship( string.format( "%s D_HT 0", b ) )
  33.         end
  34.     end
  35. end
  36.  
  37. local function EntityTakeDamage( ent, inflictor, attacker, amount, info )
  38.     local a, b
  39.    
  40.     if not ( ent:IsPlayer( ) or ent:IsNPC( ) ) then
  41.         return
  42.     end
  43.    
  44.     a = ent:GetClass( )
  45.     b = attacker:GetClass( )
  46.    
  47.     hatemap[ a ] = hatemap[ a ] or { }
  48.     hatemap[ a ][ b ] = hatemap[ a ][ b ] or 0
  49.    
  50.     hatemap[ b ] = hatemap[ b ] or { }
  51.     hatemap[ b ][ a ] = hatemap[ b ][ a ] or 0
  52.    
  53.     hatemap[ a ][ b ] = hatemap[ a ][ b ] - amount
  54.     hatemap[ b ][ a ] = hatemap[ b ][ a ] + amount
  55.    
  56.     d = hatemap[ a ][ b ]
  57.    
  58.     for k, v in ents.FindByClass( a ) do
  59.         v:AddRelationship( string.format( "%s %s %d", b, d > 0 and "D_LI" or "D_HT", math.abs( d ) ) )
  60.         if d > 0 then
  61.             v:AddRelationship( string.format( "%s D_HT 0", b ) )
  62.         end
  63.     end
  64.    
  65.     d = hatemap[ b ][ a ]
  66.    
  67.     for k, v in ents.FindByClass( b ) do
  68.         v:AddRelationship( string.format( "%s %s %d", b, d > 0 and "D_LI" or "D_HT", math.abs( d ) )
  69.         if d > 0 then
  70.             v:AddRelationship( string.format( "%s D_HT 0", b ) )
  71.         end
  72.     end
  73. end
  74.  
  75. local function OnEntityCreated( ent )
  76.     local a, k, v
  77.    
  78.     a = ent:GetClass( )
  79.    
  80.     if hatemap[ a ] and ent:IsNPC( ) then
  81.         for k, v in pairs( hatemap[ a ] ) do
  82.             ent:AddRelationship( string.format( "%s %s %d", k, v > 0 and "D_LI" or "D_HT", v ) )
  83.         end
  84.     end
  85. end
  86.  
  87. hook.Add( "OnNPCKilled", "Hatemap.OnNPCKilled", OnNPCKilled )
  88. hook.Add( "EntityTakeDamage", "Hatemap.EntityTakeDamage", EntityTakeDamage )
  89. hook.Add( "OnEntityCreated", "Hatemap.OnEntityCreated", OnEntityCreated )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement