09.08.2011, 05:58
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;
And the binfo:
And so here's an example code,
One of the bits I need explaining is:
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
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;
}
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
}
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;
}
}
pawn Код:
if(!inbusiness && !IsPlayerInRangeOfPoint(playerid, 2.0, BizInfo[business][bOutsideX], BizInfo[business][bOutsideY], BizInfo[business][bOutsideZ]))
![Cheesy](images/smilies/biggrin.png)