Help me understand this biz script please?
#1

So the business script in this gamemode I have, reads from a file and sets the enum info from the information gathered from the file, but I don't understand how it assigns the owner.. I need someone to explain me in detail exactly how it defines the owner... so here's the load biz script;

pawn Код:
public LoadBusinesses()
{
    new arrCoords[20][64];
    new strFromFile2[256];
    new File: file = fopen("bizz.cfg", io_read);
    if (file)
    {
        new idx;
        while (idx < sizeof(BizInfo))
        {
            fread(file, strFromFile2);
            split(strFromFile2, arrCoords, '|');
            strmid(BizInfo[idx][bName], arrCoords[0], 0, strlen(arrCoords[0]), 255);
            BizInfo[idx][bOwned] = strval(arrCoords[1]);
            strmid(BizInfo[idx][bOwner], arrCoords[2], 0, strlen(arrCoords[2]), 255);
            BizInfo[idx][bOutsideX] = floatstr(arrCoords[3]);
            BizInfo[idx][bOutsideY] = floatstr(arrCoords[4]);
            BizInfo[idx][bOutsideZ] = floatstr(arrCoords[5]);
            BizInfo[idx][bOutsideAng] = floatstr(arrCoords[6]);
            BizInfo[idx][bOutsideWorld] = strval(arrCoords[7]);
            BizInfo[idx][bOutsideInt] = strval(arrCoords[8]);
            BizInfo[idx][bInsideX] = floatstr(arrCoords[9]);
            BizInfo[idx][bInsideY] = floatstr(arrCoords[10]);
            BizInfo[idx][bInsideZ] = floatstr(arrCoords[11]);
            BizInfo[idx][bInsideAng] = floatstr(arrCoords[12]);
            BizInfo[idx][bInsideInt] = strval(arrCoords[13]);
            BizInfo[idx][bEntryFee] = strval(arrCoords[14]);
            BizInfo[idx][bValue] = strval(arrCoords[15]);
            BizInfo[idx][bTill] = strval(arrCoords[16]);
            BizInfo[idx][bLocked] = strval(arrCoords[17]);
            BizInfo[idx][bType] = strval(arrCoords[18]);
            BizInfo[idx][bProducts] = strval(arrCoords[19]);
            //load pickups
            if(BizInfo[idx][bOutsidePickup]) DestroyPickup(BizInfo[idx][bOutsidePickup]);
            if(BizInfo[idx][bInsidePickup]) DestroyPickup(BizInfo[idx][bInsidePickup]);
            BizInfo[idx][bOutsidePickup] = CreatePickup(1272, 23, BizInfo[idx][bOutsideX], BizInfo[idx][bOutsideY], BizInfo[idx][bOutsideZ]);
            BizInfo[idx][bInsidePickup] = CreatePickup(1272, 23, BizInfo[idx][bInsideX], BizInfo[idx][bInsideY], BizInfo[idx][bInsideZ],idx);
            //load 3dtext
            if(BizText[idx]) Delete3DTextLabel(BizText[idx]);
            new string[128];
            if(BizInfo[idx][bOwned] == 0)
            {
                new pricestring[32];
                new price = BizInfo[idx][bValue];
                new j = valstr(pricestring,price);
                while(j >= 4) { j -= 3; strins(pricestring,",",j); }
                strins(pricestring,"$",0);
                format(string, sizeof(string), "%s for Sale!\n\nPrice: %s",BizInfo[idx][bName],pricestring);
            }
            else if(BizInfo[idx][bOwned] == 1)
            {
                if(BizInfo[idx][bLocked] == 1)
                    format(string, sizeof(string), "%s\nOwner: %s\nEntry Fee: $%d",BizInfo[idx][bName],BizInfo[idx][bOwner],BizInfo[idx][bEntryFee]);
                else
                    format(string, sizeof(string), "%s\nOwner: %s\nEntry Fee: $%d",BizInfo[idx][bName],BizInfo[idx][bOwner],BizInfo[idx][bEntryFee]);
            }
            BizText[idx] = Create3DTextLabel(string,BIZ_COLOR,BizInfo[idx][bOutsideX],BizInfo[idx][bOutsideY],BizInfo[idx][bOutsideZ]+0.88,20,0,1);
            idx++;
        }
        fclose(file);
    }
    return 1;
}
And the binfo:
pawn Код:
enum bInfo
{
    bName[64],
    bOwned,
    bOwner[MAX_PLAYER_NAME],
    Float:bOutsideX,
    Float:bOutsideY,
    Float:bOutsideZ,
    Float:bOutsideAng,
    bOutsideWorld,
    bOutsideInt,
    bOutsidePickup,
    Float:bInsideX,
    Float:bInsideY,
    Float:bInsideZ,
    Float:bInsideAng,
    bInsideInt,
    bInsidePickup,
    bEntryFee,
    bValue,
    bTill,
    bLocked,
    bType,
    bProducts
}
And so here's an example code,
pawn Код:
else if(strcmp(x_nr,"lock",true) == 0)
            {
                new inbusiness = 0;
                if(IsPlayerInRangeOfPoint(playerid,5.0,BizInfo[business][bInsideX],BizInfo[business][bInsideY],BizInfo[business][bInsideZ]))
                {
                    if(GetPlayerVirtualWorld(playerid) == playerid)
                    {
                        inbusiness = 1;
                    }
                }
                if(!inbusiness && !IsPlayerInRangeOfPoint(playerid, 2.0, BizInfo[business][bOutsideX], BizInfo[business][bOutsideY], BizInfo[business][bOutsideZ]))
                {
                    SendClientMessage(playerid,COLOR_GREY,"   You are not near/inside your business.");
                    return 1;
                }
                GetPlayerName(playerid, sendername, sizeof(sendername));
                if(BizInfo[business][bLocked] == 1)
                {
                    BizInfo[business][bLocked] = 0;
                   
                    format(string, sizeof(string), "%s\nOwner: %s\nEntry Fee: $%d",BizInfo[business][bName],BizInfo[business][bOwner],BizInfo[business][bEntryFee]);
                    Update3DTextLabelText(Text3D:BizText[business], BIZ_COLOR, string);
                   
                    PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                    format(string, sizeof(string), "* %s has unlocked the door to their business.", sendername);
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    return 1;
                }
                else
                {
                    BizInfo[business][bLocked] = 1;
                   
                    format(string, sizeof(string), "%s\nOwner: %s\nEntry Fee: $%d",BizInfo[business][bName],BizInfo[business][bOwner],BizInfo[business][bEntryFee]);
                    Update3DTextLabelText(Text3D:BizText[business], BIZ_COLOR, string);
                   
                    PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                    format(string, sizeof(string), "* %s has locked the door to their business.", sendername);
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    return 1;
                }
            }
One of the bits I need explaining is:
pawn Код:
if(!inbusiness && !IsPlayerInRangeOfPoint(playerid, 2.0, BizInfo[business][bOutsideX], BizInfo[business][bOutsideY], BizInfo[business][bOutsideZ]))
How does the script know if he owns that business? I know it's something to do with idx in the load business function, I think? Be nice if someone could explain in high detail
Reply
#2

According to the command you posted above, I don't see anywhere that it checks if the player owns the business!
It is likely that the part of the command you are showing is checking one of the arguments for the command (like /biz lock), and it checks whether or not the player is the owner closer to the beginning of the command. Show the WHOLE command, and we can help you.
Reply
#3

pawn Код:
if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pBizKey] == -1)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You do not own a business.");
                return 1;
            }
            new business = PlayerInfo[playerid][pBizKey];
            new x_nr[32];
            x_nr = strtok(cmdtext, idx);
            if(!strlen(x_nr))
            {
                SendClientMessage(playerid, COLOR_WHITE, "{CC1100}USAGE: {FFFFFF} /biz [name]");
                SendClientMessage(playerid, COLOR_GRAD1, "Available names: EntryFee, Lock, Till, Restock");
                if(business == 1)
                    SendClientMessage(playerid, COLOR_GRAD1, "Available names: Gate");
                return 1;
            }
That just checks if they own a business though, then:
pawn Код:
if(!inbusiness && !IsPlayerInRangeOfPoint(playerid, 2.0, BizInfo[business][bOutsideX], BizInfo[business][bOutsideY], BizInfo[business][bOutsideZ]))
Checks if they are in the range of a business, but like you said it doesn't really show how it checks the owner.. which is the bit that confuses me.

