Help with..... Well Everything!
#1

Hello everyone,

I'm new to PAWN, and I'm trying to work on a game mode just to get myself some experience in SAMP scripting. It will not be a release, just a project for me to work on.

I don't have any experience with C but am a PHP developer by trade so have knowledge of programming etc. I have been using the BlueG and am having trouble getting my head round getting the data from the DB into variables I can use in the script but I think I am getting there.

Anyway here is my first (of many) specific questions. I am trying to skip the class selection and spawn at a point that is taken from the DB in the form of playerSpawnX, playerSpawnY, playerSpawnZ, playerSpawnAngle.

So here goes the code

return 0 onPlayerRequestClass

Код:
public OnPlayerRequestClass(playerid, classid)
{
	return 0;
}
onPlayerConnect - takes the username from samp login and checks the db then throws the data to the checkPlayerAccount callback


Код:
public OnPlayerConnect(playerid)
{

	new
 	playerName[MAX_PLAYER_NAME],
	escapedPlayerName[MAX_PLAYER_NAME];

	GetPlayerName(playerid, playerName, sizeof(playerName)); //Get the player name from SAMP login
	mysql_real_escape_string(playerName, escapedPlayerName); //Escape The Player Name
	
	resetPlayerVariables(playerid); //use the custom function that has been forwarded to reset vars so not picking up data from last user
		
   	format(szQueryInput, sizeof(szQueryInput), "SELECT playerName FROM `playeraccounts` WHERE `playerName` = '%s' LIMIT 0,1", escapedPlayerName); //set up the query
   	mysql_function_query(connection, szQueryInput, true, "CheckPlayerAccount", "is", playerid, escapedPlayerName);// run the query and collect data from database
    
   	format(szString, sizeof(szString), "[SERVER]: {FFFFFF}%s HAS JOINED THE SERVER\n", playerName);
	SendClientMessageToAll(COLOR_GREEN, szString);
    
	return 1;
	
}
checkPlayerAccount

Код:
public CheckPlayerAccount(playerid, account[])
{
    new rows, fields;
    cache_get_data(rows, fields);
    
    if(!rows) {
    	format(szString, sizeof(szString), "[SERVER]: {FFFFFF}Welcome to Liberty City Roleplay, %s! You need to register an account at our website to access this server", account);
	}
	else
	{
    	format(szString, sizeof(szString), "{FFFFFF}Welcome back, %s!", account);
	    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, szString, "{FFFFFF}Enter your password below:", "Login", "Cancel");
	}
	
	return 1;
}
check player account basically checks the account exists and collects password if it does or tells them to register on the website if it doesn't

Dialogue which collects password checks it right then throws the data to the loadPlayerInfo callback. (Ignore the regsiter code I won't be using it it will be done on a web page

Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
	switch(dialogid) {

	    case DIALOG_REGISTER: {

	        if(response) {

	            new
	                playerName[MAX_PLAYER_NAME],
	                escapedPassword[129],
	                escapedPlayerName[MAX_PLAYER_NAME];

				GetPlayerName(playerid, playerName, sizeof(playerName));

				format(szString, sizeof(szString), "{FF0000}Sorry, %s!", playerName);

	            if(!strlen(inputtext) || strlen(inputtext) > 24)
	                return ShowPlayerDialog(playerid, DIALOG_REGISTER, DIALOG_STYLE_INPUT, szString, "{FF0000}The password must be at least 1 character and not over 24 characters.\n{FFFFFF}Enter your password below:", "Register", "Cancel");

	            WP_Hash(escapedPassword, sizeof(escapedPassword), inputtext);
	            mysql_real_escape_string(playerName, escapedPlayerName);

                format(szQueryInput, sizeof(szQueryInput), "INSERT INTO `playeraccounts` (playerName, playerPassword) VALUES('%s', '%s')", escapedPlayerName, escapedPassword);
                mysql_function_query(connection, szQueryInput, false, "", "");
    			
    			format(szString, sizeof(szString), "[SERVER]: {FFFFFF}Good job, %s! You are now a player of SERVER NAME!", playerName);
    			SendClientMessage(playerid, COLOR_GREEN, szString);

				registerProcess[playerid] = 1; // REGISTERED
				
				playerVariables[playerid][pLogged] = 1;
				
				SendClientMessage(playerid, COLOR_GREEN, "[SERVER]: {FFFFFF}Now you are ready to play, use /help for further info, have fun :)"); // THIS IS A DEFAULT MESSAGE -- /help DOESN'T EXIST
				
				TogglePlayerSpectating(playerid, false);
				
			}
			else
			{

			    SendClientMessage(playerid, COLOR_BRIGHTRED, "[SERVER]: {FFFFFF}You have to register an account in order to play in SERVER NAME.");
				Kick(playerid);

			}

			return 1;
		}
		
		case DIALOG_LOGIN: {
		
		    if(response) {
		    
	            new
	                playerName[MAX_PLAYER_NAME],
	                escapedPassword[129],
	                escapedPlayerName[MAX_PLAYER_NAME];
		    
		        GetPlayerName(playerid, playerName, sizeof(playerName));
		        
		        WP_Hash(escapedPassword, sizeof(escapedPassword), inputtext);
		        mysql_real_escape_string(playerName, escapedPlayerName);
		    
                format(szQueryInput, sizeof(szQueryInput), "SELECT * FROM `playeraccounts` WHERE `playerName` = '%s' AND `playerPassword` = '%s' LIMIT 0,1", escapedPlayerName, escapedPassword);
    			mysql_function_query(connection, szQueryInput, true, "LoadPlayerData", "is", playerid, escapedPlayerName);
    			
			}
			else
			{
			    SendClientMessage(playerid, COLOR_BRIGHTRED, "[SERVER]: {FFFFFF}You have to login in your account in order to play in SERVER NAME.");
			    Kick(playerid);
			}
			
			return 1;
		}
			
	}
		
	return 0;
}
And here is the LoadPlayerData call back which is where I want the spawn to happen, ie ignoring the class selection completely.

