Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Release Forum » [script]!sellveh  () 3 Votes
[script]!sellveh [message #327514] Wed, 23 April 2008 16:13 Go to previous message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma:
General (3 Stars)
I have been writing some code for when the new patch of cnc_reborn comes out with vehicles. I wanted to ability to enable or disable the selling of vehicles in my server. I havn't tested it out very much, other then a couple of attempts. I thought the renegade community might like it and if someone does use it then they could also report back any issues/problems ahead of the reborn release so I might be able to resolve them before the patch release.

The code is based on SSGM, you will need to adapt it for renegade slightly, but I have made it clear in the comments where...

I will restate that I havn't tested it too much, there will most likely be issues, I am aware that after being ejected you can get back in, I will write code at some point to make sure that halts the sale of the vehicle, unless someone submits it...


Include this function somewhere, I chose GMMAIN.cpp
float GetValue(const char* Preset) {
	float VehValue = 0;
// These preset names need to be changed to renegade vehicle preset names, you also need to make the cost whatever you feel is the right amount to get for the sale of the vehicle
if (stricmp(Preset,"GDI_AAPC") == 0) VehValue = 3;
else if (stricmp(Preset,"GDI_Disruptor") == 0) VehValue = 100;

	return VehValue;
}



Here's the chat hook:
class sellvehChatCommand : public ChatCommandClass {
	void Triggered(int ID,const TokenClass &Text,int ChatType) {
		GameObject *MyVeh = Find_My_Veh(Get_GameObj(ID));
		GameObject *Own = Get_GameObj(ID);
		float Value = GetValue(Commands->Get_Preset_Name(MyVeh));
		int Type = Commands->Get_Player_Type(Own);
		if (Type == 2){
float Dist = Commands->Get_Distance(Commands->Get_Position(Own),Commands->Get_Position(Find_War_Factory(0)));
		if (!MyVeh) {
			Console_Input(StrFormat("ppage %d You must have a vehicle bound to you to use this command. Type !bind in teamchat to bind the vehicle you are currently in.",ID).c_str());
		}
		if (MyVeh && Value > 0 && Dist <= 20.0f) {
			Force_Occupants_Exit(MyVeh);
            Commands->Send_Custom_Event(Own,MyVeh,1112,0,0);
			Commands->Attach_Script(Own,"reb_sell_veh","");
			Console_Input(StrFormat("ppage %d Your vehicle will be sold in 15 seconds for $%f, unless it is stolen/destroyed.",ID,GetValue(Commands->Get_Preset_Name(MyVeh))).c_str());
		}
		if (MyVeh && Value == 0) {
			Console_Input(StrFormat("ppage %d This vehicle is not supported by this command, please report this bug.",ID).c_str());
		}
				if (Dist > 20.0f) {
			Console_Input(StrFormat("ppage %d To use this command you must be in close proximity to the Nod WarFactory",ID).c_str());
		}
		}
		else{
float Dist = Commands->Get_Distance(Commands->Get_Position(Own),Commands->Get_Position(Find_War_Factory(1)));
		if (!MyVeh) {
			Console_Input(StrFormat("ppage %d You must have a vehicle bound to you to use this command. Type !bind in teamchat to bind the vehicle you are currently in.",ID).c_str());
		}
		if (MyVeh && Value > 0 && Dist <= 20.0f) {
			Force_Occupants_Exit(MyVeh);
            Commands->Send_Custom_Event(Own,MyVeh,1112,0,0);
			Commands->Attach_Script(Own,"reb_sell_veh","");
			Console_Input(StrFormat("ppage %d Your vehicle will be sold in 15 seconds for $%f, unless it is stolen/destroyed.",ID,GetValue(Commands->Get_Preset_Name(MyVeh))).c_str());
		}
		if (MyVeh && Value == 0) {
			Console_Input(StrFormat("ppage %d This vehicle is not supported by this command, please report this bug.",ID).c_str());
		}
				if (Dist > 20.0f) {
			Console_Input(StrFormat("ppage %d To use this command you must be in close proximity to the GDI WarFactory",ID).c_str());
		}
		}
	}
};
ChatCommandRegistrant<sellvehChatCommand> sellvehChatCommandReg("!sellveh",CHATTYPE_ALL,0,GAMEMODE_AOW);


Here's the script that does the selling:

void reb_sell_veh::Created(GameObject *obj) {
GameObject *MyVeh = Find_My_Veh(obj);
VehID = Commands->Get_ID(MyVeh);


Commands->Start_Timer(obj, this, 15.0f, 1);
}

void reb_sell_veh::Killed(GameObject *obj, GameObject *shooter){
Console_Input(StrFormat("ppage %d Your vehicle sale has been halted",Get_Player_ID(obj)).c_str());
}

void reb_sell_veh::Timer_Expired(GameObject *obj, int number){
if(number == 1){
	if(Commands->Find_Object(VehID)){
Commands->Destroy_Object(Find_My_Veh(obj));
Commands->Give_Money(obj,GetValue(Commands->Get_Preset_Name(Find_My_Veh(obj))), 0);
	}
}
}

ScriptRegistrant<reb_sell_veh> reb_sell_veh_Registrant("reb_sell_veh","");



class reb_sell_veh : public ScriptImpClass {
	void Created(GameObject *obj);
	void Timer_Expired(GameObject *obj, int number);
	void Killed(GameObject *obj, GameObject *shooter);
	int VehID;
};




[Updated on: Fri, 30 January 2009 14:31] by Moderator

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [script]Parachute function
Next Topic: BloodMod
Goto Forum:
  


Current Time: Sun Jun 16 00:55:51 MST 2024

Total time taken to generate the page: 0.01119 seconds