Как добавить MuzzleFlash к оружию?
Как добавить MuzzleFlash к оружию?

В данной статье я покажу как добавить на оружие кастомный MuzzleFlash

Ну для начала, нужно знать что такое Muzzle Flash. Muzzle Flash это спрайт перед дулом оружия при выстреле. Всё :^)

NB! Для того, чтобы Muzzle Flash кастомный показывался хорошо в игре, нужно убрать дефолтный с v_ и p_ модельки, чтобы стандартный Muzzle Flash не перекрывал наш кастомный. Для этого достаточно убрать эвенты в модельках. В данной статье я не буду это всё показывать, делается это всё достаточно просто.
Сразу говорю, вариант не мой, брал его с кода оружий KORD'a и gubka3d.

В начале кода добавляем данный код

#define CustomMuzzle(%0) (pev(%0, pev_impulse) == g_iszMuzzleKey)
#define Sprite_SetScale(%0,%1) set_pev(%0, pev_scale, %1)

// CSprite
#define m_maxFrame 35

// Muzzle Flash
#define MUZZLE_TIME 0.06 // Время обновления спрайта Muzzle Flash
#define MUZZLE_SPRITE "sprites/x/muzzleflash_plasma.spr" // Это наш Muzzle Flash. Меняете его на свой
#define MUZZLE_CLASSNAME "ent_mf_wpn" // Сюда пишем название для нашей энтити с Muzzle Flash'ом
#define MUZZLE_INTOLERANCE 100

new g_iszMuzzleKey;

В public plugin_init() добавляем следующий код
Служит он для регистрации синка нашего Muzzle Flash'a (обновления спрайта)

RegisterHam(Ham_Think, "env_sprite", "CMuzzleFlash_Think_Pre", false);

В public plugin_precache() добавляем следующий код
// Muzzle Flash
engfunc(EngFunc_PrecacheModel, MUZZLE_SPRITE);

g_iszMuzzleKey = engfunc(EngFunc_AllocString, MUZZLE_CLASSNAME);

Дальше в конце кода добавляем следующие стоки для создания Muzzle Flash'a
stock Sprite_SetTransparency(const iSprite, const iRendermode, const Float: flAmt, const iFx = kRenderFxNone)
{
	set_pev(iSprite, pev_rendermode, iRendermode);
	set_pev(iSprite, pev_renderamt, flAmt);
	set_pev(iSprite, pev_renderfx, iFx);
}

stock Weapon_MuzzleFlash(const iPlayer, const szMuzzleSprite[], const Float: flScale, const Float: flBrightness, const iAttachment)
{
	if (global_get(glb_maxEntities) - engfunc(EngFunc_NumberOfEntities) < MUZZLE_INTOLERANCE)
	{
		return FM_NULLENT;
	}
	
	static iSprite, iszAllocStringCached;
	if (iszAllocStringCached || (iszAllocStringCached = engfunc(EngFunc_AllocString, "env_sprite")))
	{
		iSprite = engfunc(EngFunc_CreateNamedEntity, iszAllocStringCached);
	}
	
	if(pev_valid(iSprite) != 2)
	{
		return FM_NULLENT;
	}
	
	set_pev(iSprite, pev_model, szMuzzleSprite);
	set_pev(iSprite, pev_spawnflags, SF_SPRITE_ONCE);
	
	set_pev(iSprite, pev_classname, MUZZLE_CLASSNAME);
	set_pev(iSprite, pev_impulse, g_iszMuzzleKey);
	set_pev(iSprite, pev_owner, iPlayer);
	
	set_pev(iSprite, pev_aiment, iPlayer);
	set_pev(iSprite, pev_body, iAttachment);
	
	Sprite_SetTransparency(iSprite, kRenderTransAdd, flBrightness);
	Sprite_SetScale(iSprite, flScale);
	
	dllfunc(DLLFunc_Spawn, iSprite)

	return iSprite;
}

Под/над ними добавляем следующий код, который отвечает за анимацию и удаление Muzzle Flash'a
public CMuzzleFlash_Think_Pre(const iSprite)
{
	static Float: flFrame;
	
	if (pev_valid(iSprite) != 2 || !CustomMuzzle(iSprite))
	{
		return HAM_IGNORED;
	}
	
	if (pev(iSprite, pev_frame, flFrame) && ++flFrame - 1.0 < get_pdata_float(iSprite, m_maxFrame, 4))
	{
		set_pev(iSprite, pev_frame, flFrame);
		set_pev(iSprite, pev_nextthink, get_gametime() + MUZZLE_TIME);
		
		return HAM_SUPERCEDE;
	}

	set_pev(iSprite, pev_flags, FL_KILLME);
	return HAM_SUPERCEDE;
}

Теперь осталось отоброзить Muzzle Flash. Ищем функцию с выстрелом оружия (ну или просто ищите анимацию выстрела)
Так как я использую код оружий на базе batcoh'a, то если искать функцию выстрела то она выглядит так public CWeapon__PrimaryAttack_Pre(iItem)
Ну и теперь добавляем данный код в нашу функцию выстрела. Обычно я добавляю её до Анимации выстрела

Weapon_MuzzleFlash(iPlayer, MUZZLE_SPRITE, 0.1, 255.0, 1); // Индекс игрока, Спрайт, Размер, Яркость, Аттачмент выстрела (от 0 до 3, подбирайте сами)

Вот в принципе и всё, вся магия :^)

Автор:

Статья была написана специально для сайта Zombie-Amxx.Ru

Hello, our administration publishes only cannon content, put like under the post below and write the best comment, we are preparing material just for you, Darling Гость.

Comments 11
Информация
Посетители, находящиеся в группе Guests, не могут оставлять комментарии к данной публикации.
Foundation for your build
ReHLDS 3.4.0.654

ReHLDS (Reverse-engineered) - this is a new step forward that gives a second wind to our servers. ReHLDS works 2 times faster than HLDS.

AmxModx 1.8.3

AMXModX is a Metamod add-on that allows you to create new modifications for Half-Life in the Pawn language

Reunion 0.1.92

Reunion is a continuation of Dproto for ReHLDS. This is a metamod plugin that allows you to log into the 47/48 Non-Steam server.

Revoice 0.1.0.32

Revoice is a Metamod plugin that allows voice chat between non-steam and steam clients.

Metamod-r 1.3.0.127

The new Metamod-r contains a huge number of performance optimizations and much cleaner code. The kernel was written using a JIT compiler.

Ultimate Unprecacher 1.1

Ultimate Unprecacher is a plugin for MetaMod, it works on the principle of disabling unnecessary resources on your server, thereby you can free up space for resources for your plugins, using this module you can get rid of error 512!

ReAuthCheck 0.1.6

ReAuthCheck - this is a Metamod plugin that checks your players for validity, with this module for REHLDS you can protect your server from bots that constantly spam ads or simply clog up a slot on the server!

NetBufExtender (NBEX) 1.0

NetBufExtender or NBEX - This is a metamod plugin that expands the пїЅInternet bufferпїЅ: server and client buffers (not 100% guaranteed). Expands up to 64 kb. This means that players are less likely to be kicked with the error "Reliable channel overflowed"".

UserInfoNetOptimizer (UINO) 1.0

UINO пїЅ metamod plugin that allows you to remove unnecessary fields from userinfo(setinfo) when the engine passes it to other players on the server. This measure reduces the amount of data transferred and slightly reduces the chance of being kicked with "Reliable channel overflowed".

Information

Welcome to TB-TEAM.COM!

Welcome To Our New Website For CS1.6 Resources!.
Register
Create your own account!

Register Now!
Login
Already registered? Come on, log in quickly!

Login to the site