Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // SERVER side
- //
- if ( SERVER ) then
- //
- // Initialization
- //
- // Add the net-messages we need to the pool
- util.AddNetworkString( "ChatMessage" );
- // Add our "npc to xp" table...
- local class = {
- // Enemy Classes and XP to gain...
- npc_zombie = 10;
- npc_fastzombi = 10;
- npc_fastzombie_torso = 4;
- npc_headcrab_poison = 12;
- npc_zombie_torso = 3;
- npc_zombin = 15;
- npc_headcrab = 6;
- npc_headcrab_fast = 5;
- npc_headcrab_black = 9;
- npc_antlion = 7;
- npc_antlionguard = 350;
- // Default is our fall-back method..
- default = 1;
- };
- //
- // 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..
- //
- hook.Add( "PlayerDeath", "XPOnNPCDeath", function( victim, killer, _w )
- if ( IsValid( victim ) && IsValid( killer ) && killer:IsPlayer( ) && victim:IsNPC( ) ) then
- // Use the npc class to xp table above for xp if the npc exists, otherwise use the default value...
- local _xp = class[ victim:GetClass( ) ] || class.default;
- // Add XP
- killer:AddXP( _xp );
- // Network it... ( You can also now use this in ANY code you write to network a chat-message )
- net.Start( "ChatMessage" );
- // The actual message is "+<XP GIVEN> EXP Added!"
- net.WriteString( "+" .. _xp .. " EXP Added!" );
- // The color we want the chat-message to be for adding xp...
- net.WriteColor( Color( 0, 155, 0, 255 ) );
- net.Send( killer );
- end
- end );
- else
- //
- // This is the CLIENT side
- //
- //
- // Add a networking receiver for ChatMessage...
- //
- net.Receive( "ChatMessage", function( _len )
- // Read the chat text or use "N/A" if none-received... although there should always be one..
- local _text = net.ReadString( ) || "N/A";
- // Read the color, or use a default white color if none received...
- local _color = net.ReadColor( ) || color_white;
- // Now, add it to the client chat-window and play a sound...
- chat.AddText( _color, _text );
- chat.PlaySound( );
- end );
- end
- if(victim:GetClass() == "npc_antlionguard") then
- for k,v in pairs(player.GetAll()) do
- if v == killer then
- GAMEMODE:Notify(v, 1, 4, "Nice job! You defeated the Boss! You have earned and 350 EXP!")
- else
- GAMEMODE:Notify(v, 1, 4, "Player " .. killer:Name() .. " has defeated the infected boss, and gained 1500 EXP!")
- end
- end
- end
- end
- end
- hook.Add("OnNPCKilled","Levelsystem_NKilled",NPCKilled)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement