Quick question [2D Array]
#1

Hello,

I've just got a very quick question about a 2D array I'm about to start using and I'd like to check I've understood the way it needs to work.

This is the amount of workers for the business.
Код:
MAX_BUSINESS_WORKERS
This is the name of the worker.
Код:
bWorker[MAX_BUSINESS_WORKERS] = MAX_PLAYER_NAME,
Obviously I'm trying to store the PlayerName into the 2D array as a string. I'm pretty un certain on the way I've tried to do this. Could some one please elaborate?
Reply
#2

pawn Код:
new bWorker[MAX_BUSINESS_WORKERS][MAX_PLAYER_NAME];
That's a 2D array. For more read here: https://sampforum.blast.hk/showthread.php?tid=318212
Reply
#3

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
pawn Код:
new bWorker[MAX_BUSINESS_WORKERS][MAX_PLAYER_NAME];
That's a 2D array. For more read here: https://sampforum.blast.hk/showthread.php?tid=318212
Let me redefine what I'm actually saying here, sorry for such a short brief.

This array of
pawn Код:
bWorker[MAX_BUSINESS_WORKERS] = MAX_PLAYER_NAME,
Is actually inside an enum which is part of the following array
pawn Код:
#define MAX_BUSINESS_CREATED 1 //example
pawn Код:
new BusinessInfo[MAX_BUSINESS_CREATED][bInfo];
When using what you have put it is incorrect for the enum I am trying to create/use.

Could you elaborate further on my question now in regards to the new information I have specified.
Reply
#4

So you sort of want to have both workers and their name into the enum? I don't think that's possible.

The only way, I could think of is basically a 3D array - not related with BusinessInfo array.

pawn Код:
new Business_Worker[MAX_BUSINESS_CREATED][MAX_BUSINESS_WORKERS][MAX_PLAYER_NAME];
Having MAX_BUSINESS_WORKERS out of the enum would be a solution too but I believe that's not what you want as the rest of the data are not related to the workers.
Reply
#5

Quote:
Originally Posted by Konstantinos
Посмотреть сообщение
So you sort of want to have both workers and their name into the enum? I don't think that's possible.

The only way, I could think of is basically a 3D array - not related with BusinessInfo array.

pawn Код:
new Business_Worker[MAX_BUSINESS_CREATED][MAX_BUSINESS_WORKERS][MAX_PLAYER_NAME];
Having MAX_BUSINESS_WORKERS out of the enum would be a solution too but I believe that's not what you want as the rest of the data are not related to the workers.
------------------

Let me elaborate so it is understood what I'm doing.

Here's how
Код:
MAX_BUSINESS_CREATED
is defined

pawn Код:
//--------BUSINESS SYSTEM INFORMATION--------------------------------------//

//SET MAIN DEFINE AS 0
#define MAX_CREATED_BUSINESS 0
//REDEFINE THIS BY FILE CHECK - HOW MANY CREATED
new CREATED_BUSINESS = 0;
new BUSINESS_AMOUNT = MAX_CREATED_BUSINESS+CREATED_BUSINESS;

//--------BUSINESS SYSTEM INFORMATION END----------------------------------//
Here's the enum using
Код:
MAX_BUSINESS_CREATED
pawn Код:
enum bInfo
{
    //BASIC BUSINESS INFORMATION
    bCreated,//If this business exists
    bOwned,//Is this business owned?
    bOwnerName[MAX_PLAYER_NAME],//If it's owned what's the owners name?
    bBusinessName[64],//What is the business's name? - Used for text draw input "bEntraceText" defined below this line
   
    //BUSINESS NAME INFORMATION UPON ENTERING BUSINESS AREA
    bEntranceText,//The actual text draw stored in the enum
   
    //THE TYPE OF BUSINESS
    bType,//Type: This will define whether it is a shop/trucking etc
   
    //-----------------LOCATION TYPES --------------------//
    //THE LOCATION TYPE
    bLocationType,//This will determinate what TYPE OF business CAN go here
    /*
    Type 1: NOT UPGRADABLE
    Type 2: SHOP UPGRADE (INCLUDES NIGHTCLUBS && BARS)
    Type 3: VEHICLE BASED UPGRADE
    Type 4: SHOP && VEHICLE UPGRADE
    */

   
    //BUSINESS LANDLINE NUMBER
    bPhone,//Do they have a phone installed?
    bPhoneNumber,//Whats the phone number?
   
    //BUSINESS COMMUNICATION SYSTEM
    bCommunication,//Does the business have walky talkies?
   
    //BUSINESS PURCHASE SYSTEM - Certain companies will defaultly be payed to the business account of the player
    bPurchaseSystem,//Type: Do they have the ability for customers to pay by card or not?
   
    //BUSINESS FOR SALE INFORMATION
    bForSale,//Is the business for sale?
    bForSalePrice,//How much is the business for sale for?
   
    //BUSINESS FUND INFORMATION
    bFunds, //Funds: How much money does this company have? Is it in debt? (This is only set per player not ACTUAL business, reset upon updating player BUSINESS ACCOUNT +positive amount -negative amount)
   
    //BUSINESS WASTE PRODUCTION
    bWasteAmount,//Waste: Based on amount of production the business is doing, this will generate waste (THE AMOUNT)
   
    //BUSINESS PROFIT INFORMATION
    bProfitEarnt, //Earnt: This will be accumulated upon players working in the company (For companys doing nothing (DEFAULT) earnings will be set) This will define the (FUNDS) amount - || +
    bProducts, //Products: How many things (ANYTHING) does the company have to sell? (This includes ANYTHING THE BUSINESS SELLS) If the company has +1 product when some one buys from the business earnings will be higher
   
    //BUSINESS COST INFORMATION
    bWorkWage, //Wage: How much will each worker be payed? (Minimum - Maximum) Effects business income
   
    //BUSINESS WORKER INFORMATION
    MAX_BUSINESS_WORKERS, //Max: How many workers are in the business?
    bWorker[MAX_BUSINESS_WORKERS] = MAX_PLAYER_NAME, //Name: The workers name
    bPenalties[MAX_BUSINESS_WORKERS], //Penalties: How many times has the player done something wrong? (Defined by authorities, business owner)
    bWorkerExpense[MAX_BUSINESS_WORKERS], //Expense: does the player pay for fuel,repairs etc?
    bWorkerRank[MAX_BUSINESS_WORKERS], //Rank: What can they do in the business?
   
    //BUSINESS WORKER APPLICATIONS
    MAX_APPLIES_PLAYERS, //Max: How many players applied to work at this company?
    bApplied[MAX_APPLIED_PLAYERS] = MAX_PLAYER_NAME, //Name: The applicants name
   
    //BUSINESS PENALTIES
    bBusinessPenalties, //Penalties: How many times has the business done something wrong? (Defined by authorities)
    bShutdown, //Has the company been shut down? (Defined by authorities)
   
    //BUSINESS ENTRANCE/EXIT INFORMATION
    Float:bInsideX,
    Float:bInsideY,     // Exit position from the inside
    Float:bInsideZ,
    bExitArea,

    Float:bOutsideX,
    Float:bOutsideY,    // Entrance position from the outside
    Float:bOutsideZ,
    bEnterArea,
   
    Float:bJobX,
    Float:bJobY,        // Player job communication point (This will be used for both PUBLIC & PRIVATE set jobs) Join job/Apply for
    Float:bJobZ,
    bJobArea,

    Float:bVehicleInteractX,
    Float:bVehicleInteractY,    // Vehicle interaction point (Truckers need a load/refill position for example)
    Float:bVehicleInteractZ,
    bVehicleInteractArea,

    //BUSINESS VEHICLE INFORMATION
    MAX_BUSINESS_VEHICLES, //Max: How many vehicles are in this business?
    bVehicleType[MAX_BUSINESS_VEHICLES], //Type: What type of vehicle is this? (TRUCK: small/med/large) (TRANSPORT: Taxi/bus/coach) (RUBBISH: trash/sweep) < ETC
    bVehicle[MAX_BUSINESS_VEHICLES], //VehicleID: What is the ID of this vehicle? (Used to create and interact with THIS vehicle
    bVehicleModel[MAX_BUSINESS_VEHICLES], //Model: What is the vehicles model id?
   
    bVehicleX[MAX_BUSINESS_VEHICLES],
    bVehicleY[MAX_BUSINESS_VEHICLES],               //Position of the vehicle with facing angle
    bVehicleZ[MAX_BUSINESS_VEHICLES],
    bVehicleFace[MAX_BUSINESS_VEHICLES],
   
    bLastDriver[MAX_BUSINESS_VEHICLES] = MAX_PLAYER_NAME,//Last Driver: Who was driving this vehicle last? (IMPOUNDED VEHICLE by player) - (DESTROYED - by player) < ETC
   
    //BUSINESS DYNAMIC AREAS - Used for use of hotkeys, how large the plot land is (where you can put vehicles etc (RESPAWN POS example))
    bArea,//Plot size of the business (User can set respawn pos of vehicle here, open business options dialog, interact in ways like editing business) < ETC

    //BUSINESS INSURANCE FOR DISASTERS
    bInsurance,//Insurance: Does this company have insurance or not?
    bInsuranceType,//Type of insurance: What insurance type do they have? Small/Med/Large for example (free repairs on vehicles etc, vehicle recovery)
    bInsuranceClaims,//Claims: How many times has the company made a claim for something? restock of destroyed vehicle, stolen products etc
    bInsuranceCost,//Cost: How much each time an insurance payment is made it will deduct from the business funds
   
    //SPECIAL BUSINESS OBJECT/VEHICLE DEFINED BY TYPE
    MAX_BUSINESS_SPECIAL, //Max: How many special OBJECT/VEHICLE's are in this business?
    bSpecialType[MAX_BUSINESS_SPECIAL],//Special type: Is this an object or a vehicle? (Example: furniture in a shop that NEEDS a dynamic area || Vehicle)
    bSpecialArea[MAX_BUSINESS_SPECIAL],
    bSpecial[MAX_BUSINESS_SPECIAL],//SpecialID: What is the ID of the OBJECT/VEHICLE_SPECIAL (Used to create and interact with)
    bSpecialModel[MAX_BUSINESS_SPECIAL],//Model: What is the model of the OBJECT/VEHICLE_SPECIAL
   
    Float:bSpecialX[MAX_BUSINESS_SPECIAL],
    Float:bSpecialY[MAX_BUSINESS_SPECIAL],          //Position of the OBJECT/VEHICLE_SPECIAL with facing angle
    Float:bSpecialZ[MAX_BUSINESS_SPECIAL],
    Float:bSpecialFace[MAX_BUSINESS_SPECIAL]
}
new BusinessInfo[MAX_CREATED_BUSINESS][bInfo];
Here's how
Код:
MAX_CREATED_BUSINESS
is being defined further from 0

pawn Код:
forward CreatedBusinessLoad();
public CreatedBusinessLoad()
{
    new File[256];
    format(File, sizeof(File), "StreetHustle/Business/MaxCreated.ini");
    if(!dini_Exists(File))
    {
        dini_Create(File);
        dini_IntSet(File, "CREATED_BUSINESS_AMOUNT", 0);
        printf("[IMPORTANT BUSINESS INFO - NO BUSINESS AMOUNT FOUND]");
    }
   
    //LETS GET HOW MANY BUSINESSES THERE ARE TO LOAD
    CREATED_BUSINESS = dini_Int(File, "CREATED_BUSINESS_AMOUNT");
    printf("[BUSINESS INFORMATION]");
    printf("[CREATED] = %d", CREATED_BUSINESS);
    return 1;
}

forward CreatedBusinessADD(amount);
public CreatedBusinessADD(amount)
{
    new File[256];
    format(File, sizeof(File), "StreetHustle/Business/MaxCreated.ini");
    if(dini_Exists(File))
    {
        CREATED_BUSINESS += amount;
        dini_IntSet(File, "CREATED_BUSINESS_AMOUNT", CREATED_BUSINESS);
    }
    return 1;
}

forward CreatedBusinessREMOVE(amount);
public CreatedBusinessREMOVE(amount)
{
    new File[256];
    format(File, sizeof(File), "StreetHustle/Business/MaxCreated.ini");
    if(dini_Exists(File))
    {
        CREATED_BUSINESS -= amount;
        dini_IntSet(File, "CREATED_BUSINESS_AMOUNT", CREATED_BUSINESS);
    }
    return 1;
}
I need basically to be able to store the players name inside the workers array (which is inside the enum - business array) which is defined in a similar way as MAX_CREATED_BUSINESS it will check how many actually exist inside the file before proceeding to do a loop and load them all.

I hope I've elaborated enough.
Reply
#6

Looking for an explanation on this.

If any one needs a better brief on what I'm asking then please just say. I'd like to get this answered as quickly as possible. It would be nice to know before I jump in deep and debug the lot.
Reply
#7

Yes, I understood what you're trying to do but you cannot have a 2D array in the enum to store both the worker and their name. Same applies for bApplied and bLastDriver. The only way is 3D array itself (nothing to do with BusinessInfo array).
Reply
#8

Ok let me make this really simple

I have this line of code
Код:
bWorkerName[MAX_BUSINESS_WORKERS]
It's completely possible because Integers are fine with the method I'm using. I'd just like to know how in this format I need to define this as a string. I don't get why you're saying "Store both the worker and their name" - I'm simply trying to store JUST a string here and not entirely sure on how to write the line.

EDIT:

Can I simply do this?
Код:
bWorkerName[MAX_BUSINESS_WORKERS][MAX_PLAYER_NAME]
Remember it's inside an enum.

EDIT 2: Don't worry I'll just debug this.
Reply
#9

Having MAX_BUSINESS_WORKERS indicates that there may be more than 1 worker for each business. In order to store workers' name, you need another array (with size of MAX_PLAYER_NAME) so 2 arrays at once for worker and the name of the worker.

But you cannot have a 2D array inside an enum:
pawn Код:
bWorkerName[MAX_BUSINESS_WORKERS][MAX_PLAYER_NAME]
because it will give errors. The only solution is the 3D array without the use of an enumerator I mentioned before.
Reply
#10

That's just it.. I've seen the use of

Код:
eExample[MAX_EXAMPLE_AMOUNT] = MAX_PLAYER_NAME,
What exactly is this doing?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)