Advertisement
Guest User

Marin's Dynamic Biz System

a guest
Jul 6th, 2012
799
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 20.99 KB | None | 0 0
  1. //==============================================================================
  2. //==============================================================================
  3. //======            =======            =============            ================
  4. //==========   ============   ======================   =========================
  5. //==========   ============   ======================   =========================
  6. //==========   ============        =================        ====================
  7. //==========   ============   ======================   =========================
  8. //==========   ============   ======================   =========================
  9. //==========   ============            =============               =============
  10. //==============================================================================
  11. //==============================================================================
  12. //==============================================================================
  13. //==============================================================================
  14. //******************************************************************************
  15. //                 *ScotTees Dynamic Business System*
  16. //******************************************************************************
  17. //Originala FS stvorena od ruke Tee, editovana SnG.Scot_MisCuDi i [ABK]Antonio
  18. //                   |---------Credits:------------|
  19. //                   |  Zeex - Zcmd                |
  20. //                   |  Darco - Dini               |
  21. //                   |  Y_Less - Sscanf2           |
  22. //                   |  Tee - The FS               |
  23. //                   |  SnG.Scot_MisCuDi - Edit FS |
  24. //                   |  [ABK]Antonio - Edit FS     |
  25. //                   |  Incognito- Streamer plugin.|
  26. //                   |-----------------------------|
  27.  
  28.  
  29. #include <a_samp>
  30. #include <zcmd>
  31. #include <sscanf2>
  32. /*
  33.  *            Dini 1.6
  34.  *       (c) Copyright 2006-2008 by DracoBlue
  35.  *
  36.  * @author    : DracoBlue (http://dracoblue.com)
  37.  * @date      : 13th May 2006
  38.  * @update    : 16th Sep 2008
  39.  *
  40.  * This file is provided as is (no warranties).
  41.  *
  42.  * It's released under the terms of MIT.
  43.  *
  44.  * Feel free to use it, a little message in
  45.  * about box is honouring thing, isn't it?
  46.  *
  47.  */
  48.  
  49. #if defined _dini_included
  50.   #endinput
  51. #endif
  52.  
  53. #define _dini_included
  54. #pragma library dini
  55.  
  56. #if defined MAX_STRING
  57. #define DINI_MAX_STRING MAX_STRING
  58. #else
  59. #define DINI_MAX_STRING 255
  60. #endif
  61.  
  62. stock dini_Exists(filename[]) {
  63.     return fexist(filename);
  64. }
  65.  
  66. stock dini_Remove(filename[]) {
  67.     return fremove(filename);
  68. }
  69.  
  70. stock dini_Create(filename[]) {
  71.     if (fexist(filename)) return false;
  72.     new File:fhnd;
  73.     fhnd=fopen(filename,io_write);
  74.     if (fhnd) {
  75.         fclose(fhnd);
  76.         return true;
  77.     }
  78.     return false;
  79. }
  80.  
  81. stock dini_Set(filename[],key[],value[]) {
  82.     // If we have no key, it can't be set
  83.     // we also have no chance to set the value, if all together is bigger then the max string
  84.     new key_length = strlen(key);
  85.     new value_length = strlen(value);
  86.     if (key_length==0 || key_length+value_length+2>DINI_MAX_STRING) return false;
  87.  
  88.     new File:fohnd, File:fwhnd;
  89.     new tmpres[DINI_MAX_STRING];
  90.     new bool:wasset=false;
  91.  
  92.     // Let's remove the old *.part file if there was one.
  93.     format(tmpres,sizeof(tmpres),"%s.part",filename);
  94.     fremove(tmpres);
  95.  
  96.     // We'll open the source file.
  97.     fohnd=fopen(filename,io_read);
  98.     if (!fohnd) return false;
  99.  
  100.     fwhnd=fopen(tmpres,io_write);
  101.     if (!fwhnd) {
  102.         // we can't open the second file for writing, so .. let's close the open one and exit.
  103.         fclose(fohnd);
  104.         return false;
  105.     }
  106.  
  107.     while (fread(fohnd,tmpres)) {
  108.         if (
  109.             !wasset
  110.             && tmpres[key_length]=='='
  111.             && !strcmp(tmpres, key, true, key_length)
  112.         ) {
  113.                 // We've got what needs to be replaced!
  114.                 format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  115.                 wasset=true;
  116.         } else {
  117.             DINI_StripNewLine(tmpres);
  118.         }
  119.         fwrite(fwhnd,tmpres);
  120.         fwrite(fwhnd,"\r\n");
  121.     }
  122.  
  123.     if (!wasset) {
  124.         format(tmpres,sizeof(tmpres),"%s=%s",key,value);
  125.         fwrite(fwhnd,tmpres);
  126.         fwrite(fwhnd,"\r\n");
  127.     }
  128.  
  129.     fclose(fohnd);
  130.     fclose(fwhnd);
  131.  
  132.     format(tmpres,sizeof(tmpres),"%s.part",filename);
  133.     if (DINI_fcopytextfile(tmpres,filename)) {
  134.         return fremove(tmpres);
  135.     }
  136.     return false;
  137. }
  138.  
  139.  
  140. stock dini_IntSet(filename[],key[],value) {
  141.    new valuestring[DINI_MAX_STRING];
  142.    format(valuestring,DINI_MAX_STRING,"%d",value);
  143.    return dini_Set(filename,key,valuestring);
  144. }
  145.  
  146. stock dini_Int(filename[],key[]) {
  147.    return strval(dini_Get(filename,key));
  148. }
  149.  
  150. stock dini_FloatSet(filename[],key[],Float:value) {
  151.    new valuestring[DINI_MAX_STRING];
  152.    format(valuestring,DINI_MAX_STRING,"%f",value);
  153.    return dini_Set(filename,key,valuestring);
  154. }
  155.  
  156. stock Float:dini_Float(filename[],key[]) {
  157.    return floatstr(dini_Get(filename,key));
  158. }
  159.  
  160. stock dini_Bool(filename[],key[]) {
  161.    return strval(dini_Get(filename,key));
  162. }
  163.  
  164. stock dini_BoolSet(filename[],key[],value) {
  165.     if (value) {
  166.         return dini_Set(filename,key,"1");
  167.     }
  168.     return dini_Set(filename,key,"0");
  169. }
  170.  
  171. stock dini_Unset(filename[],key[]) {
  172.     // If we have no key, it can't be set
  173.     // we also have no chance to unset the key, if all together is bigger then the max string
  174.     new key_length = strlen(key);
  175.     if (key_length==0 || key_length+2>DINI_MAX_STRING) return false;
  176.  
  177.     new File:fohnd, File:fwhnd;
  178.     new tmpres[DINI_MAX_STRING];
  179.  
  180.     // Let's remove the old *.part file if there was one.
  181.     format(tmpres,DINI_MAX_STRING,"%s.part",filename);
  182.     fremove(tmpres);
  183.  
  184.     // We'll open the source file.
  185.     fohnd=fopen(filename,io_read);
  186.     if (!fohnd) return false;
  187.  
  188.     fwhnd=fopen(tmpres,io_write);
  189.     if (!fwhnd) {
  190.         // we can't open the second file for writing, so .. let's close the open one and exit.
  191.         fclose(fohnd);
  192.         return false;
  193.     }
  194.  
  195.     while (fread(fohnd,tmpres)) {
  196.         if (
  197.             tmpres[key_length]=='='
  198.             && !strcmp(tmpres, key, true, key_length)
  199.         ) {
  200.                 // We've got what needs to be removed!
  201.         } else {
  202.             DINI_StripNewLine(tmpres);
  203.             fwrite(fwhnd,tmpres);
  204.             fwrite(fwhnd,"\r\n");
  205.         }
  206.     }
  207.  
  208.     fclose(fohnd);
  209.     fclose(fwhnd);
  210.  
  211.     format(tmpres,DINI_MAX_STRING,"%s.part",filename);
  212.     if (DINI_fcopytextfile(tmpres,filename)) {
  213.         return fremove(tmpres);
  214.     }
  215.     return false;
  216. }
  217.  
  218. stock dini_Get(filename[],key[]) {
  219.     new tmpres[DINI_MAX_STRING];
  220.  
  221.     new key_length = strlen(key);
  222.     if (key_length==0 || key_length+2>DINI_MAX_STRING) return tmpres;
  223.  
  224.     new File:fohnd;
  225.     fohnd=fopen(filename,io_read);
  226.     if (!fohnd) return tmpres;
  227.  
  228.     while (fread(fohnd,tmpres)) {
  229.         if (
  230.             tmpres[key_length]=='='
  231.             && !strcmp(tmpres, key, true, key_length)
  232.         ) {
  233.             /* We've got what we need */
  234.             DINI_StripNewLine(tmpres);
  235.             strmid(tmpres, tmpres, key_length + 1, strlen(tmpres), DINI_MAX_STRING);
  236.             fclose(fohnd);
  237.             return tmpres;
  238.         }
  239.     }
  240.     fclose(fohnd);
  241.     return tmpres;
  242. }
  243.  
  244.  
  245. stock dini_Isset(filename[],key[]) {
  246.     new key_length = strlen(key);
  247.     if (key_length==0 || key_length+2>DINI_MAX_STRING) return false;
  248.  
  249.     new File:fohnd;
  250.     fohnd=fopen(filename,io_read);
  251.     if (!fohnd) return false;
  252.  
  253.     new tmpres[DINI_MAX_STRING];
  254.     while (fread(fohnd,tmpres)) {
  255.         if (
  256.                 tmpres[key_length]=='='
  257.             &&  !strcmp(tmpres, key, true, key_length)
  258.         ) {
  259.             // We've got what we need
  260.             fclose(fohnd);
  261.             return true;
  262.         }
  263.     }
  264.     fclose(fohnd);
  265.     return false;
  266. }
  267.  
  268.  
  269.  
  270. stock DINI_StripNewLine(string[]) {
  271.     new len = strlen(string);
  272.     if (string[0]==0) return ;
  273.     if ((string[len - 1] == '\n') || (string[len - 1] == '\r')) {
  274.         string[len - 1] = 0;
  275.         if (string[0]==0) return ;
  276.         if ((string[len - 2] == '\n') || (string[len - 2] == '\r')) string[len - 2] = 0;
  277.     }
  278. }
  279.  
  280. stock DINI_fcopytextfile(oldname[],newname[]) {
  281.     new File:ohnd,File:nhnd;
  282.     if (!fexist(oldname)) return false;
  283.     ohnd=fopen(oldname,io_read);
  284.     if (!ohnd) return false;
  285.     nhnd=fopen(newname,io_write);
  286.     if (!nhnd) {
  287.         fclose(ohnd);
  288.         return false;
  289.     }
  290.     new tmpres[DINI_MAX_STRING];
  291.     while (fread(ohnd,tmpres)) {
  292.         DINI_StripNewLine(tmpres);
  293.         format(tmpres,sizeof(tmpres),"%s\r\n",tmpres);
  294.         fwrite(nhnd,tmpres);
  295.     }
  296.     fclose(ohnd);
  297.     fclose(nhnd);
  298.     return true;
  299. }
  300. #include <streamer>
  301.  
  302. #define MAX_BUSS 100
  303. #define NO_OWNER "INVALID_PLAYER_ID"
  304. #define CASE_SENSETIVE  true
  305. #define White 0xFFFFFFFF
  306. #define Yellow 0xFFFF00FF
  307. #define Grey 0xC0C0C0FF
  308. #define Red 0xFF0000AA
  309. #define Green 0x45E01FFF
  310.  
  311. new cpid[32];
  312. new String[200];
  313. new file[128];
  314. new Name[MAX_PLAYER_NAME];
  315. new Float:X,Float:Y,Float:Z;
  316. new Label[128];
  317. new BizExit;
  318. enum Business
  319. {
  320.     CP,
  321.     Text3D:bLabel,
  322.     Cost,
  323.     bName[128],
  324. }
  325. new BusinessInfo[MAX_BUSS][Business];
  326. forward Payday(playerid);
  327.  
  328. stock Float:GetPosInFrontOfPlayer(playerid, &Float:x, &Float:y, Float:distance)
  329. {
  330.     new Float:a;
  331.     GetPlayerPos(playerid, x, y, a);
  332.     switch(IsPlayerInAnyVehicle(playerid))
  333.     {
  334.         case 0: GetPlayerFacingAngle(playerid, a);
  335.         case 1: GetVehicleZAngle(GetPlayerVehicleID(playerid), a);
  336.     }
  337.     x += (distance * floatsin(-a, degrees));
  338.     y += (distance * floatcos(-a, degrees));
  339.     return a;
  340. }
  341.  
  342. public OnFilterScriptInit()
  343. {
  344.     print("___________________________");
  345.     print("--Dynamic Business Loaded--");
  346.     print("      --Made by: Tee--     ");
  347.     print("___________________________");
  348.     LoadBusinesses();
  349.     SetTimer("Payday",1_800_000,true);
  350.     BizExit = CreateDynamicCP(-25.9351,-141.5631,1003.5469,1,-1,16,-1,20);
  351.     return 1;
  352. }
  353.  
  354. public OnFilterScriptExit()
  355. {
  356.     UnloadBusinesses();
  357.     return 1;
  358. }
  359. public OnPlayerEnterDynamicCP(playerid, checkpointid)
  360. {
  361.     for(new i = 0;i<MAX_BUSS;i++)
  362.     {
  363.         if(checkpointid == BusinessInfo[i][CP])
  364.         {
  365.             cpid[playerid] = i;
  366.             format(file,sizeof(file),"Business/%i.ini",i);
  367.             if(dini_Int(file, "Ima Vlasnika") == 0)
  368.             {
  369.                 ShowPlayerDialog(playerid,219,DIALOG_STYLE_MSGBOX,"Kupi Firmu","Zelis li kupiti ovu firmu?","Kupi","Odustani");
  370.             }
  371.             else
  372.             {
  373.                 SetPlayerPos(playerid, -25.132598,-139.066986,1003.546875);
  374.                 SetPlayerInterior(playerid, 16);
  375.                 SetPlayerVirtualWorld(playerid, i);
  376.                 SetPlayerFacingAngle(playerid, 359.9003);
  377.             }
  378.         }
  379.     }
  380.     if(checkpointid == BizExit)
  381.     {
  382.         format(file, sizeof(file), "Business/%i.ini", GetPlayerVirtualWorld(playerid));
  383.         SetPlayerPos(playerid, dini_Float(file, "SpawnOutX"), dini_Float(file, "SpawnOutY"), dini_Float(file, "BusZ"));
  384.         SetPlayerFacingAngle(playerid, dini_Float(file, "A"));
  385.         SetPlayerVirtualWorld(playerid, 0);
  386.         SetPlayerInterior(playerid, 0);
  387.     }
  388.     return 1;
  389. }
  390. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  391. {
  392.     if(dialogid == 219)
  393.     {
  394.         if(response == 1)
  395.         {
  396.             if(GetPlayerBusinessID(playerid) == 1)return 0;
  397.             new busid;
  398.             format(file,sizeof(file),"Business/%i.ini",cpid[playerid]);
  399.             if(GetPlayerBusinessID(playerid) > -1)return SendClientMessage(playerid,Red,"Vec posjedujes firmu");
  400.             if(dini_Int(file,"Cost") > GetPlayerMoney(playerid))return SendClientMessage(playerid,Red,"Nemas dovoljno novaca, da bi si prisutio ovu firmu.");
  401.             GivePlayerMoney(playerid, -dini_Int(file,"Cost"));
  402.             GetPlayerName(playerid,Name,sizeof(Name));
  403.             dini_Set(file, "Name", Name);
  404.             dini_Set(file, "Owner",Name);
  405.             dini_IntSet(file, "OwnedBus",1);
  406.             dini_IntSet(file, "HasOwner",1);
  407.             format(Label, sizeof(Label), "{ccccff}%s firma\n\n{999999}%s\n{00BC00}Cjena: {999999}$%i\n{00BC00}ID: {999999}%i",Name,dini_Get(file, "Owner"),dini_Int(file, "Cost"),busid);
  408.             Update3DTextLabelText(BusinessInfo[cpid[playerid]][bLabel],White,Label);
  409.             format(String,sizeof(String),"Uspijesno ste kupili firmu: %s.",dini_Get(file, "Name"));
  410.             SendClientMessage(playerid,Green,String);
  411.         }
  412.         if(response == 0)
  413.         {
  414.             SendClientMessage(playerid,Yellow,"Odabrao si da ne kupis ovaj biznis.");
  415.         }
  416.     }
  417.     if(dialogid == 220)
  418.     {
  419.         if(response == 1)
  420.         {
  421.             GetPlayerName(playerid,Name,sizeof(Name));
  422.             format(file,sizeof(file),"Business/%i.ini",GetPlayerBusinessID(playerid));
  423.             format(Label, sizeof(Label), "{ccccff}Na prodaju!\n\n{999999}Nema vlasnika\n{00BC00}: {999999}$%i",dini_Get(file, "Name"),dini_Int(file, "Cost"));
  424.             Update3DTextLabelText(BusinessInfo[cpid[playerid]][bLabel],White,Label);
  425.             dini_Set(file, "Owner","No Owner");
  426.             dini_IntSet(file, "Cost",dini_Int(file, "Cost"));
  427.             dini_IntSet(file, "OwnedBus",0);
  428.             dini_IntSet(file, "HasOwner",0);
  429.             GivePlayerMoney(playerid,dini_Int(file, "Cost")/2);
  430.             SendClientMessage(playerid,Green,"Uspijesno ste prodali biznis, te dobili 50 posto od ukupne cjene.");
  431.         }
  432.     }
  433.     return 1;
  434. }
  435.  
  436. // Ova komanda sluzi za pravljenje Business
  437. COMMAND:stvorifirmu(playerid, params[])
  438. {
  439.     new busid,cost,name[128];
  440.     new Float:x,Float:y;
  441.     if(!IsPlayerAdmin(playerid))return 0;
  442.     if(sscanf(params,"I(500000)S(Na prodaju)[128]",cost,name))return SendClientMessage(playerid, 0xFF0000AA, "Koristi: /stvorifirmu [cjena] [ime frime]");
  443.     for(new i=0; i<MAX_BUSS; i++)
  444.     {
  445.         format(file,sizeof(file),"Business/%i.ini",i);
  446.         if(!dini_Exists(file))
  447.         {
  448.             busid = i;
  449.             break;
  450.         }
  451.     }
  452.     format(file,sizeof(file),"Frime/%i.ini",busid);
  453.     BusinessInfo[busid][bName] = name;
  454.     BusinessInfo[busid][Cost] = cost;
  455.     GetPlayerPos(playerid, X, Y, Z);
  456.     GetPosInFrontOfPlayer(playerid, x, y, -2.5);
  457.     dini_Create(file);
  458.     dini_Set(file, "Name", name);
  459.     dini_Set(file, "Owner","No Owner");
  460.     dini_IntSet(file, "Cost",cost);
  461.     dini_FloatSet(file, "BusX", X);
  462.     dini_FloatSet(file, "BusY", Y);
  463.     dini_FloatSet(file, "BusZ", Z);
  464.     dini_FloatSet(file, "SpawnOutX", x);
  465.     dini_FloatSet(file, "SpawnOutY", y);
  466.     dini_FloatSet(file, "SpawnOutZ", Z);
  467.     dini_IntSet(file, "World",GetPlayerVirtualWorld(playerid));
  468.     dini_IntSet(file, "Interior",GetPlayerInterior(playerid));
  469.     dini_IntSet(file, "OwnedBus",0);
  470.     dini_IntSet(file, "HasOwner",0);
  471.     BusinessInfo[busid][CP] = CreateDynamicCP(X,Y,Z,1.0,GetPlayerVirtualWorld(playerid),GetPlayerInterior(playerid),-1,50.0);
  472.     format(Label, sizeof(Label), "{ccccff}%s\n{999999}Nema vlasnika\n{00BC00}Cjena: {999999}$%i\nID: %i", name,cost,busid);
  473.     BusinessInfo[busid][bLabel] = Create3DTextLabel(Label,White,X,Y,Z,100.0,GetPlayerVirtualWorld(playerid),1);
  474.     format(String,sizeof(String),"Firma stvorena. Ime: %s | Cjena: $%i | Vlasnik: Nema vlasnika | ID: %i",name,cost,busid);
  475.     SendClientMessage(playerid,Green,String);
  476.     return 1;
  477. }
  478. COMMAND:imefirme(playerid, params[])
  479. {
  480.     new name[128];
  481.     if(sscanf(params,"s[128]",name))return SendClientMessage(playerid, 0xFF0000AA, "Koristi: /imefirme [Ime]");
  482.     if(GetPlayerBusinessID(playerid) == -1) return SendClientMessage(playerid,Red,"Ne posjedujes firmu.");
  483.     format(file,sizeof(file),"Business/%i.ini",GetPlayerBusinessID(playerid));
  484.     dini_Set(file, "Name", name);
  485.     format(String,sizeof(String),"Ime firme promjenjeno u: %s",name);
  486.     SendClientMessage(playerid,Green,String);
  487.     format(Label, sizeof(Label), "{ccccff}%s\n\n{999999}%s\n{00BC00}Cost: {999999}$%i\n{00BC00}ID: {999999}%i",name, dini_Get(file, "Owner"),dini_Int(file, "Cost"),GetPlayerBusinessID(playerid));
  488.     Update3DTextLabelText(BusinessInfo[GetPlayerBusinessID(playerid)][bLabel],White,Label);
  489.     return 1;
  490. }
  491. //Ova komanda koristi se za brisanje firme
  492. COMMAND:brisifirmu(playerid, params[])
  493. {
  494.     new busid;
  495.     if(!IsPlayerAdmin(playerid)) return 0;
  496.     if(sscanf(params, "i", busid)) return SendClientMessage(playerid,0xC0C0C0FF,"Koristi: /brisifirmu [ID firme]");
  497.     format(file,sizeof(file),"Business/%i.ini",busid);
  498.     if(!dini_Exists(file))return SendClientMessage(playerid,Red,"Ta firma ne postoji.");
  499.     format(String,sizeof(String),"Uspijesno ste maknuli firmu ID-a: %i.",busid);
  500.     SendClientMessage(playerid,Yellow,String);
  501.     DestroyDynamicCP(BusinessInfo[busid][CP]);
  502.     Delete3DTextLabel(BusinessInfo[busid][bLabel]);
  503.     dini_Remove(file);
  504.     return 1;
  505. }
  506.  
  507. //Ova komanda omogucuje da owner proda svoju firmu
  508. COMMAND:prodajfirmu(playerid, params[])
  509. {
  510.     if(GetPlayerBusinessID(playerid) == -1)return SendClientMessage(playerid,Red,"Ne posjedujes biznis.");
  511.     ShowPlayerDialog(playerid,220,DIALOG_STYLE_MSGBOX,"Prodaja firme","Zelis li prodati firmu?","Prodaj","Odustani");
  512.     return 1;
  513. }
  514.  
  515. //This function gets the owner of a specific business.
  516. stock GetBusOwner(bussid)
  517. {
  518.     new owner[MAX_PLAYER_NAME];
  519.     format(owner, MAX_PLAYER_NAME, NO_OWNER);
  520.     format(String, sizeof(String), "Business/%i.ini", bussid);
  521.     if(dini_Exists(String))
  522.     {
  523.         format(owner, MAX_PLAYER_NAME, "%s", dini_Get(String, "Owner"));
  524.         return owner;
  525.     }
  526.     return owner;
  527. }
  528.  
  529. //This function gets a business ID (it also tells if a player owns a business or not).
  530. stock GetPlayerBusinessID(playerid)
  531. {
  532.     new returnval, found=0;
  533.     for(new i = 0;i<MAX_BUSS;i++)
  534.     {
  535.         format(String,sizeof(String),"Business/%i.ini",i);
  536.         if(dini_Exists(String))
  537.         {
  538.             GetPlayerName(playerid,Name,sizeof(Name));
  539.             if(!strcmp(Name, dini_Get(String,"Owner"), false))
  540.             {
  541.                 returnval = i;
  542.                 found = 1;
  543.             }
  544.         }
  545.     }
  546.     if(!found) returnval = -1;
  547.     return returnval;
  548. }
  549.  
  550.  
  551. //Ova komanda omogucuje da se skloni owner biza
  552. COMMAND:defirma(playerid, params[])
  553. {
  554.     new id;
  555.     if(!IsPlayerAdmin(playerid))return 0;
  556.     if(sscanf(params,"u", id))return SendClientMessage(playerid, 0xFF0000AA, "Koristi: /defirma [id]");
  557.     if(GetPlayerBusinessID(id) == -1)return SendClientMessage(playerid,Red,"Taj igraci ne posjeduje biz.");
  558.     format(String,sizeof(String),"Business/%i.ini",GetPlayerBusinessID(id));
  559.     format(Label, sizeof(Label), "{ccccff}%s\n{999999}Nema vlasnika\n{00BC00}Cjena: {999999}$%i",dini_Get(String, "Name"),dini_Int(String, "Cost"));
  560.     Update3DTextLabelText(BusinessInfo[GetPlayerBusinessID(id)][bLabel],White,Label);
  561.     dini_Set(String, "Owner","No Owner");
  562.     dini_IntSet(String, "Cost",dini_Int(String, "Cost"));
  563.     dini_IntSet(String, "OwnedBus",0);
  564.     dini_IntSet(String, "HasOwner",0);
  565.     GivePlayerMoney(id,dini_Int(String, "Cost")/4);
  566.     format(String, sizeof(String), "Igrac %s vise nije vlasnik firme.",Name);
  567.     SendClientMessage(playerid,Red, String);
  568.     return 1;
  569. }
  570.  
  571. //This function loads every business.
  572. stock LoadBusinesses()
  573. {
  574.     new count = 0;
  575.     for(new i=0; i<MAX_BUSS; i++)
  576.     {
  577.         format(String,sizeof(String),"Business/%i.ini",i); // the ID would be the name of the file, 1 2 3 4 5 etc
  578.         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?
  579.         {
  580.             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);
  581.             if(!strcmp(GetBusOwner(i), NO_OWNER, CASE_SENSETIVE))
  582.             {
  583.                 format(Label, sizeof(Label), "{ccccff}%s\n{999999}No Owner\n{00BC00}Cost: {999999}$%i",dini_Get(String, "Name"),dini_Int(String, "Cost"));
  584.                 BusinessInfo[i][bLabel] = Create3DTextLabel(Label,White,dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ")+1,100.0,0,1);
  585.             }
  586.             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
  587.             {
  588.                 format(Label, sizeof(Label), "{ccccff}%s\n\n{999999}%s\n{00BC00}Cost: {999999}$%i\n{00BC00}ID: {999999}%i",dini_Get(String, "Name"), dini_Get(String, "Owner"),dini_Int(String, "Cost"),i);
  589.                 BusinessInfo[i][bLabel] = Create3DTextLabel(Label,White,dini_Float(String, "BusX"),dini_Float(String, "BusY"),dini_Float(String, "BusZ")+1,100.0,0,1);
  590.             }
  591.             count++;
  592.         }
  593.     }
  594.     return printf("Total Businesses Loaded: %i",count);
  595. }
  596.  
  597. //This function gets the last bused business ID.
  598. stock GetLastBusinessID()
  599. {
  600.     new count = 0;
  601.     for(new i=0; i<MAX_BUSS; i++)
  602.     {
  603.         format(String,sizeof(String),"Business/%i.ini",i);
  604.         {
  605.             count++;
  606.         }
  607.     }
  608.     return count;
  609. }
  610.  
  611. //This function unloads every business.
  612. stock UnloadBusinesses()
  613. {
  614.     for(new i=0; i<MAX_BUSS; i++)
  615.     {
  616.         Delete3DTextLabel(BusinessInfo[i][bLabel]);
  617.         DestroyDynamicCP(BusinessInfo[i][CP]);
  618.     }
  619.     return 1;
  620. }
  621.  
  622. //This is used by RCON admins. Either to debug or to force a payday.
  623. COMMAND:ubrzajpay(playerid,params[])
  624. {
  625.     if(!IsPlayerAdmin(playerid))return 0;
  626.     SendClientMessage(playerid,Grey,"Ubrzali ste payday.");
  627.     for(new i=0; i < MAX_PLAYERS; i++) if(IsPlayerConnected(i)) Payday(i);
  628.     return 1;
  629. }
  630.  
  631. #define TIMEDEBUG 1 //set this to 0 if you don't want it to print the time it took for this function to execute
  632.  
  633. //This function is the payday (to pay the owners).
  634. public Payday(playerid)
  635. {
  636.     #if TIMEDEBUG == 1
  637.     new tick = GetTickCount();
  638.     #endif
  639.     if(GetPlayerBusinessID(playerid) != -1)
  640.     {
  641.         new RandMoney = rand(100_000, 250_000), msg[128];
  642.         GivePlayerMoney(playerid, RandMoney);
  643.         format(msg, sizeof(msg), "[FIRMA] Primili ste $%i", RandMoney);
  644.         SendClientMessage(playerid, Green, msg);
  645.         format(msg, sizeof(msg), "~w~Primili ste ~g~$%i ~w~iz vase firme", RandMoney);
  646.         GameTextForPlayer(playerid, msg, 4000,3);
  647.     }
  648.     else return SendClientMessage(playerid, Green, "Da imate firmu, primili biste payday!");
  649.     #if TIMEDEBUG == 1
  650.     printf("Time taken to execute Payday(): %i", GetTickCount()-tick);
  651.     #endif
  652.     return 1;
  653. }
  654. stock pName(playerid)
  655. {
  656.     new name[MAX_PLAYER_NAME];
  657.     GetPlayerName(playerid, name, sizeof(name));
  658.     return name;
  659. }
  660. stock rand(minnum = cellmin,maxnum = cellmax) return random(maxnum - minnum + 1) + minnum; //swtiches so much better
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement