Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » Working vehicle menus on SP maps, and how to purchase powerups from them and airdrop vehicles  () 1 Vote
Working vehicle menus on SP maps, and how to purchase powerups from them and airdrop vehicles [message #467296] Sat, 12 May 2012 02:46 Go to next message
Whitedragon is currently offline  Whitedragon
Messages: 832
Registered: February 2003
Location: California
Karma: 1
Colonel
I've noticed that the way vehicles and powerups are bought on coop servers is kinda ugly, using pokeable objects and chat commands. So here's some code that will allow you to have working vehicle purchase menus on SP maps. You will be able to purchase vehicles from the PT and have them airdropped in, and purchase powerups the same way as beacons. It could also be made to airdrop the powerups if you wanted to.

void Set_Vehicle_Factory_Is_Busy(VehicleFactoryGameObj *VF,bool Busy) {
	if (VF) {
		*((bool*)VF+0x8C8) = Busy; //Set_Is_Busy needs to be added to VehicleFactoryGameObj
		VF->Set_Object_Dirty_Bit(NetworkObjectClass::BIT_RARE,true);
	}
}

int VehiclePurchase(BaseControllerClass *Base,GameObject *Purchaser,unsigned int Cost,unsigned int Preset,const char *Data) {
	DefinitionClass *Def = Find_Definition(Preset);
	if (Def) {
		if (Def->Get_Class_ID() == CID_Vehicle) { //It's a vehicle
			VehicleFactoryGameObj *VF = (VehicleFactoryGameObj*)Base->Find_Building(BuildingConstants::TYPE_VEHICLE_FACTORY);
			if (!Base->Can_Generate_Vehicles() || !VF || VF->Is_Busy()) {
				return 3;
			}
			else if ((unsigned int)VF->Get_Team_Vehicle_Count() >= Get_Vehicle_Limit()) {
				return 3;
			}
			if (Purchase_Item(Purchaser,Cost)) {
				int Team = Base->Get_Player_Type();
				VehicleGameObj *Veh = Commands->Create_Object(Def->Get_Name(),Vector3(0,0,0))->As_VehicleGameObj();
				GameObject *Cin = Commands->Create_Object("Invisible_Object",VehiclePosition[Team]); //Set the position however you want
				Commands->Attach_Script(Cin,"Test_Cinematic",StringClass::getFormattedString("%s_Vehicle_Purchase.txt",Team?"GDI":"Nod")); //Create the cinematic
				Commands->Send_Custom_Event(Veh,Cin,10004,Commands->Get_ID(Veh),0); //Insert vehicle into cinematic at slot 4
				Veh->Lock_Vehicle(Purchaser->As_SoldierGameObj(),30.0f); //Lock vehicle
				Set_Vehicle_Factory_Is_Busy(VF,true);
				//You should attach a script to the vehicle that makes it invincible until it lands. The same script can also be used to make the VF not busy.
				return 0;
			}
			return 2;
		}
		else if (Def->Get_Class_ID() == CID_PowerUp) { //It's a powerup
			PowerUpGameObjDef *PowerUpDef = (PowerUpGameObjDef*)Def;
			if (PowerUpDef->GrantWeapon && Has_Weapon(Purchaser,Get_Definition_Name(PowerUpDef->GrantWeaponID))) {
				return 4; //Stop players from accidentally buying a weapon they already have
			}
			else if (Purchase_Item(Purchaser,Cost)) {
				PowerUpDef->Grant(Purchaser->As_SoldierGameObj());
				return 0;
			}
			return 2;
		}
	}
	return 4;
}


Obviously you'll need a vehicle factory on the map which can be added through leveledit or created in a script with Create_Building.


Black-Cell.net
Network Administrator (2003 - )

DragonServ, Renegade's first IRC interface bot
Creator and lead coder (2002 - )

Dragonade, Renegade's first server side modification
Lead coder (2005 - )

[Updated on: Tue, 15 May 2012 02:54]

Report message to a moderator

Re: Working vehicle menus on SP maps, and how to purchase powerups from them and airdrop vehicles [message #467352 is a reply to message #467296] Mon, 14 May 2012 11:34 Go to previous messageGo to next message
Ethenal is currently offline  Ethenal
Messages: 2532
Registered: January 2007
Location: US of A
Karma: 0
General (2 Stars)

That's actually quite cool Whitedragon! I was going to attempt making something like that myself, and since you already did, I suppose I'll just use yours instead.

Related question: if I recall correctly, PT data is loaded every map and can be changed server-side, correct? If so, could that be used to make new "powerup" entries in the PT for the code you've just posted?

Nice to have you around again. Smile


-TLS-DJ-EYE-K wrote on Mon, 18 March 2013 07:29

Instead of showing us that u aren't more inteligent than a Toast, maybe you should start becomming good in renegade Thumbs Up

Re: Working vehicle menus on SP maps, and how to purchase powerups from them and airdrop vehicles [message #467353 is a reply to message #467296] Mon, 14 May 2012 12:34 Go to previous messageGo to next message
iRANian is currently offline  iRANian
Messages: 4308
Registered: April 2011
Karma: 0
General (4 Stars)
How does purchasing powerups work this way? Do you need to change the prests for the vehicles with LevelEdit?

Long time and well respected Renegade community member, programmer, modder and tester.

Scripts 4.0 private beta tester since May 2011.

My Renegade server plugins releases
Re: Working vehicle menus on SP maps, and how to purchase powerups from them and airdrop vehicles [message #467356 is a reply to message #467296] Mon, 14 May 2012 12:51 Go to previous messageGo to next message
Whitedragon is currently offline  Whitedragon
Messages: 832
Registered: February 2003
Location: California
Karma: 1
Colonel
Edit the PT and replace the vehicle presets with powerup presets.
You can't create new buttons in the PT, so if you want to keep the normal soldiers/vehicles intact your best bet is to replace the extras.


Black-Cell.net
Network Administrator (2003 - )

DragonServ, Renegade's first IRC interface bot
Creator and lead coder (2002 - )

Dragonade, Renegade's first server side modification
Lead coder (2005 - )

[Updated on: Mon, 14 May 2012 12:58]

Report message to a moderator

Re: Working vehicle menus on SP maps, and how to purchase powerups from them and airdrop vehicles [message #467357 is a reply to message #467296] Mon, 14 May 2012 13:26 Go to previous messageGo to next message
Whitedragon is currently offline  Whitedragon
Messages: 832
Registered: February 2003
Location: California
Karma: 1
Colonel
Oh yeah, here's the character purchase hook so you can have powerups in the character menu too.

int CharacterPurchase(BaseControllerClass *Base,GameObject *Purchaser,unsigned int Cost,unsigned int Preset,const char *Data) {
	if (Base->Can_Generate_Soldiers() || !Cost) {
		DefinitionClass *Def = Find_Definition(Preset);
		if (Def->Get_Class_ID() == CID_Soldier) {
			if (Purchase_Item(Purchaser,Cost)) {
				Purchaser->As_SoldierGameObj()->Re_Init(*(SoldierGameObjDef*)Def);
				Purchaser->As_SoldierGameObj()->Post_Re_Init();
				return 0;
			}
			return 2;
		}
		else if (Def->Get_Class_ID() == CID_PowerUp) {
			PowerUpGameObjDef *PowerUpDef = (PowerUpGameObjDef*)Def;
			if (PowerUpDef->GrantWeapon && Has_Weapon(Purchaser,Get_Definition_Name(PowerUpDef->GrantWeaponID))) {
				return 4;
			}
			else if (Purchase_Item(Purchaser,Cost)) {
				PowerUpDef->Grant(Purchaser->As_SoldierGameObj());
				return 0;
			}
			return 2;
		}
	}
	return 3;
}


Black-Cell.net
Network Administrator (2003 - )

DragonServ, Renegade's first IRC interface bot
Creator and lead coder (2002 - )

Dragonade, Renegade's first server side modification
Lead coder (2005 - )
Re: Working vehicle menus on SP maps, and how to purchase powerups from them and airdrop vehicles [message #467380 is a reply to message #467352] Tue, 15 May 2012 05:43 Go to previous message
Jerad2142 is currently offline  Jerad2142
Messages: 3812
Registered: July 2006
Location: USA
Karma: 6
General (3 Stars)
Ethenal wrote on Mon, 14 May 2012 12:34

That's actually quite cool Whitedragon! I was going to attempt making something like that myself, and since you already did, I suppose I'll just use yours instead.

Related question: if I recall correctly, PT data is loaded every map and can be changed server-side, correct? If so, could that be used to make new "powerup" entries in the PT for the code you've just posted?

Nice to have you around again. Smile

It's actually loaded client side unless TT team changed it (or at least the prices are for sure if they're modified in temps etc).


Previous Topic: server crash (in tt.dll) after dead of ai
Next Topic: level edit .ddb
Goto Forum:
  


Current Time: Wed Dec 18 16:32:03 MST 2024

Total time taken to generate the page: 0.01264 seconds