Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Release Forum » [script]Parachute function  () 1 Vote
Re: Parachute function [message #301230 is a reply to message #301225] Wed, 05 December 2007 12:32 Go to previous messageGo to previous message
Hex is currently offline  Hex
Messages: 858
Registered: March 2004
Karma:
Colonel
May have a bracket missing somewere as it was pulled from one of our large plugins

Sorry I din't use your code, was just easyer to use what I already had.

//.h

class Parachute : public ScriptImpClass {
	void Created(GameObject *obj);
	void Damaged(GameObject *obj,GameObject *damager,float damage);
	void Killed(GameObject *obj, GameObject *shooter);
	void Timer_Expired(GameObject *obj,int number);
	void Custom(GameObject *obj, int message, int param, GameObject *sender);
	float health, fallin;
	int pchuteID, floaterID;
	Vector3 pos, newpos;
	bool isFalling;
};


//.cpp

void ObjectHookCall(void *data,GameObject *obj) {
	if (Is_Soldier(obj)) {
		Attach_Script_Once(obj,"Parachute","");
	}
	else if (Is_Vehicle(obj)) {
		if (!Is_DecorationPhys(obj) && (Get_Vehicle_Mode(obj) == FLYING)) {
			Attach_Script_Once(obj,"Parachute","");
		}
	}
}



void Parachute::Created(GameObject *obj) {
	isFalling = false;
	floaterID = 0;
	pchuteID = 0;
	fallin = 0;
	health = Commands->Get_Health(obj);
}

void Parachute::Damaged(GameObject *obj,GameObject *damager,float damage) {
	if (!damager && isFalling && (damage < 1000)) {
		Commands->Set_Health(obj,health);
		isFalling = false;
	}
	else {
		health = Commands->Get_Health(obj);
	}
}

void Parachute::Killed(GameObject *obj, GameObject *shooter) {
	if (Is_Vehicle(obj)) {
		if (Commands->Get_ID(obj) && obj && As_VehicleGameObj(obj)) {
			VectorClass<GameObject *> *ptr = (VectorClass<GameObject *>*)(obj+0x9AC);
			VectorClass<GameObject *> occupants = (VectorClass<GameObject *>)*ptr;
			int x = occupants.Length();
			for (int i = 0;i < x;i++) {
				if (occupants[i]) {
					Commands->Send_Custom_Event(occupants[i],occupants[i],4612,0,0);
				}
			}
		}
	}
	else if (Is_Soldier(obj)) {
		Commands->Enable_Collisions(obj);
		if (Commands->Find_Object(pchuteID)) {
			Commands->Destroy_Object(Commands->Find_Object(pchuteID));
			pchuteID = 0;
		}
		if (Commands->Find_Object(floaterID)) {
			Commands->Destroy_Object(Commands->Find_Object(floaterID));
			floaterID = 0;
		}
		isFalling = false;
	}
}

void Parachute::Timer_Expired(GameObject *obj,int number) {
	if (number == 1) {
		newpos = Commands->Get_Position(obj);
		if (newpos.Z < pos.Z) {
			fallin += pos.Z - newpos.Z;
			if (fallin > 10 && !isFalling) {
				isFalling = true;
				GameObject *floater = Commands->Create_Object("CnC_Beacon_IonCannon",Commands->Get_Position(obj));
				Commands->Set_Model(floater,"null");
				Commands->Set_Facing(floater,Commands->Get_Facing(obj));
				GameObject *pchute = Commands->Create_Object("Generic_Cinematic",Commands->Get_Position(obj));
				Commands->Set_Model(pchute,"X5D_Parachute");
				Commands->Disable_All_Collisions(pchute);
				Commands->Disable_Physical_Collisions(obj);
				Commands->Attach_To_Object_Bone(obj,floater,"");
				Commands->Attach_To_Object_Bone(pchute,obj,"");
				floaterID = Commands->Get_ID(floater);
				pchuteID = Commands->Get_ID(pchute);
			}
			pos = Commands->Get_Position(obj);
			Commands->Start_Timer(obj, this, 0.1f, 1);
		}
		else {
			Commands->Enable_Collisions(obj);
			if (Commands->Find_Object(pchuteID)) {
				Commands->Destroy_Object(Commands->Find_Object(pchuteID));
				pchuteID = 0;
			}
			if (Commands->Find_Object(floaterID)) {
				Commands->Destroy_Object(Commands->Find_Object(floaterID));
				floaterID = 0;
			}
			Commands->Start_Timer(obj, this, 2.0f, 2);
		}
	}
	else if (number == 2) {
		isFalling = false;
	}
}

void Parachute::Custom(GameObject *obj, int message, int param, GameObject *sender) {
	if (message == CUSTOM_EVENT_VEHICLE_EXIT) {
		Commands->Send_Custom_Event(sender,sender,4612,0,0);
	}
	else if (message == CUSTOM_EVENT_VEHICLE_ENTER) {
		Commands->Send_Custom_Event(sender,sender,4613,0,0);
	}
	else if (message == 4612) {
		health = Commands->Get_Health(obj);
		fallin = 0;
		pos = Commands->Get_Position(obj);
		Commands->Start_Timer(obj, this, 0.1f, 1);
	}
	else if (message == 4613) {
		isFalling = false;
		if (Commands->Find_Object(pchuteID)) {
			Commands->Destroy_Object(Commands->Find_Object(pchuteID));
			pchuteID = 0;
		}
		if (Commands->Find_Object(floaterID)) {
			Commands->Destroy_Object(Commands->Find_Object(floaterID));
			floaterID = 0;
		}
	}
}


ScriptRegistrant<Parachute> Parachute_Registrant("Parachute","");


goztow wrote on Tue, 11 May 2010 08:00

If we had to ban all who ever cheated or ever created a cheat (obj3cts and such) then I don't think there would be many members left here (sad fact).


reborn wrote on Fri, 29 January 2010 23:37

std is for pro's. Razz
 
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]AirStrike function
Next Topic: [script]!sellveh
Goto Forum:
  


Current Time: Tue Nov 26 05:14:13 MST 2024

Total time taken to generate the page: 0.01155 seconds