Golshi

[FS] Sistema de Negocios

Mar 21st, 2016
1,117
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <a_samp>
  2. #include <zcmd>
  3. #include <sscanf2>
  4. #include <dini>
  5. #include <streamer>
  6.  
  7. #define MAX_BUSS 100
  8. #define NO_OWNER "INVALID_PLAYER_ID"
  9. #define CASE_SENSETIVE  true
  10. #define White 0xFFFFFFFF
  11. #define Yellow 0xFFFF00FF
  12. #define Grey 0xC0C0C0FF
  13. #define Red 0xFF0000AA
  14. #define Green 0x45E01FFF
  15.  
  16. new cpid[32];
  17. new String[200];
  18. new file[128];
  19. new Name[MAX_PLAYER_NAME];
  20. new Float:X,Float:Y,Float:Z;
  21. new Label[128];
  22. new BizExit;
  23. enum Business
  24. {
  25.     CP,
  26.     Text3D:bLabel,
  27.     Cost,
  28.     bName[128],
  29. }
  30. new BusinessInfo[MAX_BUSS][Business];
  31. forward Payday(playerid);
  32.  
  33. stock Float:GetPosInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
  34. {
  35.     new Float:a;
  36.     GetPlayerPos(playerid, x, y, a);
  37.     switch(IsPlayerInAnyVehicle(playerid))
  38.     {
  39.         case 0: GetPlayerFacingAngle(playerid, a);
  40.         case 1: GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  41.     }
  42.     x += (distance * floatsin(-a, degrees));
  43.     y += (distance * floatcos(-a, degrees));
  44.     return a;
  45. }
  46.  
  47. public OnFilterScriptInit()
  48. {
  49.     print("___________________________");
  50.     print("--Dynamic Business Loaded--");
  51.     print("      --Made by: Tee--     ");
  52.     print("      --Traducido por--    ");
  53.     print("         --Golshi--        ");
  54.     print("___________________________");
  55.     LoadBusinesses();
  56.     SetTimer("Payday",1_800_000,true);
  57.     BizExit = CreateDynamicCP(-25.9351,-141.5631,1003.5469,1,-1,16,-1,20);
  58.     return 1;
  59. }
  60.  
  61. public OnFilterScriptExit()
  62. {
  63.     UnloadBusinesses();
  64.     return 1;
  65. }
  66. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  67. {
  68.     for(new i = 0;i<MAX_BUSS;i++)
  69.     {
  70.         if(checkpointid == BusinessInfo[i][CP])
  71.         {
  72.             cpid[playerid] = i;
  73.             format(file,sizeof(file),"Business/%i.ini",i);
  74.             if(dini_Int(file, "HasOwner") == 0)
  75.             {
  76.                 ShowPlayerDialog(playerid,219,DIALOG_STYLE_MSGBOX,"Comprar Negocio","¿Seguro que quieres comprar este negocio?","Comprar","Cancelar");
  77.             }
  78.             else
  79.             {
  80.                 SetPlayerPos(playerid, -25.132598,-139.066986,1003.546875);
  81.                 SetPlayerInterior(playerid, 16);
  82.                 SetPlayerVirtualWorld(playerid, i);
  83.                 SetPlayerFacingAngle(playerid, 359.9003);
  84.             }
  85.         }
  86.     }
  87.     if(checkpointid == BizExit)
  88.     {
  89.         format(file, sizeof(file), "Business/%i.ini", GetPlayerVirtualWorld(playerid));
  90.         SetPlayerPos(playerid, dini_Float(file, "SpawnOutX"), dini_Float(file, "SpawnOutY"), dini_Float(file, "BusZ"));
  91.         SetPlayerFacingAngle(playerid, dini_Float(file, "A"));
  92.         SetPlayerVirtualWorld(playerid, 0);
  93.         SetPlayerInterior(playerid, 0);
  94.     }
  95.     return 1;
  96. }
  97. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  98. {
  99.     if(dialogid == 219)
  100.     {
  101.         if(response == 1)
  102.         {
  103.             if(GetPlayerBusinessID(playerid) == 1)return 0;
  104.             new busid;
  105.             format(file,sizeof(file),"Business/%i.ini",cpid[playerid]);
  106.             if(GetPlayerBusinessID(playerid) > -1)return SendClientMessage(playerid,Red,"¡Ya dispones de un negocio!");
  107.             if(dini_Int(file,"Cost") > GetPlayerMoney(playerid))return SendClientMessage(playerid,Red,"¡No tienes el dinero necesario para adquirir este negocio!.");
  108.             GivePlayerMoney(playerid, -dini_Int(file,"Cost"));
  109.             GetPlayerName(playerid,Name,sizeof(Name));
  110.             dini_Set(file, "Name", Name);
  111.             dini_Set(file, "Owner",Name);
  112.             dini_IntSet(file, "OwnedBus",1);
  113.             dini_IntSet(file, "HasOwner",1);
  114.             format(Label, sizeof(Label), "{ccccff}%s's Negocio\n\n{999999}%s\n{00BC00}Costo: {999999}$%i\n{00BC00}ID: {999999}%i",Name,dini_Get(file, "Owner"),dini_Int(file, "Cost"),busid);
  115.             Update3DTextLabelText(BusinessInfo[cpid[playerid]][bLabel],White,Label);
  116.             format(String,sizeof(String),"¡Has adquirido con éxito este negocio! %s.",dini_Get(file, "Name"));
  117.             SendClientMessage(playerid,Green,String);
  118.         }
  119.         if(response == 0)
  120.         {
  121.             SendClientMessage(playerid,Yellow,"Has optado por no comprar el negocio");
  122.         }
  123.     }
  124.     if(dialogid == 220)
  125.     {
  126.         if(response == 1)
  127.         {
  128.             GetPlayerName(playerid,Name,sizeof(Name));
  129.             format(file,sizeof(file),"Business/%i.ini",GetPlayerBusinessID(playerid));
  130.             format(Label, sizeof(Label), "{ccccff}¡En Venta!\n\n{999999}No hay Dueño\n{00BC00}Costo: {999999}$%i",dini_Get(file, "Name"),dini_Int(file, "Cost"));
  131.             Update3DTextLabelText(BusinessInfo[cpid[playerid]][bLabel],White,Label);
  132.             dini_Set(file, "Dueño","Sin Dueño");
  133.             dini_IntSet(file, "Cost",dini_Int(file, "Cost"));
  134.             dini_IntSet(file, "OwnedBus",0);
  135.             dini_IntSet(file, "HasOwner",0);
  136.             GivePlayerMoney(playerid,dini_Int(file, "Cost")/2);
  137.             SendClientMessage(playerid,Green,"Has vendido tu negocio y obtuviste el 50 porciento del total");
  138.         }
  139.     }
  140.     return 1;
  141. }
  142.  
  143. // This command is used to create the business.
  144. COMMAND:crearnegocio(playerid, params[])
  145. {
  146.     new busid,cost,name[128];
  147.     new Float:x,Float:y;
  148.     if(!IsPlayerAdmin(playerid))return 0;
  149.     if(sscanf(params,"I(500000)S(For Sale)[128]",cost,name))return SendClientMessage(playerid, 0xFF0000AA, "Usa: /crearnegocio [Precio] [Nombre]");
  150.     for(new i=0; i<MAX_BUSS; i++)
  151.     {
  152.         format(file,sizeof(file),"Business/%i.ini",i);
  153.         if(!dini_Exists(file))
  154.         {
  155.             busid = i;
  156.             break;
  157.         }
  158.     }
  159.     format(file,sizeof(file),"Business/%i.ini",busid);
  160.     BusinessInfo[busid][bName] = name;
  161.     BusinessInfo[busid][Cost] = cost;
  162.     GetPlayerPos(playerid, X, Y, Z);
  163.     GetPosInFrontOfPlayer(playerid, x, y, -2.5);
  164.     dini_Create(file);
  165.     dini_Set(file, "Name", name);
  166.     dini_Set(file, "Owner","No Owner");
  167.     dini_IntSet(file, "Cost",cost);
  168.     dini_FloatSet(file, "BusX", X);
  169.     dini_FloatSet(file, "BusY", Y);
  170.     dini_FloatSet(file, "BusZ", Z);
  171.     dini_FloatSet(file, "SpawnOutX", x);
  172.     dini_FloatSet(file, "SpawnOutY", y);
  173.     dini_FloatSet(file, "SpawnOutZ", Z);
  174.     dini_IntSet(file, "World",GetPlayerVirtualWorld(playerid));
  175.     dini_IntSet(file, "Interior",GetPlayerInterior(playerid));
  176.     dini_IntSet(file, "OwnedBus",0);
  177.     dini_IntSet(file, "HasOwner",0);
  178.     BusinessInfo[busid][CP] = CreateDynamicCP(X,Y,Z,1.0,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),-1,50.0);
  179.     format(Label, sizeof(Label), "{ccccff}%s\n{999999}No Owner\n{00BC00}Cost: {999999}$%i\nID: %i", name,cost,busid);
  180.     BusinessInfo[busid][bLabel] = Create3DTextLabel(Label,White,X,Y,Z,100.0,GetPlayerVirtualWorld(playerid),1);
  181.     format(String,sizeof(String),"BusinessCreated. Name: %s | Cost: $%i | Owner: No Owner | ID: %i",name,cost,busid);
  182.     SendClientMessage(playerid,Green,String);
  183.     return 1;
  184. }
  185. COMMAND:nombrenegocio(playerid, params[])
  186. {
  187.     new name[128];
  188.     if(sscanf(params,"s[128]",name))return SendClientMessage(playerid, 0xFF0000AA, "Usage: /nombrenegocio [Nombre]");
  189.     if(GetPlayerBusinessID(playerid) == -1) return SendClientMessage(playerid,Red,"Usted no es dueño de un Negocio.");
  190.     format(file,sizeof(file),"Business/%i.ini",GetPlayerBusinessID(playerid));
  191.     dini_Set(file, "Name", name);
  192.     format(String,sizeof(String),"Negocio renombrado a: %s",name);
  193.     SendClientMessage(playerid,Green,String);
  194.     format(Label, sizeof(Label), "{ccccff}%s\n\n{999999}%s\n{00BC00}Precio: {999999}$%i\n{00BC00}ID: {999999}%i",name, dini_Get(file, "Owner"),dini_Int(file, "Cost"),GetPlayerBusinessID(playerid));
  195.     Update3DTextLabelText(BusinessInfo[GetPlayerBusinessID(playerid)][bLabel],White,Label);
  196.     return 1;
  197. }
  198. //This command is used to delete a business.
  199. COMMAND:borrarnegocio(playerid, params[])
  200. {
  201.     new busid;
  202.     if(!IsPlayerAdmin(playerid)) return 0;
  203.     if(sscanf(params, "i", busid)) return SendClientMessage(playerid,0xC0C0C0FF,"Usa: /borrarnegocio [ID Negocio]");
  204.     format(file,sizeof(file),"Business/%i.ini",busid);
  205.     if(!dini_Exists(file))return SendClientMessage(playerid,Red,"¡Ese negocio no existe!");
  206.     format(String,sizeof(String),"Has borrado satisfactoriamente el negocio ID: %i.",busid);
  207.     SendClientMessage(playerid,Yellow,String);
  208.     DestroyDynamicCP(BusinessInfo[busid][CP]);
  209.     Delete3DTextLabel(BusinessInfo[busid][bLabel]);
  210.     dini_Remove(file);
  211.     return 1;
  212. }
  213.  
  214. //This command is used to sell a business (only owners can use it).
  215. COMMAND:vendernegocio(playerid, params[])
  216. {
  217.     if(GetPlayerBusinessID(playerid) == -1)return SendClientMessage(playerid,Red,"¡Usted no es dueño de un Negocio!");
  218.     ShowPlayerDialog(playerid,220,DIALOG_STYLE_MSGBOX,"Vender Negocio","¿Seguro que quieres vender tu negocio?","Vender","Cancelar");
  219.     return 1;
  220. }
  221.  
  222. //This function gets the owner of a specific business.
  223. stock GetBusOwner(bussid)
  224. {
  225.     new owner[MAX_PLAYER_NAME];
  226.     format(owner, MAX_PLAYER_NAME, NO_OWNER);
  227.     format(String, sizeof(String), "Business/%i.ini", bussid);
  228.     if(dini_Exists(String))
  229.     {
  230.         format(owner, MAX_PLAYER_NAME, "%s", dini_Get(String, "Owner"));
  231.         return owner;
  232.     }
  233.     return owner;
  234. }
  235.  
  236. //This function gets a business ID (it also tells if a player owns a business or not).
  237. stock GetPlayerBusinessID(playerid)
  238. {
  239.     new returnval, found=0;
  240.     for(new i = 0;i<MAX_BUSS;i++)
  241.     {
  242.         format(String,sizeof(String),"Business/%i.ini",i);
  243.         if(dini_Exists(String))
  244.         {
  245.             GetPlayerName(playerid,Name,sizeof(Name));
  246.             if(!strcmp(Name, dini_Get(String,"Owner"), false))
  247.             {
  248.                 returnval = i;
  249.                 found = 1;
  250.             }
  251.         }
  252.     }
  253.     if(!found) returnval = -1;
  254.     return returnval;
  255. }
  256.  
  257.  
  258. //This command removes a player from owning a business.
  259. COMMAND:quitarlenegocio(playerid, params[])
  260. {
  261.     new id;
  262.     if(!IsPlayerAdmin(playerid))return 0;
  263.     if(sscanf(params,"u", id))return SendClientMessage(playerid, 0xFF0000AA, "Usa: /quitarlenegocio [Player ID]");
  264.     if(GetPlayerBusinessID(id) == -1)return SendClientMessage(playerid,Red,"Ese jugador no posee un negocio");
  265.     format(String,sizeof(String),"Business/%i.ini",GetPlayerBusinessID(id));
  266.     format(Label, sizeof(Label), "{ccccff}%s\n{999999}Sin Dueño\n{00BC00}Costo: {999999}$%i",dini_Get(String, "Name"),dini_Int(String, "Cost"));
  267.     Update3DTextLabelText(BusinessInfo[GetPlayerBusinessID(id)][bLabel],White,Label);
  268.     dini_Set(String, "Owner","No Owner");
  269.     dini_IntSet(String, "Cost",dini_Int(String, "Cost"));
  270.     dini_IntSet(String, "OwnedBus",0);
  271.     dini_IntSet(String, "HasOwner",0);
  272.     GivePlayerMoney(id,dini_Int(String, "Cost")/4);
  273.     format(String, sizeof(String), "You have removed %s as the owner of his/her business.",Name);
  274.     SendClientMessage(playerid,Red, String);
  275.     return 1;
  276. }
  277.  
  278. //This function loads every business.
  279. stock LoadBusinesses()
  280. {
  281.     new count = 0;
  282.     for(new i=0; i<MAX_BUSS; i++)
  283.     {
  284.         format(String,sizeof(String),"Business/%i.ini",i); // the ID would be the name of the file, 1 2 3 4 5 etc
  285.         if(dini_Exists(String)) //thats the easiest way to get IDs of them, you don't need to write it inside of the file itself if the name of the file is a number.. looks good?
  286.         {
  287.             BusinessInfo[i][CP] = CreateDynamicCP(dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ"),1.0,dini_Int(String, "World"),dini_Int(String, "Interior"),-1,100.0);
  288.             if(!strcmp(GetBusOwner(i), NO_OWNER, CASE_SENSETIVE))
  289.             {
  290.                 format(Label, sizeof(Label), "{ccccff}%s\n{999999}Sin Dueño\n{00BC00}Precio: {999999}$%i",dini_Get(String, "Name"),dini_Int(String, "Cost"));
  291.                 BusinessInfo[i][bLabel] = Create3DTextLabel(Label,White,dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ")+1,100.0,0,1);
  292.             }
  293.             if(strcmp(GetBusOwner(i), NO_OWNER, CASE_SENSETIVE))//i will be what index it's at in the loop which would be the ID as its looping through all the files
  294.             {
  295.                 format(Label, sizeof(Label), "{ccccff}%s\n\n{999999}%s\n{00BC00}Precio: {999999}$%i\n{00BC00}ID: {999999}%i",dini_Get(String, "Name"), dini_Get(String, "Owner"),dini_Int(String, "Cost"),i);
  296.                 BusinessInfo[i][bLabel] = Create3DTextLabel(Label,White,dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ")+1,100.0,0,1);
  297.             }
  298.             count++;
  299.         }
  300.     }
  301.     return printf("Total de Negocios Cargados: %i",count);
  302. }
  303.  
  304. //This function gets the last bused business ID.
  305. stock GetLastBusinessID()
  306. {
  307.     new count = 0;
  308.     for(new i=0; i<MAX_BUSS; i++)
  309.     {
  310.         format(String,sizeof(String),"Business/%i.ini",i);
  311.         {
  312.             count++;
  313.         }
  314.     }
  315.     return count;
  316. }
  317.  
  318. //This function unloads every business.
  319. stock UnloadBusinesses()
  320. {
  321.     for(new i=0; i<MAX_BUSS; i++)
  322.     {
  323.         Delete3DTextLabel(BusinessInfo[i][bLabel]);
  324.         DestroyDynamicCP(BusinessInfo[i][CP]);
  325.     }
  326.     return 1;
  327. }
  328.  
  329. //This is used by RCON admins. Either to debug or to force a payday.
  330. COMMAND:forcepayday(playerid,params[])
  331. {
  332.     if(!IsPlayerAdmin(playerid))return 0;
  333.     SendClientMessage(playerid,Grey,"You have forced a payday.");
  334.     for(new i=0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) Payday(i);
  335.     return 1;
  336. }
  337.  
  338. #define TIMEDEBUG 1 //set this to 0 if you don't want it to print the time it took for this function to execute
  339.  
  340. //This function is the payday (to pay the owners).
  341. public Payday(playerid)
  342. {
  343.     #if TIMEDEBUG == 1
  344.     new tick = GetTickCount();
  345.     #endif
  346.     if(GetPlayerBusinessID(playerid) != -1)
  347.     {
  348.         new RandMoney = rand(100_000, 250_000), msg[128];
  349.         GivePlayerMoney(playerid, RandMoney);
  350.         format(msg, sizeof(msg), "[Actualizacion de tu Negocio] Has Recibido $%i", RandMoney);
  351.         SendClientMessage(playerid, Green, msg);
  352.         format(msg, sizeof(msg), "~w~Has recibido ~g~$%i ~w~from your biz", RandMoney);
  353.         GameTextForPlayer(playerid, msg, 4000,3);
  354.     }
  355.     else return SendClientMessage(playerid, Green, "Si usted tuviera un negocio, usted habría recibido un cheque de pago!");
  356.     #if TIMEDEBUG == 1
  357.     printf("Time taken to execute Payday(): %i", GetTickCount()-tick);
  358.     #endif
  359.     return 1;
  360. }
  361. stock pName(playerid)
  362. {
  363.     new name[MAX_PLAYER_NAME];
  364.     GetPlayerName(playerid, name, sizeof(name));
  365.     return name;
  366. }
  367. stock rand(minnum = cellmin,maxnum = cellmax) return random(maxnum - minnum + 1) + minnum; //swtiches so much better
RAW Paste Data