View Single Post
  #9  
Old 03-19-2016, 05:37 PM
Coenxai's Avatar
Coenxai
Hill Giant
 
Join Date: Dec 2013
Posts: 151
Default

This is my old pet naming code. I can post the rest of it if anyone even cares.

Code:
void command_petname(Client *c, const Seperator *sep) {
	uint32 t = c->GetPTimers().GetRemainingTime(pTimerAntiQuery);
	if (!c->GetPTimers().Expired(&database, pTimerAntiQuery, false)) {
		c->Message(13, "You must wait (%is) before renaming your pet.", t);
		return;
	}

	int MAX_PET_NAME = 12;
	int MIN_PET_NAME = 3;

	if (sep->arg[1][0] == 0) {
		c->Message(15, "Clearing current pet name.");
		std::string query = StringFormat("REPLACE INTO `pets_custom_name` VALUES (%i, '')", c->CharacterID());
		auto results = database.QueryDatabase(query);
		c->GetPTimers().Start(pTimerAntiQuery, 30);
		return;
	}

	for (int i = 0; i < MAX_PET_NAME; i++) {
		if (sep->arg[1][i] == NULL) {
			break;
		}
		if (!isalpha(sep->arg[1][i])) {
			c->Message(13, "Pet names must only contain letters of the alphabet.");
			return;
		}
		if (isupper(sep->arg[1][i])) {
			sep->arg[1][i] = tolower(sep->arg[1][i]);
		}
	}

	if (strlen(sep->arg[1]) >= MAX_PET_NAME) {
		c->Message(13, "The pet name you've entered is too long. (Maximum: %i)", MAX_PET_NAME);
	}
	else if (strlen(sep->arg[1]) < MIN_PET_NAME && strlen(sep->arg[1]) > 0) {
		c->Message(13, "The pet name you've entered is too short. (Minimum: %i)", MIN_PET_NAME);
	}
	else {
		sep->arg[1][0] = toupper(sep->arg[1][0]);
		c->Message(15, "Your new pet will now be named: %s", sep->arg[1]);
		std::string query = StringFormat("REPLACE INTO `pets_custom_name` VALUES (%i, '%s')", c->CharacterID(), sep->arg[1]);
		auto results = database.QueryDatabase(query);
		c->GetPTimers().Start(pTimerAntiQuery, 30);
	}
}
__________________
"The true sign of intelligence is not knowledge but imagination."
Reply With Quote