[TUTOS] Cinquième Partie :: Ajouter une arme.


tosqualler

Messages recommandés

Dans ce tutoriale, je vais vous montrer comment ajouter une arme, pour ce faire nous allons dupliquer le python 357 magnums. Choix simple car l'arme possède que très peux de fonctions.

Nous nommerons le double du 357 un USP.

Logiciel utilisé

-Steam.

-SDK.

-Editeur C++.

-Recherche windows.

Créons les munitions.

Pour éviter toutes confusion, nous allons crée des munitions pour notre nouvelle arme.

Pour cela, rendez-vous dans la source "item_ammo.cpp". Et faites une recherche a 357. Vous obitendrez 2grosses fonctions.

[cpp]

// ========================================================================

// >> CItem_Box357Rounds

// ========================================================================

class CItem_Box357Rounds : public CItem

{

public:

DECLARE_CLASS( CItem_Box357Rounds, CItem );

void Precache( void )

{

PrecacheModel ("models/items/357ammo.mdl");

}

void Spawn( void )

{

Precache( );

SetModel( "models/items/357ammo.mdl");

BaseClass::Spawn( );

}

bool MyTouch( CBasePlayer *pPlayer )

{

if (ITEM_GiveAmmo( pPlayer, SIZE_AMMO_357, "357"))

{

if ( g_pGameRules->ItemShouldRespawn( this ) == GR_ITEM_RESPAWN_NO )

{

UTIL_Remove(this);

}

return true;

}

return false;

}

};

LINK_ENTITY_TO_CLASS(item_ammo_357, CItem_Box357Rounds);

// ========================================================================

// >> CItem_LargeBox357Rounds

// ========================================================================

class CItem_LargeBox357Rounds : public CItem

{

public:

DECLARE_CLASS( CItem_LargeBox357Rounds, CItem );

void Precache( void )

{

PrecacheModel ("models/items/357ammobox.mdl");

}

void Spawn( void )

{

Precache( );

SetModel( "models/items/357ammobox.mdl");

BaseClass::Spawn( );

}

bool MyTouch( CBasePlayer *pPlayer )

{

if (ITEM_GiveAmmo( pPlayer, SIZE_AMMO_357_LARGE, "357"))

{

if ( g_pGameRules->ItemShouldRespawn( this ) == GR_ITEM_RESPAWN_NO )

{

UTIL_Remove(this);

}

return true;

}

if (ITEM_GiveAmmo( pPlayer, SIZE_AMMO_357_LARGE, "usp"))

{

if ( g_pGameRules->ItemShouldRespawn( this ) == GR_ITEM_RESPAWN_NO )

{

UTIL_Remove(this);

}

return true;

}

return false;

}

};

LINK_ENTITY_TO_CLASS(item_ammo_357_large, CItem_LargeBox357Rounds);

[/cpp]

Faites en un copier/coller a la suite de ces dernières et changer les 357 par usp.

ATTENTION AUX MAJUSCULES... VERIFIER BIEN QUE VOUS SUIVEZ BIEN LES MAJUSCULES COMME POUR LE PISTOL PAR EXEMPLE !!!

ça donnera ceci

[cpp]

/////

// ========================================================================

// >> CItem_BoxUSPRounds

// ========================================================================

class CItem_BoxUspRounds : public CItem

{

public:

DECLARE_CLASS( CItem_BoxUspRounds, CItem ); // declaration

void Precache( void ) // mise en memoir

{

PrecacheModel ("models/items/357ammo.mdl"); // mise en memoir du model

}

void Spawn( void ) // mise en jeux

{

Precache( );

SetModel( "models/items/357ammo.mdl"); // mise en jeux du model

BaseClass::Spawn( );

}

bool MyTouch( CBasePlayer *pPlayer ) // quand le joeur touche l'entitée mise en jeux

{

if (ITEM_GiveAmmo( pPlayer, SIZE_AMMO_USP, "USP")) // si il a besoin de munition il lui en donne

{

if ( g_pGameRules->ItemShouldRespawn( this ) == GR_ITEM_RESPAWN_NO )

{

UTIL_Remove(this);

}

return true;

}

return false;

}

};

LINK_ENTITY_TO_CLASS(item_ammo_usp, CItem_BoxUspRounds); // deffinition de la class xD

// ========================================================================

// >> CItem_LargeBoxUSPRounds

// ========================================================================

class CItem_LargeBoxUspRounds : public CItem

