Errors with arrays and strings
#1

Hi, I have some errors, here is my code:

pawn Код:
#define MAX_BUSINESS 50

enum bInfo
{
  bID,
  bName,
  bOwner[MAX_PLAYER_NAME],
  bPrice,
  bInterior,
  bVirtualWorld,
  Float:bX,
  Float:bY,
  Float:bZ,
}

new BizInfo[MAX_BUSINESS][bInfo];
new BizCount = 0;

stock CreateBusiness(BizName[], BizPrice, Float:X, Float:Y, Float:Z, Interior = 0, VirtualWorld = 0)
{
  new string[51];

  BizInfo[bID] = BizCount; //The first error is here, I know that I can't do that, but how do I set the ID?
  BizCount++;
 
  new str[51];
  format(str, sizeof(str), "%s", BizName);
 
  BizInfo[bID][bName] = str; //This is the second error line
  BizInfo[bID][bPrice] = BizPrice;
  BizInfo[bID][bX] = X;
  BizInfo[bID][bY] = Y;
  BizInfo[bID][bZ] = Z;
  BizInfo[bID][bOwner] = "No Owner"; //And this is the third ! Why can't I set that array as a string?
  BizInfo[bID][bInterior] = Interior;
  BizInfo[bID][bVirtualWorld] = VirtualWorld;
 
  format(string,sizeof(string),"Businesses/Biz%d.biz.ini", BizInfo[bID]);
 
  INI_Open(string);
 
  INI_WriteString("Name", BizInfo[bID][bName]);
  INI_WriteInt("Price", BizInfo[bID][bPrice]);
  INI_WriteInt("Interior", BizInfo[bID][bInterior]);
  INI_WriteInt("VirtualWorld", BizInfo[bID][bVirtualWorld]);
  INI_WriteFloat("X", BizInfo[bID][bX]);
  INI_WriteFloat("Y", BizInfo[bID][bY]);
  INI_WriteFloat("Z", BizInfo[bID][bZ]);
  INI_WriteString("Owner", BizInfo[bID][bOwner]);
 
  INI_Save();
  INI_Close();
  return bID;
}

And I get this 3 errors, that I can't fix !
.
Код:
C:\Users\Salvastrazzullo\Desktop\sa-mp 0.3c Server\gamemodes\SLARP.pwn(3066) : error 033: array must be indexed (variable "BizInfo")
C:\Users\Salvastrazzullo\Desktop\sa-mp 0.3c Server\gamemodes\SLARP.pwn(3072) : error 006: must be assigned to an array
C:\Users\Salvastrazzullo\Desktop\sa-mp 0.3c Server\gamemodes\SLARP.pwn(3077) : error 047: array sizes do not match, or destination array is too small
Pawn compiler 3.2.3664	 	 	Copyright © 1997-2006, ITB CompuPhase


3 Errors.
.
It seems that the compiler doesn't want string in that array!

Please, can someone help me with this errors??
Reply
#2

First error:
Quote:

new BizInfo[MAX_BUSINESS][bInfo];

Quote:

BizInfo[bID] = BizCount;

Do this:
pawn Код:
BizCount++;
BizInfo[BizCount][bID] = BizCount;
(NOTE: The BizInfo[THIS][~] is already the ID. No 'bID' needed!)

Second one:
pawn Код:
BizInfo[bID][bName] = str;
Should be
pawn Код:
strins(BizInfo[bID][bName], str, 0, strlen(str));
NOTE: You can better doe BizInfo[BizCount]

third one:
Also use 'strins'
Reply
#3

Thanks!!!!!! I'll test it

EDIT:

I wrote a command with that function:

pawn Код:
if(strcmp(cmdtext, "/creabiz", true) == 0)
  {
      if(!IsPlayerAdmin(playerid)) return 1;
      tmp = strtok(cmdtext,idx);
      if(!strval(tmp)) return SendClientMessage(playerid, COLOR_RED, "USO: /creabiz [Costo].");
      new Float:X,Float:Y,Float:Z;
      GetPlayerPos(playerid, X, Y, Z);
      new int = GetPlayerInterior(playerid);
      new vw = GetPlayerVirtualWorld(playerid);
      CreateBusiness("Il Mio Business", strval(tmp), X, Y, Z, int, vw);
      return 1;
  }
But it says ' Unknown Command ' even if I am logged as admin
Reply
#4

Help, please, is it the function or the command that doesn't work?
Reply
#5

pawn Код:
if(!IsPlayerAdmin(playerid)) return 1;
Change that to 'return 0;'
Reply
#6

Already tried, and if i insert no params it show the message "USO: /.... etc.."

But when I type the params in, it shows the unknown command message

Please can you post fixed version of my createbusiness function here please ? ? ?
Reply
#7

pawn Код:
if(!strval(tmp)) return SendClientMessage(playerid, COLOR_RED, "USO: /creabiz [Costo].");
strval = string to value.
I think you meant 'if(!strlen(tmp))'.
Reply
#8

Did, but look at this screenshot

After doing /createbiz 1500



CODE:
pawn Код:
public OnPlayerCommandText(playerid, cmdtext[])
{
  new cmd[180];
  new tmp[180];
  new index;
  cmd = strtok(cmdtext,idx);

  if(strcmp(cmdtext, "/createbiz", true) == 0)
  {
      if(!IsPlayerAdmin(playerid)) return 1;
      tmp = strtok(cmdtext,idx);
      if(!strlen(tmp)) return SendClientMessage(playerid, COLOR_RED, "USO: /createbiz [Price].");
      new Float:X,Float:Y,Float:Z;
      GetPlayerPos(playerid, X, Y, Z);
      new int = GetPlayerInterior(playerid);
      new vw = GetPlayerVirtualWorld(playerid);
      CreateBusiness("Il Mio Business", strval(tmp), X, Y, Z, int, vw);
      return 1;
  }
  return GameTextForPlayer(playerid,"~r~Comando Inesistente",1000,5);
}
EDIT: Oops, too large picture xD
Reply
#9

Bump, please I need help !
Reply
#10

48 hours waiten, Bump!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)