Advertisement
Guest User

Untitled

a guest
Dec 13th, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.44 KB | None | 0 0
  1. #include <a_samp>
  2. #include <a_mysql>
  3.  
  4.  
  5.  
  6. #define Color_Grey 0xAFAFAFAA
  7. #define Color_Green 0x33AA33AA
  8. #define Color_Red 0xAA3333AA
  9.  
  10.  
  11. #define MySql_Database "Bitte_Anpassen"
  12.  
  13.  
  14. enum fCarDealer
  15. {
  16. fModel,
  17. fName[32],
  18. fPrice,
  19. Float: fX,
  20. Float: fY,
  21. Float: fZ,
  22. Float: fR,
  23. fVehid,
  24. }
  25.  
  26. new fCarDealerCars[2][fCarDealer] = {
  27. {411,"Infernus",5000,1489.6309,2838.5767,10.5474,180.6838,-1},
  28. {560,"Sultan",5000,1484.5950,2838.9211,10.5474,179.9544,-1}
  29. };
  30.  
  31. enum fCars
  32. {
  33. fModel,
  34. Float: fX,
  35. Float: fY,
  36. Float: fZ,
  37. Float: fR,
  38. fc1,
  39. fc2,
  40. fFaction,
  41. fSQLid,
  42. fVehid,
  43. bool:fExist,
  44. }
  45. new FactionCars[100][fCars];
  46.  
  47.  
  48.  
  49.  
  50. public OnFilterScriptInit()
  51. {
  52. LoadFactionCars();
  53. for(new i = 0; i < sizeof(fCarDealerCars); i++)
  54. {
  55. new c1 = random(126), c2 = random(126);
  56. fCarDealerCars[i][fVehid] = CreateVehicle(fCarDealerCars[i][fModel], fCarDealerCars[i][fX], fCarDealerCars[i][fY], fCarDealerCars[i][fZ], fCarDealerCars[i][fR], c1, c2, 60000);
  57. }
  58. return 1;
  59. }
  60.  
  61. public OnFilterScriptExit()
  62. {
  63. return 1;
  64. }
  65.  
  66. public OnPlayerCommandText(playerid, cmdtext[])
  67. {
  68. new string[128];
  69. if(strcmp(cmdtext, "/buyfcar", true) == 0)
  70. {
  71. new vehid = GetPlayerVehicleID(playerid), car = IsPlayerInAFBuyAbleCar(vehid);
  72. if(car != -1)
  73. {
  74. new Leader = CallRemoteFunction("GetPlayerLeaderID", "d", playerid);
  75. if(Leader != 0)
  76. {
  77. if(GetPlayerMoney(playerid) >= fCarDealerCars[car][fPrice])
  78. {
  79. new Slot = GetFreeFactionCarSlot();
  80. if(Slot != -1)
  81. {
  82. FactionCars[Slot][fModel] = fCarDealerCars[car][fModel];
  83. FactionCars[Slot][fFaction] = Leader;
  84. FactionCars[Slot][fExist] = true;
  85. mysql_query("INSERT INTO `factioncars`(`model`) VALUES (1)");
  86. mysql_query("SELECT max(id) FROM `factioncars`");
  87. mysql_store_result();
  88. mysql_fetch_row_format(string);
  89. FactionCars[Slot][fSQLid] = strval(string);
  90. FactionCars[Slot][fVehid] = CreateVehicle(FactionCars[Slot][fModel], 0.0, 0.0, 0.0, 0.0, 0, 0, 0);
  91. UpdateFactionCar(Slot);
  92. format(string, sizeof(string),"Info: Du hast dieses Fahrzeug für %d$ gekauft.", fCarDealerCars[car][fPrice]);
  93. SendClientMessage(playerid, Color_Green, string);
  94. GivePlayerMoney(playerid, -fCarDealerCars[car][fPrice]);
  95. return 1;
  96. }
  97. }
  98. else
  99. {
  100. format(string, sizeof(string), "Info: Du hast nicht genügend Geld. Dieses Fahrzeug kostet: %d$", fCarDealerCars[car][fPrice]);
  101. SendClientMessage(playerid, Color_Red, string);
  102. }
  103. }
  104. else return SendClientMessage(playerid, Color_Red, "Info: Du bist kein Leader einer Fraktion.");
  105. }
  106. else return SendClientMessage(playerid, Color_Red, "Info: Du befindest dich nicht in einem Kaufbaren Fahrzeug.");
  107. }
  108. if(strcmp(cmdtext, "/fpark", true) == 0)
  109. {
  110. new car = IsPlayerInAFactionCar(GetPlayerVehicleID(playerid));
  111. if(car != -1)
  112. {
  113. new Leader = CallRemoteFunction("GetPlayerLeaderID", "d", playerid);
  114. if(Leader != 0)
  115. {
  116. if(Leader == FactionCars[car][fFaction])
  117. {
  118. new Float: X, Float: Y, Float: Z, Float: R;
  119. GetPlayerPos(playerid, X, Y, Z);
  120. GetPlayerFacingAngle(playerid, R);
  121. FactionCars[car][fX] = X;
  122. FactionCars[car][fY] = Y;
  123. FactionCars[car][fZ] = Z;
  124. FactionCars[car][fR] = R;
  125. UpdateFactionCar(car);
  126. SendClientMessage(playerid, Color_Green, "Info: Fahrzeug geparkt.");
  127. return 1;
  128. }
  129. else return SendClientMessage(playerid, Color_Red, "Info: Dieses Fahrzeug gehört nicht zu deiner Fraktion.");
  130. }
  131. else return SendClientMessage(playerid, Color_Red, "Info: Du bist kein Leader.");
  132. }
  133. else return SendClientMessage(playerid, Color_Red, "Info: Du befindest dich in keinem Fraktion´s Fahrzeug.");
  134. }
  135. if(strcmp(cmdtext, "/fsellcar", true) == 0)
  136. {
  137. new car = IsPlayerInAFactionCar(GetPlayerVehicleID(playerid));
  138. if(car != -1)
  139. {
  140. new Leader = CallRemoteFunction("GetPlayerLeaderID", "d", playerid);
  141. if(Leader != 0)
  142. {
  143. if(Leader == FactionCars[car][fFaction])
  144. {
  145. for(new i = 0; i < sizeof(fCarDealerCars); i++)
  146. {
  147. if(GetVehicleModel(GetPlayerVehicleID(playerid)) == fCarDealerCars[i][fModel])
  148. {
  149. GivePlayerMoney(playerid, fCarDealerCars[i][fPrice]/2);
  150. DestroyVehicle(GetPlayerVehicleID(playerid));
  151. FactionCars[car][fExist] = false;
  152. SendClientMessage(playerid, Color_Green, "Info: Du hast dieses Fahrzeug für die hälfte des neupreises verkauft.");
  153. format(string, sizeof(string), "DELETE FROM `%s`.`factioncars` WHERE `factioncars`.`id` = %d", MySql_Database, FactionCars[car][fSQLid]);
  154. mysql_query(string);
  155. return 1;
  156. }
  157. }
  158. return 1;
  159. }
  160. else return SendClientMessage(playerid, Color_Red, "Info: Dieses Fahrzeug gehört nicht zu deiner Fraktion.");
  161. }
  162. else return SendClientMessage(playerid, Color_Red, "Info: Du bist kein Leader.");
  163. }
  164. else return SendClientMessage(playerid, Color_Red, "Info: Du befindest dich in keinem Fraktion´s Fahrzeug.");
  165. }
  166. return 0;
  167. }
  168.  
  169. public OnPlayerStateChange(playerid, newstate, oldstate)
  170. {
  171. new string[128];
  172. if(newstate == PLAYER_STATE_DRIVER)
  173. {
  174. new vehid = GetPlayerVehicleID(playerid), car = IsPlayerInAFBuyAbleCar(vehid);
  175. if(car != -1)
  176. {
  177. new Leader = CallRemoteFunction("GetPlayerLeaderID", "d", playerid);
  178. if(Leader != 0)
  179. {
  180. SendClientMessage(playerid, Color_Green, "==============[ Fraktion´s Autohaus ]===============");
  181. format(string, sizeof(string), "Model: %s", fCarDealerCars[car][fName]);
  182. SendClientMessage(playerid, Color_Grey, string);
  183. format(string, sizeof(string), "Preis: %d$", fCarDealerCars[car][fPrice]);
  184. SendClientMessage(playerid, Color_Grey, string);
  185. SendClientMessage(playerid, Color_Grey, "Du kannst dieses Fahrzeug mit \"/buyfcar\" kaufen oder einfach wieder verlassen.");
  186. SendClientMessage(playerid, Color_Green, "====================================================");
  187. return 1;
  188. }
  189. else
  190. {
  191. SendClientMessage(playerid, Color_Red, "Info: Du bist kein Leader einer Fraktion.");
  192. RemovePlayerFromVehicle(playerid);
  193. return 1;
  194. }
  195. }
  196. car = IsPlayerInAFactionCar(vehid);
  197. if(car != -1)
  198. {
  199. new Faction = CallRemoteFunction("GetPlayerFactionID", "d", playerid);
  200. if(Faction != FactionCars[car][fFaction])
  201. {
  202. SendClientMessage(playerid, Color_Red, "Info: Du befindest dich nicht in der richtigen Fraktion.");
  203. RemovePlayerFromVehicle(playerid);
  204. return 1;
  205. }
  206. }
  207. }
  208. return 1;
  209. }
  210.  
  211. stock IsPlayerInAFBuyAbleCar(carid)
  212. {
  213. for(new i = 0; i < sizeof(fCarDealerCars); i++)
  214. {
  215. if(carid == fCarDealerCars[i][fVehid])
  216. {
  217. return i;
  218. }
  219. }
  220. return -1;
  221. }
  222.  
  223. stock IsPlayerInAFactionCar(carid)
  224. {
  225. for(new i = 0; i < sizeof(FactionCars); i++)
  226. {
  227. if(FactionCars[i][fExist] == true && FactionCars[i][fVehid] == carid)
  228. {
  229. return i;
  230. }
  231. }
  232. return -1;
  233. }
  234.  
  235. stock GetFreeFactionCarSlot()
  236. {
  237. for(new i = 0; i < sizeof(FactionCars); i++)
  238. {
  239. if(FactionCars[i][fExist]==false)return i;
  240. }
  241. return -1;
  242. }
  243.  
  244. stock LoadFactionCars()
  245. {
  246. new Load[16], idx;
  247. mysql_query("SELECT * FROM factioncars");
  248. mysql_store_result();
  249. while(mysql_retrieve_row())
  250. {
  251. mysql_fetch_field_row(Load, "Model");
  252. FactionCars[idx][fModel] = strval(Load);
  253. mysql_fetch_field_row(Load, "X");
  254. FactionCars[idx][fX] = floatstr(Load);
  255. mysql_fetch_field_row(Load, "Y");
  256. FactionCars[idx][fY] = floatstr(Load);
  257. mysql_fetch_field_row(Load, "Z");
  258. FactionCars[idx][fZ] = floatstr(Load);
  259. mysql_fetch_field_row(Load, "R");
  260. FactionCars[idx][fR] = floatstr(Load);
  261. mysql_fetch_field_row(Load, "C1");
  262. FactionCars[idx][fc1] = strval(Load);
  263. mysql_fetch_field_row(Load, "C2");
  264. FactionCars[idx][fc2] = strval(Load);
  265. mysql_fetch_field_row(Load, "Faction");
  266. FactionCars[idx][fFaction] = strval(Load);
  267. mysql_fetch_field_row(Load, "id");
  268. FactionCars[idx][fSQLid] = strval(Load);
  269. FactionCars[idx][fVehid] = CreateVehicle(FactionCars[idx][fModel], FactionCars[idx][fX], FactionCars[idx][fY], FactionCars[idx][fZ], FactionCars[idx][fR], FactionCars[idx][fc1], FactionCars[idx][fc2], 60000);
  270. idx ++;
  271. }
  272. mysql_free_result();
  273. }
  274.  
  275. stock UpdateFactionCar(id)
  276. {
  277. new Query[128];
  278. if(FactionCars[id][fExist] == true)
  279. {
  280. format(Query, sizeof(Query), "UPDATE factioncars SET `Model` = '%d' WHERE `id` = '%d'", FactionCars[id][fModel], FactionCars[id][fSQLid]);
  281. mysql_query(Query);
  282. format(Query, sizeof(Query), "UPDATE factioncars SET `X` = '%f' WHERE `id` = '%d'", FactionCars[id][fX], FactionCars[id][fSQLid]);
  283. mysql_query(Query);
  284. format(Query, sizeof(Query), "UPDATE factioncars SET `Y` = '%f' WHERE `id` = '%d'", FactionCars[id][fY], FactionCars[id][fSQLid]);
  285. mysql_query(Query);
  286. format(Query, sizeof(Query), "UPDATE factioncars SET `Z` = '%f' WHERE `id` = '%d'", FactionCars[id][fZ], FactionCars[id][fSQLid]);
  287. mysql_query(Query);
  288. format(Query, sizeof(Query), "UPDATE factioncars SET `R` = '%f' WHERE `id` = '%d'", FactionCars[id][fR], FactionCars[id][fSQLid]);
  289. mysql_query(Query);
  290. format(Query, sizeof(Query), "UPDATE factioncars SET `C1` = '%d' WHERE `id` = '%d'", FactionCars[id][fc1], FactionCars[id][fSQLid]);
  291. mysql_query(Query);
  292. format(Query, sizeof(Query), "UPDATE factioncars SET `C2` = '%d' WHERE `id` = '%d'", FactionCars[id][fc2], FactionCars[id][fSQLid]);
  293. mysql_query(Query);
  294. format(Query, sizeof(Query), "UPDATE factioncars SET `Faction` = '%d' WHERE `id` = '%d'", FactionCars[id][fFaction], FactionCars[id][fSQLid]);
  295. mysql_query(Query);
  296. }
  297. return 1;
  298. }
  299. /*
  300. forward GetPlayerFactionID(playerid);
  301. public GetPlayerFactionID(playerid)
  302. {
  303. if(PlayerInfo[playerid][pLeader]!=0)return PlayerInfo[playerid][pLeader];
  304. else if(PlayerInfo[playerid][pMember]!=0)return PlayerInfo[playerid][pMember];
  305. }
  306.  
  307. forward GetPlayerLeaderID(playerid);
  308. public GetPlayerLeaderID(playerid)
  309. {
  310. return PlayerInfo[playerid][pLeader];
  311. }
  312. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement