• Register

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

Report RSS Armor in your mod

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

Posted by on - 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:

//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//
//
// Purpose: Armor for player.
//
// Made by hitmen047
//=============================================================================//
#include "cbase.h" // Это Х.З. что, но без него никак
#include "hl2_player.h" // Относится к игроку
#include "basecombatweapon.h" // Относится к "basecombatweapon"
#include "gamerules.h" // Обращение к игровым правилам
#include "items.h" // Обращение к объектам, которые можно использовать
#include "engine/IEngineSound.h" // Использует звуки
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
class CItemArmor : public CItem // Задаём класс
{
public:
  DECLARE_CLASS( CItemArmor, CItem );
  void Spawn( void ) // Спавнится наш бронежилет
  {  
  Precache( ); // Задаётся
  SetModel( "models/NeoDement/elitehelmet.mdl" ); // Моделька
  BaseClass::Spawn( ); // В итоге спавнится
  }
  void Precache( void ) // Что-то связаное с использованием
  {
  PrecacheModel ("models/NeoDement/elitehelmet.mdl"); // Моделька
  PrecacheScriptSound( "ItemArmor.Touch" ); // Звук при поднятии
  }
  bool MyTouch( CBasePlayer *pPlayer )
  {
  CHL2_Player *pHL2Player = dynamic_cast( pPlayer );
  return ( pHL2Player && pHL2Player->ApplyBattery() ); // Указываем, что игроку прибавляется энергия костюма
  }
};
LINK_ENTITY_TO_CLASS(item_armor, CItemArmor); // название энити
PRECACHE_REGISTER(item_armor); // название энити

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

Post comment Comments
SiPlus
SiPlus - - 290 comments

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

Reply Good karma Bad karma+2 votes
VovaS500 Author
VovaS500 - - 893 comments

А модель самому нужно делать.
It's your care.

Reply Good karma+1 vote
Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: