For people and teams developing mods and games with Valve's Source engine.

Report article Armor in your mod

Today we'll programming new item. It'll armor (analog of battarey). So, let's start now!

Posted by VovaS500 on Oct 1st, 2009 digg this super bookmark
Basic Server Side Coding.


The first, you must open your .sln progect and in tree you must open "Server". Now create new file "item_armor.cpp" and write there this code:

  1. C++ code:
  1. //========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Armor for player.
  4. //
  5. // Made by hitmen047
  6. //=============================================================================//
  7. #include "cbase.h" // Это Х.З. что, но без него никак
  8. #include "hl2_player.h" // Относится к игроку
  9. #include "basecombatweapon.h" // Относится к "basecombatweapon"
  10. #include "gamerules.h" // Обращение к игровым правилам
  11. #include "items.h" // Обращение к объектам, которые можно использовать
  12. #include "engine/IEngineSound.h" // Использует звуки
  13. // memdbgon must be the last include file in a .cpp file!!!
  14. #include "tier0/memdbgon.h"
  15. class CItemArmor : public CItem // Задаём класс
  16. {
  17. public:
  18.   DECLARE_CLASS( CItemArmor, CItem );
  19.   void Spawn( void ) // Спавнится наш бронежилет
  20.   {  
  21.   Precache( ); // Задаётся
  22.   SetModel( "models/NeoDement/elitehelmet.mdl" ); // Моделька
  23.   BaseClass::Spawn( ); // В итоге спавнится
  24.   }
  25.   void Precache( void ) // Что-то связаное с использованием
  26.   {
  27.   PrecacheModel ("models/NeoDement/elitehelmet.mdl"); // Моделька
  28.   PrecacheScriptSound( "ItemArmor.Touch" ); // Звук при поднятии
  29.   }
  30.   bool MyTouch( CBasePlayer *pPlayer )
  31.   {
  32.   CHL2_Player *pHL2Player = dynamic_cast( pPlayer );
  33.   return ( pHL2Player && pHL2Player->ApplyBattery() ); // Указываем, что игроку прибавляется энергия костюма
  34.   }
  35. };
  36. LINK_ENTITY_TO_CLASS(item_armor, CItemArmor); // название энити
  37. PRECACHE_REGISTER(item_armor); // название энити

Okey! That's all! No you must compill project, then copy .dll files to bin folder of your mod.

Comments
SiPlus
SiPlus Oct 2 2009, 1:50pm says:

Where is model?
Где модель?

+1 vote     reply to comment
Post a Comment

Only registered members can share their thoughts. So come on! Join the community today (totally free) and do things you never thought possible.

Established
Nov 09, 2007
Privacy
Public
Subscription
Open to all members
Contact
Send Message
Email
Members Only
Membership
Join this group
Group Watch
Track this group
Bookmark
Digg Super bookmark
Tutorial
Browse
Tutorials
Views
72 (1 today)
Report Abuse
Report article
Bookmark
Digg Super bookmark
Related Groups
Source Developers
Source Developers
Fanboys & Clans group with 397 members