Posted by: Starbreaker
Date posted: Mar 31 2005 User Rating: 5 out of 5.0 | Number of views: 9801 Number of comments: 2 | Description: This tutorial will cover the code needed to add Slams and SGM1 Grenades as Ammocrate types, and also fix the graphics for two of the existing ones. |
This tutorial will cover how to add 2 more ammo crates to your mod, and fix the model/skin for 2 others. It can also be used to create new ammo types.
After doing a bit of mapping, I could not figure out why after adding an item_ammo_crate I was getting an error model instead of the ammo crate model. Well it appears that Valve added a few to the code and the FGD, but failed to include the models for them. I also wanted to add an ammo crate for Slams and the Grenades for the SMG, so I looked into what this would be, and that is what follows.
I know people do not like/care for cut -> paste tutorials, but really there is nothing here to learn except how the crates themselves were designed, which could be very important if you want to create new ammo types for your mod. The real hard work was making the models and skins.
Ok, here is goes:
The ammo crate code starts at about line 592 in the item_ammo.cpp file.
For this to work correctly we have to add in our 2 new ammo types (the Slam and the Alt fire for the SMG1) around line 607. These have to go after everything else because of the way the crates are setup.
| |
enum { AMMOCRATE_SMALL_ROUNDS, AMMOCRATE_MEDIUM_ROUNDS, AMMOCRATE_LARGE_ROUNDS, AMMOCRATE_RPG_ROUNDS, AMMOCRATE_BUCKSHOT, AMMOCRATE_GRENADES, AMMOCRATE_357, AMMOCRATE_CROSSBOW, AMMOCRATE_AR2_ALTFIRE, AMMOCRATE_SLAM, AMMOCRATE_SMG1_ALTFIRE, NUM_AMMO_CRATE_TYPES, };
|
Next we set the model info at around line 684; we will fix a few names and add some new ones. Here is where I discovered the main problem with the fgd vs. code vs. models. Valve included only 4 ammo crate models, the smg1, ar2, rockets, and the grenades models.
| |
const char *CItem_AmmoCrate::m_lpzModelNames[NUM_AMMO_CRATE_TYPES] = { "models/items/ammocrate_bullets.mdl", "models/items/ammocrate_smg1.mdl", "models/items/ammocrate_ar2.mdl", "models/items/ammocrate_rockets.mdl", "models/items/ammocrate_buckshot.mdl", "models/items/ammocrate_grenade.mdl", "models/items/ammocrate_357.mdl",
"models/items/ammocrate_bolt.mdl", "models/items/ammocrate_ar2_ball.mdl",
"models/items/ammocrate_slam.mdl", "models/items/ammocrate_smg1_grenade.mdl",
};
|
Ok, a side note about these new models I made. I used Cannon fodders Model Decompiler to rip apart valves SMG1 ammo crate model. Now I am no modeler, so all the models I have, have the ammo boxes for the SMG ammo type in them unlike the original 4 models, that have grenades, rockets, and AR2 magazines. Maybe some kind soul out there will point me to a way to fix this, but for now they all just have big boxes in them.
Ok, here we setup the ammo types names for giving ammo, one thing I did notice, is that they all have to be named the same as the ammo type they are with the exception of the frag and the slam due to the way they are given later.
| |
const char *CItem_AmmoCrate::m_lpzAmmoNames[NUM_AMMO_CRATE_TYPES] = { "Pistol", "SMG1", "AR2", "RPG_Round", "Buckshot", "Grenade", "357", "XBowBolt", "AR2AltFire",
"Slam", "SMG1_Grenade",
};
|
Here we set how many you get. If your mod allows for more ammo of each type, change these numbers as needed.
| |
int CItem_AmmoCrate::m_nAmmoAmounts[NUM_AMMO_CRATE_TYPES] = { 300, 300, 300, 3, 120, 5, 50, 50, 3,
5, 3,
};
|
Ok, now here because of the nature of the grenades and slams, you have to give a weapon vs. ammo incase the player does not have one to begin with. If you wanted the player to receive a weapon when he opens the ammo crate, you would just add the name of the weapon to the appropriate slot.
| | const char *CItem_AmmoCrate::m_pGiveWeapon[NUM_AMMO_CRATE_TYPES] = { NULL, NULL, NULL, NULL, NULL, "weapon_frag", NULL, NULL, NULL,
"weapon_slam", NULL,
};
|
Ok, now we are going to change something to reflect a new weapon. It appears that you can open the crate by hitting them with the crowbar, but not the stun stick, and here is the fix for that:
| |
int CItem_AmmoCrate::OnTakeDamage( const CTakeDamageInfo &info ) { CBasePlayer *player = ToBasePlayer(info.GetAttacker()); if (player) { CBaseCombatWeapon *weapon = player->GetActiveWeapon();
if (weapon && (!stricmp(weapon->GetName(), "weapon_crowbar")) || (!stricmp(weapon->GetName(), "weapon_stunstick")))
{ player->EmitSound( "HL2Player.Use" ); Use(info.GetAttacker(), info.GetAttacker(), USE_TOGGLE, 0.0f); } }
return 0; }
|
Ok, that ends the code part. All we need to do now if modify the FGD to add are 2 new ammo crate types.
| | @PointClass base(Targetname, Angles) studio("models/items/ammocrate_rockets.mdl") = item_ammo_crate : "Ammo Crate" [ AmmoType(choices) : "Ammo Type" : 0 = [ 0 : "Pistol" 1 : "SMG1" 2 : "AR2" 3 : "RPG Rounds" 4 : "Buckshot" 5 : "Grenades" 6 : "357" 7 : "XBowBolt" 8 : "AR2 Alt-Fire Round" //Added slams and SMG1 Grenades - Starbreaker 23 - March - 2005 9 : "Slams" 10 : "SMG1 Grenades" ]
// Inputs input Kill(void) : "Remove the ammo crate" output OnUsed(void) : "Fires when +used by the player." ]
|
And that is all there is to it.
Click here Ammocrate.zip to get the models and skins for the new Ammocrate type and the fixed skins.
Hope you enjoy it.
Dave R. Meyers Starbreaker OZ Deathmatch |
|
User Comments
Showing comments 1-2
I cannot use the modifyed fgd ,help. :( here is my fgd:
@include "hl2mp.fgd" @PointClass base(Targetname, Angles) studio("models/items/ammocrate_rockets.mdl") = item_ammo_crate : "Ammo Crate" [ AmmoType(choices) : "Ammo Type" : 0 = [ 0 : "Pistol" 1 : "SMG1" 2 : "AR2" 3 : "RPG Rounds" 4 : "Buckshot" 5 : "Grenades" 6 : "357" 7 : "XBowBolt" 8 : "AR2 Alt-Fire Round" 9 : "Slams" 10 : "SMG1 Grenades" ]
// Inputs input Kill(void) : "Remove the ammo crate" output OnUsed(void) : "Fires when +used by the player." ]
What i have done was wrong?Edited by rookie on Jul 19 2006, 14:08:15
|
|
In the "int CItem_AmmoCrate::OnTakeDamage( const CTakeDamageInfo &info )" function, do you really mean the following line: if (weapon && (!stricmp(weapon->GetName(), "weapon_crowbar")) || (!stricmp(weapon->GetName(), "weapon_stunstick")))
I think, some brackets went wrong, and it should look like this: if (weapon && (!stricmp(weapon->GetName(), "weapon_crowbar") || !stricmp(weapon->GetName(), "weapon_stunstick"))) |
|
You must register to post a comment. If you have already registered, you must login.
|
297 Approved Articless
8 Pending Articles
3940 Registered Members
0 People Online (9 guests)
|
|