{

public:

DECLARE_CLASS( CItem_LargeBoxUspRounds, CItem ); /declaration

void Precache( void ) // mise en memoir

{

PrecacheModel ("models/items/357ammobox.mdl"); // mise en memoir du model

}

void Spawn( void ) // mise en jeux

{

Precache( );

SetModel( "models/items/357ammobox.mdl"); // mise en jeux du model

BaseClass::Spawn( );

}

bool MyTouch( CBasePlayer *pPlayer ) // quand le joeur touche l'entitée mise en jeux

{

if (ITEM_GiveAmmo( pPlayer, SIZE_AMMO_USP_LARGE, "USP")) // si il a besoin de munition il lui en donne

{

if ( g_pGameRules->ItemShouldRespawn( this ) == GR_ITEM_RESPAWN_NO )

{

UTIL_Remove(this);

}

return true;

}

return false;

}

};

LINK_ENTITY_TO_CLASS(item_ammo_USP_large, CItem_LargeBoxUspRounds); // deffinition de la class xD

/////

[/cpp]

ATTENTION :: laisser bien les models du 357, nous codons !! Nous ne modelons pas

Différence entre LARGE et BOX ::-Box = petite caisse de munition

-LARGE = grosse caisse de munition

Continuons notre recherche du 357 dans cette source, nous trouvons ceci

[cpp]

// Ammo types

enum

{

AMMOCRATE_SMALL_ROUNDS,

AMMOCRATE_MEDIUM_ROUNDS,

AMMOCRATE_LARGE_ROUNDS,

AMMOCRATE_RPG_ROUNDS,

AMMOCRATE_BUCKSHOT,

AMMOCRATE_GRENADES,

AMMOCRATE_357,

AMMOCRATE_CROSSBOW,

AMMOCRATE_AR2_ALTFIRE,

NUM_AMMO_CRATE_TYPES,

};

[/cpp]

devient logiquement

[cpp]

// Ammo types

enum

{

AMMOCRATE_SMALL_ROUNDS,

AMMOCRATE_MEDIUM_ROUNDS,

AMMOCRATE_LARGE_ROUNDS,

AMMOCRATE_RPG_ROUNDS,

AMMOCRATE_BUCKSHOT,

AMMOCRATE_GRENADES,

AMMOCRATE_357,

AMMOCRATE_USP,

AMMOCRATE_CROSSBOW,

AMMOCRATE_AR2_ALTFIRE,

NUM_AMMO_CRATE_TYPES,

};

[/cpp]

Continuons...

[cpp]

// Models names

const char *CItem_AmmoCrate::m_lpzModelNames[NUM_AMMO_CRATE_TYPES] =

{

"models/items/ammocrate_bullets.mdl", // Small rounds

"models/items/ammocrate_smg1.mdl", // Medium rounds

"models/items/ammocrate_ar2.mdl", // Large rounds

"models/items/ammocrate_rockets.mdl", // RPG rounds

"models/items/ammocrate_buckshot.mdl", // Buckshot

"models/items/ammocrate_grenade.mdl", // Grenades

"models/items/ammocrate_357.mdl", // 357

"models/items/ammocrate_bullets.mdl", // Crossbow

//FIXME: This model is incorrect!

"models/items/ammocrate_ar2.mdl", // Combine Ball

};

[/cpp]

devient

[cpp]

// Models names

const char *CItem_AmmoCrate::m_lpzModelNames[NUM_AMMO_CRATE_TYPES] =

{

"models/items/ammocrate_bullets.mdl", // Small rounds

"models/items/ammocrate_smg1.mdl", // Medium rounds

"models/items/ammocrate_ar2.mdl", // Large rounds

"models/items/ammocrate_rockets.mdl", // RPG rounds

"models/items/ammocrate_buckshot.mdl", // Buckshot

"models/items/ammocrate_grenade.mdl", // Grenades

"models/items/ammocrate_357.mdl", // 357

"models/items/ammocrate_357.mdl", // usp

"models/items/ammocrate_bullets.mdl", // Crossbow

//FIXME: This model is incorrect!

"models/items/ammocrate_ar2.mdl", // Combine Ball

};

[/cpp]

Pourquoi, je ne sais pas vraiment...Continuons encore notre recherche.

[cpp]

// Ammo type names

const char *CItem_AmmoCrate::m_lpzAmmoNames[NUM_AMMO_CRATE_TYPES] =

{

"Pistol",

"SMG1",

"AR2",

"RPG_Round",

"Buckshot",

"Grenade",

"357",

"XBowBolt",

"AR2AltFire",

};

[/cpp]

devient logiquement

[cpp]

// Ammo type names

const char *CItem_AmmoCrate::m_lpzAmmoNames[NUM_AMMO_CRATE_TYPES] =

{

"Pistol",

"SMG1",

"AR2",

"RPG_Round",

"Buckshot",

"Grenade",

"357",

"Usp",

"XBowBolt",

"AR2AltFire",

};

[/cpp]

C'est ici que sont donné les nom des munitions, qui seront apres dans le script de l'arme...Voir plus loin.

Apres nous trouvons ceci.

[cpp]

// Ammo amount given per +use

int CItem_AmmoCrate::m_nAmmoAmounts[NUM_AMMO_CRATE_TYPES] =

{

300, // Pistol

300, // SMG1

300, // AR2

3, // RPG rounds

120, // Buckshot

5, // Grenades

50, // 357

50, // Crossbow

3, // AR2 alt-fire

};

const char *CItem_AmmoCrate::m_pGiveWeapon[NUM_AMMO_CRATE_TYPES] =

{

NULL, // Pistol

NULL, // SMG1

NULL, // AR2

NULL, // RPG rounds

NULL, // Buckshot

"weapon_frag", // Grenades

NULL, // 357

NULL, // Crossbow

NULL, // AR2 alt-fire

};

#define AMMO_CRATE_CLOSE_DELAY 1.5f

[/cpp]

qui devient, comme d'habitude...

[cpp]

// Ammo amount given per +use

int CItem_AmmoCrate::m_nAmmoAmounts[NUM_AMMO_CRATE_TYPES] =

{

300, // Pistol

300, // SMG1

300, // AR2

3, // RPG rounds

120, // Buckshot

5, // Grenades

50, // 357

50, // usp

50, // Crossbow

3, // AR2 alt-fire

};

const char *CItem_AmmoCrate::m_pGiveWeapon[NUM_AMMO_CRATE_TYPES] =

{

NULL, // Pistol

NULL, // SMG1

NULL, // AR2

NULL, // RPG rounds

NULL, // Buckshot

"weapon_frag", // Grenades

NULL, // 357

NULL, // Usp

NULL, // Crossbow

NULL, // AR2 alt-fire

};

#define AMMO_CRATE_CLOSE_DELAY 1.5f

[/cpp]

Voila les munitions sont crées, des points restent obscure...Si quelqu'un a une réponse au point obscure qu'il la donne :)

Création de l'arme.

Ici, c'est le plus dure et le plus fastidieux...Crée un fichier weapon_usp.cpp dans le dossier

C:\Program Files\Steam\SteamApps\SourceMods\test\src\dlls\hl2_dll

Prenez la source de weapon_357.cpp et faites un copier/coller total dans le weapon_usp.cpp, et changer les 357 par des usp

ATTENTION AUX MAJUSCULES... VERIFIER BIEN QUE VOUS SUIVEZ BIEN LES MAJUSCULES COMME POUR LE PISTOL PAR EXEMPLE !!!

ceci donnera

[cpp]

//========= Copyright © 1996-2005, Valve Corporation, All rights reserved. ============//

//

// Purpose: usp - hand gun

//

// $NoKeywords: $

//=============================================================================//

#include "cbase.h"

#include "NPCEvent.h"

#include "basehlcombatweapon.h"

#include "basecombatcharacter.h"

#include "AI_BaseNPC.h"

#include "player.h"

#include "gamerules.h"

#include "in_buttons.h"

#include "soundent.h"

#include "game.h"

#include "vstdlib/random.h"

#include "engine/IEngineSound.h"

#include "te_effect_dispatch.h"

// memdbgon must be the last include file in a .cpp file!!!

#include "tier0/memdbgon.h"

//-----------------------------------------------------------------------------

// CWeaponUsp

//-----------------------------------------------------------------------------

class CWeaponUsp : public CBaseHLCombatWeapon

{

DECLARE_CLASS( CWeaponUsp, CBaseHLCombatWeapon );

public:

CWeaponUsp( void );

void PrimaryAttack( void );

void Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator );

DECLARE_SERVERCLASS();

DECLARE_DATADESC();

};

LINK_ENTITY_TO_CLASS( weapon_usp, CWeaponUsp );

PRECACHE_WEAPON_REGISTER( weapon_usp );

IMPLEMENT_SERVERCLASS_ST( CWeaponUsp, DT_WeaponUsp )

END_SEND_TABLE()

BEGIN_DATADESC( CWeaponUsp )

END_DATADESC()

