Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ================================================================================
- Credits
- =======
- Brandon_More (GiGi) >> Coder.
- BlueG >> MySQL Plugin.
- Zeex >> ZCMD Command Processor.
- Slick >> GetDistanceBetweenPlayers
- ========================
- Notes: This is a basic Very Basic MySQL Roleplay gamemode, It was totally
- scripted by me (GiGi - Brandon_More). I made this script strictly for revision
- work on MySQL and Pawno. This script has been tested and It does work. But if
- you have problems, feel free to contact me via: Brandon_More(SA-MP Forums) or
- Gmail: [email protected]. Thank you for reading and I hope this helps you :)
- P.s I got the IRC Code stuff off the internet.. No idea who did it.
- But needs a few fizxes.
- */
- #include <a_samp>
- #include <a_mysql>
- #include <zcmd>
- #include <string>
- #include <irc>
- #include <ircecho>
- //==============================================================================
- main( )
- {
- }
- //==============================================================================
- #define MYSQL_HOST "localhost" // DB Host / Supplier
- #define MYSQL_USER "root" // DB User
- #define MYSQL_DB "mysql_test" //DB
- #define MYSQL_PASS "password" //DB Password
- //==============================================================================
- #undef MAX_PLAYERS
- #define MAX_PLAYERS 25
- #define COLOR_GREY 0xAFAFAFAA
- //==============================================================================
- #define ALTCOMMAND:%1->%2; \
- COMMAND:%1(playerid, params[]) \
- return cmd_%2(playerid, params);
- //==============================================================================
- #define PlayerLoop(%1) for(new %1 = 0; %1 < MAX_PLAYERS; %1++) if(IsPlayerConnected(%1) && !IsPlayerNPC(%1))
- #include "irc.pwn" // All your IRC Defines / Chanel information will be inside here!
- //==============================================================================
- enum pInfo
- {
- Password[126],
- money,
- age,
- accent[12],
- }
- new PlayerInfo[MAX_PLAYERS][pInfo];
- //==============================================================================
- new PlayerLOGGED[MAX_PLAYERS];
- //==============================================================================
- new globalstring[250]; //Global String
- //==============================================================================
- new iBots[ MAX_PLAYERS ];
- //==============================================================================
- public OnGameModeInit()
- {
- mysql_connect(MYSQL_HOST,MYSQL_USER,MYSQL_DB,MYSQL_PASS);
- mysql_debug(1);
- SetGameModeText("MySQL Basic | GiGi");
- echo_Init();
- mysql_query("CREATE TABLE IF NOT EXISTS PlayerAccounts (\
- user VARCHAR(24) NOT NULL, \
- password VARCHAR(40) NOT NULL, \
- money INT(225) UNSIGNED NOT NULL DEFAULT 1000, \
- age SMALLINT(12) UNSIGNED NOT NULL DEFAULT 25, \
- accent VARCHAR(24) NOT NULL DEFAULT 'None')");
- return 1;
- }
- //==============================================================================
- public OnGameModeExit()
- {
- for(new i; i < MAX_PLAYERS; i++)
- {
- SavePlayer(i);
- IRC_Quit(iBots[i], "Server restart");
- }
- mysql_close();
- return 1;
- }
- //==============================================================================
- public OnPlayerConnect(playerid)
- {
- PlayerLOGGED[playerid]=false;
- SetTimerEx("ConnectIRC", 200, false, "d", playerid);
- new query[126], pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, sizeof(pName));
- format(query,sizeof(query), "SELECT `user` FROM `PlayerAccounts` WHERE `user` = '%s' LIMIT 1", pName);
- mysql_query(query);
- mysql_store_result();
- new rows = mysql_num_rows();
- if(rows == 1)
- {
- ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "MySQL Basic || Login", "Please Login with your password", "Login", "Cancel");
- }
- if(!rows)
- {
- ShowPlayerDialog(playerid, 1, DIALOG_STYLE_INPUT, "MySQL Basic || Register", "Please Register with a password", "Register", "Cancel");
- }
- mysql_free_result();
- return 1;
- }
- //==============================================================================
- public OnPlayerDisconnect(playerid, reason)
- {
- SavePlayer(playerid);
- if(PlayerLOGGED[playerid])
- {
- PlayerInfo[playerid][money]=1000;
- PlayerInfo[playerid][age]=25;
- myStrcpy(PlayerInfo[playerid][accent],"None");
- }
- return 1;
- }
- //==============================================================================
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case 0:
- {
- if(response)
- {
- new query[126], pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, sizeof(pName));
- format(query,sizeof(query), "SELECT * FROM PlayerAccounts WHERE user='%s' AND password = '%s'", pName, inputtext);
- mysql_query(query);
- mysql_store_result();
- if(mysql_num_rows() == 1)
- {
- LoginPlayer(playerid);
- PlayerLOGGED[playerid]=true;
- }
- else
- {
- ShowPlayerDialog(playerid, 0, DIALOG_STYLE_INPUT, "MySQL Basic || Login", "Incorrect password!\nPlease Login with your password", "Login", "Cancel");
- }
- }
- }
- case 1:
- {
- if(response)
- {
- new query[126], pName[MAX_PLAYER_NAME];
- GetPlayerName(playerid, pName, sizeof(pName));
- format(query,sizeof(query), "INSERT INTO PlayerAccounts (user,password) VALUES ('%s','%s')", pName, inputtext);
- mysql_query(query);
- SpawnPlayer(playerid);
- }
- }
- }
- return 1;
- }
- //==============================================================================
- public OnPlayerText(playerid, text[])
- {
- new stringa[256];
- new Float:px,Float:py,Float:pz;
- GetPlayerPos(playerid,px,py,pz);
- if(text[0]== '(')
- {
- new mid[250];
- strmid(mid,text,1,256,sizeof(mid));
- format(stringa,sizeof(stringa),"%s says: (( %s ))",PlayerName(playerid),mid);
- }
- else
- {
- if(!strcmp(PlayerInfo[playerid][accent],"None"))
- {
- format(globalstring, sizeof(globalstring),": ");
- }
- else
- {
- format(globalstring,sizeof(globalstring)," [%s accent]: ",PlayerInfo[playerid][accent]);
- }
- toupper(text[0]);
- format(stringa,sizeof(stringa),"%s says%s%s",PlayerName(playerid),globalstring,text);
- }
- PlayerLoop(i)
- {
- if(!IsPlayerConnected(i)) continue;
- if(!IsPlayerInRangeOfPoint(i, 60.0, px,py,pz)) continue;
- if(GetPlayerVirtualWorld(i) != GetPlayerVirtualWorld(playerid) || GetPlayerInterior(i) != GetPlayerInterior(playerid)) continue;
- new Float:dis;
- dis = GetDistanceBetweenPlayers(playerid,i);
- if(dis<=10) SendClientMessage(i,COLOR_GREY,stringa);
- }
- return 0;
- }
- public OnPlayerSpawn(playerid)
- {
- if(PlayerLOGGED[playerid])
- {
- SetPlayerPos(playerid, 1743.1909,-1862.8228,13.5758);
- }
- else
- {
- switch(random(2))
- {
- case 0:
- {
- SetPlayerCameraPos(playerid,967.4384,2559.5483,10.7003);
- SetPlayerCameraLookAt(playerid,982.4874,2561.6409,22.5239);
- SetPlayerPos(playerid,967.4384,2559.5483,5.7003);
- }
- case 1:
- {
- SetPlayerCameraPos(playerid,2058.8811,971.7955,54.5982);
- SetPlayerCameraLookAt(playerid,2057.1230,1189.4883,39.5329);
- SetPlayerPos(playerid,2058.8811,971.7955,47.5982);
- }
- case 2:
- {
- SetPlayerCameraPos(playerid,2372.1680,2141.8135,31.8135);
- SetPlayerCameraLookAt(playerid,2299.5005,2142.6213,28.8228);
- SetPlayerPos(playerid,2372.1680,2141.8135,27.8135);
- }
- }
- SetPlayerInterior(playerid,0);
- SetPlayerColor(playerid, COLOR_GREY);
- TogglePlayerControllable(playerid,false);
- }
- return 0;
- }
- //==============================================================================
- stock LoginPlayer(playerid)
- {
- new query[300], pname[24], AccountCarry[20];
- GetPlayerName(playerid, pname, 24);
- format(query, sizeof(query), "SELECT * FROM PlayerAccounts WHERE user = '%s'", pname);
- mysql_query(query);
- mysql_store_result();
- while(mysql_fetch_row_format(query,"|"))
- {
- mysql_fetch_field_row(AccountCarry, "money"); PlayerInfo[playerid][money] = strval(AccountCarry);
- GivePlayerMoney(playerid, strval(AccountCarry));
- //===============
- mysql_fetch_field_row(AccountCarry, "accent"); strmid(PlayerInfo[playerid][accent], AccountCarry, 0, strlen(AccountCarry), 50);
- //===============
- mysql_fetch_field_row(AccountCarry, "age"); PlayerInfo[playerid][age] = strval(AccountCarry);
- }
- mysql_free_result();
- SpawnPlayer(playerid);
- return 1;
- }
- //==============================================================================
- stock SavePlayer(playerid)
- {
- new pname[24];
- GetPlayerName(playerid, pname, sizeof(pname));
- new query[750];
- format(query, sizeof(query), "UPDATE PlayerAccounts SET money=%d WHERE user='%s'", PlayerInfo[playerid][money], pname);
- mysql_query(query);
- format(query, sizeof(query), "UPDATE PlayerAccounts SET accent='%s' WHERE user='%s'", PlayerInfo[playerid][accent], pname);
- mysql_query(query);
- format(query, sizeof(query), "UPDATE PlayerAccounts SET age=%d WHERE user='%s'", PlayerInfo[playerid][age], pname);
- mysql_query(query);
- return 1;
- }
- //==============================================================================
- stock myStrcpy(dest[], src[])
- {
- new i = 0;
- while ((dest[i] = src[i])) i++;
- }
- //==============================================================================
- stock PlayerName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid, name, MAX_PLAYER_NAME);
- return name;
- }
- //==============================================================================
- stock GetDistanceBetweenPlayers(playerid,playerid2) //By Slick
- {
- new Float:x1,Float:y1,Float:z1,Float:x2,Float:y2,Float:z2;
- new Float:tmpdis;
- GetPlayerPos(playerid,x1,y1,z1);
- GetPlayerPos(playerid2,x2,y2,z2);
- tmpdis = floatsqroot(floatpower(floatabs(floatsub(x2,x1)),2)+floatpower(floatabs(floatsub(y2,y1)),2)+floatpower(floatabs(floatsub(z2,z1)),2));
- return floatround(tmpdis);
- }
- //==============================================================================
- COMMAND:age(playerid, params[]) // Made this for example of loading / saving integer
- {
- new iAge;
- if(sscanf(params, "d", iAge)) return SendClientMessage(playerid, COLOR_GREY, "/Age [Age]");
- PlayerInfo[playerid][age]=iAge;
- format(globalstring, sizeof(globalstring),"[Age] Your characters age has been set to %d",iAge);
- SendClientMessage(playerid,COLOR_GREY,globalstring);
- return 1;
- }
- //==============================================================================
- COMMAND:accent(playerid, params[]) // Example of loading / saving strings
- {
- new iAccent[12];
- if(sscanf(params, "s", iAccent)) return SendClientMessage(playerid, COLOR_GREY, "/accent [accent]");
- myStrcpy(PlayerInfo[playerid][accent],iAccent);
- format(globalstring, sizeof(globalstring),"[Age] Your characters accent is now: %s",iAccent);
- SendClientMessage(playerid,COLOR_GREY,globalstring);
- return 1;
- }
- //==============================================================================
- COMMAND:commands(playerid,params[])
- {
- SendClientMessage(playerid,COLOR_GREY,"MySQL >> Basic GameMode Command selection");
- SendClientMessage(playerid,COLOR_GREY,"[COMMANDS] - /age - /acccent - /o - /irc - /stats");
- return 1;
- }
- //==============================================================================
- COMMAND:irc(playerid, params[]) // Made this command to test the ECHO Chanel
- {
- new iReason[ 128 ];
- if( sscanf ( params, "s", iReason)) return SendClientMessage(playerid, COLOR_GREY, "/irc [message]");
- format(globalstring, sizeof(globalstring), "10(ToIRC): %s [%d]: %s",PlayerName(playerid), playerid, iReason);
- iEcho(globalstring);
- return 1;
- }
- //==============================================================================
- COMMAND:o(playerid, params[])
- {
- new iText[ 128 ];
- if(sscanf(params, "s", iText)) return SendClientMessage(playerid, COLOR_GREY, "/o [message]");
- if(IsPlayerAdmin(playerid)) {
- format(globalstring,sizeof(globalstring),"{8bbc8b}(( [Global OOC] {CCFFCC}RCON Admin %s: %s {8bbc8b}))", PlayerName(playerid),iText);
- } else {
- format(globalstring,sizeof(globalstring),"{8bbc8b}(( [Global OOC] {CCFFCC}%s: %s {8bbc8b}))",PlayerName(playerid),iText);
- }
- SendClientMessageToAll(0xCCFFCC00, globalstring);
- format(globalstring, sizeof(globalstring), "10(( [Global OOC]: %s: %s ))",PlayerName(playerid), iText);
- iEcho(globalstring);
- return 1;
- }
- //==============================================================================
- COMMAND:stats(playerid,params[])
- {
- new iAge, iAccent, iMoney;
- iAge = PlayerInfo[playerid][age];
- iMoney = PlayerInfo[playerid][money];
- iAccent = PlayerInfo[playerid][accent];
- SendClientMessage(playerid, COLOR_GREY,"=========================================================");
- format(globalstring, sizeof(globalstring),"Money: [%d] - Age: [%d] - Accent: [%s]",iMoney, iAge, iAccent);
- SendClientMessage(playerid, COLOR_GREY, globalstring);
- SendClientMessage(playerid, COLOR_GREY,"=========================================================");
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment