PDA

View Full Version : Secondary max ammo greater than 10



KneeGrow
27-05-2016, 03:01 PM
An example mp5 script I've been messing with won't let me extend the maximum ammo past 250 and 10 (primary and secondary ammo)



const int MP5_MAX_AMMO = 250;
const int MP5_MAX_AMMO2 = 10;

I've tried to changes these to higher numbers, but it appears they only affect the hud.

Is there something outside of the script I have to change?

Solokiller
27-05-2016, 03:04 PM
If you're using the pre-existing AR grenade ammo type, it's hardcoded to 10 grenades maximum. If you want more, you'll have to add a new ammo type.

If you want ammo to subtract instead of add, you'll have to create a custom ammo type.

KneeGrow
27-05-2016, 03:22 PM
I've looked at other people's weapons and they all have the similar "GetItemInfo(...)" functions.
Here's a snippet of the code I'm using, if you want a look at the whole code go here -> http://pastebin.com/9DmgwwNB

Is this what's meant by creating a custom ammo type?


const int MP5_DEFAULT_GIVE = 150;
const int MP5_MAX_AMMO = 450;
const int MP5_MAX_AMMO2 = 30;
const int MP5_MAX_CLIP = 150;
const int MP5_WEIGHT = 5;




bool GetItemInfo( ItemInfo& out info )
{
info.iMaxAmmo1 = MP5_MAX_AMMO;
info.iMaxAmmo2 = MP5_MAX_AMMO2;
info.iMaxClip = MP5_MAX_CLIP;
info.iSlot = 2;
info.iPosition = 4;
info.iFlags = 0;
info.iWeight = MP5_WEIGHT;

return true;
}



void RegisterHLMP5()
{
g_CustomEntityFuncs.RegisterCustomEntity( "weapon_hlmp5", "weapon_hlmp5" );
g_ItemRegistry.RegisterWeapon( "weapon_hlmp5", "hl_weapons", "9mm", "ARgrenades" );
}

iMaxClip seems to be the only one that's working

Would changing "9mm" and "ARgrenades" to something else fix it?

Solokiller
27-05-2016, 03:30 PM
The way custom ammo types work is very confusing. You have to define the ammo name when you register the weapon. You're using "ARGrenades", which is the built-in type.
The first weapon that is precached that uses the ammo type will define the ammo settings in its GetItemInfo method. If it's a custom ammo type, that's the first registered custom weapon.
In order to have an increased maximum number of grenades, you'll have to give the ammo type a different name, and create a new ammo class so that you can place it in the world (if you want that).

Alternatively, you can use CBasePlayer::SetMaxAmmo to set the maximum ammo that a particular player can carry for the "ARGrenades" ammo type. If you use the PlayerSpawn hook to do this, it should effectively change the maximum amount for all players for the duration of the map.

I know that's very confusing and illogical, but that's how it has always worked in GoldSource. It was going to be changed to make more sense, but i doubt it will be changed now.

KneeGrow
27-05-2016, 04:01 PM
Ah, I was really hoping different weapons could share ammo types. Oh well.

Do you know which html link in the SC angelscript documentation .rar contains info about the g_ItemRegistry.RegisterWeapon(...) function?
I've got this line


g_ItemRegistry.RegisterWeapon( "weapon_mp5inator", "hl_weapons", "ammo_mp5inator");

but I want it to look like this


g_ItemRegistry.RegisterWeapon( "weapon_mp5inator", "hl_weapons", "ammo_mp5inator", "ammo_mp5nades");

I assume the parameters are: ( weapon name, contained folder, ammo type )

I'm trying to debug and I'm not sure if it's a g_ItemRegistry or
the new class for each ammo type


class MP5AmmoBox : ScriptBasePlayerAmmoEntity
{
void Spawn()
{
Precache();
g_EntityFuncs.SetModel( self, "models/w_9mmbox.mdl" );
BaseClass.Spawn();
}

void Precache()
{
g_Game.PrecacheModel( "models/w_9mmbox.mdl" );
g_SoundSystem.PrecacheSound( "items/9mmclip1.wav" );
}

bool AddAmmo( CBaseEntity@ pither )
{
int iGive;

iGive = MP5_DEFAULT_GIVE;

if( pither.GiveAmmo( iGive, "ammo_mp5inator", MP5_MAX_CARRY ) != -1 )
{
g_SoundSystem.EmitSound( self.edict(), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
return true;
}
return false;
}
}
class MP5Grenades : ScriptBasePlayerAmmoEntity
{
void Spawn()
{
Precache();
g_EntityFuncs.SetModel( self, "models/w_argrenade.mdl" );
BaseClass.Spawn();
}

void Precache()
{
g_Game.PrecacheModel( "models/w_argrenade.mdl" );
g_SoundSystem.PrecacheSound( "items/9mmclip1.wav" );
}

bool AddAmmo( CBaseEntity@ pither )
{
int iGive;

iGive = MP5_DEFAULT_GIVE2;

if( pither.GiveAmmo( iGive, "ammo_mp5inator", MP5_MAX_CARRY2 ) != -1 )
{
g_SoundSystem.EmitSound( self.edict(), CHAN_ITEM, "items/9mmclip1.wav", 1, ATTN_NORM );
return true;
}
return false;
}
}

Solokiller
27-05-2016, 04:15 PM
Weapons can share ammo types, you just can't change the ammo settings globally.

CItemRegistry contains the documentation for g_ItemRegistry.

Which problems are you having exactly?

KneeGrow
27-05-2016, 04:36 PM
Searching for g_ItemRegistry and it was located under CItemRegistry
wow I'm dumb

I think the custom ammunition is fine now.
Now I just have to find out what's keeping this from working/spawning (it worked with default ammo settings).

Solokiller
27-05-2016, 04:44 PM
Enable developer mode and increase the log level to get more information in the console. See this page (https://github.com/SamVanheer/SC_Angelscript/wiki/Debugging-Scripts) for more information.

KneeGrow
27-05-2016, 05:06 PM
Ah, finally got it.
All because somehow one of the "void" functions had a capital "V"

Thanks for all your help, the ammo section in the corner is a little stretched for space, but I'll save that for another day.
EDIT:
Gah, now out of the woods yet,
worked for one map load, then stopped working when I changed the ammo model. And the logs don't want me to find the error.

Angelscript: Starting compilation: 2 scripts
WARNING: Angelscript: (0, 0) : Failed in call to function 'Prepare' with 'void _unnamed_function_()' (Code: -2)
WARNING: Angelscript: Map script compilation failed



ignore above
All it took was a restart of the game to fix.
:v