//-----------------------------------------------------------------------------

// Purpose: Constructor

//-----------------------------------------------------------------------------

CWeaponUsp::CWeaponUsp( void )

{

m_bReloadsSingly = false;

m_bFiresUnderwater = false;

}

//-----------------------------------------------------------------------------

// Purpose:

//-----------------------------------------------------------------------------

void CWeaponUsp::Operator_HandleAnimEvent( animevent_t *pEvent, CBaseCombatCharacter *pOperator )

{

CBasePlayer *pOwner = ToBasePlayer( GetOwner() );

switch( pEvent->event )

{

case EVENT_WEAPON_RELOAD:

{

CEffectData data;

// Emit six spent shells

for ( int i = 0; i < 6; i++ )

{

data.m_vOrigin = pOwner->WorldSpaceCenter() + RandomVector( -4, 4 );

data.m_vAngles = QAngle( 90, random->RandomInt( 0, 360 ), 0 );

data.m_nEntIndex = entindex();

DispatchEffect( "ShellEject", data );

}

break;

}

}

}

//-----------------------------------------------------------------------------

// Purpose:

//-----------------------------------------------------------------------------

void CWeaponUsp::PrimaryAttack( void )

{

// Only the player fires this way so we can cast

CBasePlayer *pPlayer = ToBasePlayer( GetOwner() );

if ( !pPlayer ) // si player n'existe aps

{

return; // fin

}

if ( m_iClip1 <= 0 ) // si plus de munition dans le chargeur

{

if ( !m_bFireOnEmpty ) // si il en reste en poche

{

Reload(); // reload

}

else // sinon

{

WeaponSound( EMPTY ); // son d'arme vide

m_flNextPrimaryAttack = 0.15;

}

return; // fin de la condition

}

WeaponSound( SINGLE );

pPlayer->DoMuzzleFlash(); // aucune idée de ce qu'est le "flash"

SendWeaponAnim( ACT_VM_PRIMARYATTACK ); // animation de l'attack

pPlayer->SetAnimation( PLAYER_ATTACK1 ); // animation de l'attack

m_flNextPrimaryAttack = gpGlobals->curtime + 0.75;

m_flNextSecondaryAttack = gpGlobals->curtime + 0.75;

m_iClip1--;

Vector vecSrc = pPlayer->Weapon_ShootPosition();

Vector vecAiming = pPlayer->GetAutoaimVector( AUTOAIM_5DEGREES );

pPlayer->FireBullets( 1, vecSrc, vecAiming, vec3_origin, MAX_TRACE_LENGTH, m_iPrimaryAmmoType, 0 ); // choix des munitions en rapport avec le script de l'arme

pPlayer->SetMuzzleFlashTime( gpGlobals->curtime + 0.5 );

//Disorient the player

QAngle angles = pPlayer->GetLocalAngles();

angles.x += random->RandomInt( -1, 1 );//c'est 3commandes

angles.y += random->RandomInt( -1, 1 );//dirigent le recule avec

angles.z = 0; //les axes x,y,z

pPlayer->SnapEyeAngles( angles );

pPlayer->ViewPunch( QAngle( -8, random->RandomFloat( -2, 2 ), 0 ) );

CSoundEnt::InsertSound( SOUND_COMBAT, GetAbsOrigin(), 600, 0.2, GetOwner() );// le son joué

if ( !m_iClip1 && pPlayer->GetAmmoCount( m_iPrimaryAmmoType ) <= 0 ) // si plus de muntions dans le chargeur et dans la poche xD

{

// HEV suit - indicate out of ammo condition

pPlayer->SetSuitUpdate( "!HEV_AMO0", FALSE, 0 ); // indication sur l'HUD qu'on en a plus

}

}

[/cpp]

Lancer une recherche Windows ( démarrer => recherche ), mettez comme destination le dossier du MOD, et taper 357, après votre recherche qui ne donnera rien, ajouter la fonction recherche dans le contenu du fichier. Et la une liste de source s'affiche :) c'est toute celle a modifier !! Enfin presque.

Commençons par "c_baseanimating.cpp"

Trouvez les lignes du 357, faites-en un copier/coller a la suite du 357 et changer 357 par USP

[cpp]

else if ( Q_stricmp( token, "357" ) == 0 )

{

weaponType = MUZZLEFLASH_357;

}

else if ( Q_stricmp( token, "USP" ) == 0 )

{

weaponType = MUZZLEFLASH_USP;

}

[/cpp]

Maintenant "c_te_legacytempents.cpp", un peux plus dure, faites comme pour la source précédente un copier/coller...

[cpp]

case MUZZLEFLASH_357:

if ( firstPerson )

{

MuzzleFlash_357_Player( entityIndex, attachmentIndex );

}

break;

case MUZZLEFLASH_USP:

if ( firstPerson )

{

MuzzleFlash_Usp_Player( entityIndex, attachmentIndex );

}

break;

[/cpp]

C’est une condition d'existence utilisant un switch...

En cherchant dans cette source, nous trouvons une énorme fonction

[cpp]

void CTempEnts::MuzzleFlash_357_Player( int entityIndex, int attachmentIndex )

{

...

}

[/cpp]

Ben comme a notre habitudes, copier/coller la a la suite, en changeant les 357 par usp...

ATTENTION AUX MAJUSCULES... VERIFIER BIEN QUE VOUS SUIVEZ BIEN LES MAJUSCULES COMME POUR LE PISTOL PAR EXEMPLE !!!

Cela donne...

[cpp]

////////////////////

//==================================================

// Purpose:

//==================================================

void CTempEnts::MuzzleFlash_Usp_Player( int entityIndex, int attachmentIndex )

{

VPROF_BUDGET( "MuzzleFlash_USP_Player", VPROF_BUDGETGROUP_PARTICLE_RENDERING );

CSmartPtr pSimple = CSimpleEmitter::Create( "MuzzleFlash_Usp_Player" );

pSimple->SetDrawBeforeViewModel( true );

Vector origin;

QAngle angles;

// Get our attachment's transformation matrix

FX_GetAttachmentTransform( entityIndex, attachmentIndex, &origin, &angles );

Vector forward;

AngleVectors( angles, &forward, NULL, NULL );

SimpleParticle *pParticle;

Vector offset;

// Smoke

offset = origin + forward * 8.0f;

pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), pSimple->GetPMaterial( "particle/particle_smokegrenade" ), offset );

if ( pParticle == NULL )

return;

pParticle->m_flLifetime = 0.0f;

pParticle->m_flDieTime = random->RandomFloat( 0.5f, 1.0f );

pParticle->m_vecVelocity.Init();

pParticle->m_vecVelocity = forward * random->RandomFloat( 8.0f, 64.0f );

pParticle->m_vecVelocity[2] += random->RandomFloat( 4.0f, 16.0f );

int color = random->RandomInt( 200, 255 );

pParticle->m_uchColor[0] = color;

pParticle->m_uchColor[1] = color;

pParticle->m_uchColor[2] = color;

pParticle->m_uchStartAlpha = random->RandomInt( 64, 128 );

pParticle->m_uchEndAlpha = 0;

pParticle->m_uchStartSize = random->RandomInt( 2, 4 );

pParticle->m_uchEndSize = pParticle->m_uchStartSize * 8.0f;

pParticle->m_flRoll = random->RandomInt( 0, 360 );

pParticle->m_flRollDelta = random->RandomFloat( -0.5f, 0.5f );

float flScale = random->RandomFloat( 1.25f, 1.5f );

// Flash

for ( int i = 1; i < 6; i++ )

{

offset = origin + (forward * (i*8.0f*flScale));

pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), pSimple->GetPMaterial( VarArgs( "effects/muzzleflash%d_noz", random->RandomInt(1,4) ) ), offset );

if ( pParticle == NULL )

return;

pParticle->m_flLifetime = 0.0f;

pParticle->m_flDieTime = 0.01f;

pParticle->m_vecVelocity.Init();

pParticle->m_uchColor[0] = 255;

pParticle->m_uchColor[1] = 255;

pParticle->m_uchColor[2] = 200+random->RandomInt(0,55);

pParticle->m_uchStartAlpha = 255;

pParticle->m_uchEndAlpha = 255;

pParticle->m_uchStartSize = ( (random->RandomFloat( 6.0f, 8.0f ) * (8-(i))/6) * flScale );

pParticle->m_uchEndSize = pParticle->m_uchStartSize;

pParticle->m_flRoll = random->RandomInt( 0, 360 );

pParticle->m_flRollDelta = 0.0f;

//les "pParticle" concerne les reflets sur le model de l'arme :)

}

}

////////////////////

[/cpp]

Voila nous avons fini le "c_te_legacytempents.cpp", passons au suivant le "c_te_legacytempents.h"

( la seront déclaré ce qui a dans "c_te_legacytempents.cpp" )

Copier/coller/renommer comme d'habitude ce que vous trouvez...

[cpp]