Here's another one:
pawn Код:
else if(strcmp(x_nr,"restock",true) == 0)
            {
                if(IsPlayerInRangeOfPoint(playerid,25.0,BizInfo[business][bInsideX],BizInfo[business][bInsideY],BizInfo[business][bInsideZ]))
                {
                    if(GetPlayerVirtualWorld(playerid) == business)
                    {
                        tmp = strtok(cmdtext, idx);
                        if(!strlen(tmp))
                        {
                            SendClientMessage(playerid, COLOR_WHITE, "{CC1100}USAGE: {FFFFFF} /biz restock [amount]");
                            format(string, sizeof(string), "   Your business has %d products.", BizInfo[business][bProducts]);
                            SendClientMessage(playerid,COLOR_YELLOW,string);
                            return 1;
                        }
                        new amount = strval(tmp);
                        if(amount > PlayerInfo[playerid][pProducts]) return SendClientMessage(playerid,COLOR_GREY,"   You don't have that many products.");
                        if(amount < 1 || amount > 500) return SendClientMessage(playerid,COLOR_GREY,"   Cannot restock below 1 product or above 500 products.");
                        if(amount + BizInfo[business][bProducts] > 500) return SendClientMessage(playerid,COLOR_GREY,"   Your business can only hold 500 max products.");
                        BizInfo[business][bProducts] += amount;
                        PlayerInfo[playerid][pProducts] -=amount;
                        format(string, sizeof(string), "   You have restocked %d products into your business. Total Products: %d", amount,BizInfo[business][bProducts]);
                        SendClientMessage(playerid,COLOR_LIGHTBLUE,string);
                    }
                }
                else
                {
                    return SendClientMessage(playerid,COLOR_GREY,"   You are not inside your business.");
                }
            }

See:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid,25.0,BizInfo[business][bInsideX],BizInfo[business][bInsideY],BizInfo[business][bInsideZ]))
Reply
#4

You are still not showing the whole command, but only some. If you wouldn't mind, you could privately send me your OnPlayerCommandText callback via PM and I can try to explain it to you there. Otherwise, post the whole command here.
Reply
#5

pawn Код:
if(IsPlayerConnected(playerid))
        {
            if(PlayerInfo[playerid][pBizKey] == -1)
            {
                SendClientMessage(playerid, COLOR_GREY, "   You do not own a business.");
                return 1;
            }
            new business = PlayerInfo[playerid][pBizKey];
            new x_nr[32];
            x_nr = strtok(cmdtext, idx);
            if(!strlen(x_nr))
            {
                SendClientMessage(playerid, COLOR_WHITE, "{CC1100}USAGE: {FFFFFF} /biz [name]");
                SendClientMessage(playerid, COLOR_GRAD1, "Available names: EntryFee, Lock, Till, Restock");
                if(business == 1)
                    SendClientMessage(playerid, COLOR_GRAD1, "Available names: Gate");
                return 1;
            }
is the start of it, after that is the first x_nr, e.g.:
pawn Код:
else if(strcmp(x_nr,"lock",true) == 0)
            {
                new inbusiness = 0;
                if(IsPlayerInRangeOfPoint(playerid,5.0,BizInfo[business][bInsideX],BizInfo[business][bInsideY],BizInfo[business][bInsideZ]))
                {
                    if(GetPlayerVirtualWorld(playerid) == playerid)
                    {
                        inbusiness = 1;
                    }
                }
                if(!inbusiness && !IsPlayerInRangeOfPoint(playerid, 2.0, BizInfo[business][bOutsideX], BizInfo[business][bOutsideY], BizInfo[business][bOutsideZ]))
                {
                    SendClientMessage(playerid,COLOR_GREY,"   You are not near/inside your business.");
                    return 1;
                }
                GetPlayerName(playerid, sendername, sizeof(sendername));
                if(BizInfo[business][bLocked] == 1)
                {
                    BizInfo[business][bLocked] = 0;
                   
                    format(string, sizeof(string), "%s\nOwner: %s\nEntry Fee: $%d",BizInfo[business][bName],BizInfo[business][bOwner],BizInfo[business][bEntryFee]);
                    Update3DTextLabelText(Text3D:BizText[business], BIZ_COLOR, string);
                   
                    PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                    format(string, sizeof(string), "* %s has unlocked the door to their business.", sendername);
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    return 1;
                }
                else
                {
                    BizInfo[business][bLocked] = 1;
                   
                    format(string, sizeof(string), "%s\nOwner: %s\nEntry Fee: $%d",BizInfo[business][bName],BizInfo[business][bOwner],BizInfo[business][bEntryFee]);
                    Update3DTextLabelText(Text3D:BizText[business], BIZ_COLOR, string);
                   
                    PlayerPlaySound(playerid, 1145, 0.0, 0.0, 0.0);
                    format(string, sizeof(string), "* %s has locked the door to their business.", sendername);
                    ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);
                    return 1;
                }
            }
