Guest User

Untitled

a guest
Oct 9th, 2011
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.91 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <SII>
  4. #include <sscanf2>
  5. #include <gvar>
  6.  
  7. #define MAX_PROPS 100//Self explanatory
  8. #define PROP_DEFAULT_LABEL_DISTANCE 30.0//Self explanatory
  9. #define PROP_DEFAULT_NAME "Newly propertaii created"//Original name of a newly create prop
  10. #define File "Admin/Props/%i.ini"//Self explanatory
  11. #define DIALOG_DEFAULT_RANGE 2360//Default dialog range
  12. //=============================== [RRGGBB] =====================================
  13. #define lblue "{33BBCC}"
  14. #define lgrey "{BEBEBE}"
  15. #define lyellow2 "{E1DE1C}"
  16. //============================= [Colors] =======================================
  17. #define green 0x00DE28FF
  18. #define red 0xFF0000FF
  19. #define yellow 0xF5FF00FF
  20. #define white 0xF0F0F0FF
  21. //============================= [Colors] =======================================
  22. forward GiveCash();
  23. enum PropInfo
  24. {
  25. Float:XPos,
  26. Float:YPos,
  27. Float:ZPos,
  28. Owner[23],
  29. Owned,
  30. Price,
  31. Ownings,
  32. Pickup,
  33. World,
  34. Name[128]
  35. };
  36. new PInfo[MAX_PROPS][PropInfo];
  37. new PropCount;
  38. new Text3D:PropLabel[MAX_PROPS];
  39. new NearPickup[MAX_PLAYERS];
  40. new EditingProp[MAX_PLAYERS];
  41. new PlayerEarnings[MAX_PLAYERS];
  42. new PlayerAmmountOfProperties[MAX_PLAYERS];
  43. new Propertyprice[MAX_PLAYERS];
  44. new CurrentPropName[MAX_PLAYERS][30];
  45. public OnFilterScriptInit()
  46. {
  47. print("\n--------------------------------------");
  48. print("FProps - Property system");
  49. print("--------------------------------------\n");
  50. SetTimer("GiveCash",60000,true);
  51. LoadProps();
  52. for(new i; i < MAX_PROPS; i++)
  53. {
  54. if(PInfo[i][Owned] == 1)
  55. {
  56. for(new j = 0; j < GetMaxPlayers();i++)
  57. {
  58. if(IsPlayerConnected(j))
  59. {
  60. if(strcmp(PInfo[i][Owner], GetPName(j), true) == 0)
  61. {
  62. PlayerEarnings[j] = PlayerEarnings[j]+PInfo[i][Ownings];
  63. PlayerAmmountOfProperties[j]++;
  64. }
  65. }
  66. }
  67. }
  68. }
  69. return 1;
  70. }
  71.  
  72. public OnFilterScriptExit()
  73. {
  74. SetGVarInt("Pickups",GetGVarInt("Pickups")-PropCount);
  75. return 1;
  76. }
  77.  
  78. public OnPlayerConnect(playerid)
  79. {
  80. PlayerEarnings[playerid] = 0;//Preventing the player earning from the owner of the last property connected (Hard to explain xD)
  81. for(new i; i < MAX_PROPS; i++)
  82. {
  83. if(PInfo[i][Owned] == 1)
  84. {
  85. if(strcmp(PInfo[i][Owner], GetPName(playerid), true) == 0)
  86. {
  87. PlayerEarnings[playerid] = PlayerEarnings[playerid]+PInfo[i][Ownings];
  88. PlayerAmmountOfProperties[playerid]++;
  89. }
  90. }
  91. }
  92. return 1;
  93. }
  94.  
  95. COMMAND:createprop(playerid,params[])
  96. {
  97. if(!IsPlayerAdmin(playerid)) return 0;
  98. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+9,1,"Default name","Choose the default property name \n","Next »","Cancel");
  99. return 1;
  100. }
  101.  
  102. COMMAND:gotoprop(playerid,params[])
  103. {
  104. if(!IsPlayerAdmin(playerid)) return 0;
  105. new id;
  106. if(sscanf(params,"i",id)) return SendHelpMessage(playerid,"/gotoprop <propid>","It will teleport you to the specified property id");
  107. new file[64];
  108. format(file,sizeof(file),File,id);
  109. if(!INI_Exist(file)) return SendClientMessage(playerid,red,"That property does not exist!");
  110. INI_Open(file);
  111. SetPlayerPos(playerid,INI_ReadFloat("XPos"),INI_ReadFloat("YPos")+2,INI_ReadFloat("ZPos"));
  112. INI_Close();
  113. return 1;
  114. }
  115.  
  116. stock SendHelpMessage(playerid, const str1[],const str2[])
  117. {
  118. new string[160];
  119. format(string,sizeof(string),""lyellow2"USAGE: "lgrey"%s",str1);
  120. SendClientMessage(playerid,0xFF1E00FF,string);
  121. format(string,sizeof(string),""lblue"FUNCTION: "lgrey"%s",str2);
  122. SendClientMessage(playerid,0xFF1E00FF,string);
  123. return 1;
  124. }
  125.  
  126. public OnPlayerPickUpPickup(playerid,pickupid)
  127. {
  128. new str[250];
  129. for(new i = 0; i < MAX_PROPS;i++)
  130. {
  131. if(pickupid == PInfo[i][Pickup])
  132. {
  133. if(NearPickup[playerid] == 1) return 0;
  134. NearPickup[playerid] = 1;
  135. EditingProp[playerid] = i;
  136. if(PInfo[i][Owned] == 0)
  137. {
  138. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE,2,"Property","Buy Property","Choose","Cancel");
  139. }
  140. else if(PInfo[i][Owned] == 1 && strcmp(PInfo[i][Owner], GetPName(playerid), true) != 0)
  141. {
  142. format(str,sizeof(str),"Owned: Yes \nOwner: %s \nOwnings: %i \nProperty name: %s",PInfo[i][Owner],PInfo[i][Ownings],PInfo[i][Name]);
  143. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+1,0,"Property",str,"Ok","Close");
  144. }
  145. else if(strcmp(PInfo[i][Owner], GetPName(playerid), true) == 0)
  146. {
  147. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+2,2,"Property","Sell property \nChange property name \nDeposit money \nWithdraw money","Choose","Cancel");
  148. }
  149. break;
  150. }
  151. }
  152. return 1;
  153. }
  154.  
  155. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  156. {
  157. #define propid EditingProp[playerid]
  158. new string[200];
  159. if(dialogid == DIALOG_DEFAULT_RANGE+9)
  160. {
  161. if(!response) return 0;
  162. format(CurrentPropName[playerid],30,"%s",inputtext);
  163. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+4,1,"Price","How much will the property cost? \n","Next »","Back «");
  164. }
  165. if(dialogid == DIALOG_DEFAULT_RANGE+5)
  166. {
  167. if(!response) return ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+4,1,"Price","How much will the property cost? \n","Next »","Back «");
  168. new Float:x,Float:y,Float:z,ID = PropCount,ownerstring[120],file[128];
  169. if(!IsPlayerAdmin(playerid)) return 0;
  170. if(!isNumeric(inputtext)) return SendClientMessage(playerid,red,"Must be a numeric value!");
  171. format(ownerstring,sizeof(ownerstring),""lyellow2"Property name: %s \nOwner: None \nCost: %i \nOwnings: %i \nProperty id: %i",CurrentPropName[playerid],Propertyprice[playerid],strval(inputtext),ID);
  172. format(PInfo[ID][Owner],4,"%s","None");
  173. format(PInfo[ID][Name],200,"%s",CurrentPropName[playerid]);
  174. format(file,sizeof(file),File,ID);
  175. GetPlayerPos(playerid,x,y,z);
  176. PInfo[ID][XPos] = x;
  177. PInfo[ID][YPos] = y;
  178. PInfo[ID][ZPos] = z;
  179. PInfo[ID][Price] = Propertyprice[playerid];
  180. PInfo[ID][Ownings] = strval(inputtext);
  181. PInfo[ID][World] = GetPlayerVirtualWorld(playerid);
  182. PInfo[GetGVarInt("Pickups")][Pickup] = CreatePickup(1273,23,x,y,z,GetPlayerVirtualWorld(playerid));
  183. PropLabel[ID] = Create3DTextLabel(ownerstring,white,x,y,z+0.7,PROP_DEFAULT_LABEL_DISTANCE,GetPlayerVirtualWorld(playerid));
  184. INI_Open(file);
  185. INI_WriteFloat("XPos",x);
  186. INI_WriteFloat("YPos",y);
  187. INI_WriteFloat("ZPos",z);
  188. INI_WriteInt("Price",Propertyprice[playerid]);
  189. INI_WriteInt("Ownings",strval(inputtext));
  190. INI_WriteInt("World",GetPlayerVirtualWorld(playerid));
  191. INI_WriteInt("Owned",0);
  192. INI_WriteString("Owner","None");
  193. INI_WriteString("Name",CurrentPropName[playerid]);
  194. INI_Save();
  195. INI_Close();
  196. PropCount++;
  197. SetGVarInt("Pickups",GetGVarInt("Pickups")+1);
  198. }
  199. if(dialogid == DIALOG_DEFAULT_RANGE+4)
  200. {
  201. if(!response) return ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+9,1,"Default name","Choose the default property name \n","Next »","Cancel");
  202. if(!isNumeric(inputtext)) return SendClientMessage(playerid,red,"Must be a numeric value!");
  203. Propertyprice[playerid] = strval(inputtext);
  204. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+5,1,"Ownings","How much will the owner gain for each minute? \n","Create","Back «");
  205. }
  206. if(!response)
  207. {
  208. NearPickup[playerid] = 0;
  209. return 0;
  210. }
  211. if(dialogid == DIALOG_DEFAULT_RANGE)
  212. {
  213. switch(listitem)
  214. {
  215. case 0:
  216. {
  217. new file[128];
  218. if(GetPlayerMoney(playerid) < PInfo[propid][Price]) {SendClientMessage(playerid,red,"You dont have enough cash!");NearPickup[playerid] = 0;return 1;}//Added brackets here
  219. format(PInfo[propid][Owner],23,"%s",GetPName(playerid));
  220. PInfo[propid][Owned] = 1;
  221. PlayerAmmountOfProperties[playerid]++;
  222. PlayerEarnings[playerid] = PlayerEarnings[playerid]+PInfo[propid][Ownings];
  223. format(string,sizeof(string),""lyellow2"Property name: %s \nOwner: %s \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[propid][Name],PInfo[propid][Owner],PInfo[propid][Price],PInfo[propid][Ownings],propid);
  224. Update3DTextLabelText(PropLabel[propid],yellow,string);
  225. GivePlayerMoney(propid,-PInfo[propid][Price]);
  226. format(file,sizeof(file),File,propid);
  227. INI_Open(file);
  228. INI_WriteInt("Owned",1);
  229. INI_WriteString("Owner",PInfo[propid][Owner]);
  230. INI_Save();
  231. INI_Close();
  232. }
  233. }
  234. NearPickup[playerid] = 0;
  235. }
  236. if(dialogid == DIALOG_DEFAULT_RANGE+2)
  237. {
  238. switch(listitem)
  239. {
  240. case 0:
  241. {
  242. new file[128];
  243. format(file,sizeof(file),File,propid);
  244. format(PInfo[propid][Owner],23,"None",GetPName(playerid));
  245. PInfo[propid][Owned] = 0;
  246. format(PInfo[propid][Name],200,"%s",PROP_DEFAULT_NAME);
  247. PlayerAmmountOfProperties[playerid]--;
  248. PlayerEarnings[playerid] -= PInfo[propid][Ownings];
  249. format(string,sizeof(string),""lyellow2"Prop name: %s \nOwner: None \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[propid][Name],PInfo[propid][Price],PInfo[propid][Ownings],propid);
  250. Update3DTextLabelText(PropLabel[propid],yellow,string);
  251. NearPickup[playerid] = 0;
  252. INI_Open(file);
  253. INI_WriteInt("Owned",0);
  254. INI_WriteString("Owner","None");
  255. INI_WriteString("Name",PROP_DEFAULT_NAME);
  256. INI_Save();
  257. INI_Close();
  258. NearPickup[playerid] = 0;
  259. }
  260. case 1:
  261. {
  262. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+3,1,"Property","Insert the name name of the property you want to change\n","Ok","Cancel");
  263. }
  264. case 2:
  265. {
  266. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+6,1,"Deposit","How much money would you like to deposit? \n","Deposit","Cancel");
  267. }
  268. case 3:
  269. {
  270. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+8,1,"Withdraw","How much money would you like to withdraw \n","Withdraw","Cancel");
  271. }
  272. }
  273. }
  274. if(dialogid == DIALOG_DEFAULT_RANGE+6)
  275. {
  276. NearPickup[playerid] = 0;
  277. if(!isNumeric(inputtext)) return SendClientMessage(playerid,red,"Must be a numeric value!");
  278. if(strval(inputtext) > GetPlayerMoney(playerid)) return SendClientMessage(playerid,red,"You don't have that much money!");
  279. static Float:p[3],file[64];
  280. GetPlayerPos(playerid, p[0], p[1], p[2]);
  281. format(file,sizeof(file),File,propid);
  282. INI_Open(file);
  283. INI_WriteInt("Deposited",INI_ReadInt("Deposited")+strval(inputtext));
  284. format(string,sizeof(string),"You had: %i \nYou now have: %i \nYou deposited: %i \nYou now have in in total %i in your property",GetPlayerMoney(playerid),GetPlayerMoney(playerid)-strval(inputtext),strval(inputtext),INI_ReadInt("Deposited"));
  285. INI_Save();
  286. INI_Close();
  287. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+7,0,"Deposited",string,"Ok","");
  288. GivePlayerMoney(playerid,-strval(inputtext));
  289. PlayerPlaySound(playerid, 1057, p[0], p[1], p[2]);
  290. }
  291. if(dialogid == DIALOG_DEFAULT_RANGE+8)
  292. {
  293. NearPickup[playerid] = 0;
  294. if(!isNumeric(inputtext)) return SendClientMessage(playerid,red,"Must be a numeric value!");
  295. static Float:p[3],file[64];
  296. GetPlayerPos(playerid, p[0], p[1], p[2]);
  297. format(file,sizeof(file),File,propid);
  298. INI_Open(file);
  299. if(INI_ReadInt("Deposited") < strval(inputtext)) return SendClientMessage(playerid,red,"You don't have that much money!");
  300. INI_WriteInt("Deposited",INI_ReadInt("Deposited")-strval(inputtext));
  301. format(string,sizeof(string),"You had: %i \nYou now have: %i \nYou with drawed: %i \nYou now have in total %i in your property",GetPlayerMoney(playerid),strval(inputtext),strval(inputtext),INI_ReadInt("Deposited"));
  302. INI_Save();
  303. INI_Close();
  304. ShowPlayerDialog(playerid,DIALOG_DEFAULT_RANGE+7,0,"Withdrawed",string,"Ok","");
  305. GivePlayerMoney(playerid,strval(inputtext));
  306. PlayerPlaySound(playerid, 1057, p[0], p[1], p[2]);
  307. }
  308. if(dialogid == DIALOG_DEFAULT_RANGE+3)
  309. {
  310. new file[128];
  311. NearPickup[playerid] = 0;
  312. format(file,sizeof(file),File,propid);
  313. if(strlen(inputtext) == 0) return 0;
  314. format(PInfo[propid][Name],200,"%s",inputtext);
  315. format(string,sizeof(string),""lyellow2"Prop name: %s \nOwner: %s \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[propid][Name],PInfo[propid][Owner],PInfo[propid][Price],PInfo[propid][Ownings],propid);
  316. Update3DTextLabelText(PropLabel[propid],yellow,string);
  317. SendClientMessage(playerid,green,"Property name successfully changed!");
  318. NearPickup[playerid] = 0;
  319. INI_Open(file);
  320. INI_WriteString("Name",PInfo[propid][Name]);
  321. INI_Save();
  322. INI_Close();
  323. }
  324. if(dialogid == DIALOG_DEFAULT_RANGE+1)
  325. {
  326. NearPickup[playerid] = 0;
  327. }
  328. return 0;
  329. }
  330.  
  331. stock GetPName(playerid)
  332. {
  333. new p_name[MAX_PLAYER_NAME];
  334. GetPlayerName(playerid,p_name,sizeof(p_name));
  335. return p_name;
  336. }
  337.  
  338. public GiveCash()
  339. {
  340. new string[200];
  341. for(new i = 0; i < MAX_PLAYERS;i++)
  342. {
  343. if(IsPlayerConnected(i))
  344. {
  345. if(PlayerAmmountOfProperties[i] > 0)
  346. {
  347. GivePlayerMoney(i,PlayerEarnings[i]);
  348. format(string,sizeof(string),""lgrey"You have earned "lyellow2"%i$ "lgrey"from your properties!",PlayerEarnings[i]);
  349. SendClientMessage(i,white,string);
  350. }
  351. }
  352. }
  353. }
  354.  
  355. stock LoadProps()
  356. {
  357. new file[128],ownername[23],name[200],ownerstring[200];
  358. for(new i = 0; i < MAX_PROPS;i++)
  359. {
  360. format(file,sizeof(file),File,i);
  361. if(INI_Exist(file))
  362. {
  363. INI_Open(file);
  364. INI_ReadString(ownername,"Owner",23);
  365. INI_ReadString(name,"Name",200);
  366. format(PInfo[i][Owner],23,"%s",ownername);
  367. format(PInfo[i][Name],200,"%s",name);
  368. PInfo[i][XPos] = INI_ReadFloat("XPos");
  369. PInfo[i][YPos] = INI_ReadFloat("YPos");
  370. PInfo[i][ZPos] = INI_ReadFloat("ZPos");
  371. PInfo[i][Price] = INI_ReadInt("Price");
  372. PInfo[i][Ownings] = INI_ReadInt("Ownings");
  373. PInfo[i][World] = INI_ReadInt("World");
  374. PInfo[i][Owned] = INI_ReadInt("Owned");
  375. PInfo[i][Pickup] = CreatePickup(1273,23,PInfo[i][XPos],PInfo[i][YPos],PInfo[i][ZPos],PInfo[i][World]);
  376. if(PInfo[i][Owned] == 1)
  377. {
  378. format(ownerstring,sizeof(ownerstring),""lyellow2"Prop name: %s \nOwner: %s \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[i][Name],PInfo[i][Owner],PInfo[i][Price],PInfo[i][Ownings],i);
  379. PropLabel[i] = Create3DTextLabel(ownerstring,white,PInfo[i][XPos],PInfo[i][YPos],PInfo[i][ZPos]+0.7,PROP_DEFAULT_LABEL_DISTANCE,PInfo[i][World]);
  380. }
  381. else
  382. {
  383. format(ownerstring,sizeof(ownerstring),""lyellow2"Prop name: %s \nOwner: None \nCost: %i \nOwnings: %i \nProperty id: %i",PInfo[i][Name],PInfo[i][Price],PInfo[i][Ownings],i);
  384. PropLabel[i] = Create3DTextLabel(ownerstring,white,PInfo[i][XPos],PInfo[i][YPos],PInfo[i][ZPos]+0.7,PROP_DEFAULT_LABEL_DISTANCE,PInfo[i][World]);
  385. }
  386. INI_Close();
  387. PropCount++;
  388. SetGVarInt("Pickups",GetGVarInt("Pickups")+1);
  389. }
  390. }
  391. printf("Loaded properties: %i",PropCount);
  392. return 1;
  393. }
  394. //Dunno who made this :b
  395. stock isNumeric(const string[])
  396. {
  397. new length=strlen(string);
  398. if (length==0) return false;
  399. for (new i = 0; i < length; i++)
  400. {
  401. if (
  402. (string[i] > '9' || string[i] < '0' && string[i]!='-' && string[i]!='+') // Not a number,'+' or '-'
  403. || (string[i]=='-' && i!=0) // A '-' but not at first.
  404. || (string[i]=='+' && i!=0) // A '+' but not at first.
  405. ) return false;
  406. }
  407. if (length==1 && (string[0]=='-' || string[0]=='+')) return false;
  408. return true;
  409. }
  410.  
Advertisement
Add Comment
Please, Sign In to add comment