// Combine

void MuzzleFlash_Combine_Player( int entityIndex, int attachmentIndex );

void MuzzleFlash_Combine_NPC( int entityIndex, int attachmentIndex );

// 357

void MuzzleFlash_357_Player( int entityIndex, int attachmentIndex );

// USP

void MuzzleFlash_Usp_Player( int entityIndex, int attachmentIndex );

// RPG

void MuzzleFlash_RPG_NPC( int entityIndex, int attachmentIndex );

[/cpp]

Suivant..."func_break.cpp"

Copier/coller/renommer comme d'habitude ce que vous trouvez...

( ça devient lourd n'est-ce pas xD bah nous dupliquons donc logique xD)

[cpp]

"weapon_357", // 12

"ammo_357", // 13

"weapon_usp", // 12

"ammo_usp", // 13

[/cpp]

Suivant..."items.h"

Copier/coller/renomer comme d'habitude ce que vous trouvez...

[cpp]

#define SIZE_AMMO_357 6

#define SIZE_AMMO_357_LARGE 20

#define SIZE_AMMO_USP 6

#define SIZE_AMMO_USP_LARGE 20

[/cpp]

ICI c'est intéressant...C'est les munitions ce trouvant dans les boite de munitions...Voir la partie "crée munition"

Suivant..."shareddefs.h"

Copier/coller/renommer comme d'habitude ce que vous trouvez...

[cpp]

MUZZLEFLASH_COMBINE,

MUZZLEFLASH_357,

MUZZLEFLASH_USP,

MUZZLEFLASH_RPG,

[/cpp]

Ici c'est les déclarations des variables flash :D mais qu'est-ce c'est flash? Point obscur pour moi...

Suivant..."c_weapon__stubs_hl2.cpp"

Copier/coller/renommer comme d'habitude ce que vous trouvez...Même si ici vous voyez HL2MP

( ça ne changera peut être rien mais on ne sait jamais )

[cpp]

#ifndef HL2MP

STUB_WEAPON_CLASS( weapon_ar2, WeaponAR2, C_HLMachineGun );

STUB_WEAPON_CLASS( weapon_frag, WeaponFrag, C_BaseHLCombatWeapon );

STUB_WEAPON_CLASS( weapon_rpg, WeaponRPG, C_BaseHLCombatWeapon );

STUB_WEAPON_CLASS( weapon_pistol, WeaponPistol, C_BaseHLCombatWeapon );

STUB_WEAPON_CLASS( weapon_shotgun, WeaponShotgun, C_BaseHLCombatWeapon );

STUB_WEAPON_CLASS( weapon_smg1, WeaponSMG1, C_HLSelectFireMachineGun );

STUB_WEAPON_CLASS( weapon_357, Weapon357, C_BaseHLCombatWeapon );

STUB_WEAPON_CLASS( weapon_usp, WeaponUsp, C_BaseHLCombatWeapon );

STUB_WEAPON_CLASS( weapon_crossbow, WeaponCrossbow, C_BaseHLCombatWeapon );

STUB_WEAPON_CLASS( weapon_slam, Weapon_SLAM, C_BaseHLCombatWeapon );

STUB_WEAPON_CLASS( weapon_crowbar, WeaponCrowbar, C_BaseHLBludgeonWeapon );

#endif

[/cpp]

Suivant..."hl2mp_player.cpp"

Copier/coller/renommer comme d'habitude ce que vous trouvez...Même si ici vous voyez HL2MP

( ça ne changera peut être rien mais on ne sait jamais )

[cpp]

CBasePlayer::GiveAmmo( 32, "357" ); // nombre de munitions de type 357

CBasePlayer::GiveAmmo( 32, "usp" ); // nombre de munitions de type usp

...

GiveNamedItem( "weapon_pistol" ); // donne l'arme pistol

GiveNamedItem( "weapon_357" ); // donne l'arme 357

GiveNamedItem( "weapon_usp" ); // donne l'arme usp

[/cpp]

Au fait, c'est ce qui gère la commande, "impulse 101" qui donne toute les armes

Suivant..."hl2_player.cpp"

Copier/coller/renommer comme d'habitude ce que vous trouvez...

[cpp]

BaseClass::GiveAmmo( 5, "grenade");

BaseClass::GiveAmmo( 32, "357" );

BaseClass::GiveAmmo( 32, "Usp" );

BaseClass::GiveAmmo( 16, "XBowBolt" );

...

GiveNamedItem( "weapon_357" );

GiveNamedItem( "weapon_usp" );

GiveNamedItem( "weapon_crossbow" );

[/cpp]

ICI EST GERER TOUT LES VARIABLES DU IMPULSE...Regardez ce que donne par exemple le 83 ou le 82...

Suivant..."item_ammo.cpp"

DEJA FAIT :)

Suivant..."item_dynamic_resupply.cpp"

Copier/coller/renommer comme d'habitude ce que vous trouvez...

[cpp]

{ "weapon_frag", "Grenade", 1, 0.1f },

{ "item_ammo_357", "357", SIZE_AMMO_357, 0.0f },

{ "item_ammo_usp", "Usp", SIZE_AMMO_USP, 0.0f },

{ "item_ammo_crossbow", "XBowBolt", SIZE_AMMO_CROSSBOW, 0.0f },

[/cpp]

[cpp]

DEFINE_KEYFIELD( m_flDesiredAmmo[6], FIELD_FLOAT, "DesiredAmmoGrenade" ),

DEFINE_KEYFIELD( m_flDesiredAmmo[7], FIELD_FLOAT, "DesiredAmmo357" ),

DEFINE_KEYFIELD( m_flDesiredAmmo[8], FIELD_FLOAT, "DesiredAmmoUsp" ),

DEFINE_KEYFIELD( m_flDesiredAmmo[9], FIELD_FLOAT, "DesiredAmmoCrossbow" ),

[/cpp]

[cpp]

m_flDesiredAmmo[6] = 0.1; // Grenade

m_flDesiredAmmo[7] = 0; // 357

m_flDesiredAmmo[8] = 0; // usp

m_flDesiredAmmo[9] = 0; // Crossbow

[/cpp]

Suivant..."npc_combines.cpp"

On n'y touche pas

Suivant..."weapon_357.cpp"

On l'a déjà fait

Suivant..."hl2_gamerules.cpp"

Copier/coller/renommer comme d'habitude ce que vous trouvez...

[cpp]

ConVar sk_plr_dmg_357 ( "sk_plr_dmg_357", "0", FCVAR_REPLICATED );

ConVar sk_npc_dmg_357 ( "sk_npc_dmg_357", "0", FCVAR_REPLICATED );

ConVar sk_max_357 ( "sk_max_357", "0", FCVAR_REPLICATED );

ConVar sk_plr_dmg_usp ( "sk_plr_dmg_usp", "10", FCVAR_REPLICATED ); // 10 comme 10 de dégats

ConVar sk_npc_dmg_usp ( "sk_npc_dmg_usp", "60", FCVAR_REPLICATED ); // 60 comme 60munitions en poche

ConVar sk_max_usp ( "sk_max_usp", "0", FCVAR_REPLICATED );

[/cpp]

Vous pouvez a tout moment changer la valeur des variables grace au commande pile apres ConVar ( = commande console )

[cpp]

def.AddAmmoType("357", DMG_BULLET, TRACER_LINE_AND_WHIZ, "sk_plr_dmg_357", "sk_npc_dmg_357", "sk_max_357", BULLET_IMPULSE(800, 5000), 0 );

def.AddAmmoType("Usp", DMG_BULLET, TRACER_LINE_AND_WHIZ, "sk_plr_dmg_usp", "sk_npc_dmg_usp", "sk_max_usp", BULLET_IMPULSE(800, 5000), 0 );

[/cpp]

Suivant..."weapon_357.cpp" du dossier HL2MP

On n'y touche pas

Suivant..."hl2mp_gamerules.cpp"

Copier/coller/renommer comme d'habitude ce que vous trouvez...Même si ici vous voyez HL2MP

( ça ne changera peut etre rien mais on ne sait jamais )

[cpp]

def.AddAmmoType("SMG1", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 225, BULLET_IMPULSE(200, 1225), 0 );

def.AddAmmoType("357", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 12, BULLET_IMPULSE(800, 5000), 0 );

def.AddAmmoType("Usp", DMG_BULLET, TRACER_LINE_AND_WHIZ, 0, 0, 12, BULLET_IMPULSE(800, 5000), 0 );

def.AddAmmoType("XBowBolt", DMG_BULLET, TRACER_LINE, 0, 0, 10, BULLET_IMPULSE(800, 8000), 0 );

[/cpp]

VOTRE ARME EST CRÉE...

Faire le script de son arme.

Aller dans le dossier

C:\Program Files\Steam\SteamApps\SourceMods\test\scripts

Copier/coller le fichier weapon_357.txt en weapon_usp.txt

[cpp]

