Advertisement
Guest User

Untitled

a guest
Feb 20th, 2015
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.48 KB | None | 0 0
  1. //
  2. // SERVER side
  3. //
  4. if ( SERVER ) then
  5. //
  6. // Initialization
  7. //
  8.  
  9. // Add the net-messages we need to the pool
  10. util.AddNetworkString( "ChatMessage" );
  11.  
  12. // Add our "npc to xp" table...
  13. local class = {
  14. // Enemy Classes and XP to gain...
  15. npc_zombie = 10;
  16. npc_fastzombi = 10;
  17. npc_fastzombie_torso = 4;
  18. npc_headcrab_poison = 12;
  19. npc_zombie_torso = 3;
  20. npc_zombin = 15;
  21. npc_headcrab = 6;
  22. npc_headcrab_fast = 5;
  23. npc_headcrab_black = 9;
  24. npc_antlion = 7;
  25. npc_antlionguard = 350;
  26.  
  27. // Default is our fall-back method..
  28. default = 1;
  29. };
  30.  
  31.  
  32. //
  33. // With hooks we only want to return non-nil for specific behavior.. You returned nil so you're fine but I condensed it all to 1 line..
  34. //
  35. hook.Add( "PlayerDeath", "XPOnNPCDeath", function( victim, killer, _w )
  36. if ( IsValid( victim ) && IsValid( killer ) && killer:IsPlayer( ) && victim:IsNPC( ) ) then
  37. // Use the npc class to xp table above for xp if the npc exists, otherwise use the default value...
  38. local _xp = class[ victim:GetClass( ) ] || class.default;
  39.  
  40. // Add XP
  41. killer:AddXP( _xp );
  42.  
  43. // Network it... ( You can also now use this in ANY code you write to network a chat-message )
  44. net.Start( "ChatMessage" );
  45. // The actual message is "+<XP GIVEN> EXP Added!"
  46. net.WriteString( "+" .. _xp .. " EXP Added!" );
  47.  
  48. // The color we want the chat-message to be for adding xp...
  49. net.WriteColor( Color( 0, 155, 0, 255 ) );
  50. net.Send( killer );
  51. end
  52. end );
  53. else
  54. //
  55. // This is the CLIENT side
  56. //
  57.  
  58.  
  59. //
  60. // Add a networking receiver for ChatMessage...
  61. //
  62. net.Receive( "ChatMessage", function( _len )
  63. // Read the chat text or use "N/A" if none-received... although there should always be one..
  64. local _text = net.ReadString( ) || "N/A";
  65.  
  66. // Read the color, or use a default white color if none received...
  67. local _color = net.ReadColor( ) || color_white;
  68.  
  69. // Now, add it to the client chat-window and play a sound...
  70. chat.AddText( _color, _text );
  71. chat.PlaySound( );
  72. end );
  73. end
  74. if(victim:GetClass() == "npc_antlionguard") then
  75. for k,v in pairs(player.GetAll()) do
  76. if v == killer then
  77. GAMEMODE:Notify(v, 1, 4, "Nice job! You defeated the Boss! You have earned and 350 EXP!")
  78. else
  79. GAMEMODE:Notify(v, 1, 4, "Player " .. killer:Name() .. " has defeated the infected boss, and gained 1500 EXP!")
  80. end
  81. end
  82. end
  83. end
  84. end
  85. hook.Add("OnNPCKilled","Levelsystem_NKilled",NPCKilled)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement