Renegade Public Forums
C&C: Renegade --> Dying since 2003™, resurrected in 2024!
Home » Renegade Discussions » Mod Forum » !rtc c++
Re: !rtc c++ [message #451020 is a reply to message #451012] Mon, 08 August 2011 15:19 Go to previous message
Xpert is currently offline  Xpert
Messages: 1588
Registered: December 2005
Location: New York City
Karma:
General (1 Star)
engine_player.cpp
int Get_Team_Player_Count(int Team)
{
	int Total = 0;
	GenericSLNode *x = BaseGameObjList->HeadNode;
	while (x)
	{
		GameObject *o = (GameObject *)x->NodeData;
		if (o && Commands->Is_A_Star(o))
		{
			if (Get_Team(Get_Player_ID(o)) == Team)
			{
			Total++;
		}
		}
		x = x->NodeNext;
	}
	return Total;
}


gmmain.h
class RTC_timer : public ScriptImpClass {
	void Created(GameObject *obj);
	void Timer_Expired(GameObject *obj,int number);
	int ID;
};


gmmain.cpp
bool IsRTC = false;
int idrtc = 0;

struct swapped {
	std::string SwappedPlayerName;
};

std::vector<swapped> SwappedPlayers;  

bool SwapCheck(int ID) {
	for (int i = 0; i < SwappedPlayers.size(); i++) {
		if (SwappedPlayers[i].SwappedPlayerName == Get_Player_Name_By_ID(ID)) {
			return true;
		}
	}
	return false;
}

void SwapAddPlayer(int ID) {
	if (SwapCheck(ID) == false) {
		swapped temp;
		temp.SwappedPlayerName = Get_Player_Name_By_ID(ID);
		SwappedPlayers.push_back(temp);
	}
}

void SwapClearPlayers() {
	SwappedPlayers.erase(SwappedPlayers.begin(), SwappedPlayers.end());
}

void RequestTeamChange(const char *Name) {
	GameObject *Player = Get_GameObj_By_Player_Name(Name);
	int ID = Get_Player_ID(Player);
	int GDIPlayers = Get_Team_Player_Count(0);
	int NodPlayers = Get_Team_Player_Count(1);

	if (!IsRTC) {
		if (GDIPlayers > 0 && NodPlayers > 0) {
			GameObject *rtccontroller = Commands->Create_Object("Invisible_Object",Vector3(0.0f,0.0f,20.0f));
			idrtc = ID;
			Commands->Attach_Script(rtccontroller,"RTC_timer","");
			Console_Input(StrFormat("msg %s has requested to change teams. Type !rtc if you would like to change teams.",Name).c_str());
			IsRTC = true;
		}
		else {
			Console_Input(StrFormat("ppage %d There are not enough players for you to request a team change.",ID).c_str());
		}
	}
	else if (IsRTC) {
		GameObject *obj = Get_GameObj(idrtc);
		if (!obj) {
			GameObject *rtccontroller = Commands->Create_Object("Invisible_Object",Vector3(0.0f,0.0f,20.0f));
			idrtc = ID;
			Commands->Attach_Script(rtccontroller,"RTC_timer","");
			Console_Input(StrFormat("msg %s has requested to change teams. Type !rtc if you would like to change teams.",Name).c_str());
		}
		else {
			if (Get_Team(ID) != Get_Team(idrtc)) {
				Console_Input(StrFormat("team2 %d %i",ID,Get_Team(idrtc)).c_str());
				SwapAddPlayer(ID);
				Console_Input(StrFormat("team2 %d %i",idrtc,Commands->Get_Player_Type(Player)).c_str());
				SwapAddPlayer(idrtc);
				Console_Input(StrFormat("msg %s and %s have changed teams! The !rtc command is up for new request.",Name,Get_Player_Name_By_ID(idrtc)).c_str());
				Console_Input("player_info");
				GameObject *timerthing = Find_Object_With_Script("RTC_timer");
				Remove_Script(timerthing,"RTC_timer");
				Commands->Destroy_Object(timerthing);
				IsRTC = false;
				idrtc = 0;
			}
			else if (ID == idrtc) {
				Console_Input(StrFormat("msg %s has revoked their !rtc request. The !rtc command is up for new request.",Get_Player_Name_By_ID(idrtc)).c_str());
				GameObject *timerthing = Find_Object_With_Script("RTC_timer");
				Remove_Script(timerthing,"RTC_timer");
				Commands->Destroy_Object(timerthing);
				IsRTC = false;
				idrtc = 0;
			}
			else if (Get_Team(ID) == Get_Team(idrtc)) {
				Console_Input(StrFormat("ppage %d You're on the same team, you cannot swap with %s.",ID,Get_Player_Name_By_ID(idrtc)).c_str());
			}
		}
	}
}

void RTC_timer::Created(GameObject *obj) {
	Commands->Start_Timer(obj, this,60.0f, 1);
}

void RTC_timer::Timer_Expired(GameObject *obj, int number) {
	if (number == 1) {
		IsRTC = false;
		GameObject *obj2 = Get_GameObj(idrtc);
		if (!obj2) {
			idrtc = 0;
			Commands->Destroy_Object(obj);
			Destroy_Script();
		}
		else {
			Console_Input(StrFormat("msg %s's request to change teams has expired.",Get_Player_Name_By_ID(idrtc)).c_str());
			Console_Input(StrFormat("ppage %d Your request to change teams has timed out.",idrtc).c_str());
			idrtc = 0;
			Commands->Destroy_Object(obj);
			Destroy_Script();
		}
	}
}
ScriptRegistrant<RTC_timer> RTC_timer_Registrant("RTC_timer","");

class RTCChatCommand : public ChatCommandClass {
	void Triggered(int ID,const TokenClass &Text,int ChatType) {
		if (SwapCheck(ID) == false) {
			RequestTeamChange(Get_Player_Name_By_ID(ID));	
		}
		else {
			Console_Input(StrFormat("ppage %d You have already swapped once this map.",ID).c_str());
		}
	}
};
ChatCommandRegistrant<RTCChatCommand> RTCChatCommandReg("!swap;!rtc;!requestteamchange",CHATTYPE_ALL,0,GAMEMODE_ALL);



Copying just the command class doesn't make the code work. You need everything else that makes up the command.


http://i32.photobucket.com/albums/d42/XpertMaverick/xpertyankee.jpg

Creator of NetGuard, an IRC network regulator.
Developer of the CloudyServ 0.982-X project.
Developer of the CloudyServ Ren-X bot.

Part time streamer - https://twitch.tv/gg_wonder

[Updated on: Mon, 08 August 2011 15:35]

Report message to a moderator

 
Read Message
Read Message
Previous Topic: renx texture efects
Next Topic: Looking for names of the public, team and private message sounds
Goto Forum:
  


Current Time: Fri Dec 20 23:24:03 MST 2024

Total time taken to generate the page: 0.00640 seconds