Advertisement
Guest User

Opas Objectstreamer

a guest
Mar 13th, 2010
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.00 KB | None | 0 0
  1. /****************************************
  2.  
  3. ####### ######## ########
  4. # # # # # #
  5. # # # # # #
  6. # # # # # # #####
  7. # # ######## ######## #
  8. # # # # # #####
  9. # # # # # #
  10. ####### # # # #####
  11.  
  12. >> OBJECTSTREAMER <<
  13. >> VERSION 3.0.0 <<
  14. >> STREAM ENGINE FS <<
  15.  
  16. ****************************************/
  17. #define MAX_STREAMOBJ 2000 //Maximum Objects (Total)
  18. #define MAX_SLOTS 500 //Your Player Slots
  19. #define WARNING_COLOR 0xBBBBBBFF //Color Code
  20. #define LABEL_COLOR 0xBBBBBBFF //Color Code
  21. #define LABEL_COLOR2 0x00FF00FF //Color Code (Used while editing objects)
  22. #define DIALOG_ID 8072 //Should not be used in other Scripts
  23. #define DIALOG_ID2 8073 //Should not be used in other Scripts
  24. #define DIALOG_ID3 8074 //Should not be used in other Scripts
  25. #define DIALOG_ID4 8075 //Should not be used in other Scripts
  26. #define DIALOG_ID5 8076 //Should not be used in other Scripts
  27. #define DIALOG_ID6 8077 //Should not be used in other Scripts
  28. #define DIALOG_ID7 8078 //Should not be used in other Scripts
  29. #define DIALOG_ID8 8079 //Should not be used in other Scripts
  30. #define DIALOG_ID9 8080 //Should not be used in other Scripts
  31. #define DIALOG_ID10 8081 //Should not be used in other Scripts
  32. #define DIALOG_ID11 8082 //Should not be used in other Scripts
  33. #define DIALOG_ID12 8083 //Should not be used in other Scripts
  34. #define DIALOG_ID13 8084 //Should not be used in other Scripts
  35. #define DIALOG_ID14 8085 //Should not be used in other Scripts
  36. #define CONFIG_FILE "opa_objects/opa_objects.cfg" //Your configuration file
  37. #define LOG_FILE "opa_objects/opa_objects.log" //Your log file
  38. #define SAVEOBJ_FILE "opa_objects/savedobjects.txt"//Your file for /saveobj
  39. #define LOG_ACTIVE 1 //logfile On(1)/Off(0)
  40. #define TEXTDRAW 1 //Use a Textdraw while waiting for the map?
  41. #define SEND_WARN 1 //Send Warn-Message to Player?
  42. #define ANTIFAIL 1 //Enable Anti-Config-Fail?
  43. #define CALLBACK 0 //Enable "OnObjectStreamIn"?
  44. #define ROTATE 1 //Enable RotateObject?
  45. /***************************************/
  46. #include <a_samp>
  47. forward test();
  48. forward remoteObject(xx1,Float:xx2,Float:xx3,Float:xx4,Float:xx5,Float:xx6,Float:xx7);
  49. forward remoteVirtual(xx1,xx2);
  50. forward remoteMove(xx1,Float:xx2,Float:xx3,Float:xx4,Float:xx5);
  51. forward remoteSetPos(xx1,Float:xx2,Float:xx3,Float:xx4);
  52. forward remoteSetRot(xx1,Float:xx2,Float:xx3,Float:xx4);
  53. forward remoteDestroy(xx1);
  54. forward remoteStop(xx1);
  55. forward remoteConnectGM();
  56. forward remoteConnectFS();
  57. forward remoteMakeWait(playerid);
  58. forward remoteObjectEx();
  59. forward remoteDestroyEx();
  60. forward remoteIsStreamed(xx1,xx2);
  61. forward remoteGetPos(xx1,&Float:xx2,&Float:xx3,&Float:xx4);
  62. forward remoteGetRot(xx1,&Float:xx2,&Float:xx3,&Float:xx4);
  63. forward remoteGetModel(xx1,&xx2);
  64. forward remoteGetVw(xx1,&xx2);
  65. new obj,DRAW_DISTANCE=125,MAXPLAYEROBJ=254,kill,timeT=948;
  66. enum oen{mod,Float:x,Float:y,Float:z,Float:rx,Float:ry,Float:rz,vw};
  67. new p[MAX_SLOTS][MAX_STREAMOBJ],o[MAX_STREAMOBJ][oen],bool:invalid[MAX_STREAMOBJ];
  68. new bool:warn[MAX_SLOTS],bool:wait[MAX_SLOTS],crash[MAX_SLOTS],admin=-1;
  69. new PlayerText3D:noob[MAX_STREAMOBJ],edit=-1,step=5,exobjects;
  70. new olist[10],anfang,bool:nichtnochmal,lastfile[50];
  71. #if ROTATE==1
  72. new Float:moveStep[MAX_STREAMOBJ][3],moveTime[MAX_STREAMOBJ],moveTimer[MAX_STREAMOBJ];
  73. forward mo(lol);
  74. forward remoteMoveRot(xx1,Float:xx2,Float:xx3,Float:xx4,xx5);
  75. #endif
  76. #if TEXTDRAW==1
  77. forward hideText(playerid);
  78. new Text:Textdraw0,Text:Textdraw1;
  79. #endif
  80. #define DINI_MAX_STRING 255
  81. #define dcmd(%1,%2,%3) if ((strcmp((%3)[1], #%1, true, (%2)) == 0) && ((((%3)[(%2) + 1] == 0) && (dcmd_%1(playerid, "")))||(((%3)[(%2) + 1] == 32) && (dcmd_%1(playerid, (%3)[(%2) + 2]))))) return 1
  82. public OnFilterScriptInit()
  83. {
  84. print("\n...Opas Objectstremer loading [1/2]...\n");
  85. #if LOG_ACTIVE==1
  86. if(!fexist(LOG_FILE))
  87. {
  88. new File:ffhandle=fopen(LOG_FILE,io_write);
  89. fclose(ffhandle);
  90. }
  91. #endif
  92. log("Starting streamer...");
  93. for(new n;n<MAX_OBJECTS;n++)o[n][vw]=-1;
  94. if(fexist(CONFIG_FILE))
  95. {
  96. new xz=strval(dini_Get(CONFIG_FILE,"drawdistance"));
  97. #if ANTIFAIL==1
  98. if(xz<5||xz>400)
  99. {
  100. log("[Antifail] drawdistance should be 5-400");
  101. xz=125;
  102. }
  103. #endif
  104. DRAW_DISTANCE=xz;
  105. xz=strval(dini_Get(CONFIG_FILE,"maxplayerobj"));
  106. #if ANTIFAIL==1
  107. if(xz<1||xz>254)
  108. {
  109. log("[Antifail] maxplayerobj should be 1-254");
  110. xz=254;
  111. }
  112. #endif
  113. MAXPLAYEROBJ=xz;
  114. xz=strval(dini_Get(CONFIG_FILE,"timer"));
  115. #if ANTIFAIL==1
  116. if(xz<200||xz>3500)
  117. {
  118. log("[Antifail] timer should be 200-3500");
  119. xz=948;
  120. }
  121. #endif
  122. timeT=xz;
  123. xz=strval(dini_Get(CONFIG_FILE,"step"));
  124. #if ANTIFAIL==1
  125. if(xz<1||xz>100)
  126. {
  127. log("[Antifail] step should be 1-100");
  128. xz=5;
  129. }
  130. #endif
  131. step=xz;
  132. }
  133. kill=SetTimer("test",timeT,1);
  134. #if TEXTDRAW==1
  135. Textdraw0 = TextDrawCreate(307.000000,181.000000,"~n~LOADING MAP...~n~PLEASE WAIT~n~_");
  136. TextDrawUseBox(Textdraw0,1);
  137. TextDrawBoxColor(Textdraw0,0x00000066);
  138. TextDrawTextSize(Textdraw0,0.000000,131.000000);
  139. TextDrawAlignment(Textdraw0,2);
  140. TextDrawBackgroundColor(Textdraw0,0xff000033);
  141. TextDrawFont(Textdraw0,1);
  142. TextDrawLetterSize(Textdraw0,0.299999,1.100000);
  143. TextDrawColor(Textdraw0,0xffffffff);
  144. TextDrawSetOutline(Textdraw0,1);
  145. TextDrawSetProportional(Textdraw0,1);
  146. TextDrawSetShadow(Textdraw0,1);
  147. Textdraw1 = TextDrawCreate(307.000000,181.000000,"~n~LOADING MAP...~n~DONE~n~_");
  148. TextDrawUseBox(Textdraw1,1);
  149. TextDrawBoxColor(Textdraw1,0x00000066);
  150. TextDrawTextSize(Textdraw1,0.000000,131.000000);
  151. TextDrawAlignment(Textdraw1,2);
  152. TextDrawBackgroundColor(Textdraw1,0x00ff0033);
  153. TextDrawFont(Textdraw1,1);
  154. TextDrawLetterSize(Textdraw1,0.299999,1.100000);
  155. TextDrawColor(Textdraw1,0xffffffff);
  156. TextDrawSetOutline(Textdraw1,1);
  157. TextDrawSetProportional(Textdraw1,1);
  158. TextDrawSetShadow(Textdraw1,1);
  159. #endif
  160. log("Successfully started!");
  161. return 1;
  162. }
  163. public OnFilterScriptExit()
  164. {
  165. fsexit();
  166. return 1;
  167. }
  168. public OnGameModeExit()
  169. {
  170. fsexit();
  171. SendRconCommand("reloadfs opa_objects");
  172. return 1;
  173. }
  174. stock fsexit()
  175. {
  176. for(new i;i<MAX_SLOTS;i++)
  177. {
  178. if(IsPlayerConnected(i))
  179. {
  180. for(new n;n<obj;n++)
  181. {
  182. if(p[i][n]!=0)DestroyPlayerObject(i,p[i][n]);
  183. }
  184. }
  185. }
  186. settings();
  187. KillTimer(kill);
  188. CallRemoteFunction("remoteExit","");
  189. }
  190. settings()
  191. {
  192. if(!fexist(CONFIG_FILE))
  193. {
  194. new File:ffhandle=fopen(CONFIG_FILE,io_write);
  195. fclose(ffhandle);
  196. }
  197. new stt[120];
  198. format(stt,sizeof stt,"%d",DRAW_DISTANCE);
  199. dini_Set(CONFIG_FILE,"drawdistance",stt);
  200. format(stt,sizeof stt,"%d",((!exobjects)?(MAXPLAYEROBJ):((MAXPLAYEROBJ+exobjects>254)?(254):(MAXPLAYEROBJ+exobjects))));
  201. dini_Set(CONFIG_FILE,"maxplayerobj",stt);
  202. format(stt,sizeof stt,"%d",timeT);
  203. dini_Set(CONFIG_FILE,"timer",stt);
  204. format(stt,sizeof stt,"%d",step);
  205. dini_Set(CONFIG_FILE,"step",stt);
  206. }
  207. public remoteIsStreamed(xx1,xx2)
  208. {
  209. if(!p[xx2][xx1])return 0;
  210. return 1;
  211. }
  212. public OnPlayerCommandText(playerid,cmdtext[])
  213. {
  214. if(!strcmp(cmdtext,"/streamer",true))
  215. {
  216. if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,WARNING_COLOR,"You are not an Admin!");
  217. return mainmenu(playerid);
  218. }
  219. if(!strcmp(cmdtext,"/olist",true))
  220. {
  221. if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,WARNING_COLOR,"You are not an Admin!");
  222. if(admin!=playerid)return SendClientMessage(playerid,WARNING_COLOR,"You have not activated the Mapeditor!");
  223. return objfile(lastfile);
  224. }
  225. dcmd(object,6,cmdtext);
  226. dcmd(saveobj,7,cmdtext);
  227. return 0;
  228. }
  229. explode(const strsrc[], strdest[][], delimiter)
  230. {
  231. new li,aNum,len;
  232. for(new i;i<=strlen(strsrc);i++)if(strsrc[i]==delimiter||i==strlen(strsrc))
  233. {
  234.  
  235. len=strmid(strdest[aNum],strsrc,li,i,128);
  236. strdest[aNum][len]=0;
  237. li=i+1;
  238. aNum++;
  239. }
  240. return 1;
  241. }
  242. objfile(filenamex[])
  243. {
  244. new filename[50];
  245. format(filename,sizeof filename,"opa_objects/modelid/%s",filenamex);
  246. if(admin==-1)return 0;
  247. #define strlim 1024
  248. new dtxt[strlim];
  249. if(!fexist(filename))return 0;
  250. new File:xd=fopen(filename,io_read),zeile[100],zeila[2][100],i;
  251. for(;;)
  252. {
  253. fread(xd,zeile);
  254. if(i<anfang)
  255. {
  256. i++;
  257. continue;
  258. }
  259. if(!strlen(zeile))
  260. {
  261. nichtnochmal=true;
  262. break;
  263. }
  264. explode(zeile,zeila,'|');
  265. olist[i-anfang]=strval(zeila[0]);
  266. if(i!=anfang)format(dtxt,sizeof dtxt,"%s\n%s",dtxt,zeila[1]);
  267. else format(dtxt,sizeof dtxt,"%s",zeila[1]);
  268. i++;
  269. if(i==anfang+10)break;
  270. }
  271. anfang+=10;
  272. ShowPlayerDialog(admin,DIALOG_ID12,DIALOG_STYLE_LIST,"Opas Objectstreamer - Create Object",dtxt,"Create","Next page");
  273. fclose(xd);
  274. format(lastfile,sizeof lastfile,filenamex);
  275. return 1;
  276. }
  277. #if ROTATE==1
  278. public remoteMoveRot(xx1,Float:xx2,Float:xx3,Float:xx4,xx5)
  279. {
  280. if(moveTime[xx1]!=0)return 0;
  281. if(xx5%50!=0)return 0;
  282. moveTime[xx1]=xx5/50;
  283. moveStep[xx1][0]=(xx2-o[xx1][rx])/moveTime[xx1];
  284. moveStep[xx1][1]=(xx3-o[xx1][ry])/moveTime[xx1];
  285. moveStep[xx1][2]=(xx4-o[xx1][rz])/moveTime[xx1];
  286. moveTimer[xx1]=SetTimerEx("mo",50,1,"d",xx1);
  287. return 1;
  288. }
  289. public mo(lol)
  290. {
  291. remoteSetRot(lol,o[lol][rx]+moveStep[lol][0],o[lol][ry]+moveStep[lol][1],o[lol][rz]+moveStep[lol][2]);
  292. moveTime[lol]--;
  293. if(!moveTime[lol])
  294. {
  295. KillTimer(moveTimer[lol]);
  296. moveTimer[lol]=0;
  297. moveStep[lol][0]=0;
  298. moveStep[lol][1]=0;
  299. moveStep[lol][2]=0;
  300. }
  301. }
  302. #endif
  303. dcmd_saveobj(playerid,prm[])
  304. {
  305. if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,WARNING_COLOR,"You are not an Admin!");
  306. if(admin!=playerid)return SendClientMessage(playerid,WARNING_COLOR,"You have not activated the Mapeditor!");
  307. new i,com[40];
  308. if(sscanf(prm,"dz",i,com))return SendClientMessage(playerid,WARNING_COLOR,"/saveobj [objectid] [comment]");
  309. if(i>=MAX_STREAMOBJ||invalid[i]||i<0)return SendClientMessage(playerid,WARNING_COLOR,"Invalid objectid!");
  310. if(!fexist(SAVEOBJ_FILE))
  311. {
  312. new File:ffhandle=fopen(SAVEOBJ_FILE,io_write);
  313. fclose(ffhandle);
  314. }
  315. new File:log2=fopen(SAVEOBJ_FILE,io_append);
  316. if(!log2)return SendClientMessage(playerid,WARNING_COLOR,"Failed saving");
  317. new ostr[300];
  318. format(ostr,sizeof ostr,"CreateObject(%d,%f,%f,%f,%f,%f,%f,%d);//%s\r\n",o[i][mod],o[i][x],o[i][y],o[i][z],o[i][rx],o[i][ry],o[i][rz],o[i][vw],com);
  319. fwrite(log2,ostr);
  320. fclose(log2);
  321. new send[128];
  322. if(!strlen(com))format(send,sizeof send,"Object %d saved",i);
  323. else format(send,sizeof send,"Object %d saved [%s]",i,com);
  324. return SendClientMessage(playerid,WARNING_COLOR,send);
  325. }
  326. mainmenu(playerid)
  327. {
  328. new inf[270],infoon[8];
  329. if(playerid==admin)format(infoon,sizeof infoon,"On");
  330. else if(admin!=-1)format(infoon,sizeof infoon,"In Use");
  331. else format(infoon,sizeof infoon,"Off");
  332. format(inf,sizeof inf,"Drawdistance: %d\nAnti-Crash warns: %d\nMaximum PlayerObjects: %d\nTimer: %d ms\nMapditor: %s\nSave Configuration\nSave Map...\nCreate Object here (Enter ID)\nCreate Object here (Objectlist)\nUtilization: Players:[%d%%] Server:[%d%%] Timer:[%d]\nInfo",DRAW_DISTANCE,allwarns(),MAXPLAYEROBJ,timeT,infoon,effort(),seffort(),teff());
  333. return ShowPlayerDialog(playerid,DIALOG_ID,DIALOG_STYLE_LIST,"Opas Objectstreamer",inf,"OK","Finish");
  334. }
  335. effort()
  336. {
  337. new Float:pro,pcount;
  338. for(new i;i<MAX_SLOTS;i++)if(IsPlayerConnected(i)&&!IsPlayerNPC(i))for(new n;n<obj;n++)if(p[i][n]!=0)pro++;
  339. for(new i;i<MAX_SLOTS;i++)if(IsPlayerConnected(i)&&!IsPlayerNPC(i))pcount++;
  340. pro=floatdiv(pro,pcount);
  341. new Float:tester=floatdiv(MAXPLAYEROBJ,100);
  342. pro=floatdiv(pro,tester);
  343. return floatround(pro);
  344. }
  345. seffort()
  346. {
  347. new pro,pcount,worst;
  348. for(new i;i<MAX_SLOTS;i++)if(IsPlayerConnected(i)&&!IsPlayerNPC(i))pcount++;
  349. pro=pcount*obj;
  350. worst=MAX_STREAMOBJ*MAX_SLOTS;
  351. new Float:ret=floatdiv(1,floatdiv(worst,pro));
  352. ret=ret*100;
  353. return floatround(ret);
  354. }
  355. teff()
  356. {
  357. new pcount;
  358. for(new i;i<MAX_SLOTS;i++)if(IsPlayerConnected(i)&&!IsPlayerNPC(i))pcount++;
  359. return pcount*obj;
  360. }
  361. dcmd_object(playerid,prm[])
  362. {
  363. if(!IsPlayerAdmin(playerid))return SendClientMessage(playerid,WARNING_COLOR,"You are not an Admin!");
  364. if(admin!=playerid)return SendClientMessage(playerid,WARNING_COLOR,"You have not activated the Mapeditor!");
  365. new objid;
  366. if(sscanf(prm,"d",objid))return SendClientMessage(playerid,WARNING_COLOR,"/object [objectid]");
  367. if(objid>=obj||invalid[objid]||objid<0)return SendClientMessage(playerid,WARNING_COLOR,"Invalid objectid!");
  368. return showobject(playerid,objid);
  369. }
  370. showobject(playerid,oid)
  371. {
  372. new title[100],lol2[320];
  373. format(title,sizeof title,"Opas Objectstreamer - Object %d",oid);
  374. format(lol2,sizeof lol2,"World: %d\nX: %f\nY: %f\nZ: %f\nDelete",o[oid][vw],o[oid][x],o[oid][y],o[oid][z]);
  375. edit=oid;
  376. keep(edit);
  377. return ShowPlayerDialog(playerid,DIALOG_ID6,DIALOG_STYLE_LIST,title,lol2,"Change...","Done");
  378. }
  379. showposdia()
  380. {
  381. new dfg[300];
  382. format(dfg,sizeof dfg,"X +\nX -\nY +\nY -\nZ +\nZ -\nRotation\n-----------------\nStep: %d\nFaster\nSlower",step);
  383. return ShowPlayerDialog(admin,DIALOG_ID8,DIALOG_STYLE_LIST,"Opas Objectstreamer - Change Position",dfg,"OK","Done");
  384. }
  385. public OnDialogResponse(playerid,dialogid,response,listitem,inputtext[])
  386. {
  387. if(IsPlayerAdmin(playerid))
  388. {
  389. if(dialogid==DIALOG_ID&&response)
  390. {
  391. switch(listitem)
  392. {
  393. case 0:ShowPlayerDialog(playerid,DIALOG_ID2,DIALOG_STYLE_INPUT,"Opas Objectstreamer - Change Drawdistance","Enter a Number between 5 and 400","OK","Cancel");
  394. case 1:
  395. {
  396. new inf[400],name[MAX_PLAYER_NAME],Float:f[3],did;
  397. for(new i;i<MAX_SLOTS;i++)if(warn[i])
  398. {
  399. GetPlayerName(playerid,name,sizeof name);
  400. GetPlayerPos(playerid,f[0],f[1],f[2]);
  401. did=1;
  402. format(inf,sizeof inf,"%s%s[%d]: %.2f %.2f %.2f\n",inf,name,i,f[0],f[1],f[2]);
  403. }
  404. if(!did)format(inf,sizeof inf,"No player is warned");
  405. ShowPlayerDialog(playerid,DIALOG_ID3,DIALOG_STYLE_LIST,"Opas Objectstreamer - Warned Players",inf,"OK","Reset");
  406. }
  407. case 2:
  408. {
  409. new xt1[450];
  410. format(xt1,sizeof xt1,"Change Maximum PlayerObjects\n\nSamp Maximum:\t254\nGlobal Objects:\t%d\n-----------------------------------------\nBest:\t\t\t%d\nYour Setting:\t\t%d",exobjects,254-exobjects,MAXPLAYEROBJ);
  411. ShowPlayerDialog(playerid,DIALOG_ID4,DIALOG_STYLE_INPUT,"Opas Objectstreamer",xt1,"OK","Cancel");
  412. }
  413. case 3:ShowPlayerDialog(playerid,DIALOG_ID5,DIALOG_STYLE_INPUT,"Opas Objectstreamer - Change Timer Time","Enter a Number between 200 and 3500 ms","OK","Cancel");
  414. case 4:
  415. {
  416. if(admin==-1)
  417. {
  418. login(playerid);
  419. SendClientMessage(playerid,WARNING_COLOR,"Mapeditor enabled");
  420. }
  421. else if(admin==playerid)
  422. {
  423. logout();
  424. SendClientMessage(playerid,WARNING_COLOR,"Mapeditor disabled");
  425. }
  426. else
  427. {
  428. new ooo[128],nnng[MAX_PLAYER_NAME];
  429. GetPlayerName(admin,nnng,sizeof nnng);
  430. format(ooo,sizeof ooo,"Cannot load Mapeditor, %s has already activated it",nnng);
  431. SendClientMessage(playerid,WARNING_COLOR,ooo);
  432. }
  433. }
  434. case 5:
  435. {
  436. settings();
  437. SendClientMessage(playerid,WARNING_COLOR,"Configuration Saved");
  438. }
  439. case 6:ShowPlayerDialog(playerid,DIALOG_ID10,DIALOG_STYLE_INPUT,"Opas Objectstreamer - Save Map","Enter the filename\nMap will be saved as filename.txt","OK","Cancel");
  440. case 7:ShowPlayerDialog(playerid,DIALOG_ID9,DIALOG_STYLE_INPUT,"Opas Objectstreamer - Create Object here","Enter the modelid","OK","Cancel");
  441. case 8:
  442. {
  443. ShowPlayerDialog(playerid,DIALOG_ID11,DIALOG_STYLE_LIST,"Opas Objectstreamer - Create Object here","Weapons.txt\nNature.txt\nFun Stuff.txt\nBarriers.txt\nVarious.txt\nVarious II.txt\nVarious III.txt\nMisc.txt\nMisc II.txt\nOpen by name...","OK","Cancel");
  444. }
  445. case 10:ShowPlayerDialog(playerid,DIALOG_ID14,DIALOG_STYLE_LIST,"Opas Objectstreamer - Info","Script by KleinerOpa\n/streamer => Mainmenu\n/olist => Display the last Objectlist again\n/object [id] => Edit the object\n/saveobj => Save the object\nBugs? Need help? PM me in the forum","OK","Back");
  446. }
  447. return 1;
  448. }
  449. else if(dialogid==DIALOG_ID2)
  450. {
  451. if(!response)return mainmenu(playerid);
  452. new val=strval(inputtext);
  453. if(val<5||val>400)return SendClientMessage(playerid,WARNING_COLOR,"Error: Has to be between 5 and 400");
  454. DRAW_DISTANCE=val;
  455. new str[128];
  456. format(str,sizeof str,"New Drawdistance: %d",DRAW_DISTANCE);
  457. return SendClientMessage(playerid,WARNING_COLOR,str);
  458. }
  459. else if(dialogid==DIALOG_ID3&&!response)
  460. {
  461. for(new u;u<MAX_SLOTS;u++)warn[u]=false;
  462. return SendClientMessage(playerid,WARNING_COLOR,"Warnings deleted");
  463. }
  464. else if(dialogid==DIALOG_ID4)
  465. {
  466. if(!response)return mainmenu(playerid);
  467. new val=strval(inputtext);
  468. if(val<1||val>254-exobjects)
  469. {
  470. new xt1[128];
  471. format(xt1,sizeof xt1,"Error: Has to be between 1 and %d",254-exobjects);
  472. return SendClientMessage(playerid,WARNING_COLOR,xt1);
  473. }
  474. MAXPLAYEROBJ=val;
  475. new str[128];
  476. format(str,sizeof str,"New Maximum PlayerObjects: %d",MAXPLAYEROBJ);
  477. return SendClientMessage(playerid,WARNING_COLOR,str);
  478. }
  479. else if(dialogid==DIALOG_ID5)
  480. {
  481. if(!response)return mainmenu(playerid);
  482. new val=strval(inputtext);
  483. if(val<200||val>3500)return SendClientMessage(playerid,WARNING_COLOR,"Error: Has to be between 200 and 3500");
  484. timeT=val;
  485. KillTimer(kill);
  486. kill=SetTimer("test",timeT,1);
  487. new str[128];
  488. format(str,sizeof str,"New Timer Time: %d",timeT);
  489. return SendClientMessage(playerid,WARNING_COLOR,str);
  490. }
  491. else if(dialogid==DIALOG_ID6)
  492. {
  493. if(!response)
  494. {
  495. new fi=edit;
  496. edit=-1;
  497. keep(fi);
  498. return 1;
  499. }
  500. switch(listitem)
  501. {
  502. case 0:
  503. {
  504. ShowPlayerDialog(playerid,DIALOG_ID7,DIALOG_STYLE_INPUT,"Opas Objectstreamer - Change Virtualworld","Enter the new World","OK","Cancel");
  505. }
  506. case 1,2,3:
  507. {
  508. showposdia();
  509. }
  510. case 4:
  511. {
  512. remoteDestroy(edit);
  513. SendClientMessage(playerid,WARNING_COLOR,"Object Destroyed");
  514. edit=-1;
  515. }
  516. }
  517. return 1;
  518. }
  519. else if(dialogid==DIALOG_ID7)
  520. {
  521. if(!response)return showobject(playerid,edit);
  522. new val=strval(inputtext);
  523. if(val<-1)return SendClientMessage(playerid,WARNING_COLOR,"Error: Has to be between -1 and ...");
  524. remoteVirtual(edit,val);
  525. return showobject(playerid,edit);
  526. }
  527. else if(dialogid==DIALOG_ID8)
  528. {
  529. if(!response)return showobject(playerid,edit);
  530. new Float:step10=step/10.0;
  531. switch(listitem)
  532. {
  533. case 0:remoteSetPos(edit,o[edit][x]+step10,o[edit][y],o[edit][z]);
  534. case 1:remoteSetPos(edit,o[edit][x]-step10,o[edit][y],o[edit][z]);
  535. case 2:remoteSetPos(edit,o[edit][x],o[edit][y]+step10,o[edit][z]);
  536. case 3:remoteSetPos(edit,o[edit][x],o[edit][y]-step10,o[edit][z]);
  537. case 4:remoteSetPos(edit,o[edit][x],o[edit][y],o[edit][z]+step10);
  538. case 5:remoteSetPos(edit,o[edit][x],o[edit][y],o[edit][z]-step10);
  539. case 6:
  540. {
  541. new Float:lol;
  542. GetPlayerFacingAngle(playerid,lol);
  543. remoteSetRot(edit,o[edit][rx],o[edit][ry],lol);
  544. }
  545. case 9:step++;
  546. case 10:step--;
  547. }
  548. return showposdia();
  549. }
  550. else if(dialogid==DIALOG_ID9)
  551. {
  552. if(!response)return mainmenu(playerid);
  553. new val=strval(inputtext);
  554. if(val<1)return ShowPlayerDialog(playerid,DIALOG_ID9,DIALOG_STYLE_INPUT,"Opas Objectstreamer - Create Object here","Enter the modelid\n[[Enter a valid ID!]]","OK","Cancel");
  555. new Float:lol[4];
  556. GetPlayerPos(playerid,lol[0],lol[1],lol[2]);
  557. GetPlayerFacingAngle(playerid,lol[3]);
  558. new fish1=remoteObject(val,lol[0],lol[1],lol[2],0.0,0.0,lol[3]);
  559. if(!fish1)SendClientMessage(playerid,WARNING_COLOR,"Failed to create object");
  560. else
  561. {
  562. new rr[128];
  563. format(rr,sizeof rr,"Object %d created",obj-1);
  564. SendClientMessage(playerid,WARNING_COLOR,rr);
  565. }
  566. return mainmenu(playerid);
  567. }
  568. else if(dialogid==DIALOG_ID10)
  569. {
  570. if(!response)return mainmenu(playerid);
  571. new filen[65];
  572. format(filen,sizeof filen,"%s.txt",inputtext);
  573. if(fexist(filen))return SendClientMessage(playerid,WARNING_COLOR,"Error: this file already exists");
  574. new zeile[300];
  575. new File:bob=fopen(filen,io_write);
  576. if(!bob)
  577. {
  578. new gold1[128];
  579. format(gold1,sizeof gold1,"Mapfile [%s]: saving failed",filen);
  580. log(gold1);
  581. return SendClientMessage(playerid,WARNING_COLOR,gold1);
  582. }
  583. new lolh[120],wname[MAX_PLAYER_NAME],date[3];
  584. GetPlayerName(playerid,wname,sizeof wname);
  585. getdate(date[0],date[1],date[2]);
  586. format(lolh,sizeof lolh,"//Created with Opas Objectstreamer\r\n//%d.%d.%d by %s",date[2],date[1],date[0],wname);
  587. fwrite(bob,lolh);
  588. for(new i;i<obj;i++)if(!invalid[i])
  589. {
  590. format(zeile,sizeof zeile,"\r\nCreateObject(%d,%f,%f,%f,%f,%f,%f,%d);//%d",o[i][mod],o[i][x],o[i][y],o[i][z],o[i][rx],o[i][ry],o[i][rz],o[i][vw],i);
  591. fwrite(bob,zeile);
  592. }
  593. fclose(bob);
  594. new gold[128];
  595. format(gold,sizeof gold,"Saved mapfile [%s]",filen);
  596. log(gold);
  597. return SendClientMessage(playerid,WARNING_COLOR,gold);
  598. }
  599. else if(dialogid==DIALOG_ID11)
  600. {
  601. if(!response)return mainmenu(playerid);
  602. if(admin!=playerid)return SendClientMessage(playerid,WARNING_COLOR,"You have not activated the Mapeditor");
  603. new fxx[50],bool:self;
  604. switch(listitem)
  605. {
  606. case 0:fxx="Weapons.txt";
  607. case 1:fxx="Nature.txt";
  608. case 2:fxx="Fun Stuff.txt";
  609. case 3:fxx="Barriers.txt";
  610. case 4:fxx="Various.txt";
  611. case 5:fxx="Various II.txt";
  612. case 6:fxx="Various III.txt";
  613. case 7:fxx="Misc.txt";
  614. case 8:fxx="Misc II.txt";
  615. case 9:self=true;
  616. }
  617. if(self)return ShowPlayerDialog(playerid,DIALOG_ID13,DIALOG_STYLE_INPUT,"Opas Objectstreamer","Enter the filename\nDon't forget the extension!","OK","Cancel");
  618. objfile(fxx);
  619. return 1;
  620. }
  621. else if(dialogid==DIALOG_ID13)
  622. {
  623. if(!response)return mainmenu(playerid);
  624. if(!objfile(inputtext))return ShowPlayerDialog(playerid,DIALOG_ID13,DIALOG_STYLE_INPUT,"Opas Objectstreamer","Enter the filename\nDon't forget the extension!\n[[Error: That file doesn't exists!]]","OK","Cancel");
  625. return 1;
  626. }
  627. else if(dialogid==DIALOG_ID12)
  628. {
  629. if(!response)
  630. {
  631. if(!nichtnochmal)objfile(lastfile);
  632. else
  633. {
  634. nichtnochmal=false;
  635. anfang=0;
  636. }
  637. return 1;
  638. }
  639. nichtnochmal=false;
  640. anfang=0;
  641. new Float:lol[4];
  642. GetPlayerPos(playerid,lol[0],lol[1],lol[2]);
  643. GetPlayerFacingAngle(playerid,lol[3]);
  644. new fish1=remoteObject(olist[listitem],lol[0],lol[1],lol[2],0.0,0.0,lol[3]);
  645. if(!fish1)SendClientMessage(playerid,WARNING_COLOR,"Failed to create object");
  646. else
  647. {
  648. new rr[128];
  649. format(rr,sizeof rr,"Object %d created",obj-1);
  650. SendClientMessage(playerid,WARNING_COLOR,rr);
  651. }
  652. return 1;
  653. }
  654. else if(dialogid==DIALOG_ID14)return mainmenu(playerid);
  655. return 1;
  656. }
  657. return 0;
  658. }
  659. login(playerid)
  660. {
  661. admin=playerid;
  662. for(new i;i<obj;i++)if(!invalid[i])
  663. {
  664. new sr[250];
  665. format(sr,sizeof sr,"Object %d\nModel: %d World: %d\n[%.2f|%.2f|%.2f]",i,o[i][mod],o[i][vw],o[i][x],o[i][y],o[i][z]);
  666. noob[i]=CreatePlayer3DTextLabel(playerid,sr,LABEL_COLOR,o[i][x],o[i][y],o[i][z],35.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0);
  667. }
  668. return 1;
  669. }
  670. logout()
  671. {
  672. for(new i;i<obj;i++)if(!invalid[i])
  673. {
  674. DeletePlayer3DTextLabel(admin,noob[i]);
  675. }
  676. admin=-1;
  677. return 1;
  678. }
  679. public test()
  680. {
  681. for(new i;i<MAX_SLOTS;i++)
  682. {
  683. if(!IsPlayerConnected(i)||IsPlayerNPC(i))continue;
  684. for(new n;n<obj;n++)if(!invalid[n])
  685. {
  686. if((IsPlayerInRangeOfPoint(i,DRAW_DISTANCE,o[n][x],o[n][y],o[n][z]))&&((o[n][vw]==-1)||(GetPlayerVirtualWorld(i)==o[n][vw])))
  687. {
  688. if(!p[i][n])
  689. {
  690. if(crash[i]<=MAXPLAYEROBJ)
  691. {
  692. p[i][n]=CreatePlayerObject(i,o[n][mod],o[n][x],o[n][y],o[n][z],o[n][rx],o[n][ry],o[n][rz]);
  693. crash[i]++;
  694. #if CALLBACK==1
  695. CallRemoteFunction("OnObjectStreamIn","dd",i,n);
  696. #endif
  697. }
  698. else if(!warn[i])
  699. {
  700. #if SEND_WARN==1
  701. SendClientMessage(i,WARNING_COLOR,"Warning(opa_objectstreamer): Limit reached");
  702. #endif
  703. sendAdminWarn(i);
  704. warn[i]=true;
  705. }
  706. }
  707. }
  708. else if(p[i][n]!=0)
  709. {
  710. DestroyPlayerObject(i,p[i][n]);
  711. p[i][n]=0;
  712. crash[i]--;
  713. #if CALLBACK==1
  714. CallRemoteFunction("OnObjectStreamOut","dd",i,n);
  715. #endif
  716. }
  717. }
  718. if(wait[i])
  719. {
  720. wait[i]=false;
  721. TogglePlayerControllable(i,1);
  722. #if TEXTDRAW==1
  723. TextDrawHideForPlayer(i,Textdraw0);
  724. TextDrawShowForPlayer(i,Textdraw1);
  725. SetTimerEx("hideText",500,0,"d",i);
  726. #else
  727. GameTextForPlayer(i,"~w~LOADING MAP...~n~~g~DONE",500,6);
  728. #endif
  729. }
  730. }
  731. }
  732. #if TEXTDRAW==1
  733. public hideText(playerid)TextDrawHideForPlayer(playerid,Textdraw1);
  734. #endif
  735. public remoteObjectEx()
  736. {
  737. exobjects++;
  738. MAXPLAYEROBJ--;
  739. }
  740. public remoteDestroyEx()
  741. {
  742. exobjects--;
  743. if(MAXPLAYEROBJ<254)MAXPLAYEROBJ++;
  744. }
  745. allwarns()
  746. {
  747. new ret;
  748. for(new i;i<MAX_SLOTS;i++)if(warn[i])ret++;
  749. return ret;
  750. }
  751. sendAdminWarn(i)
  752. {
  753. new strr[128],namee[MAX_PLAYER_NAME],Float:b[3];
  754. GetPlayerName(i,namee,sizeof namee);
  755. GetPlayerPos(i,b[0],b[1],b[2]);
  756. format(strr,sizeof strr,"Warning(opa_objectstreamer@%s[%d]): Limit reached@%02f|%02f|%02f",namee,i,b[0],b[1],b[2]);
  757. for(new e;e<MAX_SLOTS;e++)if(IsPlayerAdmin(e))SendClientMessage(e,WARNING_COLOR,strr);
  758. format(strr,sizeof strr,"PlayerWarning: %s[%d]|%02f|%02f|%02f\n",namee,i,b[0],b[1],b[2]);
  759. log(strr);
  760. }
  761. keep(objx)
  762. {
  763. if(admin==-1)return 1;
  764. new sr[250];
  765. format(sr,sizeof sr,"Object %d\nModel: %d World: %d\n[%.2f|%.2f|%.2f]",objx,o[objx][mod],o[objx][vw],o[objx][x],o[objx][y],o[objx][z]);
  766. DeletePlayer3DTextLabel(admin,noob[objx]);
  767. if(objx!=edit)noob[objx]=CreatePlayer3DTextLabel(admin,sr,LABEL_COLOR,o[objx][x],o[objx][y],o[objx][z],35.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0);
  768. else noob[objx]=CreatePlayer3DTextLabel(admin,sr,LABEL_COLOR2,o[objx][x],o[objx][y],o[objx][z],35.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0);
  769. return 1;
  770. }
  771. public remoteObject(xx1,Float:xx2,Float:xx3,Float:xx4,Float:xx5,Float:xx6,Float:xx7)
  772. {
  773. if(obj>MAX_STREAMOBJ)return 0;
  774. o[obj][mod]=xx1;
  775. o[obj][x]=xx2;
  776. o[obj][y]=xx3;
  777. o[obj][z]=xx4;
  778. o[obj][rx]=xx5;
  779. o[obj][ry]=xx6;
  780. o[obj][rz]=xx7;
  781. if(admin!=-1)
  782. {
  783. new sr[250];
  784. format(sr,sizeof sr,"Object %d\nModel: %d World: %d\n[%.2f|%.2f|%.2f]",obj,o[obj][mod],o[obj][vw],o[obj][x],o[obj][y],o[obj][z]);
  785. noob[obj]=CreatePlayer3DTextLabel(admin,sr,LABEL_COLOR,o[obj][x],o[obj][y],o[obj][z],35.0,INVALID_PLAYER_ID,INVALID_VEHICLE_ID,0);
  786. }
  787. obj++;
  788. CallRemoteFunction("remoteNumber","d",obj);
  789. return 1;
  790. }
  791. public remoteVirtual(xx1,xx2)
  792. {
  793. o[xx1][vw]=xx2;
  794. keep(xx1);
  795. return 1;
  796. }
  797. public remoteMove(xx1,Float:xx2,Float:xx3,Float:xx4,Float:xx5)
  798. {
  799. for(new i;i<MAX_SLOTS;i++)
  800. {
  801. if(p[i][xx1]!=0)
  802. {
  803. MovePlayerObject(i,p[i][xx1],xx2,xx3,xx4,xx5);
  804. }
  805. }
  806. o[xx1][x]=xx2;
  807. o[xx1][y]=xx3;
  808. o[xx1][z]=xx4;
  809. keep(xx1);
  810. return 1;
  811. }
  812. public remoteSetPos(xx1,Float:xx2,Float:xx3,Float:xx4)
  813. {
  814. for(new i;i<MAX_SLOTS;i++)
  815. {
  816. if(p[i][xx1]!=0)
  817. {
  818. SetPlayerObjectPos(i,p[i][xx1],xx2,xx3,xx4);
  819. }
  820. }
  821. o[xx1][x]=xx2;
  822. o[xx1][y]=xx3;
  823. o[xx1][z]=xx4;
  824. keep(xx1);
  825. return 1;
  826. }
  827. public remoteSetRot(xx1,Float:xx2,Float:xx3,Float:xx4)
  828. {
  829. for(new i;i<MAX_SLOTS;i++)
  830. {
  831. if(p[i][xx1]!=0)
  832. {
  833. SetPlayerObjectRot(i,p[i][xx1],xx2,xx3,xx4);
  834. }
  835. }
  836. o[xx1][rx]=xx2;
  837. o[xx1][ry]=xx3;
  838. o[xx1][rz]=xx4;
  839. keep(xx1);
  840. return 1;
  841. }
  842. public remoteDestroy(xx1)
  843. {
  844. for(new i;i<MAX_SLOTS;i++)
  845. {
  846. if(p[i][xx1]!=0)
  847. {
  848. DestroyPlayerObject(i,p[i][xx1]);
  849. p[i][xx1]=0;
  850. crash[i]--;
  851. }
  852. }
  853. o[xx1][mod]=0;
  854. o[xx1][x]=0;
  855. o[xx1][y]=0;
  856. o[xx1][z]=0;
  857. o[xx1][rx]=0;
  858. o[xx1][ry]=0;
  859. o[xx1][rz]=0;
  860. o[xx1][vw]=-1;
  861. invalid[xx1]=true;
  862. if(admin!=-1)
  863. {
  864. DeletePlayer3DTextLabel(admin,noob[xx1]);
  865. }
  866. return 1;
  867. }
  868. public remoteStop(xx1)
  869. {
  870. for(new i;i<MAX_SLOTS;i++)
  871. {
  872. if(p[i][xx1]!=0)
  873. {
  874. StopPlayerObject(i,p[i][xx1]);
  875. }
  876. }
  877. }
  878. public remoteConnectGM()log("Gamemode Connected!");
  879. public remoteConnectFS()log("Filterscript Connected!");
  880. public remoteMakeWait(playerid)
  881. {
  882. if(wait[playerid])return 0;
  883. TogglePlayerControllable(playerid,0);
  884. wait[playerid]=true;
  885. #if TEXTDRAW==1
  886. TextDrawShowForPlayer(playerid,Textdraw0);
  887. #else
  888. GameTextForPlayer(playerid,"~w~LOADING MAP...~n~~r~PLEASE WAIT",timeT,6);
  889. #endif
  890. return 1;
  891. }
  892. log(string[])
  893. {
  894. #if LOG_ACTIVE==1
  895. new kkk[134],xtime[3];
  896. gettime(xtime[0],xtime[1],xtime[2]);
  897. format(kkk,sizeof kkk,"[%02d:%02d:%02d]%s\r\n",xtime[0],xtime[1],xtime[2],string);
  898. new File:fff=fopen(LOG_FILE,io_append);
  899. fwrite(fff,kkk);
  900. fclose(fff);
  901. #endif
  902. printf("[opa_objects] %s",string);
  903. }
  904. public OnPlayerDisconnect(playerid,reason)
  905. {
  906. if(playerid==admin)logout();
  907. for(new n;n<obj;n++)
  908. {
  909. if(p[playerid][n]!=0)
  910. {
  911. DestroyPlayerObject(playerid,p[playerid][n]);
  912. p[playerid][n]=0;
  913. }
  914. }
  915. crash[playerid]=0;
  916. warn[playerid]=false;
  917. wait[playerid]=false;
  918. }
  919. //----------DINI BY DRACOBLUE------------//
  920. dini_Set(filename[],key[],value[]) {
  921. new key_length = strlen(key);
  922. new value_length = strlen(value);
  923. if (key_length==0 || key_length+value_length+2>DINI_MAX_STRING) return false;
  924.  
  925. new File:fohnd, File:fwhnd;
  926. new tmpres[DINI_MAX_STRING];
  927. new bool:wasset=false;
  928. format(tmpres,sizeof(tmpres),"%s.part",filename);
  929. fremove(tmpres);
  930.  
  931. fohnd=fopen(filename,io_read);
  932. if (!fohnd) return false;
  933.  
  934. fwhnd=fopen(tmpres,io_write);
  935. if (!fwhnd) {
  936. fclose(fohnd);
  937. return false;
  938. }
  939.  
  940. while (fread(fohnd,tmpres)) {
  941. if (
  942. !wasset
  943. && tmpres[key_length]=='='
  944. && !strcmp(tmpres, key, true, key_length)
  945. ) {
  946. format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  947. wasset=true;
  948. } else {
  949. DINI_StripNewLine(tmpres);
  950. }
  951. fwrite(fwhnd,tmpres);
  952. fwrite(fwhnd,"\r\n");
  953. }
  954.  
  955. if (!wasset) {
  956. format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  957. fwrite(fwhnd,tmpres);
  958. fwrite(fwhnd,"\r\n");
  959. }
  960.  
  961. fclose(fohnd);
  962. fclose(fwhnd);
  963.  
  964. format(tmpres,sizeof(tmpres),"%s.part",filename);
  965. if (DINI_fcopytextfile(tmpres,filename)) {
  966. return fremove(tmpres);
  967. }
  968. return false;
  969. }
  970. dini_Get(filename[],key[]) {
  971. new tmpres[DINI_MAX_STRING];
  972.  
  973. new key_length = strlen(key);
  974. if (key_length==0 || key_length+2>DINI_MAX_STRING) return tmpres;
  975.  
  976. new File:fohnd;
  977. fohnd=fopen(filename,io_read);
  978. if (!fohnd) return tmpres;
  979.  
  980. while (fread(fohnd,tmpres)) {
  981. if (
  982. tmpres[key_length]=='='
  983. && !strcmp(tmpres, key, true, key_length)
  984. ) {
  985. DINI_StripNewLine(tmpres);
  986. strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), DINI_MAX_STRING);
  987. fclose(fohnd);
  988. return tmpres;
  989. }
  990. }
  991. fclose(fohnd);
  992. return tmpres;
  993. }
  994. DINI_fcopytextfile(oldname[],newname[]) {
  995. new File:ohnd,File:nhnd;
  996. if (!fexist(oldname)) return false;
  997. ohnd=fopen(oldname,io_read);
  998. if (!ohnd) return false;
  999. nhnd=fopen(newname,io_write);
  1000. if (!nhnd) {
  1001. fclose(ohnd);
  1002. return false;
  1003. }
  1004. new tmpres[DINI_MAX_STRING];
  1005. while (fread(ohnd,tmpres)) {
  1006. DINI_StripNewLine(tmpres);
  1007. format(tmpres,sizeof(tmpres),"%s\r\n",tmpres);
  1008. fwrite(nhnd,tmpres);
  1009. }
  1010. fclose(ohnd);
  1011. fclose(nhnd);
  1012. return true;
  1013. }
  1014. DINI_StripNewLine(string[]) {
  1015. new len = strlen(string);
  1016. if (string[0]==0) return ;
  1017. if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  1018. string[len - 1] = 0;
  1019. if (string[0]==0) return ;
  1020. if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  1021. }
  1022. }
  1023. //----------SSCANF BY Y_LESS------------//
  1024. stock sscanf(string[], format[], {Float,_}:...)
  1025. {
  1026. #if defined isnull
  1027. if (isnull(string))
  1028. #else
  1029. if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  1030. #endif
  1031. {
  1032. return format[0];
  1033. }
  1034. #pragma tabsize 4
  1035. new
  1036. formatPos = 0,
  1037. stringPos = 0,
  1038. paramPos = 2,
  1039. paramCount = numargs(),
  1040. delim = ' ';
  1041. while (string[stringPos] && string[stringPos] <= ' ')
  1042. {
  1043. stringPos++;
  1044. }
  1045. while (paramPos < paramCount && string[stringPos])
  1046. {
  1047. switch (format[formatPos++])
  1048. {
  1049. case '\0':
  1050. {
  1051. return 0;
  1052. }
  1053. case 'i', 'd':
  1054. {
  1055. new
  1056. neg = 1,
  1057. num = 0,
  1058. ch = string[stringPos];
  1059. if (ch == '-')
  1060. {
  1061. neg = -1;
  1062. ch = string[++stringPos];
  1063. }
  1064. do
  1065. {
  1066. stringPos++;
  1067. if ('0' <= ch <= '9')
  1068. {
  1069. num = (num * 10) + (ch - '0');
  1070. }
  1071. else
  1072. {
  1073. return -1;
  1074. }
  1075. }
  1076. while ((ch = string[stringPos]) > ' ' && ch != delim);
  1077. setarg(paramPos, 0, num * neg);
  1078. }
  1079. case 'h', 'x':
  1080. {
  1081. new
  1082. num = 0,
  1083. ch = string[stringPos];
  1084. do
  1085. {
  1086. stringPos++;
  1087. switch (ch)
  1088. {
  1089. case 'x', 'X':
  1090. {
  1091. num = 0;
  1092. continue;
  1093. }
  1094. case '0' .. '9':
  1095. {
  1096. num = (num << 4) | (ch - '0');
  1097. }
  1098. case 'a' .. 'f':
  1099. {
  1100. num = (num << 4) | (ch - ('a' - 10));
  1101. }
  1102. case 'A' .. 'F':
  1103. {
  1104. num = (num << 4) | (ch - ('A' - 10));
  1105. }
  1106. default:
  1107. {
  1108. return -1;
  1109. }
  1110. }
  1111. }
  1112. while ((ch = string[stringPos]) > ' ' && ch != delim);
  1113. setarg(paramPos, 0, num);
  1114. }
  1115. case 'c':
  1116. {
  1117. setarg(paramPos, 0, string[stringPos++]);
  1118. }
  1119. case 'f':
  1120. {
  1121. setarg(paramPos, 0, _:floatstr(string[stringPos]));
  1122. }
  1123. case 'p':
  1124. {
  1125. delim = format[formatPos++];
  1126. continue;
  1127. }
  1128. case '\'':
  1129. {
  1130. new
  1131. end = formatPos - 1,
  1132. ch;
  1133. while ((ch = format[++end]) && ch != '\'') {}
  1134. if (!ch)
  1135. {
  1136. return -1;
  1137. }
  1138. format[end] = '\0';
  1139. if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  1140. {
  1141. if (format[end + 1])
  1142. {
  1143. return -1;
  1144. }
  1145. return 0;
  1146. }
  1147. format[end] = '\'';
  1148. stringPos = ch + (end - formatPos);
  1149. formatPos = end + 1;
  1150. }
  1151. case 'u':
  1152. {
  1153. new
  1154. end = stringPos - 1,
  1155. id = 0,
  1156. bool:num = true,
  1157. ch;
  1158. while ((ch = string[++end]) && ch != delim)
  1159. {
  1160. if (num)
  1161. {
  1162. if ('0' <= ch <= '9')
  1163. {
  1164. id = (id * 10) + (ch - '0');
  1165. }
  1166. else
  1167. {
  1168. num = false;
  1169. }
  1170. }
  1171. }
  1172. if (num && IsPlayerConnected(id))
  1173. {
  1174. setarg(paramPos, 0, id);
  1175. }
  1176. else
  1177. {
  1178. #if !defined foreach
  1179. #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  1180. #define __SSCANF_FOREACH__
  1181. #endif
  1182. string[end] = '\0';
  1183. num = false;
  1184. new
  1185. name[MAX_PLAYER_NAME];
  1186. id = end - stringPos;
  1187. foreach (Player, playerid)
  1188. {
  1189. GetPlayerName(playerid, name, sizeof (name));
  1190. if (!strcmp(name, string[stringPos], true, id))
  1191. {
  1192. setarg(paramPos, 0, playerid);
  1193. num = true;
  1194. break;
  1195. }
  1196. }
  1197. if (!num)
  1198. {
  1199. setarg(paramPos, 0, INVALID_PLAYER_ID);
  1200. }
  1201. string[end] = ch;
  1202. #if defined __SSCANF_FOREACH__
  1203. #undef foreach
  1204. #undef __SSCANF_FOREACH__
  1205. #endif
  1206. }
  1207. stringPos = end;
  1208. }
  1209. case 's', 'z':
  1210. {
  1211. new
  1212. i = 0,
  1213. ch;
  1214. if (format[formatPos])
  1215. {
  1216. while ((ch = string[stringPos++]) && ch != delim)
  1217. {
  1218. setarg(paramPos, i++, ch);
  1219. }
  1220. if (!i)
  1221. {
  1222. return -1;
  1223. }
  1224. }
  1225. else
  1226. {
  1227. while ((ch = string[stringPos++]))
  1228. {
  1229. setarg(paramPos, i++, ch);
  1230. }
  1231. }
  1232. stringPos--;
  1233. setarg(paramPos, i, '\0');
  1234. }
  1235. default:
  1236. {
  1237. continue;
  1238. }
  1239. }
  1240. while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  1241. {
  1242. stringPos++;
  1243. }
  1244. while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  1245. {
  1246. stringPos++;
  1247. }
  1248. paramPos++;
  1249. }
  1250. do
  1251. {
  1252. if ((delim = format[formatPos++]) > ' ')
  1253. {
  1254. if (delim == '\'')
  1255. {
  1256. while ((delim = format[formatPos++]) && delim != '\'') {}
  1257. }
  1258. else if (delim != 'z')
  1259. {
  1260. return delim;
  1261. }
  1262. }
  1263. }
  1264. while (delim > ' ');
  1265. return 0;
  1266. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement