• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] Team Selection (MySQL)
#1
Hello dier forum member's.

I have a question about a team selection,?specifically in mysql login / register system.

I would like to make coops and robbers selection, after register give selection menu, where u know select of 3 type's, and spawn with it.?

Other about save/load that selected team i can make, just that "after spawn not".

Please, can u help me?

(script is maded by GTLS on samp-forum.?link)



PHP Code:
#include <a_samp>

#include <a_mysql> // Currently its R41-4.

#include <bcrypt> //Bcrypt is the best way of encrypting passwords.

#include <foreach> //foreach standalone version



//Defining MySQL stuff here



#define DB_HOST "localhost" //IP of your host. In case of using it on same pc, use localhost or 127.0.0.1

#define DB_NAME "login" //Name of Database you are gonna use.. I have used login, but change it according to your needs.

#define DB_USER "root" //User name of your MySQL client.

#define DB_PASS "" //Password of your MySQL client.



//Default Username is root and password is blank. You still gotta define them

//Make sure to install XAMPP server. Start Apache and MySQL service when you start the server. You can manage SQL databases from PHPMyAdmin which comes in built in XAMPP.



enum //Always use some kind of structure for Dialog IDs.

{

DIALOG_ASK,

DIALOG_REGISTER,

DIALOG_LOGIN

};



enum pinfo

{

MasterID,

Float:PX,

Float:PY,

Float:PZ,

Float:Rot,

Skin,

Level,



bool:LoggedIn

};

new 
pInfo[MAX_PLAYERS][pinfo];



new 
MySQL:handle//This connection handle of data type MySQL is required to carry out Mysql operations.



main()

{

printf("Login Script Loaded");

}



public 
OnGameModeInit()

{

handle mysql_connect(DB_HOSTDB_USERDB_PASSDB_NAME);



if(
mysql_errno(handle) == 0printf("[MYSQL] Connection successful"); //returns number of errors. 0 means no errors..

else

{

? ?new 
error[100];

? ?
mysql_error(errorsizeof(error), handle);

printf("[MySQL] Connection Failed : %s"error);

}



return 
1;

}



public 
OnGameModeExit()

{

foreach(new 
Player)

{

if(
pInfo[i][LoggedIn]) SavePlayerData(i);

}

mysql_close(handle);

return 
1;

}



public 
OnPlayerConnect(playerid)

{

new 
query[64];

new 
pname[MAX_PLAYER_NAME];

GetPlayerName(playeridpnamesizeof(pname));

mysql_format(handlequerysizeof(query), "SELECT COUNT(Name) from `users` where Name = '%s' "pname);

mysql_tquery(handlequery"OnPlayerJoin""d"playerid);

return 
1;

}



public 
OnPlayerDisconnect(playeridreason)

{

if(
pInfo[playerid][LoggedIn]) SavePlayerData(playerid);

pInfo[playerid][LoggedIn] = false;

return 
1;

}



public 
OnPlayerSpawn(playerid)

{

? ?
//Set your spawn info here...

return 1;

}



SavePlayerData(playerid)

{

new 
query[256], pname[MAX_PLAYER_NAME], Float:pxFloat:pyFloat:pzFloat:rot;

GetPlayerName(playeridpnamesizeof(pname));

GetPlayerPos(playeridpxpypz);

GetPlayerFacingAngle(playeridrot);

mysql_format(handlequerysizeof(query), "UPDATE `users` set PosX = %f, PosY = %f, PosZ = %f, Rot = %f, Skin = %d, Level = %d WHERE Master_ID = %d"pxpypzrotpInfo[playerid][Skin], pInfo[playerid][Level], pInfo[playerid][MasterID]);

mysql_query(handlequery);

printf("Saved %s's data"pname);

return 
1;

}





public 
OnDialogResponse(playeriddialogidresponselistiteminputtext[])

{

switch(
dialogid)

{

case 
DIALOG_REGISTER:

? ?{

if(
response)

{

? ?
bcrypt_hash(inputtext12"OnPassHash""d"playerid);

}

else 
Kick(playerid);

}



case 
DIALOG_LOGIN:

{

if(
response)

{

new 
query[128], pname[MAX_PLAYER_NAME];

GetPlayerName(playeridpnamesizeof(pname));

? ? 
SetPVarString(playerid"Unhashed_Pass",inputtext);

mysql_format(handlequerysizeof(query), "SELECT password, Master_ID from `users` WHERE Name = '%s'"pname);

mysql_tquery(handlequery"OnPlayerLogin""d"playerid);

}

else 
Kick(playerid);

}

}



return 
1;

}



forward OnPlayerJoin(playerid);

public 
OnPlayerJoin(playerid)

{

new 
rows;

cache_get_value_index_int(00rows);



if(
rowsShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"Login""This account is found on your database. Please login""Login""Quit");





else 
ShowPlayerDialog(playeridDIALOG_REGISTERDIALOG_STYLE_PASSWORD"Register""This account not is found on your database. Please register""Register""Quit");

return 
1;

}



forward OnPlayerRegister(playerid);

public 
OnPlayerRegister(playerid)

{

SendClientMessage(playerid0x0033FFFF /*Blue*/"Thank you for registering! You can now Login");

? ?
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"Login""Thank you for registering! You can now Login with\npassword you just used to register.""Login""Quit");

return 
1;

}