I know it finds the owner with this code:
pawn Код:
if(IsPlayerInRangeOfPoint(playerid,25.0,BizInfo[business][bInsideX],BizInfo[business][bInsideY],BizInfo[business][bInsideZ]))
But I don't understand how at all..
Reply
#6

Alright, I think I may have found out.

pawn Код:
new business = PlayerInfo[playerid][pBizKey];
This variable holds a ID of a business key that the player has. If that value is not -1, then we know the player owns a business, by this check
pawn Код:
if(PlayerInfo[playerid][pBizKey] == -1)
{
   SendClientMessage(playerid, COLOR_GREY, "   You do not own a business.");
   return 1;
}
Now at this point, we know they own the business with the index inside the BizInfo array of business (which is equal to PlayerInfo[playerid][pBizKey]). So, with this check
pawn Код:
if(IsPlayerInRangeOfPoint(playerid,25.0,BizInfo[business][bInsideX],BizInfo[business][bInsideY],BizInfo[business][bInsideZ]))
We see whether or not they are within the certain range of the business they own.

So, what really checks if they have a business is the value held by PlayerInfo[playerid][pBizKey]. If it is a value other than -1, they own a business, which you can access the BizInfo array directly from with that index.
Reply
#7

Quote:
Originally Posted by Grim_
Посмотреть сообщение
Alright, I think I may have found out.

pawn Код:
new business = PlayerInfo[playerid][pBizKey];
This variable holds a ID of a business key that the player has. If that value is not -1, then we know the player owns a business, by this check
pawn Код:
if(PlayerInfo[playerid][pBizKey] == -1)
{
   SendClientMessage(playerid, COLOR_GREY, "   You do not own a business.");
   return 1;
}
Now at this point, we know they own the business with the index inside the BizInfo array of business (which is equal to PlayerInfo[playerid][pBizKey]). So, with this check
pawn Код:
if(IsPlayerInRangeOfPoint(playerid,25.0,BizInfo[business][bInsideX],BizInfo[business][bInsideY],BizInfo[business][bInsideZ]))
We see whether or not they are within the certain range of the business they own.

So, what really checks if they have a business is the value held by PlayerInfo[playerid][pBizKey]. If it is a value other than -1, they own a business, which you can access the BizInfo array directly from with that index.
I see.. but I don't understand how/where it defines the business as the persons as pBizKey..
Reply
#8

Each business has it's own unique ID. When the player purchases that business, their variable, PlayerInfo[playerid][pBizKey], gets assigned that value. It gets saved into their profile, and loads when they log-in.

When you want to check if they have a business, you'll know as long as that value is something other than -1 (as the unique IDs for the businesses start at 0). Then, knowing they have that specific unique ID, which also acts as the businesses index inside the BizInfo array, you can access the data directly by using it within the BizInfo array.
Reply
#9

Quote:
Originally Posted by Grim_
Посмотреть сообщение
Each business has it's own unique ID. When the player purchases that business, their variable, PlayerInfo[playerid][pBizKey], gets assigned that value. It gets saved into their profile, and loads when they log-in.

When you want to check if they have a business, you'll know as long as that value is something other than -1 (as the unique IDs for the businesses start at 0). Then, knowing they have that specific unique ID, which also acts as the businesses index inside the BizInfo array, you can access the data directly by using it within the BizInfo array.
Okay I think i understand now. thankyou so much for the help.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)