Advertisement
Guest User

Haus System v1.0 Beta

a guest
Aug 11th, 2011
509
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.06 KB | None | 0 0
  1. #include <a_samp>
  2. #include <dini>
  3. #include <sscanf>
  4. #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
  5.  
  6. #define COLOR_WHITE 0xFFFFFFFF
  7. #define COLOR_BLACK 0x0A0A0AFF
  8. #define COLOR_GREEN 0x05FF00FF
  9. #define COLOR_RED 0xFF0000FF
  10. #define COLOR_ORANGE 0xFFDC00FF
  11. #define COLOR_BLUE 0x0A00FFFF
  12.  
  13. forward LoadHouse(number);
  14. forward UpdateHouse(number);
  15.  
  16. #define MAX_HOUSES 100
  17. new Text3D:HouseLabel[MAX_HOUSES];
  18.  
  19. #if defined FILTERSCRIPT
  20.  
  21. public OnFilterScriptInit()
  22. {
  23. print("\n--------------------------------------");
  24. print("House System by Sascha Loishandl");
  25. print("--------------------------------------\n");
  26. return 1;
  27. }
  28.  
  29. public OnFilterScriptExit()
  30. {
  31. return 1;
  32. }
  33.  
  34. #else
  35.  
  36. main()
  37. {
  38. print("\n----------------------------------");
  39. print("House System by Sascha Loishandl");
  40. print("----------------------------------\n");
  41. }
  42.  
  43. #endif
  44.  
  45. public OnGameModeInit()
  46. {
  47. SetGameModeText("House Test System");
  48. AddPlayerClass(15, 0, 0, 0, 0, 24, 500, 29, 500, 30, 500);
  49. if(!fexist("House/Info.ini"))
  50. {
  51. dini_Create("House/Info.ini");
  52. dini_IntSet("House/Info.ini", "Max", 0);
  53. }
  54. for(new h = 0; h < MAX_HOUSES; h++)
  55. {
  56. LoadHouse(h);
  57. }
  58. return 1;
  59. }
  60.  
  61. public OnGameModeExit()
  62. {
  63. return 1;
  64. }
  65.  
  66. public OnPlayerRequestClass(playerid, classid)
  67. {
  68. SetPlayerPos(playerid, 0, 0, 0);
  69. SetPlayerCameraPos(playerid, 10, 0, 0);
  70. SetPlayerCameraLookAt(playerid, 0, 0, 0);
  71. return 1;
  72. }
  73.  
  74. public OnPlayerConnect(playerid)
  75. {
  76. return 1;
  77. }
  78.  
  79. public OnPlayerDisconnect(playerid, reason)
  80. {
  81. return 1;
  82. }
  83.  
  84. public OnPlayerSpawn(playerid)
  85. {
  86. return 1;
  87. }
  88.  
  89. public OnPlayerDeath(playerid, killerid, reason)
  90. {
  91. return 1;
  92. }
  93.  
  94. public OnVehicleSpawn(vehicleid)
  95. {
  96. return 1;
  97. }
  98.  
  99. public OnVehicleDeath(vehicleid, killerid)
  100. {
  101. return 1;
  102. }
  103.  
  104. public OnPlayerText(playerid, text[])
  105. {
  106. return 1;
  107. }
  108.  
  109. public OnPlayerCommandText(playerid, cmdtext[])
  110. {
  111. dcmd(createhouse,11,cmdtext);
  112. dcmd(buyhouse,8,cmdtext);
  113. dcmd(besichtigen, 11, cmdtext);
  114. dcmd(exit,4,cmdtext);
  115. dcmd(enter, 5, cmdtext);
  116. return 1;
  117. }
  118.  
  119.  
  120.  
  121. /*********************************************************************
  122. ******************** Haus Betreten (enter) ***************************
  123. *********************************************************************/
  124. dcmd_enter(playerid, params[])
  125. {
  126. #pragma unused params
  127. new hName[100];
  128. new Float: hx, Float: hy, Float: hz;
  129. new Float: hix, Float: hiy, Float: hiz;
  130. new in, vw, verschlossen, inbesitz;
  131. new pName[MAX_PLAYER_NAME], string[100];
  132. GetPlayerName(playerid, pName, sizeof(pName));
  133. for(new h = 0; h < MAX_HOUSES; h++)
  134. {
  135. format(hName, sizeof(hName), "House/Haus%d.ini", h);
  136. if(fexist(hName))
  137. {
  138. hx = dini_Float(hName, "hx");
  139. hy = dini_Float(hName, "hy");
  140. hz = dini_Float(hName, "hz");
  141. if(IsPlayerInRangeOfPoint(playerid, 3, hx, hy, hz))
  142. {
  143. inbesitz = dini_Int(hName, "InBesitz");
  144. if(inbesitz == 0)
  145. {
  146. SendClientMessage(playerid,COLOR_RED,"Du kannst dieses Haus nicht betreten. Versuchs mal mit /besichtigen.");
  147. }
  148. else
  149. {
  150. verschlossen = dini_Int(hName, "Verschlossen");
  151. if(verschlossen == 0)
  152. {
  153. in = dini_Int(hName, "Interior");
  154. vw = dini_Int(hName, "VirtualWorld");
  155. hix = dini_Float(hName, "hix");
  156. hiy = dini_Float(hName, "hiy");
  157. hiz = dini_Float(hName, "hiz");
  158. SetPlayerInterior(playerid, in);
  159. SetPlayerVirtualWorld(playerid, vw);
  160. SetPlayerPos(playerid, hix, hiy, hiz);
  161. }
  162. else
  163. {
  164. format(string, sizeof(string), "%s", dini_Get(hName, "Besitzer"));
  165. if(strcmp(pName, string, false) == 0)
  166. {
  167. in = dini_Int(hName, "Interior");
  168. vw = dini_Int(hName, "VirtualWorld");
  169. hix = dini_Float(hName, "hix");
  170. hiy = dini_Float(hName, "hiy");
  171. hiz = dini_Float(hName, "hiz");
  172. SetPlayerInterior(playerid, in);
  173. SetPlayerVirtualWorld(playerid, vw);
  174. SetPlayerPos(playerid, hix, hiy, hiz);
  175. }
  176. else
  177. {
  178. SendClientMessage(playerid,COLOR_RED,"Dieses Haus ist leider verschlossen.");
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }
  185. return 1;
  186. }
  187.  
  188.  
  189. /*********************************************************************
  190. ******************** Haus Verlassen (exit) ***************************
  191. *********************************************************************/
  192. dcmd_exit(playerid, params[])
  193. {
  194. #pragma unused params
  195. new hName[100];
  196. new Float: hx, Float: hy, Float: hz;
  197. new Float: hix, Float: hiy, Float: hiz;
  198. new in, vw;
  199. for(new h = 0; h < MAX_HOUSES; h++)
  200. {
  201. format(hName, sizeof(hName), "House/Haus%d.ini", h);
  202. if(fexist(hName))
  203. {
  204. hix = dini_Float(hName, "hix");
  205. hiy = dini_Float(hName, "hiy");
  206. hiz = dini_Float(hName, "hiz");
  207. if(IsPlayerInRangeOfPoint(playerid, 3, hix, hiy, hiz))
  208. {
  209. in = dini_Int(hName, "Interior");
  210. vw = dini_Int(hName, "VirtualWorld");
  211. if(in == GetPlayerInterior(playerid) && vw == GetPlayerVirtualWorld(playerid))
  212. {
  213. hx = dini_Float(hName, "hx");
  214. hy = dini_Float(hName, "hy");
  215. hz = dini_Float(hName, "hz");
  216. SetPlayerInterior(playerid, 0);
  217. SetPlayerVirtualWorld(playerid, 0);
  218. SetPlayerPos(playerid, hx, hy, hz);
  219. }
  220. }
  221. }
  222. }
  223. return 1;
  224. }
  225.  
  226. /*********************************************************************
  227. ************************ Haus Besichtigen ****************************
  228. *********************************************************************/
  229. dcmd_besichtigen(playerid, params[])
  230. {
  231. #pragma unused params
  232. new hName[100];
  233. new Float: hx, Float: hy, Float: hz;
  234. new Float: hix, Float: hiy, Float: hiz;
  235. new inbesitz;
  236. for(new h = 0; h < MAX_HOUSES; h++)
  237. {
  238. format(hName, sizeof(hName), "House/Haus%d.ini", h);
  239. if(fexist(hName))
  240. {
  241. hx = dini_Float(hName, "hx");
  242. hy = dini_Float(hName, "hy");
  243. hz = dini_Float(hName, "hz");
  244. if(IsPlayerInRangeOfPoint(playerid, 3, hx, hy, hz))
  245. {
  246. inbesitz = dini_Int(hName, "InBesitz");
  247. if(inbesitz == 0)
  248. {
  249. hix = dini_Float(hName, "hix");
  250. hiy = dini_Float(hName, "hiy");
  251. hiz = dini_Float(hName, "hiz");
  252. SetPlayerVirtualWorld(playerid, dini_Int(hName, "VirtualWorld"));
  253. SetPlayerInterior(playerid, dini_Int(hName, "Interior"));
  254. SetPlayerPos(playerid, hix, hiy, hiz);
  255. SendClientMessage(playerid, COLOR_RED, "Tippe /exit um das Haus wieder zu verlassen.");
  256. }
  257. else
  258. {
  259. SendClientMessage(playerid, COLOR_RED, "Du kannst dieses Haus nicht besichtigen.");
  260. }
  261. }
  262. }
  263. }
  264. return 1;
  265. }
  266.  
  267.  
  268.  
  269.  
  270. /*********************************************************************
  271. ************************ Haus Kaufen *********************************
  272. *********************************************************************/
  273. dcmd_buyhouse(playerid, params[])
  274. {
  275. #pragma unused params
  276. new hName[100];
  277. new Float: hx, Float: hy, Float: hz;
  278. new inbesitz, preis;
  279. new pName[MAX_PLAYER_NAME];
  280. GetPlayerName(playerid, pName, sizeof(pName));
  281. for(new h = 0; h < MAX_HOUSES; h++)
  282. {
  283. format(hName, sizeof(hName), "House/Haus%d.ini", h);
  284. if(fexist(hName))
  285. {
  286. hx = dini_Float(hName, "hx");
  287. hy = dini_Float(hName, "hy");
  288. hz = dini_Float(hName, "hz");
  289. if(IsPlayerInRangeOfPoint(playerid, 3, hx, hy, hz))
  290. {
  291. inbesitz = dini_Int(hName, "InBesitz");
  292. preis = dini_Int(hName, "Preis");
  293. if(inbesitz == 0)
  294. {
  295. if(GetPlayerMoney(playerid) >= preis)
  296. {
  297. GivePlayerMoney(playerid, GetPlayerMoney(playerid) - preis);
  298. dini_IntSet(hName, "InBesitz", 2);
  299. dini_IntSet(hName, "Preis", 0);
  300. dini_Set(hName, "Besitzer", pName);
  301. //Dem Spieler wird das Haus zugeteilt usw..
  302. UpdateHouse(h);
  303. SendClientMessage(playerid, COLOR_RED, "Du hast dieses Haus nun erfolgreich gekauft.");
  304. }
  305. else
  306. {
  307. SendClientMessage(playerid, COLOR_RED, "Du hast nicht genug Geld um dieses Haus zu kaufen.");
  308. }
  309. }
  310. else
  311. {
  312. SendClientMessage(playerid, COLOR_RED, "Dieses Haus steht nicht zum Verkauf bereit.");
  313. }
  314. }
  315. }
  316. }
  317. }
  318.  
  319.  
  320.  
  321. /*********************************************************************
  322. ****************** Befehl zum Haus erstellen *************************
  323. *********************************************************************/
  324. dcmd_createhouse(playerid, params[])
  325. {
  326. new Float:hx, Float: hy, Float:hz;
  327. new Preis;
  328. if(sscanf(params,"d",Preis))
  329. { return SendClientMessage(playerid,COLOR_RED,"USAGE: /createhouse [Preis]"); }
  330. /*if(!IsPlayerAdmin(playerid)) //Deine Admin definition
  331. { return SendClientMessage(playerid,COLOR_RED,"Dein Admin Level reicht nicht aus."); }*/
  332. GetPlayerPos(playerid ,hx, hy, hz);
  333. new hName[40];
  334. dini_IntSet("House/Info.ini", "Max", dini_Int("House/Info.ini","Max") + 1);
  335. if(dini_Int("House/Info.ini", "Max") > MAX_HOUSES)
  336. { return SendClientMessage(playerid,COLOR_RED,"Die Maximale Anzahl an Häuser wurde erreicht."); }
  337. format(hName,sizeof(hName), "House/Haus%d.ini", dini_Int("House/Info.ini","Max"));
  338. dini_Create(hName);
  339. dini_FloatSet(hName, "hx", hx);
  340. dini_FloatSet(hName, "hy", hy);
  341. dini_FloatSet(hName, "hz", hz);
  342. dini_IntSet(hName, "InBesitz", 0);
  343. dini_Set(hName, "Besitzer", "Niemand");
  344. dini_IntSet(hName, "Preis", Preis);
  345. dini_IntSet(hName, "VirtualWorld", dini_Int("House/Info.ini","Max"));
  346. dini_IntSet(hName, "Interior", 1);
  347. dini_FloatSet(hName, "hix", 244.411987);
  348. dini_FloatSet(hName, "hiy", 305.032989);
  349. dini_FloatSet(hName, "hiz", 999.148437);
  350. dini_IntSet(hName, "ID", dini_Int("House/Info.ini", "Max"));
  351. dini_IntSet(hName, "Verschlossen", 1);
  352. LoadHouse(dini_Int("House/Info.ini", "Max"));
  353. SendClientMessage(playerid, COLOR_RED, "Haus wurde erfolgreich erstellt.");
  354. return 1;
  355. }
  356.  
  357.  
  358.  
  359. /*************************************************************************
  360. ************************* Haus Updaten ***********************************
  361. *************************************************************************/
  362. public UpdateHouse(number)
  363. {
  364. new hName[40];
  365. format(hName, sizeof(hName), "House/Haus%d.ini", number);
  366. if(!fexist(hName))
  367. { return 0; }
  368. new string[200];
  369. new besitzer[100];
  370. format(besitzer, sizeof(besitzer), "%s", dini_Get(hName, "Besitzer"));
  371. new preis = dini_Int(hName, "Preis");
  372. new inbesitz = dini_Int(hName, "InBesitz");
  373.  
  374. if(inbesitz == 0)
  375. {
  376. format(string,sizeof(string),"Diese Haus ist zu Verkaufen\nPreis: %d$\n/buyhouse zum kaufen\noder /besichtigen zum Ansehen", preis);
  377. }
  378. else if(inbesitz == 1)
  379. {
  380. format(string,sizeof(string),"Besitzer: %s\nMiete: %d$\nTippe: /rentroom", besitzer, preis);
  381. }
  382. else if(inbesitz == 2)
  383. {
  384. format(string,sizeof(string),"Besitzer: %s", besitzer);
  385. }
  386. Update3DTextLabelText(HouseLabel[number], COLOR_BLUE, string);
  387. return 1;
  388. }
  389.  
  390.  
  391.  
  392. /************************************************************************
  393. ************************* Haus Laden ************************************
  394. ************************************************************************/
  395. public LoadHouse(number)
  396. {
  397. new hName[40];
  398. format(hName, sizeof(hName), "House/Haus%d.ini", number);
  399. if(!fexist(hName))
  400. { return 0; }
  401. new Float: hx, Float: hy, Float: hz;
  402. hx = dini_Float(hName, "hx");
  403. hy = dini_Float(hName, "hy");
  404. hz = dini_Float(hName, "hz");
  405. CreatePickup(1239, 1, hx, hy, hz);
  406. new string[200];
  407. new besitzer[100];
  408. format(besitzer, sizeof(besitzer), "%s", dini_Get(hName, "Besitzer"));
  409. new preis = dini_Int(hName, "Preis");
  410. new inbesitz = dini_Int(hName, "InBesitz");
  411.  
  412. if(inbesitz == 0)
  413. {
  414. format(string,sizeof(string),"Diese Haus ist zu Verkaufen\nPreis: %d$\n/buyhouse zum kaufen\noder /besichtigen zum Ansehen", preis);
  415. }
  416. else if(inbesitz == 1)
  417. {
  418. format(string,sizeof(string),"Besitzer: %s\nMiete: %d$\nTippe: /rentroom", besitzer, preis);
  419. }
  420. else if(inbesitz == 2)
  421. {
  422. format(string,sizeof(string),"Besitzer: %s", besitzer);
  423. }
  424. HouseLabel[number] = Create3DTextLabel(string,COLOR_BLUE, hx, hy, hz, 20, 0, 1);
  425. return 1;
  426. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement