Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Bankssystem by Items4Landwirt aka Music4You
- - Es ist verboten meinen Namen aus dem Skript zu löschen!
- - Es ist verboten Dieses Skript nocheinmal zu veröffentlichen
- - Es ist verboten Dieses Skript als eigenes auszugeben.
- Ich danke BlackAce für sein gutes Tutorial für SQLlite.
- http://forum.sa-mp.de/gta-multiplayer-mods/san-andreas-multiplayer/scripting-base/tutorials/121557-sqlite-die-alternative-zu-mysql/
- Nun noch ein Paar YT Kanäle, von guten Freunden
- Music4You http://www.youtube.com/user/Music4You43
- Items4Sacred http://www.youtube.com/user/items4sacred
- Metalletsplay666 http://www.youtube.com/user/MetalLetsPlay666
- */
- #define FILTERSCRIPT
- ////=============== Includes ===============
- #include <a_samp>
- #include <ocmd>
- #include <streamer>
- //=============== Defines ===============
- #define rot 0xFF0A00FF
- #define gruen 0x4BB400FF
- #define SCM SendClientMessage
- #define Bankmenu 1001
- #define Einzahlung 1002
- #define Kontostand 1003
- #define Auszahlung 1004
- #define Pinauswahl 1005
- #define Pinaueingabe 1006
- #define bankhelp 1007
- #define Ueberweisung 1008
- #define Summe 1009
- #define Fehler 1010
- #define MAX_ATMS 20
- ////=============== News ===============
- new DB:Database;
- new bankein;
- new bankaus;
- new ueberweisman[MAX_PLAYERS];
- enum bank
- {
- Guthaben,
- Konto
- }
- new BankInfo[MAX_PLAYERS][bank];
- enum ATM
- {
- ID,
- Float:X,
- Float:Y,
- Float:Z,
- Float:Angle,
- atmobjekt,
- bool:erstellt
- }
- new ATMInfo[MAX_ATMS][ATM];
- public OnFilterScriptInit()
- {
- print("\n=================================================");
- print(" SQLLite Banksystem by Music4You aka Items4Landwirt");
- print("===================================================\n");
- Database = db_open("Bank.db");
- db_query(Database,"CREATE TABLE IF NOT EXISTS `bank`(`Name`,`Konto`,`Pin`,`Guthaben`)");
- db_query(Database,"CREATE TABLE IF NOT EXISTS `atm`(`ID`,`X`,`Y`,`Z`,`A`)");
- new DBResult:Result, str[512], rows;
- for(new i=0;i<MAX_ATMS;i++)
- {
- format(str,sizeof(str),"SELECT * FROM `atm` WHERE `ID` = '%i'",i);
- Result = db_query(Database,str);
- rows = db_num_rows(Result);
- if(rows == 0)continue;
- db_get_field_assoc(Result,"X",str,sizeof(str));
- ATMInfo[i][X]=floatstr(str);
- db_get_field_assoc(Result,"Y",str,sizeof(str));
- ATMInfo[i][Y]=floatstr(str);
- db_get_field_assoc(Result,"Z",str,sizeof(str));
- ATMInfo[i][Z]=floatstr(str);
- db_get_field_assoc(Result,"A",str,sizeof(str));
- ATMInfo[i][Angle]=floatstr(str);
- ATMInfo[i][erstellt] = true;
- ATMInfo[i][atmobjekt] = CreateDynamicObject(2942,ATMInfo[i][X],ATMInfo[i][Y],ATMInfo[i][Z]-0.5,0,0,ATMInfo[i][Angle]);
- db_free_result(Result);
- }
- //=============== bank interior ===============
- CreateObject(14789, 1424.690308, -1004.066162, 1643.018677, 0.0000, 0.0000, 90.0000);
- CreateObject(2774, 1433.026245, -1004.643921, 1635.819824, 0.0000, 0.0000, 0.0000);
- CreateObject(2774, 1429.296997, -1004.618652, 1641.281128, 0.0000, 0.0000, 0.0000);
- CreateObject(2774, 1440.957031, -979.682068, 1640.297729, 0.0000, 0.0000, 0.0000);
- CreateObject(2774, 1429.337158, -979.545288, 1639.723389, 0.0000, 0.0000, 0.0000);
- CreateObject(2774, 1449.314087, -984.505005, 1648.023193, 0.0000, 0.0000, 0.0000);
- CreateObject(2774, 1413.914063, -984.515381, 1643.073486, 0.0000, 0.0000, 0.0000);
- CreateObject(1886, 1448.510132, -1003.642944, 1647.093994, 19.7670, 0.0000, 223.3584);
- CreateObject(1886, 1414.706543, -980.604431, 1647.061646, 19.7670, 0.0000, 43.3584);
- CreateObject(2774, 1430.416870, -999.017273, 1638.722412, 0.0000, 269.7592, 0.0000);
- CreateObject(2774, 1408.149292, -998.996826, 1638.722412, 0.0000, 269.7592, 180.0000);
- CreateObject(2774, 1443.577271, -986.634644, 1638.723389, 0.0000, 269.7592, 270.0000);
- CreateObject(2774, 1443.604492, -998.998169, 1647.797485, 0.0000, 0.0000, 0.0000);
- CreateObject(11359, 1414.356201, -988.985352, 1639.795898, 0.0000, 0.0000, 90.0000);
- CreateObject(2774, 1413.927368, -986.011719, 1643.046997, 0.0000, 0.0000, 270.0000);
- CreateObject(2774, 1413.763672, -992.085388, 1643.673340, 0.0000, 0.0000, 0.0000);
- CreateObject(626, 1427.554565, -997.322998, 1640.766479, 0.0000, 0.0000, 135.0000);
- CreateObject(626, 1427.488281, -990.752502, 1640.841553, 0.0000, 0.0000, 135.0000);
- CreateObject(2773, 1427.756714, -995.781189, 1639.310181, 0.0000, 0.0000, 0.0000);
- CreateObject(2773, 1427.694946, -992.841431, 1639.310181, 0.0000, 0.0000, 0.0000);
- CreateObject(2773, 1427.596924, -989.128601, 1639.301514, 0.0000, 0.0000, 0.0000);
- CreateObject(2773, 1429.863159, -982.927368, 1639.310181, 0.0000, 0.0000, 90.0000);
- CreateObject(626, 1427.665283, -983.128601, 1640.841553, 0.0000, 0.0000, 236.2500);
- CreateObject(2773, 1432.755859, -982.990784, 1639.310181, 0.0000, 0.0000, 90.0000);
- CreateObject(626, 1434.648315, -983.188904, 1640.841553, 0.0000, 0.0000, 236.2500);
- CreateObject(2773, 1437.091431, -983.054993, 1639.310181, 0.0000, 0.0000, 90.0000);
- CreateObject(2773, 1440.040283, -983.012756, 1639.310181, 0.0000, 0.0000, 90.0000);
- CreateObject(3462, 1448.466919, -993.014465, 1640.297974, 0.0000, 0.0000, 0.0000);
- CreateObject(3462, 1448.512085, -982.992615, 1640.181519, 0.0000, 0.0000, 0.0000);
- CreateObject(626, 1441.636230, -997.047729, 1640.741455, 0.0000, 0.0000, 146.2500);
- CreateObject(14632, 1443.648682, -995.934631, 1638.667725, 0.0000, 0.0000, 90.0000);
- CreateObject(14632, 1432.156372, -1018.015259, 1639.988159, 0.0000, 0.0000, 270.0000);
- CreateObject(1514, 1432.294922, -998.852478, 1639.740112, 0.0000, 0.0000, 180.0000);
- CreateObject(1514, 1438.352539, -998.846741, 1639.815674, 0.0000, 0.0000, 180.0000);
- CreateObject(2773, 1435.183838, -996.759277, 1639.301514, 0.0000, 0.0000, 0.0000);
- CreateObject(2773, 1435.152466, -993.932556, 1639.301514, 0.0000, 0.0000, 0.0000);
- CreateObject(2773, 1439.338623, -996.658691, 1639.301514, 0.0000, 0.0000, 0.0000);
- CreateObject(2773, 1439.288940, -994.000671, 1639.301514, 0.0000, 0.0000, 0.0000);
- CreateObject(1723, 1426.280151, -994.863586, 1638.707275, 0.0000, 0.0000, 270.0000);
- CreateObject(1723, 1426.244629, -991.150452, 1638.732300, 0.0000, 0.0000, 270.0000);
- CreateObject(1723, 1422.277466, -996.935059, 1638.682251, 0.0000, 0.0000, 90.0000);
- CreateObject(1723, 1422.279297, -993.210022, 1638.657227, 0.0000, 0.0000, 90.0000);
- CreateObject(2637, 1424.232422, -992.173584, 1638.838745, 0.0000, 0.0000, 270.0000);
- CreateObject(2637, 1424.228516, -995.704163, 1638.838745, 0.0000, 0.0000, 270.0000);
- CreateObject(3657, 1432.633301, -987.739014, 1639.202393, 0.0000, 0.0000, 0.0000);
- CreateObject(3657, 1432.631104, -986.977234, 1639.202393, 0.0000, 0.0000, 180.0000);
- CreateObject(3657, 1438.111572, -986.977539, 1639.202393, 0.0000, 0.0000, 180.0000);
- CreateObject(3657, 1438.086304, -987.730713, 1639.227417, 0.0000, 0.0000, 0.0000);
- CreateObject(2961, 1439.028320, -999.826660, 1639.211304, 0.0000, 0.0000, 0.0000);
- CreateObject(2961, 1433.505615, -999.827637, 1639.301392, 0.0000, 0.0000, 0.0000);
- CreateObject(2946, 1414.355225, -990.513489, 1638.755615, 0.0000, 0.0000, 0.0000);
- CreateObject(2946, 1414.380249, -987.392517, 1638.755005, 0.0000, 0.0000, 180.0000);
- CreateObject(2963, 1424.165283, -1004.815674, 1640.781128, 0.0000, 0.0000, 270.0000);
- CreateObject(2963, 1426.806763, -1004.832520, 1640.826904, 0.0000, 0.0000, 90.0000);
- CreateObject(1886, 1414.730591, -993.523010, 1646.908569, 17.1887, 0.0000, 67.5000);
- CreateObject(2773, 1431.414551, -996.845825, 1639.301514, 0.0000, 0.0000, 0.0000);
- CreateObject(2773, 1431.473389, -994.017090, 1639.301514, 0.0000, 0.0000, 0.0000);
- CreateObject(632, 1434.735352, -987.757507, 1639.131226, 0.0000, 0.0000, 213.7500);
- CreateObject(2942, 1417.713623, -980.475159, 1639.363525, 0.0000, 0.0000, 0.0000);
- CreateObject(1216, 1443.281372, -989.311279, 1639.387817, 0.0000, 0.0000, 270.0000);
- CreateObject(2942, 1421.217163, -980.448914, 1639.385498, 0.0000, 0.0000, 0.0000);
- CreateObject(2942, 1424.630493, -980.526672, 1639.371460, 0.0000, 0.0000, 0.0000);
- CreateObject(1216, 1443.277832, -991.424866, 1639.424194, 0.0000, 0.0000, 270.0000);
- CreateObject(1216, 1443.251221, -987.278198, 1639.376221, 0.0000, 0.0000, 270.0000);
- CreateObject(1216, 1443.259766, -985.484985, 1639.376221, 0.0000, 0.0000, 270.0000);
- CreateObject(2773, 1441.228638, -993.042969, 1639.301514, 0.0000, 0.0000, 270.0000);
- CreateObject(2824, 1424.297241, -992.054932, 1639.247681, 0.0000, 0.0000, 78.7500);
- bankein = CreatePickup(1318,1,1462.2754,-1011.1824,26.8438,-1);
- bankaus = CreatePickup(1318,1,1414.7997,-989.0223,1639.7843,-1);
- return 1;
- }
- public OnFilterScriptExit()
- {
- for(new i = 0; i < MAX_PLAYERS; i++)
- {
- SaveBank(i);
- }
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- new DBResult:Result, str[512];
- format(str, sizeof(str), "SELECT * FROM `bank` WHERE Name = '%s'",SpielerName(playerid));
- Result = db_query(Database,str);
- db_get_field_assoc(Result,"Konto",str,sizeof(str));
- BankInfo[playerid][Konto]=strval(str);
- db_get_field_assoc(Result,"Guthaben",str,sizeof(str));
- BankInfo[playerid][Guthaben]=strval(str);
- db_free_result(Result);
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- SaveBank(playerid);
- return 1;
- }
- ocmd:atm(playerid,params[])
- {
- if(BankInfo[playerid][Konto]!=1) return SCM(playerid,rot,"Du hast kein Bankkonto");
- if(IsATM(playerid) != -1)
- {
- ShowPlayerDialog(playerid,Pinaueingabe,DIALOG_STYLE_INPUT,"Pineingabe","Gebe nun deinen Bankpin ein, um auf dein Bankkonto zuzugreifen","Weiter","Abbrechen");
- }
- else
- {
- SCM(playerid,rot,"Du bist an keinem ATM");
- }
- return 1;
- }
- ocmd:bank(playerid,params[])
- {
- new query[128];
- if(!IsPlayerInRangeOfPoint(playerid,10,1417.7145,-981.6283,1639.7843)) return SCM(playerid,rot,"Du bist nicht in Der Bank");
- if(BankInfo[playerid][Konto]!=0) return SCM(playerid,rot,"Du hast bereits ein Bankkonto");
- ShowPlayerDialog(playerid,Pinauswahl,DIALOG_STYLE_INPUT,"Pineingabe","Um ein Bankkonto zu erstellen musst du vorher einen Sicheren Bankpin eingeben,\n diesen musst du dir merken!","Weiter","");
- format(query,sizeof(query),"INSERT INTO `bank` (`Name`) VALUES ('%s')",SpielerName(playerid));
- db_query(Database,query);
- return 1;
- }
- ocmd:bankhilfe(playerid,params[])
- {
- SCM(playerid,gruen,"/bank -> Bankkonto erstellen, nur in der Bank");
- SCM(playerid,gruen,"/atm -> Bankkonto aufrufen, nur in der Bank");
- return 1;
- }
- ocmd:catm(playerid,params[])
- {
- new Float:x,Float:y,Float:z,Float:a, query[256];
- if(!IsPlayerAdmin(playerid)) return SCM(playerid,rot,"Du bist nicht befugt!");
- GetPlayerPos(playerid, x, y, z);
- GetPlayerFacingAngle(playerid,a);
- for(new i = 0;i < MAX_ATMS; i++)
- {
- if(ATMInfo[i][erstellt] == true)continue;
- ATMInfo[i][erstellt] = true;
- ATMInfo[i][X] = x;
- ATMInfo[i][Y] = y;
- ATMInfo[i][Z] = z;
- ATMInfo[i][Angle] = a;
- ATMInfo[i][atmobjekt] = CreateDynamicObject(2942,x,y,z-0.5,0,0,a);
- format(query,sizeof(query),"INSERT INTO `atm` (`ID`, `X`,`Y`,`Z`,`A`) VALUES ('%i','%f','%f','%f','%f')",i,x,y,z,a);
- db_query(Database,query);
- SCM(playerid,gruen,"ATM erstellt");
- return 1;
- }
- return 1;
- }
- ocmd:delatm(playerid, params[])
- {
- if(!IsPlayerAdmin(playerid)) return SCM(playerid,rot,"Du bist nicht befugt!");
- new id = IsATM(playerid),query[256];
- if(id != -1)
- {
- ATMInfo[id][erstellt] = false;
- ATMInfo[id][X] = 0.0;
- ATMInfo[id][Y] = 0.0;
- ATMInfo[id][Z] = 0.0;
- ATMInfo[id][Angle] = 0;
- SCM(playerid,gruen,"Du hast den ATM gelöscht");
- DestroyDynamicObject(ATMInfo[id][atmobjekt]);
- format(query,sizeof(query),"SELECT * FROM atm WHERE ID = '%d'",id);
- format(query,sizeof(query),"DELETE FROM atm WHERE ID = '%d'",id);
- db_query(Database,query);
- return 1;
- }
- else
- {
- SCM(playerid,rot,"Du bist an keinem ATM");
- }
- return 1;
- }
- ocmd:delallatm(playerid,params[])
- {
- if(!IsPlayerAdmin(playerid)) return SCM(playerid,rot,"Du bist nicht befugt!");
- for(new i=0,query[128];i<MAX_ATMS;i++)
- {
- ATMInfo[i][erstellt] = false;
- ATMInfo[i][X] = 0.0;
- ATMInfo[i][Y] = 0.0;
- ATMInfo[i][Z] = 0.0;
- ATMInfo[i][Angle] = 0;
- DestroyDynamicObject(ATMInfo[i][atmobjekt]);
- format(query,sizeof(query),"SELECT * FROM atm WHERE ID = '%d'",i);
- format(query,sizeof(query),"DELETE FROM atm WHERE ID = '%d'",i);
- db_query(Database,query);
- }
- SCM(playerid,gruen,"Du hast alle ATMs gelöscht");
- return 1;
- }
- public OnPlayerPickUpPickup(playerid, pickupid)
- {
- if(pickupid == bankein)
- {
- SetPlayerPos(playerid,1417.2261,-989.1280,1639.7843);
- SetPlayerInterior(playerid,0);
- }
- if(pickupid == bankaus)
- {
- SetPlayerPos(playerid,1471.2754,-1011.1824,26.8438);
- SetPlayerInterior(playerid,0);
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case Pinauswahl:
- {
- if(response)
- {
- if(!strlen(inputtext))
- {
- ShowPlayerDialog(playerid,Pinauswahl,DIALOG_STYLE_INPUT,"Pineingabe","Um ein Bankkonto zu erstellen musst du vorher einen Sicheren Bankpin eingeben,\n diesen musst du dir merken!","Weiter","");
- return 1;
- }
- new query[128];
- format(query,128,"UPDATE `bank` SET `Pin` = '%s' WHERE `Name` = '%s'",inputtext,SpielerName(playerid));
- db_query(Database,query);
- BankInfo[playerid][Konto]=1;
- BankInfo[playerid][Guthaben]+=300;
- SCM(playerid,gruen,"konto erstellt");
- }
- }
- case Pinaueingabe:
- {
- if(response)
- {
- new str[128],DBResult:Result;
- format(str, sizeof(str), "SELECT * FROM `bank` WHERE Name = '%s' AND Pin = '%s'",SpielerName(playerid),inputtext);
- Result = db_query(Database,str);
- if(db_num_rows(Result) > 0)
- {
- ShowPlayerDialog(playerid,Bankmenu,DIALOG_STYLE_LIST,"Transaktionen","Einzahlung\nAuszahlung\nKontostand\nÜberweisen","Wählen","Beenden");
- }
- else
- {
- ShowPlayerDialog(playerid,Pinaueingabe,DIALOG_STYLE_INPUT,"Pineingabe","Gebe nun deinen Bankpin ein, um auf dein Bankkonto zuzugreifen","Weiter","Abbrechen");
- }
- db_free_result(Result);
- }
- }
- case Bankmenu:
- {
- if(response)
- {
- if(listitem == 0)
- {
- ShowPlayerDialog(playerid,Einzahlung,DIALOG_STYLE_INPUT,"Einzahlung","Summe eingeben:","Einzahlen","Verlassen");
- }
- if(listitem == 1)
- {
- ShowPlayerDialog(playerid,Auszahlung,DIALOG_STYLE_INPUT,"Auszahlung","Summe eingeben:","Auszahlen","Verlassen");
- }
- if(listitem == 2)
- {
- new str[128];
- format(str,sizeof(str),"Kontostand: %d$",BankInfo[playerid][Guthaben]);
- ShowPlayerDialog(playerid,Kontostand,DIALOG_STYLE_MSGBOX,"Kontostand",str,"Schließen","");
- }
- if(listitem == 3)
- {
- }
- }
- }
- case Einzahlung:
- {
- new str[128];
- if(!response)return ShowPlayerDialog(playerid,Bankmenu,DIALOG_STYLE_LIST,"Transaktionen","Einzahlung\nAuszahlung\nKontostand\nÜberweisen","Wählen","Beenden");
- if(GetPlayerMoney(playerid) < strval(inputtext))return SendClientMessage(playerid,rot,"Du hast nicht genug Geld dabei!");
- GivePlayerMoney(playerid, - strval(inputtext));
- BankInfo[playerid][Guthaben] += strval(inputtext);
- format(str,sizeof(str),"Sie haben %d$ auf ihr Konto eingezahlt",strval(inputtext));
- SCM(playerid,gruen,str);
- }
- case Auszahlung:
- {
- new str[128];
- if(!response)return ShowPlayerDialog(playerid,Bankmenu,DIALOG_STYLE_LIST,"Transaktionen","Einzahlung\nAuszahlung\nKontostand\nÜberweisen","Wählen","Beenden");
- if(BankInfo[playerid][Guthaben] < strval(inputtext))return SendClientMessage(playerid,rot,"Du hast nicht genug auf dem Konto!");
- GivePlayerMoney(playerid,strval(inputtext));
- BankInfo[playerid][Guthaben] -= strval(inputtext);
- format(str,sizeof(str),"Sie haben %d$ von ihrem Konto abgehoben",strval(inputtext));
- SCM(playerid,gruen,str);
- }
- case Ueberweisung:
- {
- new pID;
- if(!response)return ShowPlayerDialog(playerid,Bankmenu,DIALOG_STYLE_LIST,"Transaktionen","Einzahlung\nAuszahlung\nKontostand\nÜberweisung","Wählen","Beenden");
- if(sscanf(inputtext,"u",pID))return ShowPlayerDialog(playerid,Fehler,DIALOG_STYLE_MSGBOX,"Transaktion","Ungültige Angabe!","Schließen","") ;
- if(!IsPlayerConnected(pID))return ShowPlayerDialog(playerid,Fehler,DIALOG_STYLE_MSGBOX,"Transaktion","Ungültiger Empfänger!","Schließen","") ;
- if (pID == playerid)return ShowPlayerDialog(playerid,Fehler,DIALOG_STYLE_MSGBOX,"Transaktion","Ungültiger Empfänger!","Schließen","") ;
- ShowPlayerDialog(playerid,Summe,DIALOG_STYLE_INPUT,"Überweisung","Summe eingeben:","Überweisen","Verlassen");
- ueberweisman[playerid] = pID;
- ueberweisman[pID] = playerid;
- }
- case Summe:
- {
- new pID = ueberweisman[playerid];
- new str[128],str2[128];
- if(!response)return ShowPlayerDialog(playerid,Bankmenu,DIALOG_STYLE_LIST,"Transaktionen","Einzahlung\nAuszahlung\nKontostand\nÜberweisung","Wählen","Beenden");
- if(GetPlayerMoney(playerid)< strval(inputtext))return SendClientMessage(playerid,rot,"Du hast nicht genug Geld auf dem Konto!");
- BankInfo[playerid][Guthaben] -= strval(inputtext);
- BankInfo[pID][Guthaben] += strval(inputtext);
- format(str,sizeof(str),"Sie haben %d$ auf das Konto von %s überwiesen",strval(inputtext),SpielerName(pID));
- SCM(playerid,gruen,str);
- format(str2,sizeof(str2),"%s hat ihnen %d$ auf ihr Konto überwiesen",SpielerName(playerid),strval(inputtext));
- SendClientMessage(pID,gruen,str2);
- }
- }
- return 0;
- }
- stock SpielerName(playerid)
- {
- new name[MAX_PLAYER_NAME];
- GetPlayerName(playerid,name,sizeof(name));
- return name;
- }
- stock SaveBank(playerid)
- {
- new query[128];
- format(query,128,"UPDATE `bank` SET `Konto` = '%i', `Guthaben` = '%i' WHERE `Name` = '%s'",BankInfo[playerid][Konto],BankInfo[playerid][Guthaben],SpielerName(playerid));
- db_query(Database,query);
- return 1;
- }
- stock IsATM(playerid)
- {
- new i=0;
- while(i != MAX_ATMS)
- {
- if(IsPlayerInRangeOfPoint(playerid, 3.0, ATMInfo[i][X], ATMInfo[i][Y], ATMInfo[i][Z]) || IsPlayerInRangeOfPoint(playerid,10,1417.7145,-981.6283,1639.7843))
- {
- return i;
- }
- i++;
- }
- return -1;
- }
- stock sscanf(string[], format[], {Float,_}:...)
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = ' ';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i', 'd':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
Add Comment
Please, Sign In to add comment