Guest User

Untitled

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