Код:
public LoadPlayerData(playerid, account[])
{
    new rows, fields, playerSkin, playerCash, playerSpawnX, playerSpawnY, playerSpawnZ, playerSpawnAngle;
    cache_get_data(rows, fields);

    if(rows) {

		// EXPLANATION OF cache_get_row:
		// THE FIRST VAR IS THE ROW FOUND.
		// THE SECOND VAR IS THE COLUMN OF THE ROW.
		// THE THIRD VAR IS A TEMPORARY VAR IN WHICH I STORE THE RESULT -- AFTERWARDS I ASSIGN THAT VALUE INTO A LOCAL ONE.

		cache_get_row(0, 0, szQueryOutput); // pInternalID
		playerVariables[playerid][pInternalID] = strval(szQueryOutput);

		cache_get_row(0, 16, szQueryOutput);
		playerVariables[playerid][pHasDrivingLicence] = strval(szQueryOutput);
		
		cache_get_row(0, 3, szQueryOutput); // Skin
		playerSkin =  strval(szQueryOutput);
		
		cache_get_row(0, 4, szQueryOutput);
		playerCash = strval(szQueryOutput);
		
		cache_get_row(0, 5, szQueryOutput);
		playerSpawnX = strval(szQueryOutput);
		
		cache_get_row(0, 6, szQueryOutput);
		playerSpawnY = strval(szQueryOutput);
		
		cache_get_row(0, 7, szQueryOutput);
		playerSpawnX = strval(szQueryOutput);
		
		cache_get_row(0, 8, szQueryOutput);
		playerSpawnAngle = strval(szQueryOutput);
		
		SetSpawnInfo(playerid,0,playerSkin,playerSpawnX,playerSpawnY,playerSpawnZ,playerSpawnAngle,-1,-1,-1,-1,-1,-1);
		SpawnPlayer(playerid);
		GivePlayerMoney(playerid,playerCash);

    	format(szString, sizeof(szString), "[SERVER]: {FFFFFF}Welcome back in SERVER NAME, %s! Have fun playing.", account);
    	SendClientMessage(playerid, COLOR_GREEN, szString);
    	
    	TogglePlayerSpectating(playerid, false);
	}
	else
	{
    	format(szString, sizeof(szString), "{FF0000}Sorry, %s!", account);
	    ShowPlayerDialog(playerid, DIALOG_LOGIN, DIALOG_STYLE_PASSWORD, szString, "{FF0000}The password is WRONG!\n{FFFFFF}Enter your password below:", "Login", "Cancel");
	}

	return 1;
}
Im struggling to get this to work. I know its a hell of a lot of code (its a hacked up version of MYSQL BASE CLEAN I downloaded from here).

I would appreciate if someone could take a look through and advise firstly why this doesn't work (It goes to the choose class screen, and spawn doesn't do anything) and secondly please give me PAwn for dummies break down on if I am handline taking data from the DB and setting it into variable right.

Many Thanks in advance.

I'm actually willing to pay someone a drink in paypal to go through this with me if thats what it takes.

Thanks
Reply


Messages In This Thread
Help with..... Well Everything! - by liam1412 - 30.03.2013, 12:46
Re: Help with..... Well Everything! - by RajatPawar - 30.03.2013, 13:31
Re: Help with..... Well Everything! - by liam1412 - 30.03.2013, 15:03
Re: Help with..... Well Everything! - by liam1412 - 30.03.2013, 15:07
Re: Help with..... Well Everything! - by RajatPawar - 30.03.2013, 15:10
Re: Help with..... Well Everything! - by liam1412 - 30.03.2013, 15:31
Re: Help with..... Well Everything! - by Konstantinos - 30.03.2013, 15:44

Forum Jump:


Users browsing this thread: 2 Guest(s)