// 357

WeaponData

{

// Weapon data is loaded by both the Game and Client DLLs.

"printname" "#HL2_357Handgun" // nom de l'arme dans le HUD

"viewmodel" "models/weapons/v_357.mdl" // mode de l'arme en vue FPS

"playermodel" "models/weapons/w_357.mdl" // model de l'arme a terre

"anim_prefix" "python" // nom de l'animation de la prise de l'arme

"bucket" "1" // position dans le menu des armes ( 1 = les pistolets )

"bucket_position" "1" // position par rapport au autre pistolet ( 0 = pistol, 1 = 357, nous mettrons 2 )

"clip_size" "6"

"default_clip" "6"

"primary_ammo" "357" // type de munition, nous mettrons usp au lieu de 357

"secondary_ammo" "None"

"weight" "7"

"item_flags" "0"

// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds)

SoundData

{

"empty" "Weapon_Pistol.Empty"

"single_shot" "Weapon_357.Single"

}

// Weapon Sprite data is loaded by the Client DLL.

TextureData

{

"weapon"

{

"font" "WeaponIcons"

"character" "e"

}

"weapon_s"

{

"font" "WeaponIconsSelected"

"character" "e"

}

"ammo"

{

"font" "WeaponIcons"

"character" "q"

}

"crosshair"

{

"font" "Crosshairs"

"character" "Q"

}

"autoaim"

{

"file" "sprites/crosshairs"

"x" "0"

"y" "48"

"width" "24"

"height" "24"

}

}

}

[/cpp]

Le reste, il suffit de lire, les lettres correspondent à la place dans les fichiers des textures...

Mon weapon_usp

[cpp]

// USP

WeaponData

{

// Weapon data is loaded by both the Game and Client DLLs.

"printname" "USP"

"viewmodel" "models/weapons/v_357.mdl"

"playermodel" "models/weapons/w_357.mdl"

"anim_prefix" "python"

"bucket" "1"

"bucket_position" "3"

"clip_size" "6"

"default_clip" "10"

"primary_ammo" "usp"

"secondary_ammo" "None"

"weight" "7"

"item_flags" "0"

// Sounds for the weapon. There is a max of 16 sounds per category (i.e. max 16 "single_shot" sounds)

SoundData

{

"empty" "Weapon_Pistol.Empty"

"single_shot" "Weapon_357.Single"

}

// Weapon Sprite data is loaded by the Client DLL.

TextureData

{

"weapon"

{

"font" "WeaponIcons"

"character" "e"

}

"weapon_s"

{

"font" "WeaponIconsSelected"

"character" "e"

}

"ammo"

{

"font" "WeaponIcons"

"character" "q"

}

"crosshair"

{

"font" "Crosshairs"

"character" "Q"

}

"autoaim"

{

"file" "sprites/crosshairs"

"x" "0"

"y" "48"

"width" "24"

"height" "24"

}

}

}

[/cpp]

Tester son arme.

Utilisez la source de la map test, enlevé les entités pour le 357...compiler, lancer.

Dans le jeu taper dans la console

give weapon_357

give weapon_usp

Et vous aurez 2armes différentes :)

Ajouter les entités de son arme dans une map.

Une recherche préalable dans la configuration de hammer est préférable, car vous devrez changer le chemin du fichier FGD...

Direction

C:\Program Files\Steam\SteamApps\votre_compte\sourcesdk\bin

Copier/coller le fichier halflife2.fgd

Dans

C:\Program Files\Steam\SteamApps\SourceMods\test

Et faites en sorte que hammer l'utilise

Ouvrez halflife2.fgd avec bloc-notes par exemple

Et comme a notre habitude copier/coller tout ce qui se rapporte au 357 et renommer usp...

Maintenant dans hammer se trouveront les entités pour l'usp...

Je n’ai pas retesté après. Ce tutos et ces recherches dans le SDK m’ont prit toute une après-midi…

Les sources et le MOD viendront plus tard...Mal de tete xD

EDIT :: bug trouvé, les munitions ne sont pas encore associer a l'arme...Je travaille encore dessu...

EDIT2 :: bug corriger, les variables gerant les munitions et les degat etaient sur 0 voir le "hl2_gamerules.cpp". Normalement tout fonctionne, je dis normalement car pour trouver se bug j'ai dut beaucoup beaucoup modifier la source et ça un peu partout

Lien vers le commentaire
Partager sur d’autres sites

Archivé

Ce sujet est désormais archivé et ne peut plus recevoir de nouvelles réponses.