All pastes #2051548 Raw Edit

Unnamed

public text v1 · immutable
#2051548 ·published 2011-04-28 13:44 UTC
rendered paste body
gmscripts.cpp:
    Inside MDB_SSGM_Player::Created:

Commands->Attach_Script(obj,"IRAN_Fix_Pistol_Ammo","");

    Outside of all scopes:

void IRAN_Fix_Pistol_Ammo::Created(GameObject *obj) {
	Commands->Start_Timer(obj,this,0.1f,33); //this is needed to workaround shit not working inside ::Created
}

void IRAN_Fix_Pistol_Ammo::Timer_Expired(GameObject *obj, int number) {
	if ( number == 33) {
		Set_Max_Inventory_Bullets(obj,"Weapon_Pistol_Player",999); //appears to be needed
		Set_Bullets(obj,"Weapon_Pistol_Player",12); //this appears to need to be this amount
		Commands->Start_Timer(obj,this,1.0f,35); //fix refills, will run every one sec
	}

	if ( number == 35) {
		Set_Bullets(obj,"Weapon_Pistol_Player",-1);
		Commands->Start_Timer(obj,this,1.0f,35); //fix refills, will loop every one sec
	}
}

ScriptRegistrant<IRAN_Fix_Pistol_Ammo> IRAN_Fix_Pistol_Ammo_Registrant("IRAN_Fix_Pistol_Ammo","");

gmscripts.h:

class IRAN_Fix_Pistol_Ammo : public ScriptImpClass {
	void Created(GameObject *obj);
	void Timer_Expired(GameObject *obj, int number);
};
engine_weap.h:

void Set_Max_Inventory_Bullets(GameObject *obj,const char *weapon,int bullets); //aded by iran

engine_weap.cpp:

void Set_Max_Inventory_Bullets(GameObject *obj,const char *weapon,int bullets)
{
	if (!Commands->Get_ID(obj) || !obj)
	{
		return;
	}
	PhysicalGameObj *o2 = ((ScriptableGameObj *)obj)->As_PhysicalGameObj();
	if (!o2)
	{
		return;
	}
	ArmedGameObj *o3 = o2->As_ArmedGameObj();
	if (!o3)
	{
		return;
	}
	WeaponBagClass *w = o3->WeaponBag;
	int x = w->Vector.Count();
	for (int i = 0;i < x;i++)
	{
		if (w->Vector[i])
		{
			if (!_stricmp(w->Vector[i]->WeaponDef->Get_Name(),weapon))
			{
				w->Vector[i]->WeaponDef->MaxInventoryRounds.Set(bullets);
			}
		}
	}
}