McBastard112

LA Handystem v0.1

Dec 2nd, 2012
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 7.75 KB | None | 0 0
  1. /*** LA Handystem v0.1 ***/
  2. /*** (c) 2012 by Logan Adams ***/
  3. /*** Danke an:
  4.        Kleiner_Opa (für OCMD)
  5.        Das SA:MP-Team (für SAMP)
  6.        Strickenkid (für das MySQL Plugin)
  7.        Y_Less (für sscanf2)
  8. */
  9.  
  10. //Includes
  11. #include <a_samp>
  12. #include <mysql>
  13. #include <ocmd>
  14. #include <sscanf2>
  15.  
  16. //Farben
  17. #define ROT 0xFF0000FF
  18. #define BLAU 0x0000FFFF
  19. #define GOLD 0xFFF000FF
  20.  
  21. //Einstellungen
  22. #define VERSION "0.1"
  23. #define SQL_HOST "anpassen"
  24. #define SQL_DATA "anpassen"
  25. #define SQL_PASS "anpassen"
  26. #define SQL_USER "anpassen"
  27. new ggPlayerName[MAX_PLAYERS][MAX_PLAYER_NAME];
  28.  
  29. enum eHandyInfo
  30. {
  31.     Handynummer,
  32.     bool:TelefoniertGerade,
  33.     TelefonPartner
  34. }
  35.  
  36. new _Handy[MAX_PLAYERS][eHandyInfo];
  37.  
  38. public OnFilterScriptInit()
  39. {
  40.     print("\n--------------------------------------");
  41.     printf("LA Handystem v%s by Logan Adams successfully loaded.",VERSION);
  42.     print("--------------------------------------\n");
  43.     new MySQL:connection;
  44.     connection = mysql_init(LOG_ALL,1);
  45.     mysql_connect(SQL_HOST,SQL_USER,SQL_PASS,SQL_DATA,connection,1);
  46.     if(mysql_ping() == 0) {
  47.         printf("[LA-Handysystem]: MySQL Verbindung steht: %s,%s,%s",SQL_HOST,SQL_USER,SQL_DATA);
  48.         CreatePhoneTable();
  49.     }
  50.     else
  51.         print("[LA-Handysystem]: MySQL Verbindung fehlgeschlagen. Bitte passe SQL-Host,User,Passwort,Datenbank + Passwort bitte ihm Skript an!");
  52.     return 1;
  53. }
  54.  
  55. public OnFilterScriptExit()
  56. {
  57.     mysql_close();
  58.     return 1;
  59. }
  60.  
  61. public OnPlayerConnect(playerid)
  62. {
  63.     _Handy[playerid][TelefoniertGerade] = false;
  64.     _Handy[playerid][TelefonPartner] = -1;
  65.     GetPlayerName(playerid,ggPlayerName[playerid],MAX_PLAYER_NAME);
  66.     return 1;
  67. }
  68.  
  69. public OnPlayerDisconnect(playerid,reason)
  70. {
  71.     if(_Handy[playerid][TelefoniertGerade] == true) {
  72.         SendClientMessage(_Handy[playerid][TelefonPartner],BLAU,"Dein Gesprächspartner ist gerade offline gegangen! Das Gespräch wurde beendet!");
  73.         _Handy[playerid][TelefoniertGerade] = false;
  74.         _Handy[playerid][TelefonPartner] = -1;
  75.     }
  76.     _Handy[playerid][TelefoniertGerade] = false;
  77.     _Handy[playerid][TelefonPartner] = -1;
  78.     new que[150];
  79.     format(que,sizeof que,"UPDATE `handy` SET `Name` = '%s',`Handynummer` = '%d'",ggPlayerName[playerid],_Handy[playerid][Handynummer]);
  80.     mysql_query(que);
  81.     return 1;
  82. }
  83.  
  84. public OnPlayerSpawn(playerid)
  85. {
  86.     if(PlayerExists(playerid) <= 0) {
  87.         new str[128];
  88.         SendClientMessage(playerid,BLAU,"Du hast noch kein Handy, ein Konto würde für dich eingerichtet ;)");
  89.         do {
  90.             new zahlen[7];
  91.             format(zahlen,7,"%d%d%d%d%d%d",random(10),random(10),random(10),random(10),random(10),random(10));
  92.             _Handy[playerid][Handynummer] = strval(zahlen);
  93.         } while(ExistsPhoneNumber(_Handy[playerid][Handynummer]) > 0);
  94.         format(str,sizeof str,"Deine Handynummer lautet: %d. Der Score in der Tableiste steht für die Handynummer!",_Handy[playerid][Handynummer]);
  95.         SendClientMessage(playerid,BLAU,str);
  96.         SetPlayerScore(playerid,_Handy[playerid][Handynummer]);
  97.         new query[150];
  98.         format(query,sizeof query,"INSERT INTO `handy`(`Name`,`Handynummer`) VALUES('%s','%d')",ggPlayerName[playerid],_Handy[playerid][Handynummer]);
  99.         mysql_query(query);
  100.     }
  101.     else {
  102.         new query[150],data[30];
  103.         format(query,sizeof query,"SELECT * FROM `handy` WHERE `Name` = '%s'",ggPlayerName[playerid]);
  104.         mysql_query(query);
  105.         mysql_store_result();
  106.         mysql_fetch_field("Handynummer",data); _Handy[playerid][Handynummer] = strval(data);
  107.         SetPlayerScore(playerid,_Handy[playerid][Handynummer]);
  108.         mysql_free_result();
  109.     }
  110.     return 1;
  111. }
  112.  
  113. public OnPlayerCommandText(playerid,cmdtext [])
  114. {
  115.     return 0;
  116. }
  117.  
  118. public OnPlayerText(playerid,text [])
  119. {
  120.     if(_Handy[playerid][TelefoniertGerade] == true) {
  121.         new str[128];
  122.         format(str,sizeof str,"[Handy] --> Du: %s",text);
  123.         SendClientMessage(playerid,GOLD,str);
  124.         format(str,sizeof str,"[Handy] %s: %s",ggPlayerName[playerid],text);
  125.         SendClientMessage(_Handy[playerid][TelefonPartner],GOLD,str);
  126.         return 0;
  127.     }
  128.     return 1;
  129. }
  130.  
  131. ocmd:call(playerid,params[])
  132. {
  133.     new nummer,str[128];
  134.     if(sscanf(params,"i",nummer))return SendClientMessage(playerid,ROT,"Benutze: /call [Handynummer]");
  135.     if(!IsPlayerConnected(GetIDByNumber(nummer)))return SendClientMessage(playerid,ROT,"Entweder ist der Spieler mit der Nummer offline oder diese Nummer ist falsch!");
  136.     if(playerid == GetIDByNumber(nummer))return SendClientMessage(playerid,ROT,"Du kannst nicht dich selbst anrufen!");
  137.     format(str,sizeof str,"Verbindungsaufbau zum Spieler %s mit der Nummer %d ...",ggPlayerName[GetIDByNumber(nummer)],nummer);
  138.     SendClientMessage(playerid,BLAU,str);
  139.     format(str,sizeof str,"Dein Handy klingelt! Spieler %s ist am Apperat! Willst du den Anruf mit /p annehmen oder mit /h ablehnen ?",ggPlayerName[playerid]);
  140.     SendClientMessage(GetIDByNumber(nummer),BLAU,str);
  141.     _Handy[playerid][TelefoniertGerade] = true;
  142.     _Handy[GetIDByNumber(nummer)][TelefoniertGerade] = true;
  143.     _Handy[playerid][TelefonPartner] = GetIDByNumber(nummer);
  144.     _Handy[GetIDByNumber(nummer)][TelefonPartner] = playerid;
  145.     return 1;
  146. }
  147.  
  148. ocmd:h(playerid,params[])
  149. {
  150.     #pragma unused params
  151.     if(_Handy[playerid][TelefoniertGerade] == false) return SendClientMessage(playerid,ROT,"Du telefonierst im Moment doch gar nicht ..!");
  152.     _Handy[playerid][TelefoniertGerade] = false;   
  153.     SendClientMessage(_Handy[playerid][TelefonPartner],ROT,"Dein Gesprächspartner hat aufgelegt bzw. deinen Anruf abgelehnt!");
  154.     SendClientMessage(playerid,ROT,"Du hast aufgelegt!");
  155.     _Handy[playerid][TelefonPartner] = -1;
  156.     _Handy[TelefonPartner][TelefoniertGerade] = false;
  157.     _Handy[TelefonPartner][TelefonPartner] = -1;
  158.     return 1;
  159. }
  160.  
  161. ocmd:p(playerid,params[])
  162. {
  163.     #pragma unused params
  164.     if(_Handy[playerid][TelefoniertGerade] == false)return SendClientMessage(playerid,ROT,"Dich ruft im Moment doch keiner an!");
  165.     _Handy[playerid][TelefoniertGerade] = true;
  166.     SendClientMessage(_Handy[playerid][TelefonPartner],BLAU,"Dein Gesprächspartner hat deinen Anruf angenommen! Rede mit ihm nun über den normalen Chat!");
  167.     return 1;
  168. }
  169.  
  170. ocmd:sms(playerid,params[])
  171. {
  172.     new nummer,msg[128];
  173.     if(sscanf(params,"is[128]",nummer,msg))return SendClientMessage(playerid,ROT,"Benutze: /sms [Handynummer] [Text]");
  174.     if(!IsPlayerConnected(GetIDByNumber(nummer)))return SendClientMessage(playerid,ROT,"Entweder ist der Spieler mit der Nummer offline oder diese Nummer ist falsch!");
  175.     if(GetIDByNumber(nummer) == playerid) return SendClientMessage(playerid,ROT,"Du kannst dir nicht selber SMS schreiben!");
  176.     format(msg,sizeof msg,"[SMS von %s]: %s",ggPlayerName[playerid],msg);
  177.     SendClientMessage(GetIDByNumber(nummer),GOLD,msg);
  178.     SendClientMessage(playerid,GOLD,"SMS erfolgreich abgeschickt!");
  179.     return 1;
  180. }
  181.  
  182. stock CreatePhoneTable()
  183. {
  184.     new query[400];
  185.     format(query,sizeof query,"CREATE TABLE IF NOT EXISTS `handy` (");
  186.     strcat(query,"`ID` int(11) NOT NULL AUTO_INCREMENT,");
  187.     strcat(query,"`Name` varchar(24) COLLATE latin1_german1_ci NOT NULL,");
  188.     strcat(query,"`Handynummer` int(30) NOT NULL,");
  189.     strcat(query,"PRIMARY KEY (`ID`))");
  190.     strcat(query,"ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_german1_ci AUTO_INCREMENT=1 ;");
  191.     mysql_query(query);
  192.     return 1;
  193. }
  194.  
  195. stock ExistsPhoneNumber(nummer)
  196. {
  197.     new query[80],cnt = -1;
  198.     format(query,sizeof query,"SELECT * FROM `handy` WHERE `Handynummer` = '%d'",nummer);
  199.     mysql_query(query);
  200.     mysql_store_result();
  201.     cnt = mysql_num_rows();
  202.     mysql_free_result();
  203.     return cnt;
  204. }
  205.  
  206. stock PlayerExists(playerid)
  207. {
  208.     new query[80],count = -1;
  209.     format(query,sizeof query,"SELECT * FROM `handy` WHERE `Name` = '%s'",ggPlayerName[playerid]);
  210.     mysql_query(query);
  211.     mysql_store_result();
  212.     count = mysql_num_rows();
  213.     mysql_free_result();
  214.     return count;
  215. }
  216.  
  217. stock GetIDByNumber(nummer)
  218. {
  219.     new pid = -1;
  220.     for(new i=0;i<MAX_PLAYERS;i++) {
  221.         if(!IsPlayerConnected(i))continue;
  222.         if(IsPlayerNPC(i))continue;
  223.         if(_Handy[i][Handynummer] == nummer) {
  224.             pid = i;
  225.             break;
  226.         }
  227.     }
  228.     return pid;
  229. }
Add Comment
Please, Sign In to add comment