Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » How to Turn the Ped on after a specific time
Re: How to Turn the Ped on after a specific time [message #451224 is a reply to message #451200] Wed, 10 August 2011 20:59 Go to previous messageGo to previous message
Jerad2142 is currently offline  Jerad2142
Messages: 3813
Registered: July 2006
Location: USA
Karma:
General (3 Stars)
Here you go then.

void JMG_Prevent_Ped_Beacons_Time::Created(GameObject *obj)
{
	for (int x = 0;x < 128;x++)
	{
       	ion[x] = false;
		nuke[x] = false;
	}
	Commands->Start_Timer(obj,this,Get_Float_Parameter("Time_Seconds"),1003943);
}

void JMG_Prevent_Ped_Beacons_Time::Entered(GameObject *obj, GameObject *enter)
{
	int PlayerID = Get_Player_ID(enter);
	if (!PlayerID)
		return;
	if (Has_Weapon(enter,"CnC_Weapon_IonCannonBeacon_Player") && Get_Current_Bullets(enter) > 0)
	{
		if (!Remove_Weapon_Safely(enter,"CnC_Weapon_IonCannonBeacon_Player","CNC_Weapon_Pistol_Player "))
			return;
		ion[PlayerID] = true;
	}
	if (Has_Weapon(enter,"CnC_Weapon_NukeBeacon_Player") && Get_Current_Bullets(enter) > 0)
	{
		if (!Remove_Weapon_Safely(enter,"CnC_Weapon_NukeBeacon_Player","CNC_Weapon_Pistol_Player "))
			return;
		nuke[PlayerID] = true;
	}
}

void JMG_Prevent_Ped_Beacons_Time::Exited(GameObject *obj, GameObject *exit)
{
	int PlayerID = Get_Player_ID(exit);
	if (!PlayerID)
		return;
	if (ion[PlayerID])
		Commands->Give_Powerup(exit,"CnC_POW_IonCannonBeacon_Player",false);
	if (nuke[PlayerID])
		Commands->Give_Powerup(exit,"CnC_POW_Nuclear_Missle_Beacon",false);
	ion[PlayerID] = false;
	nuke[PlayerID] = false;
}

void JMG_Prevent_Ped_Beacons_Time::Timer_Expired(GameObject *obj, int number)
{
	if (number == 1003943)
	{
		for (int x = 1;x < 128;x++)
		{
			GameObject *Player = Get_GameObj(x);
			if (!Player)
				continue;
			if (ion[x])
				Commands->Give_Powerup(Player,"CnC_POW_IonCannonBeacon_Player",false);
			if (nuke[x])
				Commands->Give_Powerup(Player,"CnC_POW_Nuclear_Missle_Beacon",false);
		}
		Remove_Script(obj,"z_Prevent_Ped_Beacons_Time");
	}
}

bool JMG_Prevent_Ped_Beacons_Time::Remove_Weapon_Safely(GameObject *obj,const char *WeaponName,const char *SelectWeapon)
{
	const char *CurrentWeapon = Get_Current_Weapon(obj);
	if (CurrentWeapon)
		if (!_stricmp(CurrentWeapon,WeaponName))
		{
			if (Has_Weapon(obj,SelectWeapon))
			{
				Commands->Select_Weapon(obj,SelectWeapon);
				Remove_Weapon(obj,WeaponName);
				Commands->Select_Weapon(obj,SelectWeapon);
				return true;
			}
		}
		else
		{
			Remove_Weapon(obj,WeaponName);
			return true;
		}
	return false;
}

ScriptRegistrant<JMG_Prevent_Ped_Beacons_Time> JMG_Prevent_Ped_Beacons_Time("JMG_Prevent_Ped_Beacons_Time","Time_Seconds=600000:float ");


class JMG_Prevent_Ped_Beacons_Time : public ScriptImpClass {
	bool ion[128];
	bool nuke[128];
	void Created(GameObject *obj);
	void Timer_Expired(GameObject *obj, int number);
	void Entered(GameObject *obj, GameObject *enter);
	void Exited(GameObject *obj, GameObject *exit);
	bool Remove_Weapon_Safely(GameObject *obj,const char *WeaponName,const char *SelectWeapon);
};


But there you go beings you are so picky, a version that checks for ammo and does not give you a beacon if its empty, in addition, it does potentially 3,599 less useless checks in a 30 minute game per player in zone.

I will admit I did not really read though your original post, and though you called the timer originally from created instead of entered.

And yours still can crash the fds if the player/entering object has no weapon.
And will fail to do anything if they are not holding the beacon, and if they are the server can crash when it removes the beacon.

Also, if you could time jumping or walking in and out of the zone you could set off multiple copies of the timer that slowly flooding the server with more and more pointless checks.

Finally, your script doesn't deactivate after a certain amount of time, which was rather the point of this thread in the first place...


[Updated on: Wed, 10 August 2011 22:16]

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
Previous Topic: Need someone familiar with vehicle boning
Next Topic: Having some issues modifying the Airstrip waypoints serverside
Goto Forum:
  


Current Time: Sat Dec 28 16:55:19 MST 2024

Total time taken to generate the page: 0.00996 seconds