forward OnPlayerLogin(playerid);

public 
OnPlayerLogin(playerid)

{

new 
pPass[255], unhashed_pass[128];

GetPVarString(playerid"Unhashed_Pass",unhashed_pass,sizeof(unhashed_pass));

if(
cache_num_rows())

{

cache_get_value_index(00pPass);

cache_get_value_index_int(01pInfo[playerid][MasterID]);

bcrypt_check(unhashed_passpPass"OnPassCheck""dd",playeridpInfo[playerid][MasterID]);

? }

? ?else 
printf("ERROR ");

return 
1;

}



forward OnPassHash(playerid);

public 
OnPassHash(playerid)

{

new 
pass[BCRYPT_HASH_LENGTH], query[128], pname[MAX_PLAYER_NAME];

? ?
GetPlayerName(playeridpnamesizeof(pname));

? ?
bcrypt_get_hash(pass);

? ?
mysql_format(handlequerysizeof(query), "INSERT INTO `users`(Name, Password) VALUES('%s', '%e')"pnamepass);

mysql_tquery(handlequery"OnPlayerRegister""d"playerid);

return 
1;

}



forward OnPassCheck(playeridDBID);

public 
OnPassCheck(playeridDBID)

{

? ?if(
bcrypt_is_equal())

{

SetPlayerInfo(playeridDBID);

}

else 
ShowPlayerDialog(playeridDIALOG_LOGINDIALOG_STYLE_PASSWORD"Login""The password you just entered is wrong.\nPlease Try again!""Login""Quit");

return 
1;

}



SetPlayerInfo(playeriddbid)

{

new 
query[128];

mysql_format(handlequerysizeof(query), "SELECT ?PosX, PosY, PosZ, Rot, Skin, Level FROM `users` WHERE Master_ID = %d"dbid);

new 
Cache:result mysql_query(handlequery);



cache_get_value_index_float(00pInfo[playerid][PX]);

cache_get_value_index_float(01pInfo[playerid][PY]);

cache_get_value_index_float(02pInfo[playerid][PZ]);

cache_get_value_index_float(03pInfo[playerid][Rot]);

cache_get_value_index_int(04pInfo[playerid][Skin]);

cache_get_value_index_int(05pInfo[playerid][Level]);



pInfo[playerid][LoggedIn] = true;



cache_delete(result);



SetPlayerScore(playeridpInfo[playerid][Level]);

SetSpawnInfo(playerid0pInfo[playerid][Skin], pInfo[playerid][PX], pInfo[playerid][PY], pInfo[playerid][PZ],pInfo[playerid][Rot], 000000);



TogglePlayerSpectating(playeridfalse);

TogglePlayerControllable(playeridtrue);



new 
name[MAX_PLAYER_NAME], str[80];

GetPlayerName(playeridnamesizeof(name));

format(strsizeof(str), "{00FF22}Welcome to the server, {FFFFFF}%s"name);

SendClientMessage(playerid, -1str);

DeletePVar(playerid"Unhashed_Pass");



SpawnPlayer(playerid);

return 
1;


OG

Since of 2011


Discord: zeetayn#2166

  Reply
#2
bump.
OG

Since of 2011


Discord: zeetayn#2166

  Reply
#3
Clarify your problem. It's unclear what you're asking.
  Reply


Forum Jump: