Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Release Forum » [script]!sellveh  () 3 Votes
Re: !sellveh [message #334825 is a reply to message #327514] Thu, 12 June 2008 03:09 Go to previous messageGo to previous message
reborn is currently offline  reborn
Messages: 3231
Registered: September 2004
Location: uk - london
Karma:
General (3 Stars)
I've actually changed that quite a bit now anyway, for cnc_reborn there have been some map releases with temped vehicles so it makes sense to do it the way I did with GetValue, however for renegade you can get the cost directly from the preset itself.
Actually this will still most likely work for renegade, and still allow you to adapt if you have temped vehicle presets in your server too. Here's my updated version.


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);
		int Type = Commands->Get_Player_Type(Own);
		if (Type == 2){
float Dist = Commands->Get_Distance(Commands->Get_Position(Own),Commands->Get_Position(Find_Soldier_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 && 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 you re-enter it or it is stolen/destroyed.",ID,GetValue(Commands->Get_Preset_Name(MyVeh))).c_str());
			sellingveh = true;
		}
		if (Dist > 20.0f) {
			Console_Input(StrFormat("ppage %d To use this command you must be in close proximity to the Nod HON",ID).c_str());
		}
		}
		else{
float Dist = Commands->Get_Distance(Commands->Get_Position(Own),Commands->Get_Position(Find_Soldier_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 && 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 you re-enter it or it is stolen/destroyed.",ID,GetValue(Commands->Get_Preset_Name(MyVeh))).c_str());
			sellingveh = true;
		}
				if (Dist > 20.0f) {
			Console_Input(StrFormat("ppage %d To use this command you must be in close proximity to the GDI Barracks",ID).c_str());
		}
		}
	}
};
ChatCommandRegistrant<sellvehChatCommand> sellvehChatCommandReg("!sellveh",CHATTYPE_ALL,0,GAMEMODE_AOW);



This will now mean that it gets the vehicles value directly from the preset itself and halves it, unless the preset doesn't exist (i.e it's a temped preset you made yourself), then it will try to get the value from GetValue.
void reb_sell_veh::Timer_Expired(GameObject *obj, int number){
if(number == 1){
	if(Commands->Find_Object(VehID)){
unsigned int worth;
worth = (Get_Cost((Commands->Get_Preset_Name(Commands->Find_Object(VehID))))/2);
if (worth > 0){
Console_Input(StrFormat("ppage %d Your vehicle was successfully sold for $%i.",Get_Player_ID(obj),worth).c_str());
Commands->Give_Money(obj,GetValue(Commands->Get_Preset_Name(Find_My_Veh(obj))), 0);
Commands->Destroy_Object(Find_My_Veh(obj));
sellingveh = false;
}
else {
		float value = GetValue(Commands->Get_Preset_Name(Find_My_Veh(obj)));
Console_Input(StrFormat("ppage %d Your vehicle was successfully sold for $%f.",Get_Player_ID(obj),value).c_str());
Commands->Give_Money(obj,GetValue(Commands->Get_Preset_Name(Find_My_Veh(obj))), 0);
Commands->Destroy_Object(Find_My_Veh(obj));
sellingveh = false;
	}
	}
}
}


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;
};


Had to change MDB_SSGM_Vehicle_Owner a little bit...

void MDB_SSGM_Vehicle_Owner::Custom(GameObject *obj, int message, int param, GameObject *sender) {
	if (message == 1111) {
		Commands->Destroy_Object(Commands->Find_Object(IconID));
		Commands->Destroy_Object(Commands->Find_Object(IconID2));
		Destroy_Script();
	}
	else if (message == 1112) {
		IsLocked = true;
		if (Commands->Get_ID(Get_Vehicle_Occupant(obj,0)) != MyOwner(3)) Force_Occupant_Exit(obj,0);
		if (GetIconBone(obj,1)) {
			Commands->Destroy_Object(Commands->Find_Object(IconID));
			GameObject *Icon = Commands->Create_Object_At_Bone(obj,"Invisible_Object",GetIconBone(obj,1));
			Commands->Set_Model(Icon,"p_keycrd_red");
			Commands->Attach_To_Object_Bone(Icon,obj,GetIconBone(obj,1));
			IconID = Commands->Get_ID(Icon);
		}
		if (GetIconBone(obj,2)) {
			Commands->Destroy_Object(Commands->Find_Object(IconID2));
			GameObject *Icon2 = Commands->Create_Object_At_Bone(obj,"Invisible_Object",GetIconBone(obj,2));
			Commands->Set_Model(Icon2,"p_keycrd_red");
			Commands->Attach_To_Object_Bone(Icon2,obj,GetIconBone(obj,2));
			IconID2 = Commands->Get_ID(Icon2);
		}
	}
	else if (message == 1113) {
		IsLocked = false;
		if (GetIconBone(obj,1)) {
			Commands->Destroy_Object(Commands->Find_Object(IconID));
			GameObject *Icon = Commands->Create_Object_At_Bone(obj,"Invisible_Object",GetIconBone(obj,1));
			Commands->Set_Model(Icon,"o_em_apc");
			Commands->Attach_To_Object_Bone(Icon,obj,GetIconBone(obj,1));
			IconID = Commands->Get_ID(Icon);
		}
		if (GetIconBone(obj,2)) {
			Commands->Destroy_Object(Commands->Find_Object(IconID2));
			GameObject *Icon2 = Commands->Create_Object_At_Bone(obj,"Invisible_Object",GetIconBone(obj,2));
			Commands->Set_Model(Icon2,"o_em_apc");
			Commands->Attach_To_Object_Bone(Icon2,obj,GetIconBone(obj,2));
			IconID2 = Commands->Get_ID(Icon2);
		}
	}
	else if (message == CUSTOM_EVENT_VEHICLE_ENTER) {
		if (Commands->Get_Player_Type(sender) != Team) {
			Console_Input(StrFormat("ppage %d The enemy has stolen your vehicle!",MyOwner(2)).c_str());
			Commands->Destroy_Object(Commands->Find_Object(IconID));
			Commands->Destroy_Object(Commands->Find_Object(IconID2));
			Destroy_Script();
		}
		else if (IsLocked && Commands->Get_ID(Get_Vehicle_Occupant(obj,0)) == Commands->Get_ID(sender) && Commands->Get_ID(sender) != MyOwner(3)) {
			Commands->Control_Enable(sender,false);
			Commands->Start_Timer(obj,this,0.5f,3);
			Console_Input(StrFormat("pamsg %d The vehicle you entered is locked and belongs to %ls.",Get_Player_ID(sender),Get_Wide_Player_Name_By_ID(MyOwner(2))).c_str());
		}
		else if (Commands->Get_ID(Get_Vehicle_Occupant(obj,0)) == Commands->Get_ID(sender) && Commands->Get_ID(sender) != MyOwner(3)) {
			Console_Input(StrFormat("ppage %d Warning! %ls has entered your bound vehicle. If you wish to remove them type !vkick in teamchat.",MyOwner(2),Get_Wide_Player_Name(sender)).c_str());
		}
 if (IsLocked && Commands->Get_ID(Get_Vehicle_Occupant(obj,0)) == Commands->Get_ID(sender) && Commands->Get_ID(sender) == MyOwner(3)) {
	 if(sellingveh){
Remove_Script(Get_GameObj(MyOwner(2)),"reb_sell_veh");
Console_Input(StrFormat("ppage %d Your vehicle sale has been halted because you re-entered your vehicle.",MyOwner(2)).c_str());
sellingveh = false;
	 }
}

	}
}



float GetValue(const char* Preset) {
	float VehValue = 0;

if (stricmp(Preset,"test") == 0) VehValue = 1;
else if (stricmp(Preset,"GDI Harvester MP2") == 0) VehValue = 300;
else if (stricmp(Preset,"GDI Harverster MP") == 0) VehValue = 300;
else if (stricmp(Preset,"GDI Titan") == 0) VehValue = 700;
else if (stricmp(Preset,"GDI Wolverine") == 0) VehValue = 300;
else if (stricmp(Preset,"GDI Orca") == 0) VehValue = 500;
else if (stricmp(Preset,"GDI Orca Bomber") == 0) VehValue = 500;
else if (stricmp(Preset,"NOD Harverster MP") == 0) VehValue = 300;
else if (stricmp(Preset,"Nod TickTank TS") == 0) VehValue = 550;
else if (stricmp(Preset,"Nod TickTank") == 0) VehValue = 525;
else if (stricmp(Preset,"Nod Buggy") == 0) VehValue = 200;
else if (stricmp(Preset,"GDI Titan TS") == 0) VehValue = 600;
else if (stricmp(Preset,"Nod TickTank TS") == 0) VehValue = 550;
else if (stricmp(Preset,"Nod Buggy TS") == 0) VehValue = 250;

	return VehValue;
}


You will need to change this to your renegade temped presets (if you have any, if not you should change the reb_sell_veh script and nt even bother with this at all.

float GetValue(const char* Preset) {
	float VehValue = 0;

if (stricmp(Preset,"test") == 0) VehValue = 1;
else if (stricmp(Preset,"GDI Harvester MP2") == 0) VehValue = 300;
else if (stricmp(Preset,"GDI Harverster MP") == 0) VehValue = 300;
else if (stricmp(Preset,"GDI Titan") == 0) VehValue = 700;
else if (stricmp(Preset,"GDI Wolverine") == 0) VehValue = 300;
else if (stricmp(Preset,"GDI Orca") == 0) VehValue = 500;
else if (stricmp(Preset,"GDI Orca Bomber") == 0) VehValue = 500;
else if (stricmp(Preset,"NOD Harverster MP") == 0) VehValue = 300;
else if (stricmp(Preset,"Nod TickTank TS") == 0) VehValue = 550;
else if (stricmp(Preset,"Nod TickTank") == 0) VehValue = 525;
else if (stricmp(Preset,"Nod Buggy") == 0) VehValue = 200;
else if (stricmp(Preset,"GDI Titan TS") == 0) VehValue = 600;
else if (stricmp(Preset,"Nod TickTank TS") == 0) VehValue = 550;
else if (stricmp(Preset,"Nod Buggy TS") == 0) VehValue = 250;

	return VehValue;
}


Also, you need to include this as a global variable

bool sellingveh = false;



 
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: Fri Nov 22 20:45:56 MST 2024

Total time taken to generate the page: 0.00977 seconds