Referral function?
#3

Quote:
Originally Posted by serqq
Посмотреть сообщение
Okay, I'm assuming that you are using newest version of MySQL plugin and you have created connection to your database.

To start off, let's define our dialog id:
Код:
#define DIALOG_ID_REFERRAL_CHECK 2137
Then we need to put our dialog into OnPlayerConnect(or anywhere where you want it).
Код:
public OnPlayerConnect(playerid) {
	ShowPlayerDialog(playerid, DIALOG_ID_REFERRAL_CHECK, DIALOG_STYLE_INPUT,"Referral system", "If someone invited you to this server, input his name below", "OK", "Cancel");
//your code here
}
Next, let's handle the dialog response.
Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
	switch(dialogid) 
	{
		case DIALOG_ID_REFERRAL_CHECK: 
		{
			if(!response) {
				//here you can put code that will execute when player clicks "Cancel" - the right button;
				return 1;
			}
			else {
				//you can add if's checking if user input is empty etc.
				new 	Query[128];
				mysql_format(YOUR_MYSQL_HANDLE, Query, sizeof Query,"SELECT * FROM `table_name` WHERE `Username` = '%e'", inputtext);
				mysql_tquery(YOUR_MYSQL_HANDLE, Query, "OnReferralNameCheck", playerid, inputtext);

			}
		}
	}
}
Don't forget to replace YOUR_MYSQL_HANDLE with handle that you're using to connect to your database and `table_name` with your table name!

And to end this simple script, create function that checks if that name is valid, and if it is add 1 to `Referrals` column.
Код:
forward OnReferralNameCheck(playerid, const name[]); 
public OnReferralNameCheck(playerid, const name[]) 
{
	if(cache_num_rows()) {
		//user has put right name
		new Query[128];
		mysql_format(YOUR_MYSQL_HANDLE, Query, sizeof Query,"UPDATE `table_name` SET `Referrals` = `Referrals` + 1 WHERE `Username` = '%e'", name);
		mysql_tquery(YOUR_MYSQL_HANDLE, Query);
	}
	else {
		//user has put wrong name
		SendClientMessage(playerid, -1, "This user doesn't exist!");
		ShowPlayerDialog(playerid, DIALOG_ID_REFERRAL_CHECK, DIALOG_STYLE_INPUT,"Referral system", "If someone invited you here, input his name below", "OK", "Cancel");
	}
	cache_unset_active();
}

Edited some stuffs to match my gamemode, thanks a lot, it works fine!
Reply


Messages In This Thread
Referral function? - by DarkMythHunter - 14.12.2018, 14:01
Re: Referral function? - by serqq - 14.12.2018, 18:20
Re: Referral function? - by DarkMythHunter - 16.12.2018, 02:42
Re: Referral function? - by DarkMythHunter - 21.12.2018, 12:09
Re: Referral function? - by DarkMythHunter - 21.12.2018, 13:29
Re: Referral function? - by DarkMythHunter - 21.12.2018, 13:39
Re: Referral function? - by DarkMythHunter - 23.12.2018, 12:05

Forum Jump:


Users browsing this thread: 1 Guest(s)