Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #define dcmd(%1,%2,%3) if (!strcmp((%3)[1], #%1, true, (%2)) && ((((%3)[(%2) + 1] == '\0') && (dcmd_%1(playerid, ""))) || (((%3)[(%2) + 1] == ' ') && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
- #define c4sellerx 1512.6119
- #define c4sellery -1460.3040
- #define c4sellerz 9.5000
- #define c4price 500
- #define C4BUYDIALOG 20000
- #define C4LICDIALOG 20001 //layincar
- #define C4PLANTDIALOG 20002
- forward Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2);
- public OnFilterScriptInit()
- {
- printf("Bloodys C4-System geladen");
- Create3DTextLabel("Ich bin der C4 Händler!\nBenutze /c4kaufen, um bei mir eine C4 zu kaufen!",0x00FF00FF,c4sellerx,c4sellery,c4sellerz,5,0,0);
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- SetPVarInt(playerid,"c4car",2500);
- ApplyAnimation(playerid,"BOMBER","BOM_Plant",2.0,0,0,0,0,0);
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- dcmd(c4status,8,cmdtext);
- dcmd(c4kaufen,8,cmdtext);
- dcmd(c4legen,7,cmdtext);
- dcmd(c4zuenden,9,cmdtext);
- dcmd(c4nehmen,8,cmdtext);
- dcmd(ac4geben,8,cmdtext);
- dcmd(c4defuse,8,cmdtext);
- dcmd(ac4entfernen,12,cmdtext);
- dcmd(c4check,7,cmdtext);
- dcmd(c4remove,8,cmdtext);
- return 0;
- }
- dcmd_c4status(playerid,params[])
- {
- #pragma unused params
- if(GetPVarInt(playerid,"c4counter")==0) return SendClientMessage(playerid,0x00FF00FF,"Du hast keine C4.");
- else if(GetPVarInt(playerid,"c4counter")==1) return SendClientMessage(playerid,0x00FF00FF,"Du hast eine C4 dabei.");
- else if (GetPVarInt(playerid,"c4counter")==2 || GetPVarInt(playerid,"c4counter")==3) return SendClientMessage(playerid,0x00FF00FF,"Du hast deine C4 schon platziert.");
- return 1;
- }
- dcmd_c4kaufen(playerid,params[])
- {
- #pragma unused params
- if(IsPlayerInRangeOfPoint(playerid,5,c4sellerx,c4sellery,c4sellerz))
- {
- if(GetPVarInt(playerid,"c4counter")==0)
- {
- new tmpstr[180];
- format(tmpstr,sizeof(tmpstr),"Möchtest du eine C4 kaufen? Ganz heiße Ware, damit sind früher Leute explodiert, die bei Fleischberg gegessen haben!\nDer Preis beträgt nur %d$!",c4price);
- ShowPlayerDialog(playerid,C4BUYDIALOG,DIALOG_STYLE_MSGBOX,"Möchtest du eine C4 kaufen?",tmpstr,"Kaufen!","Lieber doch nicht");
- }
- else
- {
- SendClientMessage(playerid,0xFF0000,"Sorry, du hast schon eine C4..verknall erstmal die, Dude!");
- }
- }
- return 1;
- }
- dcmd_c4legen(playerid,params[])
- {
- #pragma unused params
- if(GetPVarInt(playerid,"c4counter")==0)
- return SendClientMessage(playerid,0xFF0000FF,"Du hast keine C4 bei dir.");
- else if(GetPVarInt(playerid,"c4counter")==2 || GetPVarInt(playerid,"c4counter")==3 )
- return SendClientMessage(playerid,0xFF0000FF,"Du hast die C4 schon gelegt!");
- //Ab diesem Punkt ist der Spieler befugt, eine C4 zu legen.
- if(IsPlayerInAnyVehicle(playerid))
- return ShowPlayerDialog(playerid,C4LICDIALOG,DIALOG_STYLE_MSGBOX,"C4 im Auto legen?","Du bist in einem Fahrzeug. Möchtest du die C4 in das Fahrzeug legen?","Ja","Nein");
- new Float:x;
- new Float:y;
- new Float:z;
- GetPlayerPos(playerid,x,y,z);
- GetXYInFrontOfPlayer(playerid,x,y,0.7);
- new objectid=CreateObject(1654,x,y,z-0.8,0,0,0);
- SetPVarInt(playerid,"c4object",objectid);
- SetPVarFloat(playerid,"c4x",x);
- SetPVarFloat(playerid,"c4y",y);
- SetPVarFloat(playerid,"c4z",z);
- SetPVarInt(playerid,"c4counter",2);
- ClearAnimations(playerid);
- ApplyAnimation(playerid,"BOMBER","BOM_Plant",2.0,0,0,0,0,0);
- SendClientMessage(playerid,0x00FF00FF,"Die C4 wurde erfolgreich gelegt. Benutze /c4zuenden, damit es PUFF macht");
- return 1;
- }
- dcmd_c4zuenden(playerid,params[])
- {
- #pragma unused params
- if(GetPVarInt(playerid,"c4counter")==0)
- return SendClientMessage(playerid,0xFF0000FF,"Du hast überhaupt keine C4, Trottel!");
- if(GetPVarInt(playerid,"c4counter")==1)
- return SendClientMessage(playerid,0xFF0000FF,"Du musst die C4 erstmal legen, Trottel!");
- if(GetPVarInt(playerid,"c4counter")==3)
- {
- SetPVarInt(playerid,"c4counter",0);
- return SendClientMessage(playerid,0xFF0000FF,"Fernzünder erfolgreich betätigt");
- }
- //Rausfinden, wo die C4 ist
- new tmpcar=GetPVarInt(playerid,"c4car");
- if(tmpcar!=2500) //Es wird ne Karre gesprengt..yes, baby!
- {
- new Float:x;
- new Float:y;
- new Float:z;
- GetVehiclePos(tmpcar,x,y,z);
- CreateExplosion(x,y,z,7,20.0); // <<<<Beste Zeile im Script
- new Float:x2;
- new Float:y2;
- new Float:z2;
- new objectid=GetPVarInt(playerid,"c4object");
- DestroyObject(objectid);
- for(new i;i<MAX_VEHICLES;i++)
- {
- GetVehiclePos(i,x2,y2,z2);
- new Float:d=Distance(x,y,z,x2,y2,z2);
- if(d<=30) //Alles in der Umgebung soll mitrauchen
- {
- new Float:newhealth;
- new Float:oldhealth;
- GetVehicleHealth(i,oldhealth);
- newhealth=oldhealth-(1100-(d*40));
- SetVehicleHealth(i,newhealth);
- }
- }
- for(new l;l<MAX_PLAYERS;l++)
- {
- if(IsPlayerInRangeOfPoint(l,7,x,y,z))
- {
- SetPlayerHealth(l,0.0);
- }
- }
- SendClientMessage(playerid,0x00FF00FF,"Fernzünder erfolgreich betätigt");
- SetPVarInt(playerid,"c4counter",0);
- SetPVarFloat(playerid,"c4x",0);
- SetPVarFloat(playerid,"c4y",0);
- SetPVarFloat(playerid,"c4z",0);
- SetPVarInt(playerid,"c4car",2500);
- return 1;
- }
- else
- {
- new Float:x=GetPVarFloat(playerid,"c4x");
- new Float:y=GetPVarFloat(playerid,"c4y");
- new Float:z=GetPVarFloat(playerid,"c4z");
- if(x==0&&y==0&&z==0)
- return SendClientMessage(playerid,0xFF0000FF,"FEHLERCODE 1337 LOL ZOMFG ROFL LMAO!!!!!");
- //Code Copy%Paste 8)
- CreateExplosion(x,y,z,7,20.0); // <<<<Beste Zeile im Script
- new objectid=GetPVarInt(playerid,"c4object");
- DestroyObject(objectid);
- new Float:x2;
- new Float:y2;
- new Float:z2;
- for(new i;i<MAX_VEHICLES;i++)
- {
- GetVehiclePos(i,x2,y2,z2);
- new Float:d=Distance(x,y,z,x2,y2,z2);
- if(d<=30) //Alles in der Umgebung soll mitrauchen
- {
- new Float:newhealth;
- new Float:oldhealth;
- GetVehicleHealth(i,oldhealth);
- newhealth=oldhealth-(1100-(d*40));
- SetVehicleHealth(i,newhealth);
- }
- }
- for(new l;l<MAX_PLAYERS;l++)
- {
- if(IsPlayerInRangeOfPoint(l,7,x,y,z))
- {
- SetPlayerHealth(l,0.0);
- }
- }
- SendClientMessage(playerid,0x00FF00FF,"Fernzünder erfolgreich betätigt");
- SetPVarInt(playerid,"c4counter",0);
- SetPVarFloat(playerid,"c4x",0);
- SetPVarFloat(playerid,"c4y",0);
- SetPVarFloat(playerid,"c4z",0);
- SetPVarInt(playerid,"c4car",2500);
- }
- return 1;
- }
- dcmd_c4nehmen(playerid,params[])
- {
- #pragma unused params
- if(GetPVarInt(playerid,"c4counter")==0)
- return SendClientMessage(playerid,0xFF0000FF,"Du hast nichtmal nen Zünder, Trottel");
- if(GetPVarInt(playerid,"c4counter")==1)
- return SendClientMessage(playerid,0xFF0000FF,"Du hast deine C4 noch, Trottel");
- if(IsPlayerInAnyVehicle(playerid))
- {
- if(GetPlayerVehicleID(playerid)==GetPVarInt(playerid,"c4car"))
- {
- SetPVarInt(playerid,"c4counter",1);
- SetPVarFloat(playerid,"c4x",0);
- SetPVarFloat(playerid,"c4y",0);
- SetPVarFloat(playerid,"c4z",0);
- SetPVarInt(playerid,"c4car",2500);
- SendClientMessage(playerid,0x00FF00FF,"Du hast dir deine C4 wieder genommen.");
- }
- }
- new Float:x;
- new Float:y;
- new Float:z;
- new Float:x2=GetPVarFloat(playerid,"c4x");
- new Float:y2=GetPVarFloat(playerid,"c4y");
- new Float:z2=GetPVarFloat(playerid,"c4z");
- GetPlayerPos(playerid,x,y,z);
- if(Distance(x,y,z,x2,y2,z2)<2.0)
- {
- new objectid=GetPVarInt(playerid,"c4object");
- DestroyObject(objectid);
- SetPVarInt(playerid,"c4counter",1);
- SetPVarFloat(playerid,"c4x",0);
- SetPVarFloat(playerid,"c4y",0);
- SetPVarFloat(playerid,"c4z",0);
- SetPVarInt(playerid,"c4car",2500);
- SendClientMessage(playerid,0x00FF00FF,"Du hast dir deine C4 wieder genommen.");
- return 1;
- }
- else
- {
- return SendClientMessage(playerid,0xFF0000FF,"Du bist bei keiner aufnehmbaren C4!");
- }
- }
- dcmd_ac4geben(playerid,params[]) //ADMINBEFEHL
- {
- if(0==0)
- {
- new pid;
- if(sscanf(params,"u",pid)) return SendClientMessage(playerid,0xFF0000FF,"Benutzung: /ac4geben SPIELER");
- if(!IsPlayerConnected(pid)) return SendClientMessage(playerid,0xFF0000FF,"Der angegebene Spieler ist nicht online!");
- SetPVarInt(pid,"c4counter",1);
- SendClientMessage(pid,0x00FF00FF,"Du hast nun eine C4!");
- new tstr[MAX_PLAYER_NAME];
- GetPlayerName(pid,tstr,sizeof(tstr));
- new tstr2[128];
- format(tstr2,sizeof(tstr2),"Du hast dem Spieler %s eine C4 gegeben!",tstr);
- SendClientMessage(playerid,0x00FF00FF,tstr2);
- }
- return 1;
- }
- dcmd_c4defuse(playerid,params[]) //PD Befehl
- {
- #pragma unused params
- if(1==1) //TODO
- {
- if(IsPlayerInAnyVehicle(playerid))
- {
- new x=GetPlayerVehicleID(playerid);
- for(new i;i<MAX_PLAYERS;i++)
- {
- if(x==GetPVarInt(i,"c4car")&&GetPVarInt(i,"c4counter")==2)
- {
- new j=random(100);
- if(j<=25) //BOOOOM hrhr
- {
- new Float:x1;
- new Float:y1;
- new Float:z1;
- GetVehiclePos(x,x1,y1,z1);
- CreateExplosion(x1,y1,z1,7,20.0); // <<<<Beste Zeile im Script
- new objectid=GetPVarInt(i,"c4object");
- DestroyObject(objectid);
- new Float:x2;
- new Float:y2;
- new Float:z2;
- for(new k;k<MAX_VEHICLES;k++)
- {
- GetVehiclePos(k,x2,y2,z2);
- new Float:d=Distance(x1,y1,z1,x2,y2,z2);
- if(d<=30) //Alles in der Umgebung soll mitrauchen
- {
- new Float:newhealth;
- new Float:oldhealth;
- GetVehicleHealth(i,oldhealth);
- newhealth=oldhealth-(1100-(d*40));
- SetVehicleHealth(i,newhealth);
- }
- }
- for(new l;l<MAX_PLAYERS;l++)
- {
- if(IsPlayerInRangeOfPoint(l,7,x1,y1,z1))
- {
- SetPlayerHealth(l,0.0);
- }
- }
- SetPVarInt(i,"c4counter",3);
- SetPVarFloat(i,"c4x",0);
- SetPVarFloat(i,"c4y",0);
- SetPVarFloat(i,"c4z",0);
- return SendClientMessage(playerid,0xFF0000FF,"Du hast den falschen Draht durchgeschnitten...shit happenz!");
- }
- else //Not BOOM...aaawwww
- {
- SetPVarInt(i,"c4counter",3);
- SetPVarFloat(i,"c4x",0);
- SetPVarFloat(i,"c4y",0);
- SetPVarFloat(i,"c4z",0);
- return SendClientMessage(playerid,0x00FF00FF,"Du hast den richtigen Draht durchgeschnitten! Die C4 wurde entschärft!");
- }
- }//if pvarzeugs
- }
- return SendClientMessage(playerid,0xFF0000FF,"Du hast keine C4 in dem Fahrzeug gefunden.");
- }
- new Float:x;
- new Float:y;
- new Float:z;
- GetPlayerPos(playerid,x,y,z);
- for(new i;i<MAX_PLAYERS;i++)
- {
- if(GetPVarInt(i,"c4counter")==2)
- {
- new Float:x1=GetPVarFloat(i,"c4x");
- new Float:y1=GetPVarFloat(i,"c4y");
- new Float:z1=GetPVarFloat(i,"c4z");
- if(Distance(x,y,z,x1,y1,z1)<2) //Boom oder nicht Boom, das ist hier die Frage!
- {
- new j=random(100);
- if(j<=25) //BOOOOM hrhr
- {
- CreateExplosion(x1,y1,z1,7,15.0); // <<<<Beste Zeile im Script
- new objectid=GetPVarInt(i,"c4object");
- DestroyObject(objectid);
- new Float:x2;
- new Float:y2;
- new Float:z2;
- for(new k;k<MAX_VEHICLES;k++)
- {
- GetVehiclePos(k,x2,y2,z2);
- new Float:d=Distance(x1,y1,z1,x2,y2,z2);
- if(d<=30) //Alles in der Umgebung soll mitrauchen
- {
- new Float:newhealth;
- new Float:oldhealth;
- GetVehicleHealth(i,oldhealth);
- newhealth=oldhealth-(1100-(d*40));
- SetVehicleHealth(i,newhealth);
- }
- }
- for(new l;l<MAX_PLAYERS;l++)
- {
- if(IsPlayerInRangeOfPoint(l,7,x1,y1,z1))
- {
- SetPlayerHealth(l,0.0);
- }
- }
- SetPVarInt(i,"c4counter",3);
- SetPVarFloat(i,"c4x",0);
- SetPVarFloat(i,"c4y",0);
- SetPVarFloat(i,"c4z",0);
- return SendClientMessage(playerid,0xFF0000FF,"Du hast den falschen Draht durchgeschnitten...shit happenz!");
- }
- else //Not BOOM...aaawwww
- {
- new objectid=GetPVarInt(i,"c4object");
- DestroyObject(objectid);
- SetPVarInt(i,"c4counter",3);
- SetPVarFloat(i,"c4x",0);
- SetPVarFloat(i,"c4y",0);
- SetPVarFloat(i,"c4z",0);
- return SendClientMessage(playerid,0x00FF00FF,"Du hast den richtigen Draht durchgeschnitten! Die C4 wurde entschärft!");
- }
- }
- }
- } //For Schleife
- SendClientMessage(playerid,0xFF0000FF,"Du bist bei keiner C4");
- }//NO COP
- return 1;
- }
- dcmd_ac4entfernen(playerid,params[]) //ADMINBEFEHL
- {
- if(0==0) //TODO
- {
- new pid;
- if(sscanf(params,"u",pid)) return SendClientMessage(playerid,0xFF0000FF,"Benutzung: /ac4entfernen SPIELER");
- if(!IsPlayerConnected(pid)) return SendClientMessage(playerid,0xFF0000FF,"Der angegebene Spieler ist nicht online!");
- if(GetPVarInt(pid,"c4counter")==0)
- return SendClientMessage(playerid,0xFF0000FF,"Der Spieler hat gar keine C4");
- else if(GetPVarInt(pid,"c4counter")==2)
- return SendClientMessage(playerid,0xFF0000FF,"Der Spieler hat die C4 schon gelegt, sie ist nicht entfernbar.");
- else if(GetPVarInt(pid,"c4counter")==3)
- return SendClientMessage(playerid,0xFF0000FF,"Die C4 ist schon entschärft, der Spieler weiß dass nur noch nicht.");
- SetPVarInt(pid,"c4counter",0);
- SetPVarFloat(pid,"c4x",0);
- SetPVarFloat(pid,"c4y",0);
- SetPVarFloat(pid,"c4z",0);
- new tstr[MAX_PLAYER_NAME];
- GetPlayerName(pid,tstr,sizeof(tstr));
- new tstr2[128];
- format(tstr2,sizeof(tstr2),"Du hast dem Spieler %s die C4 weggenommen!",tstr);
- SendClientMessage(playerid,0x00FF00FF,tstr2);
- }
- return 1;
- }
- dcmd_c4check(playerid,params[])//PDBEFEHL
- {
- if(0==0) //IsPlayerCop
- {
- new pid;
- if(sscanf(params,"u",pid)) return SendClientMessage(playerid,0xFF0000FF,"Benutzung: /c4check SPIELER");
- if(!IsPlayerConnected(pid)) return SendClientMessage(playerid,0xFF0000FF,"Der angegebene Spieler ist nicht online.");
- new Float:x;
- new Float:y;
- new Float:z;
- GetPlayerPos(pid,x,y,z);
- if(IsPlayerInRangeOfPoint(playerid,5,x,y,z))
- {
- switch(GetPVarInt(pid,"c4counter"))
- {
- case 0: SendClientMessage(playerid,0x00FF00FF,"Der Spieler hat keine C4 bei sich.");
- case 1: SendClientMessage(playerid,0xFF0000FF,"Der Spieler hat eine C4 bei sich!");
- case 2..3: SendClientMessage(playerid,0x0000FFFF,"Du findest nur noch den Zünder beim Spieler.....");
- }
- }
- else
- SendClientMessage(playerid,0xFF0000FF,"Der Spieler ist zu weit weg!");
- }
- return 1;
- }
- dcmd_c4remove(playerid,params[]) //PD BEFEHL
- {
- if(0==0) //IsPlayerCop
- {
- new pid;
- if(sscanf(params,"u",pid)) return SendClientMessage(playerid,0xFF0000FF,"Benutzung: /c4remove SPIELER");
- if(!IsPlayerConnected(pid)) return SendClientMessage(playerid,0xFF0000FF,"Der angegebene Spieler ist nicht verbunden.");
- new Float:x;
- new Float:y;
- new Float:z;
- GetPlayerPos(pid,x,y,z);
- if(IsPlayerInRangeOfPoint(playerid,5,x,y,z))
- {
- switch(GetPVarInt(pid,"c4counter"))
- {
- case 0: SendClientMessage(playerid,0xFF0000FF,"Der Spieler hat gar nix bei sich.");
- case 1:
- {
- SendClientMessage(pid,0x00FF00FF,"Ein Polizist hat dir die C4 weggenommen...das schöne Geld!");
- SendClientMessage(playerid,0x00FF00FF,"Du hast dem Spieler die C4 weggenommen");
- SetPVarInt(pid,"c4counter",0);
- SetPVarInt(pid,"c4car",2500);
- SetPVarFloat(pid,"c4x",0);
- SetPVarFloat(pid,"c4y",0);
- SetPVarFloat(pid,"c4z",0);
- }
- case 2..3:
- {
- SendClientMessage(pid,0xFF0000FF,"Ein Cop hat dir den Zünder abgenommen. Die Bombe ist damit nutzlos und verrotet. Shit happenz!");
- SendClientMessage(playerid,0x00FF00FF,"Du hast dem Spieler den Zünder abgenommen. Die Menschheit ist damit in letzter Sekunde gerettet worden!");
- new objectid=GetPVarInt(pid,"c4object");
- DestroyObject(objectid);
- SetPVarInt(pid,"c4counter",0);
- SetPVarInt(pid,"c4car",2500);
- SetPVarFloat(pid,"c4x",0);
- SetPVarFloat(pid,"c4y",0);
- SetPVarFloat(pid,"c4z",0);
- }
- }
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- switch(dialogid)
- {
- case C4BUYDIALOG:
- {
- if(response)
- {
- new pmoney=GetPlayerMoney(playerid);
- if(pmoney<c4price) //GELDCHECK
- {
- SendClientMessage(playerid,0xFF0000FF,"Du Flachzange hast nicht genug Geld dabei...wolltest mich bescheißen, wa? Nich mit mir!");
- new Float:phealth;
- GetPlayerHealth(playerid,phealth);
- SetPlayerHealth(playerid,phealth-30.0);
- return 1;
- }
- if(GetPVarInt(playerid,"c4counter")!=0)
- return SendClientMessage(playerid,0xFF0000FF,"Exception 1338. Lauf solange du noch kannst...");
- SendClientMessage(playerid,0x00FF00FF,"Okay, hier ist das gute Stück...viel Spaß!");
- GivePlayerMoney(playerid,-c4price);
- }
- }
- case C4LICDIALOG:
- {
- if(response)
- {
- SendClientMessage(playerid,0x00FF00FF,"Du hast die C4 unterm Sitz versteckt. Sie ist SCHARF! Benutz den /c4zuenden, damits Puff macht!");
- SetPVarInt(playerid,"c4counter",2);
- SetPVarInt(playerid,"c4car",GetPlayerVehicleID(playerid));
- }
- }
- }
- return 0;
- }
- stock Float:Distance(Float:x1, Float:y1, Float:z1, Float:x2, Float:y2, Float:z2)
- {
- new Float:result = floatsqroot(floatpower(floatsub(x2,x1),2)+floatpower(floatsub(y2,y1),2)+floatpower(floatsub(z2,z1),2));
- return result;
- }
- stock GetXYInFrontOfPlayer(playerid, &Float:x2, &Float:y2, Float:distance)
- {
- new Float:a;
- GetPlayerPos(playerid, x2, y2, a);
- GetPlayerFacingAngle(playerid, a);
- if(GetPlayerVehicleID(playerid))
- {
- GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
- }
- x2 += (distance * floatsin(-a, degrees));
- y2 += (distance * floatcos(-a, degrees));
- }
- /*----------------------------------------------------------------------------*-
- Function:
- sscanf
- Params:
- string[] - String to extract parameters from.
- format[] - Parameter types to get.
- {Float,_}:... - Data return variables.
- Return:
- 0 - Successful, not 0 - fail.
- Notes:
- A fail is either insufficient variables to store the data or insufficient
- data for the format string - excess data is disgarded.
- A string in the middle of the input data is extracted as a single word, a
- string at the end of the data collects all remaining text.
- The format codes are:
- c - A character.
- d, i - An integer.
- h, x - A hex number (e.g. a colour).
- f - A float.
- s - A string.
- z - An optional string.
- pX - An additional delimiter where X is another character.
- '' - Encloses a litteral string to locate.
- u - User, takes a name, part of a name or an id and returns the id if they're connected.
- Now has IsNumeric integrated into the code.
- Added additional delimiters in the form of all whitespace and an
- optioanlly specified one in the format string.
- -*----------------------------------------------------------------------------*/
- 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;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement