HLFX.Ru Forum (https://hlfx.ru/forum/index.php)
- Half-Life SDK (https://hlfx.ru/forum/forumdisplay.php?forumid=8)
-- Smoke Grenade (https://hlfx.ru/forum/showthread.php?threadid=1514)
Отправлено (_-=ZhekA=-_) 26-09-2008 в 12:48:
Smoke Grenade
Вот я пытался сделать этот тутор, но все попытки четны
http://www.hl-lab.ru/?s=hl-lab&l=ru...&o=readarticles
Я конечно не уверен, но мне кажется, что этот тутор не доделанный
Там не сказано, как сделать так, чтоб появился значек гранаты так где всё оружие .
А вот и на что он ругается
C++ Source Code:
1 | --------------------Configuration: hl - Win32 Release-------------------- |
4 | F:\SDK\Microsoft_Visual\code_src\dlls\sgrenade.cpp(229) : error C2664: 'UTIL_SetOrigin' : cannot convert parameter 1 from 'struct entvars_s *' to 'class CBaseEntity *' |
5 | Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast |
8 | sgrenade.obj - 1 error(s), 0 warning(s) |
Сам тутор
C++ Source Code:
1 | Smoke Grenade - In this tutorial, I will show you how to create a simple smoke grenade, and how to be able to put them in maps. If there are any problems let me know and I will try and fix it for you. * Fixed * There was a error in the code, one leter was supposed to be capital but wasn’t so it caused some problems and I forgot to tell to create a txt file for the weapon to be shown in the hud correctly… soryy |
3 | First, create a new file called sgrenade.cpp and add it to your project. |
4 | Not really much too explain, its just a copy of the normal grenade and modified so it doesn't explode, but instead release smoke |
5 | Select the Following code as paste it into that file: |
9 | -------------------------------------------------------------------------------- |
11 | The Grenade will be in slot 0 (where the crowbar is) which you can change below |
12 | Smoke Grenade Made By Craten Toby |
23 | #define WEAPON_SMOKEGRENADE 16 |
24 | #define SMOKETIME 8 // 8 seconds for smoke |
26 | #define SMOKE_SLOTNUMBER 0 // The slot it is in ( 0 is crowbar area, 1 is pistol area, etc… ) |
27 | #define SMOKE_POSITION 3 // Position Is what column the weapon is in, for example - in slot 1, the pistol is position 1, the magnum is 2, and so forth. Try not to put the same position number as another weapon, or it might cause problems. |
33 | HANDGRENADE_THROW1, // toss |
34 | HANDGRENADE_THROW2, // medium |
35 | HANDGRENADE_THROW3, // hard |
42 | class CSmokeGrenade : public CBasePlayerWeapon |
46 | void Precache( void ); |
47 | int iItemSlot( void ) { return 5; } |
48 | int GetItemInfo(ItemInfo *p); |
50 | void PrimaryAttack( void ); |
52 | BOOL CanHolster( void ); |
54 | void WeaponIdle( void ); |
55 | void SmokeThink( void ); |
57 | float m_flReleaseThrow; |
59 | LINK_ENTITY_TO_CLASS( weapon_smokegrenade, CSmokeGrenade ); |
63 | void CSmokeGrenade::Spawn( ) |
66 | m_iId=WEAPON_SMOKEGRENADE; |
67 | SET_MODEL(ENT(pev), "models/w_grenade.mdl"); |
69 | pev->dmg=gSkillData.plrDmgHandGrenade; |
71 | FallInit();// get ready to fall down. |
78 | void CSmokeGrenade::Precache( void ) |
80 | PRECACHE_MODEL("models/w_grenade.mdl"); |
81 | PRECACHE_MODEL("models/v_grenade.mdl"); |
82 | PRECACHE_MODEL("models/p_grenade.mdl"); |
83 | PRECACHE_SOUND ("weapons/xbow_fly1.wav"); |
84 | PRECACHE_SOUND ("common/null.wav"); |
89 | int CSmokeGrenade::GetItemInfo(ItemInfo *p) |
91 | p->pszName=STRING(pev->classname); |
92 | p->pszAmmo1="Smoke Grenade"; |
96 | p->iMaxClip=WEAPON_NOCLIP; |
99 | p->iId=m_iId=WEAPON_SMOKEGRENADE; |
101 | p->iFlags=ITEM_FLAG_LIMITINWORLD | ITEM_FLAG_EXHAUSTIBLE; |
110 | BOOL CSmokeGrenade::Deploy( ) |
113 | return DefaultDeploy( "models/v_grenade.mdl", "models/p_grenade.mdl", HANDGRENADE_DRAW, "crowbar" ); |
118 | BOOL CSmokeGrenade::CanHolster( void ) |
120 | // can only holster hand grenades when not primed! |
121 | return ( m_flStartThrow==0 ); |
126 | void CSmokeGrenade::Holster( ) |
128 | m_pPlayer->m_flNextAttack=gpGlobals->time + 0.5; |
129 | if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]) |
131 | SendWeaponAnim( HANDGRENADE_HOLSTER ); |
136 | m_pPlayer->pev->weapons &=~(1<<WEAPON_SMOKEGRENADE); |
137 | SetThink( DestroyItem ); |
138 | pev->nextthink=gpGlobals->time + 0.1; |
141 | EMIT_SOUND(ENT(m_pPlayer->pev), CHAN_WEAPON, "common/null.wav", 1.0, ATTN_NORM); |
150 | void CSmokeGrenade::PrimaryAttack() |
152 | if (!m_flStartThrow && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] > 0) |
154 | m_flStartThrow=gpGlobals->time; |
157 | SendWeaponAnim( HANDGRENADE_PINPULL ); |
158 | m_flTimeWeaponIdle=gpGlobals->time + 0.5; |
166 | void CSmokeGrenade::SmokeThink( void ) |
168 | pev->velocity=pev->velocity * 0.4; |
169 | pev->sequence=RANDOM_LONG( 1, 1 ); |
171 | if (pev->dmgtime < gpGlobals->time){ |
172 | EMIT_SOUND(ENT(pev), CHAN_WEAPON, "common/null.wav", 1 , ATTN_NORM); |
173 | pev->velocity=Vector( 0, 0, 0 ); |
178 | EMIT_SOUND(ENT(pev), CHAN_WEAPON, "weapons/xbow_fly1.wav", .3 , ATTN_NORM); |
184 | MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin ); |
185 | WRITE_BYTE( TE_SMOKE ); |
186 | WRITE_COORD( pev->origin.x ); |
187 | WRITE_COORD( pev->origin.y ); |
188 | WRITE_COORD( pev->origin.z ); |
189 | WRITE_SHORT( g_sModelIndexSmoke ); |
190 | WRITE_BYTE( (pev->dmg - 50) * 0.80 ); // scale * 10 |
191 | WRITE_BYTE( 12 ); // framerate |
196 | m_flTimeWeaponIdle=gpGlobals->time + RANDOM_FLOAT ( 10, 15 ); |
198 | pev->nextthink=gpGlobals->time + 0.3; |
203 | void CSmokeGrenade::WeaponIdle( void ) |
205 | if (m_flReleaseThrow==0) |
206 | m_flReleaseThrow=gpGlobals->time; |
208 | if (m_flTimeWeaponIdle > gpGlobals->time) |
213 | Vector angThrow=m_pPlayer->pev->v_angle + m_pPlayer->pev->punchangle; |
216 | angThrow.x=-10 + angThrow.x * ((90 - 10) / 90.0); |
218 | angThrow.x=-10 + angThrow.x * ((90 + 10) / 90.0); |
220 | float flVel=(90 - angThrow.x) * 4; |
224 | UTIL_MakeVectors( angThrow ); |
226 | Vector vecSrc=m_pPlayer->pev->origin + m_pPlayer->pev->view_ofs + gpGlobals->v_forward * 16; |
228 | Vector vecThrow=gpGlobals->v_forward * flVel + m_pPlayer->pev->velocity; |
232 | // alway explode 3 seconds after the pin was pulled |
234 | CGrenade *pGrenade=GetClassPtr( (CGrenade *)NULL ); |
236 | UTIL_SetOrigin( pGrenade->pev, vecSrc ); |
237 | pGrenade->pev->velocity=vecThrow; |
238 | pGrenade->pev->angles=UTIL_VecToAngles(pGrenade->pev->velocity); |
239 | pGrenade->pev->owner=ENT(m_pPlayer->pev); |
240 | pGrenade->pev->dmgtime=gpGlobals->time + SMOKETIME; |
242 | pGrenade->SetThink( SmokeThink ); |
243 | pGrenade->pev->nextthink=gpGlobals->time + 0.1; |
244 | SET_MODEL(ENT(pGrenade->pev), "models/w_grenade.mdl"); |
250 | SendWeaponAnim( HANDGRENADE_THROW1 ); |
252 | else if (flVel < 1000) |
254 | SendWeaponAnim( HANDGRENADE_THROW2 ); |
258 | SendWeaponAnim( HANDGRENADE_THROW3 ); |
263 | // player "shoot" animation |
264 | m_pPlayer->SetAnimation( PLAYER_ATTACK1 ); |
267 | m_flNextPrimaryAttack=gpGlobals->time + 0.5; |
268 | m_flTimeWeaponIdle=gpGlobals->time + 0.5; |
270 | m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]--; |
272 | if ( !m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] ) |
274 | // just threw last grenade |
275 | // set attack times in the future, and weapon idle in the future so we can see the whole throw |
276 | // animation, weapon idle will automatically retire the weapon for us. |
277 | m_flTimeWeaponIdle=m_flNextSecondaryAttack=m_flNextPrimaryAttack=gpGlobals->time + 0.5;// ensure that the animation can finish playing |
281 | else if (m_flReleaseThrow > 0) |
283 | // we've finished the throw, restart. |
286 | if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]) |
288 | SendWeaponAnim( HANDGRENADE_DRAW ); |
301 | if (m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType]) |
304 | float flRand=RANDOM_FLOAT(0, 1); |
307 | iAnim=HANDGRENADE_IDLE; |
308 | m_flTimeWeaponIdle=gpGlobals->time + RANDOM_FLOAT ( 10, 15 );// how long till we do this again. |
312 | iAnim=HANDGRENADE_FIDGET; |
313 | m_flTimeWeaponIdle=gpGlobals->time + 75.0 / 30.0; |
316 | SendWeaponAnim( iAnim ); |
319 | -------------------------------------------------------------------------------- |
327 | Lots of Code!! Not much too explain except it basically is a grenade. |
328 | Next is declaring the smoke grenade as a new item. Open Weapons.cpp and scroll down to around line 375 and find the following code: |
334 | -------------------------------------------------------------------------------- |
335 | UTIL_PrecacheOtherWeapon("weapon_handgrenade"); |
336 | -------------------------------------------------------------------------------- |
342 | Now right after the code UTIL_PrecacheOtherWeapon("weapon_handgrenade"); insert the following code: |
348 | -------------------------------------------------------------------------------- |
349 | UTIL_PrecacheOtherWeapon("weapon_smokegrenade"); |
350 | -------------------------------------------------------------------------------- |
358 | Now this is just the grenade, now we have to make it so you can place them in maps. |
360 | In your mod's root directory, create a file called "DATA.FGD" if you don't already have a .fgd file. If you are just putting this into normal halflife make the same file but put it into the halflife/valve/ folder. |
362 | Now in this file put this line in it: |
365 | Code: FGD [ DATA.FGD ] |
366 | -------------------------------------------------------------------------------- |
368 | @PointClass size(-16 -16 0, 16 16 16)=weapon_smokegrenade: "Smoke Grenade" [] |
370 | -------------------------------------------------------------------------------- |
371 | Code: FGD [ DATA.FGD ] |
378 | In WorldCraft under game configurations in the options menu, include the DATA.FGD file or the file you put the PointClass in, and you will be able to place smoke grenades on your map. |
382 | Ok One More thing that I forgot, we need to create a file called "weapon_smokegrenade.txt" and place it in your mod's sprite directory. |
383 | In this file put the following Code: |
388 | Code: TXT [ weapon_smokegrenade.txt ] |
389 | -------------------------------------------------------------------------------- |
391 | weapon 320 320hud1 160 0 80 20 |
392 | weapon_s 320 320hud1 160 20 80 20 |
393 | ammo 320 320hud2 36 34 18 18 |
394 | weapon 640 640hud3 0 0 170 45 |
395 | weapon_s 640 640hud6 0 0 170 45 |
396 | ammo 640 640hud7 48 96 24 24 |
398 | -------------------------------------------------------------------------------- |
399 | Code: TXT [ weapon_smokegrenade.txt ] |
407 | Now this made the sprite of the smoke grenade a grenade when you pick it from the hud. |
411 | You should be all set now, just compile and run it, feel free to modify it. |
__________________
Kiss my ass if you don't like my Ford!
------------------------------------------
Game Area51 Update 1
First Person Shooter Released Jul 24, 2017
The game is a 3d shooter with the elements of the quest.
http://button.moddb.com/download/medium/125531.png
Отправлено XaeroX 26-09-2008 в 13:08:
Ругается потому, что тутор под спирит. Замени там
C++ Source Code:
UTIL_SetOrigin(pev, pev->origin) |
на C++ Source Code:
UTIL_SetOrigin(this, pev->origin) |
.__________________
Отправлено (_-=ZhekA=-_) 26-09-2008 в 13:12:
XaeroX
А гды ты нашел в туторе эту строку ?
C++ Source Code:
UTIL_SetOrigin(pev, pev->origin) |
__________________
Kiss my ass if you don't like my Ford!
------------------------------------------
Game Area51 Update 1
First Person Shooter Released Jul 24, 2017
The game is a 3d shooter with the elements of the quest.
http://button.moddb.com/download/medium/125531.png
Отправлено Дядя Миша 26-09-2008 в 13:31:
XaeroX это млин не тутор под спирит, это у нас кое-кто под паранойю кодит 
Добавлено 26-09-2008 в 17:31:
Цитата:
А гды ты нашел в туторе эту строку ?
просто слов нету...__________________
My Projects: download page
F.A.Q по XashNT
Блог разработчика в телеграме
Цитата:
C:\DOCUME~1\C4C5~1\LOCALS~1\Temp\a33328if(72) : see declaration of 'size_t'
Отправлено (_-=ZhekA=-_) 26-09-2008 в 14:13:
Приверил на обычной хл - работает, но я бы ''это'' дымовой гранатой не назвал бы
В кс в 100 раз лучше 
Как сделать, что б на кс хоть немного было похоже ?
__________________
Kiss my ass if you don't like my Ford!
------------------------------------------
Game Area51 Update 1
First Person Shooter Released Jul 24, 2017
The game is a 3d shooter with the elements of the quest.
http://button.moddb.com/download/medium/125531.png
Отправлено Ku2zoff 26-09-2008 в 15:02:
(_-=ZhekA=-_) Чтобы дым был реалистичней надо несколько раз повторить эту мессагу:
C++ Source Code:
2 | MESSAGE_BEGIN( MSG_PVS, SVC_TEMPENTITY, pev->origin ); |
4 | WRITE_COORD( pev->origin.x ); |
5 | WRITE_COORD( pev->origin.y ); |
6 | WRITE_COORD( pev->origin.z ); |
7 | WRITE_SHORT( g_sModelIndexSmoke ); |
8 | WRITE_BYTE( (pev->dmg - 50) * 0.80 ); // scale * 10 |
9 | WRITE_BYTE( 12 ); // framerate |
Только вместо pev->origin задавать другие координаты, юнитов на 8 или 12 во все четыре стороны от ориджина. Ну и размер дыма уменьшить. Поэкспериментируй, должно неплохо получиться, я раньше так делал.
Отправлено (_-=ZhekA=-_) 26-09-2008 в 15:20:
Ku2zoff
А как в кс эта драната сделана ? 
__________________
Kiss my ass if you don't like my Ford!
------------------------------------------
Game Area51 Update 1
First Person Shooter Released Jul 24, 2017
The game is a 3d shooter with the elements of the quest.
http://button.moddb.com/download/medium/125531.png
Отправлено XaeroX 26-09-2008 в 15:40:
(_-=ZhekA=-_) не задавай глупых вопросов. Ku2zoff - не автор КС, откуда ему знать?
__________________
Отправлено (_-=ZhekA=-_) 26-09-2008 в 16:18:
XaeroX
Да, я знаю что он не автор ну может знает, малоли 
__________________
Kiss my ass if you don't like my Ford!
------------------------------------------
Game Area51 Update 1
First Person Shooter Released Jul 24, 2017
The game is a 3d shooter with the elements of the quest.
http://button.moddb.com/download/medium/125531.png
Отправлено Дядя Миша 26-09-2008 в 16:59:
Цитата:
Как сделать, что б на кс хоть немного было похоже ?
Автор тутора похоже тоже об этом не знал.
А в кс ЕМНИП серый туман заливает весь уровень.__________________
My Projects: download page
F.A.Q по XashNT
Блог разработчика в телеграме
Цитата:
C:\DOCUME~1\C4C5~1\LOCALS~1\Temp\a33328if(72) : see declaration of 'size_t'
Отправлено XaeroX 26-09-2008 в 17:06:
Цитата:
Дядя Миша писал:
А в кс ЕМНИП серый туман заливает весь уровень
Нет. Там много-много спрайтов. Это хорошо видно, если включить опцию d_spriteskip (или как-то так, при этом альфа-блендинга нет на спрайтах. Многие это юзают как чит)__________________
Отправлено Дядя Миша 26-09-2008 в 20:09:
Цитата:
Там много-много спрайтов.
Нууу, ChainStudios еще в 2001 году подобными методами реализовала локальный туман в ретрибушене.__________________
My Projects: download page
F.A.Q по XashNT
Блог разработчика в телеграме
Цитата:
C:\DOCUME~1\C4C5~1\LOCALS~1\Temp\a33328if(72) : see declaration of 'size_t'
Отправлено XaeroX 27-09-2008 в 07:27:
Дядя Миша ну кстати да, там примерно так же. Только спрайты гораздо большего скейла.
__________________
Отправлено Дядя Миша 27-09-2008 в 11:30:
XaeroX надо полагать в КС - обычные темпэнтити, как вариант можно заюзать код бузеровского дождя для достижения лучшего эффекта.
Ну или авроры из спирита.
__________________
My Projects: download page
F.A.Q по XashNT
Блог разработчика в телеграме
Цитата:
C:\DOCUME~1\C4C5~1\LOCALS~1\Temp\a33328if(72) : see declaration of 'size_t'
Отправлено (_-=ZhekA=-_) 27-09-2008 в 14:38:
Цитата:
Дядя Миша писал:
XaeroX надо полагать в КС - обычные темпэнтити, как вариант можно заюзать код бузеровского дождя для достижения лучшего эффекта.
Ну или авроры из спирита.
Знать бы как это сделать ( для обычной хл ) 
__________________
Kiss my ass if you don't like my Ford!
------------------------------------------
Game Area51 Update 1
First Person Shooter Released Jul 24, 2017
The game is a 3d shooter with the elements of the quest.
http://button.moddb.com/download/medium/125531.png