Advertisement
vicesource

Dealership

May 1st, 2011
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 15.23 KB | None | 0 0
  1. // ---------------- LoadCar (não sei se é importante) ----------------
  2.  
  3. public LoadCar()
  4. {
  5.     new arrCoords[13][64];
  6.     new strFromFile2[256];
  7.     new File: file = fopen("cars.cfg", io_read);
  8.     if (file)
  9.     {
  10.         new idx = 184;
  11.         while (idx < sizeof(CarInfo))
  12.         {
  13.             fread(file, strFromFile2);
  14.             split(strFromFile2, arrCoords, ',');
  15.             CarInfo[idx][cModel] = strval(arrCoords[0]);
  16.             CarInfo[idx][cLocationx] = floatstr(arrCoords[1]);
  17.             CarInfo[idx][cLocationy] = floatstr(arrCoords[2]);
  18.             CarInfo[idx][cLocationz] = floatstr(arrCoords[3]);
  19.             CarInfo[idx][cAngle] = floatstr(arrCoords[4]);
  20.             CarInfo[idx][cColorOne] = strval(arrCoords[5]);
  21.             CarInfo[idx][cColorTwo] = strval(arrCoords[6]);
  22.             strmid(CarInfo[idx][cOwner], arrCoords[7], 0, strlen(arrCoords[7]), 255);
  23.             strmid(CarInfo[idx][cDescription], arrCoords[8], 0, strlen(arrCoords[8]), 255);
  24.             CarInfo[idx][cValue] = strval(arrCoords[9]);
  25.             CarInfo[idx][cLicense] = strval(arrCoords[10]);
  26.             CarInfo[idx][cOwned] = strval(arrCoords[11]);
  27.             CarInfo[idx][cLock] = strval(arrCoords[12]);
  28.             printf("CarInfo: %d Owner:%s LicensePlate %s",idx,CarInfo[idx][cOwner],CarInfo[idx][cLicense]);
  29.             idx++;
  30.         }
  31.     }
  32.     return 1;
  33. }
  34.  
  35. public SaveCarCoords()
  36. {
  37.     new idx;
  38.     new File: file2;
  39.     while (idx < sizeof(CarInfo))
  40.     {
  41.         new coordsstring[256];
  42.         format(coordsstring, sizeof(coordsstring), "%d|%f|%f|%f|%f|%d|%d\n",
  43.         CarInfo[idx][cModel],
  44.         CarInfo[idx][cLocationx],
  45.         CarInfo[idx][cLocationy],
  46.         CarInfo[idx][cLocationz],
  47.         CarInfo[idx][cAngle],
  48.         CarInfo[idx][cColorOne],
  49.         CarInfo[idx][cColorTwo]);
  50.         if(idx == 0)
  51.         {
  52.             file2 = fopen("cars.cfg", io_write);
  53.         }
  54.         else
  55.         {
  56.             file2 = fopen("cars.cfg", io_append);
  57.         }
  58.         fwrite(file2, coordsstring);
  59.         idx++;
  60.         fclose(file2);
  61.     }
  62.     return 1;
  63. }
  64.  
  65. // ---------------- IsAtDealership ----------------
  66.  
  67. public IsAtDealership(playerid)
  68. {
  69.     if(IsPlayerConnected(playerid))
  70.     {
  71.         if(PlayerToPoint(50,playerid,114.9868, 1063.8870, 18.8080))
  72.         {
  73.             return 1;
  74.         }
  75.     }
  76.     return 0;
  77. }
  78.  
  79. // ---------------- Comando /v (apenas a parte de vender) ----------------
  80.  
  81.  
  82.     if(strcmp(cmd, "/v", true) == 0 || strcmp(cmd, "/vehicle", true) == 0) //
  83.     {
  84.         if(IsPlayerConnected(playerid))
  85.         {
  86.             if(gPlayerLogged[playerid] == 0)
  87.             {
  88.                 SendClientMessage(playerid, COLOR_GREY, "   You need to login first ! ");
  89.                 return 1;
  90.             }
  91.             new x_nr[64];
  92.             x_nr = strtok(cmdtext, idx);
  93.             if(!strlen(x_nr))
  94.             {
  95.                 SendClientMessage(playerid, COLOR_WHITE, "HINT: (/v)ehicle [name]");
  96.                 SendClientMessage(playerid, COLOR_WHITE, "Available names: park, lock(1-3), sell, sellto, color, carowner");
  97.                 return 1;
  98.             }
  99.  
  100.             if(strcmp(x_nr,"sell",true) == 0)
  101.             {
  102.                 if(IsAtDealership(playerid))
  103.                 {
  104.                     if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3])
  105.                     {
  106.                         GetPlayerName(playerid, sendername, sizeof(sendername));
  107.                         new ownvehkey;
  108.                         if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
  109.                         else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
  110.                         else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3]) { ownvehkey = PlayerInfo[playerid][pPcarkey3]; }
  111.                         else { return 1; }
  112.                         if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)
  113.                         {
  114.                             new carsellprice = CarInfo[ownvehkey][cValue] / 4 * 3;
  115.                             new Float:x,Float:y,Float:z;
  116.                             new Float:a;
  117.                             CarInfo[ownvehkey][cOwned] = 0;
  118.                             strmid(CarInfo[ownvehkey][cOwner], "Dealership", 0, strlen("Dealership"), 999);
  119.                             SafeGivePlayerMoney(playerid,carsellprice);
  120.                             PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  121.                             format(string, sizeof(string), "~w~You have sold your car for: ~n~~g~$%d", carsellprice);
  122.                             GameTextForPlayer(playerid, string, 10000, 3);
  123.                             GetVehiclePos(ownvehkey, x, y, z);
  124.                             GetVehicleZAngle(ownvehkey, a);
  125.                             CarInfo[ownvehkey][cLocationx] = x;
  126.                             CarInfo[ownvehkey][cLocationy] = y;
  127.                             CarInfo[ownvehkey][cLocationz] = z;
  128.                             CarInfo[ownvehkey][cAngle] = a;
  129.                             if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { PlayerInfo[playerid][pPcarkey] = 999; }
  130.                             else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { PlayerInfo[playerid][pPcarkey2] = 999; }
  131.                             else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3]) { PlayerInfo[playerid][pPcarkey3] = 999; }
  132.                             RemovePlayerFromVehicle(playerid);
  133.                             TogglePlayerControllable(playerid, 1);
  134.                             if(PlayerInfo[playerid][pLocal] == ownvehkey)
  135.                             {
  136.                                 SetPlayerInterior(playerid,0);
  137.                                 SetPlayerPos(playerid,CarInfo[ownvehkey][cLocationx],CarInfo[ownvehkey][cLocationy],CarInfo[ownvehkey][cLocationz]);
  138.                                 PlayerInfo[playerid][pInt] = 0;
  139.                             }
  140.                             OnPropUpdate();
  141.                             OnPlayerUpdate(playerid);
  142.                             DestroyVehicle(ownvehkey);
  143.                             CreateVehicle(CarInfo[ownvehkey][cModel],CarInfo[ownvehkey][cLocationx],CarInfo[ownvehkey][cLocationy],CarInfo[ownvehkey][cLocationz]+1.0,CarInfo[ownvehkey][cAngle],CarInfo[ownvehkey][cColorOne],CarInfo[ownvehkey][cColorTwo],60000);
  144.                             return 1;
  145.                         }
  146.                     }
  147.                     else
  148.                     {
  149.                         SendClientMessage(playerid, COLOR_GREY, "  You have to sit at your own car to sell it! ");
  150.                         return 1;
  151.                     }
  152.                 }
  153.                 else
  154.                 {
  155.                     SendClientMessage(playerid, COLOR_GREY, "You are not at a dealership");
  156.                     return 1;
  157.                 }
  158.             }
  159.             else if(strcmp(x_nr,"sellto",true) == 0)
  160.             {
  161.                 if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2] || GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3])
  162.                 {
  163.                     GetPlayerName(playerid, sendername, sizeof(sendername));
  164.                     new ownvehkey;
  165.                     if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey]) { ownvehkey = PlayerInfo[playerid][pPcarkey]; }
  166.                     else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey2]) { ownvehkey = PlayerInfo[playerid][pPcarkey2]; }
  167.                     else if(GetPlayerVehicleID(playerid) == PlayerInfo[playerid][pPcarkey3]) { ownvehkey = PlayerInfo[playerid][pPcarkey3]; }
  168.                     else { return 1; }
  169.                     if(strcmp(sendername, CarInfo[ownvehkey][cOwner], true) == 0)
  170.                     {
  171.                         tmp = strtok(cmdtext, idx);
  172.                         if(!strlen(tmp))
  173.                         {
  174.                             SendClientMessage(playerid, COLOR_WHITE, "HINT: /v sellto [playerid/PartOfName] [price]");
  175.                             return 1;
  176.                         }
  177.                         giveplayerid = ReturnUser(tmp);
  178.                         if(IsPlayerConnected(giveplayerid))
  179.                         {
  180.                             if(giveplayerid != INVALID_PLAYER_ID)
  181.                             {
  182.                                 if(ProxDetectorS(8.0, playerid, giveplayerid))
  183.                                 {
  184.                                     if(PlayerInfo[giveplayerid][pPcarkey] == 999)
  185.                                     {
  186.                                         tmp = strtok(cmdtext, idx);
  187.                                         if(!strlen(tmp))
  188.                                         {
  189.                                             SendClientMessage(playerid, COLOR_WHITE, "HINT: /v sellto [playerid/PartOfName] [price]");
  190.                                             return 1;
  191.                                         }
  192.                                         new price;
  193.                                         price = strval(tmp);
  194.                                         if(price < 1 || price > 1500000)
  195.                                         {
  196.                                             SendClientMessage(playerid, COLOR_GREY, "  Price not lower then 1 and not higher then 1500000. ");
  197.                                             return 1;
  198.                                         }
  199.                                         GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
  200.                                         format(string, sizeof(string), "* You offerd %s to buy your car for $%d .", giveplayer, price);
  201.                                         SendClientMessage(playerid, COLOR_WHITE, string);
  202.                                         format(string, sizeof(string), "* Car Owner %s offered you to buy his/her car for $%d (type /accept ownablecar) to buy.", playername, price);
  203.                                         SendClientMessage(giveplayerid, COLOR_WHITE, string);
  204.                                         OwnableCarOffer[giveplayerid] = playerid;
  205.                                         OwnableCarID[giveplayerid] = ownvehkey;
  206.                                         OwnableCarPrice[giveplayerid] = price;
  207.                                         return 1;
  208.                                     }
  209.                                     else if(PlayerInfo[giveplayerid][pPcarkey2] == 999)
  210.                                     {
  211.                                         tmp = strtok(cmdtext, idx);
  212.                                         if(!strlen(tmp))
  213.                                         {
  214.                                             SendClientMessage(playerid, COLOR_WHITE, "HINT: /v sellto [playerid/PartOfName] [price]");
  215.                                             return 1;
  216.                                         }
  217.                                         new price;
  218.                                         price = strval(tmp);
  219.                                         if(price < 1 || price > 1500000)
  220.                                         {
  221.                                             SendClientMessage(playerid, COLOR_GREY, "  Price not lower then 1 and not higher then 1500000. ");
  222.                                             return 1;
  223.                                         }
  224.                                         GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
  225.                                         format(string, sizeof(string), "* You offerd %s to buy your car for $%d .", giveplayer, price);
  226.                                         SendClientMessage(playerid, COLOR_WHITE, string);
  227.                                         format(string, sizeof(string), "* Car Owner %s offered you to buy his/her car for $%d (type /accept ownablecar) to buy.", playername, price);
  228.                                         SendClientMessage(giveplayerid, COLOR_WHITE, string);
  229.                                         OwnableCarOffer[giveplayerid] = playerid;
  230.                                         OwnableCarID[giveplayerid] = ownvehkey;
  231.                                         OwnableCarPrice[giveplayerid] = price;
  232.                                         return 1;
  233.                                     }
  234.                                     else if(PlayerInfo[giveplayerid][pPcarkey3] == 999)
  235.                                     {
  236.                                         tmp = strtok(cmdtext, idx);
  237.                                         if(!strlen(tmp))
  238.                                         {
  239.                                             SendClientMessage(playerid, COLOR_WHITE, "HINT: /v sellto [playerid/PartOfName] [price]");
  240.                                             return 1;
  241.                                         }
  242.                                         new price;
  243.                                         price = strval(tmp);
  244.                                         if(price < 1 || price > 1500000)
  245.                                         {
  246.                                             SendClientMessage(playerid, COLOR_GREY, "  Price not lower then 1 and not higher then 1500000. ");
  247.                                             return 1;
  248.                                         }
  249.                                         GetPlayerName(giveplayerid, giveplayer, sizeof(giveplayer));
  250.                                         format(string, sizeof(string), "* You offerd %s to buy your car for $%d .", giveplayer, price);
  251.                                         SendClientMessage(playerid, COLOR_WHITE, string);
  252.                                         format(string, sizeof(string), "* Car Owner %s offered you to buy his/her car for $%d (type /accept ownablecar) to buy.", playername, price);
  253.                                         SendClientMessage(giveplayerid, COLOR_WHITE, string);
  254.                                         OwnableCarOffer[giveplayerid] = playerid;
  255.                                         OwnableCarID[giveplayerid] = ownvehkey;
  256.                                         OwnableCarPrice[giveplayerid] = price;
  257.                                         return 1;
  258.                                     }
  259.                                     else
  260.                                     {
  261.                                         SendClientMessage(playerid, COLOR_GREY, "   Player has 3 cars already ! ");
  262.                                         return 1;
  263.                                     }
  264.                                 }
  265.                                 else
  266.                                 {
  267.                                     SendClientMessage(playerid, COLOR_GREY, "   Player is not near you ! ");
  268.                                     return 1;
  269.                                 }
  270.                             }
  271.                         }
  272.                     }
  273.                     else
  274.                     {
  275.                         SendClientMessage(playerid, COLOR_GREY, "  This is not your car");
  276.                         return 1;
  277.                     }
  278.                 }
  279.                 else
  280.                 {
  281.                     SendClientMessage(playerid, COLOR_GREY, "  You have to sit at your own car to sell it");
  282.                     return 1;
  283.                 }
  284.             }
  285.  
  286. // ---------------- Comando /asellcar e /acarsell (admin vender um carro)(penso que são comandos iguais) ----------------
  287.  
  288.     if(!strcmp(cmdtext, "/asellcar", true))
  289.     {
  290.         if(IsPlayerConnected(playerid))
  291.         {
  292.             if(gPlayerLogged[playerid] == 0)
  293.             {
  294.                 SendClientMessage(playerid, COLOR_GREY, "   You need to login first !");
  295.                 return 1;
  296.             }
  297.             if(!IsAtDealership(playerid))
  298.             {
  299.                 SendClientMessage(playerid, COLOR_GREY, "   You are not at dealership ! ");
  300.                 return 1;
  301.             }
  302.             if(PlayerInfo[playerid][pAdmin] >= 1337)
  303.             {
  304.                 new vehid = GetPlayerVehicleID(playerid);
  305.                 new Float:x,Float:y,Float:z;
  306.                 new Float:a;
  307.                 CarInfo[vehid][cOwned] = 0;
  308.                 strmid(CarInfo[vehid][cOwner], "Dealership", 0, strlen("Dealership"), 999);
  309.                 PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  310.                 GameTextForPlayer(playerid, "~w~You have admin sold the vehicle", 10000, 3);
  311.                 GetVehiclePos(vehid, x, y, z);
  312.                 GetVehicleZAngle(vehid, a);
  313.                 CarInfo[vehid][cLocationx] = x;
  314.                 CarInfo[vehid][cLocationy] = y;
  315.                 CarInfo[vehid][cLocationz] = z;
  316.                 CarInfo[vehid][cAngle] = a;
  317.                 RemovePlayerFromVehicle(playerid);
  318.                 TogglePlayerControllable(playerid, 1);
  319.                 OnPropUpdate();
  320.                 DestroyVehicle(vehid);
  321.                 CreateVehicle(CarInfo[vehid][cModel],CarInfo[vehid][cLocationx],CarInfo[vehid][cLocationy],CarInfo[vehid][cLocationz]+1.0,CarInfo[vehid][cAngle],CarInfo[vehid][cColorOne],CarInfo[vehid][cColorTwo],60000);
  322.                 return 1;
  323.             }
  324.             else
  325.             {
  326.                 SendClientMessage(playerid, COLOR_GREY, "   You're not authorized to use that command !");
  327.                 return 1;
  328.             }
  329.         }
  330.         return 1;
  331.     }
  332.  
  333.     if(strcmp(cmd, "/acarsell", true) == 0)
  334.     {
  335.         if(IsPlayerConnected(playerid))
  336.         {
  337.             GetPlayerName(playerid, playername, sizeof(playername));
  338.             tmp = strtok(cmdtext, idx);
  339.             if(!strlen(tmp))
  340.             {
  341.                 SendClientMessage(playerid, COLOR_GRAD1, "USAGE: /acarsell [bizid]");
  342.                 return 1;
  343.             }
  344.             new car = strval(tmp);
  345.             if(PlayerInfo[playerid][pAdmin] >= 4)
  346.             {
  347.                 strmid(CarInfo[car][cOwner], "Dealership", 0, strlen("Dealership"), 999);
  348.                 PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
  349.                 CarInfo[car][cOwned] = 0;
  350.                 CarInfo[car][cLock] = 1;
  351.                 format(string, sizeof(string), "~w~You have sold the Car");
  352.                 GameTextForPlayer(playerid, string, 2500, 3);
  353.                 OnPropUpdate();
  354.             }
  355.             else
  356.             {
  357.                 SendClientMessage(playerid, COLOR_WHITE, "You are not an admin.");
  358.             }
  359.         }
  360.         return 1;
  361.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement