[Rep++]Help!!![Houseid problem][Read it ALL,Rep++]
#1

Well,my house system is 99.9% done now,thanks to you guys and your help(including the admin who deleted my previous topic,once again,I am not hyronic).So,the game loads,and everything works perfect,houses are there with their price,specifications,etc.,but I can only buy the last house added in my script.So what's wrong?And another error is that if I restart server,then the houses delete,but I think that by a little braining I'd be able to fix that,however,help is welcome.The code is here:

pawn Код:
#define hPATH "/HousesDB/%s.ini"
#define DIALOG_oHOUSE 11
#define DIALOG_HOUSE 12
#define DIALOG_sHOUSE 13
#define DIALOG_aHOUSEs 14

new gHouseSell[MAX_PLAYERS];

#define MAX_HOUSES 35

enum hInfo
{
   Text3D:hText,
   Owner[MAX_PLAYER_NAME],
   DefaultPrice,
   SellPrice,
   Interior,
   hSell,
   hPickup,
   ehPickup,
   Float:EnterPos[3],
   Float:ExitPos[3],
   Float:TelePos[3]
}

new HouseInfo[MAX_HOUSES][hInfo];


stock HousesDB(houseid)
{
   new string[256];
   format(string,sizeof(string),hPATH,HouseInfo[houseid][Owner]);
   return string;
}

forward LoadHouse_Data(houseid,name[],value[]);

public LoadHouse_Data(houseid,name[],value[])
{
   INI_String("Owner",HouseInfo[houseid][Owner],24);
   INI_Int("SellPrice",HouseInfo[houseid][SellPrice]);
   INI_Int("Interior",HouseInfo[houseid][Interior]);
   INI_Float("TeleX",HouseInfo[houseid][TelePos][0]);
   INI_Float("TeleY",HouseInfo[houseid][TelePos][1]);
   INI_Float("TeleZ",HouseInfo[houseid][TelePos][2]);
   INI_Float("EnterX",HouseInfo[houseid][EnterPos][0]);
   INI_Float("EnterY",HouseInfo[houseid][EnterPos][1]);
   INI_Float("EnterZ",HouseInfo[houseid][EnterPos][2]);
   INI_Float("ExitX",HouseInfo[houseid][ExitPos][0]);
   INI_Float("ExitY",HouseInfo[houseid][ExitPos][1]);
   INI_Float("ExitZ",HouseInfo[houseid][ExitPos][2]);
   INI_Int("ForSell",HouseInfo[houseid][hSell]);
   return 1;
}

stock CreateHouse(Price,Float:EnterX,Float:EnterY,Float:EnterZ,Float:ExitX,Float:ExitY,Float:ExitZ,Layout,Float:TeleX,Float:TeleY,Float:TeleZ)
{
   new houseid;
   HouseInfo[houseid][DefaultPrice] = Price;
   HouseInfo[houseid][EnterPos][0] = EnterX;
   HouseInfo[houseid][EnterPos][1] = EnterY;
   HouseInfo[houseid][EnterPos][2] = EnterZ;
   HouseInfo[houseid][ExitPos][0] = ExitX;
   HouseInfo[houseid][ExitPos][1] = ExitY;
   HouseInfo[houseid][ExitPos][2] = ExitZ;
   HouseInfo[houseid][Interior] = Layout;
   HouseInfo[houseid][TelePos][0] = TeleX;
   HouseInfo[houseid][TelePos][1] = TeleY;
   HouseInfo[houseid][TelePos][2] = TeleZ;
   HouseInfo[houseid][SellPrice]=0;
   HouseInfo[houseid][hPickup] = CreatePickup(1273,1,EnterX,EnterY,EnterZ,-1);
   HouseInfo[houseid][ehPickup] = CreatePickup(1272,1,ExitX,ExitY,ExitZ,-1);
   HouseInfo[houseid][hSell]=0;
   new string[250];
   if(!HouseInfo[houseid][Owner][0]) format(string,sizeof(string),"{FOR SELL}\nPrice:%d$",Price);
   else if(HouseInfo[houseid][Owner][0] != 0)
   {
      if(HouseInfo[houseid][hSell]==0) format(string,sizeof(string),"Owner:%s",HouseInfo[houseid][Owner]);
      else if(HouseInfo[houseid][hSell]==1) format(string,sizeof(string),"{FOR SELL}\nOwner:%s\nSell price:%d$",HouseInfo[houseid][Owner],HouseInfo[houseid][SellPrice]);
   }
   HouseInfo[houseid][hText] = Create3DTextLabel(string,COLOR_BLUE,EnterX,EnterY,EnterZ+0.5,50.0,0,0);
   houseid++;
   return 1;
}

public OnPlayerConnect(playerid)
{
  gHouseSell[playerid]=0;
  if(GetPVarInt(playerid,"HouseOwner")==1)
  {
      new houseid;
      INI_ParseFile(HousesDB(houseid), "LoadHouse_%d", .bExtra = true, .extra = houseid);
  }
 return 1;
}

public OnPlayerDisconnect(playerid, reason)
{
    if(GetPVarInt(playerid,"HouseOwner") == 1)
    {
              new pName[MAX_PLAYER_NAME];
              GetPlayerName(playerid,pName,sizeof(pName));
              new houseid;
              for(new i=0;i<=MAX_HOUSES;i++)
              {
                if(HouseInfo[i][Owner] != 0 && !strcmp(pName,HouseInfo[i][Owner][0]))
                {
                    houseid=i;
                    break;
                }
              }
              new INI:hFile = INI_Open(HousesDB(houseid));
              INI_SetTag(hFile,"HouseInfo");
              INI_WriteString(hFile,"Owner",pName);
              INI_WriteInt(hFile,"SellPrice",HouseInfo[houseid][SellPrice]);
              INI_WriteInt(hFile,"Interior",HouseInfo[houseid][Interior]);
              INI_WriteFloat(hFile,"TeleX",HouseInfo[houseid][TelePos][0]);
              INI_WriteFloat(hFile,"TeleY",HouseInfo[houseid][TelePos][1]);
              INI_WriteFloat(hFile,"TeleZ",HouseInfo[houseid][TelePos][2]);
              INI_WriteFloat(hFile,"EnterX",HouseInfo[houseid][EnterPos][0]);
              INI_WriteFloat(hFile,"EnterY",HouseInfo[houseid][EnterPos][1]);
              INI_WriteFloat(hFile,"EnterZ",HouseInfo[houseid][EnterPos][2]);
              INI_WriteFloat(hFile,"ExitX",HouseInfo[houseid][ExitPos][0]);
              INI_WriteFloat(hFile,"ExitY",HouseInfo[houseid][ExitPos][1]);
              INI_WriteFloat(hFile,"ExitZ",HouseInfo[houseid][ExitPos][2]);
              INI_WriteInt(hFile,"ForSell",HouseInfo[houseid][hSell]);
              INI_Close(hFile);
    }
 return 1;
}

public OnPlayerPickUpPickup(playerid, pickupid)
{
    new houseid;
    for(new i=0;i<=MAX_HOUSES;i++)
    {
       if(IsPlayerInRangeOfPoint(playerid,3.0,HouseInfo[i][EnterPos][0],HouseInfo[i][EnterPos][1],HouseInfo[i][EnterPos][2]))
       {
          houseid=i;
          break;
       }
    }
    if(pickupid==HouseInfo[houseid][hPickup])
    {
         new pName[MAX_PLAYER_NAME];
         GetPlayerName(playerid,pName,sizeof(pName));
         if(HouseInfo[houseid][Owner] != 0)
         {
           if(!strcmp(pName,HouseInfo[houseid][Owner][0]))
           {
              if(HouseInfo[houseid][hSell]==0){if(gHouseSell[playerid]==0) ShowPlayerDialog(playerid,DIALOG_oHOUSE,DIALOG_STYLE_LIST,"HouseInfo","Enter house\nSell house","Select","Cancel");}
              else if(HouseInfo[houseid][hSell]==1) ShowPlayerDialog(playerid,DIALOG_aHOUSEs,DIALOG_STYLE_MSGBOX,"House Sale","Do you want to abort house selling?","Yes","No");
           }
           else SendClientMessage(playerid,COLOR_RED,"This house is already owned/not owned by you!");
         }
         else if(!HouseInfo[houseid][Owner][0])
         {
             new string[256];
             if(HouseInfo[houseid][hSell]==0) format(string,sizeof(string),"Do you want to buy this house for %d$?",HouseInfo[houseid][DefaultPrice]);
             else if(HouseInfo[houseid][hSell]==1) format(string,sizeof(string),"Do you want to buy this house for %d$?",HouseInfo[houseid][SellPrice]);
             ShowPlayerDialog(playerid,DIALOG_HOUSE,DIALOG_STYLE_MSGBOX,"HouseInfo",string,"Yes","No");
         }
   }
   if(pickupid==HouseInfo[houseid][ehPickup])
   {
         SetPlayerPos(playerid,HouseInfo[houseid][EnterPos][0],HouseInfo[houseid][EnterPos][1],HouseInfo[houseid][EnterPos][2]);
         SetPlayerInterior(playerid,0);
   }
  return 1;
}

public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
      if(dialogid==11)
   {
      if(response==0) return SendClientMessage(playerid,COLOR_RED,"Action aborted");
      if(response==1)
      {
          new houseid;
          for(new i=0;i<=MAX_HOUSES;i++)
          {
           if(IsPlayerInRangeOfPoint(playerid,3.0,HouseInfo[i][EnterPos][0],HouseInfo[i][EnterPos][1],HouseInfo[i][EnterPos][2]))
           {
            houseid=i;
            break;
           }
          }
          switch(listitem)
          {
            case 0:
            {
              SetPlayerPos(playerid,HouseInfo[houseid][TelePos][0],HouseInfo[houseid][TelePos][1],HouseInfo[houseid][TelePos][2]);
              SetPlayerInterior(playerid,HouseInfo[houseid][Interior]);
              SendClientMessage(playerid,COLOR_YELLOW,"Home,sweet home!!!");
              SendClientMessage(playerid,COLOR_GREEN,"Welcome to your house!");
            }
            case 1:
            {
               gHouseSell[playerid] = 1;
               ShowPlayerDialog(playerid,DIALOG_sHOUSE,DIALOG_STYLE_INPUT,"House Sell Price","Insert price:","Sell","Cancel");
            }
          }
        }
   }
   if(dialogid==12)
   {
      if(response==0) return SendClientMessage(playerid,COLOR_RED,"Action aborted");
      if(response==1)
      {
         if(GetPVarInt(playerid,"HouseOwner")==1) return SendClientMessage(playerid,COLOR_RED,"You already own a house!");
         else
         {
              new houseid;
              for(new j=0;j<=MAX_HOUSES;j++)
              {
               if(IsPlayerInRangeOfPoint(playerid,3.0,HouseInfo[j][EnterPos][0],HouseInfo[j][EnterPos][1],HouseInfo[j][EnterPos][2]))
               {
                 houseid=j;
                 break;
               }
              }
              new playerid2;
              if(HouseInfo[houseid][hSell]==0)
              {
                     if(GetPlayerMoney(playerid)<HouseInfo[houseid][DefaultPrice]) SendClientMessage(playerid,COLOR_RED,"You don't have enogh money to buy this house!");
                     else GivePlayerMoney(playerid,-HouseInfo[houseid][DefaultPrice]);
              }
              else if(HouseInfo[houseid][hSell]==1)
              {
                 if(GetPlayerMoney(playerid)<HouseInfo[houseid][SellPrice]) SendClientMessage(playerid,COLOR_RED,"You don't have enough money to buy this house!");
                 else
                 {
                   GivePlayerMoney(playerid,-HouseInfo[houseid][SellPrice]);
                   new OK=0;
                   for(new i=0;i<=MAX_PLAYERS;i++)
                   {
                      new iName[24];
                      GetPlayerName(i,iName,sizeof(iName));
                      if(!strcmp(iName,HouseInfo[houseid][Owner][0]))
                      {
                           playerid2=i;
                           break;
                      }
                   }
                   if(OK==1)
                   {
                      SetPVarInt(playerid2,"HouseOwner",0);
                      GivePlayerMoney(playerid,HouseInfo[houseid][SellPrice]);
                      SendClientMessage(playerid2,COLOR_GREEN,"Your house has been succesfully sold!");
                   }
                   else
                   {
                   SetPVarInt(HouseInfo[houseid][Owner],"HouseOwner",0);
                   new INI:PFile = INI_Open(Accounts(HouseInfo[houseid][Owner]));
                   INI_SetTag(PFile,"Data");
                   INI_WriteInt(PFile,"Money",Cash[HouseInfo[houseid][Owner]]+HouseInfo[houseid][SellPrice]);
                   INI_Close(PFile);
                   }
                 }
              }
              new pName[MAX_PLAYER_NAME];
              GetPlayerName(playerid,pName,sizeof(pName));
              new string[250];
              format(HouseInfo[houseid][Owner],24,"%s",pName);
              format(string,sizeof(string),"Owner:%s",HouseInfo[houseid][Owner]);
              Update3DTextLabelText(HouseInfo[houseid][hText],COLOR_BLUE,string);
              SendClientMessage(playerid,COLOR_GREEN,"You have succesfully bhought this house!");
              HouseInfo[houseid][DefaultPrice] = 0;
              SetPVarInt(playerid,"HouseOwner",1);
              HouseInfo[houseid][hSell]=0;
              new INI:hFile = INI_Open(HousesDB(houseid));
              INI_SetTag(hFile,"HouseInfo");
              INI_WriteString(hFile,"Owner",pName);
              INI_WriteInt(hFile,"SellPrice",HouseInfo[houseid][SellPrice]);
              INI_WriteInt(hFile,"Interior",HouseInfo[houseid][Interior]);
              INI_WriteFloat(hFile,"TeleX",HouseInfo[houseid][TelePos][0]);
              INI_WriteFloat(hFile,"TeleY",HouseInfo[houseid][TelePos][1]);
              INI_WriteFloat(hFile,"TeleZ",HouseInfo[houseid][TelePos][2]);
              INI_WriteFloat(hFile,"EnterX",HouseInfo[houseid][EnterPos][0]);
              INI_WriteFloat(hFile,"EnterY",HouseInfo[houseid][EnterPos][1]);
              INI_WriteFloat(hFile,"EnterZ",HouseInfo[houseid][EnterPos][2]);
              INI_WriteFloat(hFile,"ExitX",HouseInfo[houseid][ExitPos][0]);
              INI_WriteFloat(hFile,"ExitY",HouseInfo[houseid][ExitPos][1]);
              INI_WriteFloat(hFile,"ExitZ",HouseInfo[houseid][ExitPos][2]);
              INI_WriteInt(hFile,"ForSell",HouseInfo[houseid][hSell]);
              INI_Close(hFile);
           }
        }
      }
     if(dialogid==13)
     {
         if(response==0) { SendClientMessage(playerid,COLOR_RED,"Action aborted!");gHouseSell[playerid] = 0;}
         if(response==1)
         {
               new houseid;
               for(new i=0;i<=MAX_HOUSES;i++)
               {
                 if(IsPlayerInRangeOfPoint(playerid,3.0,HouseInfo[i][EnterPos][0],HouseInfo[i][EnterPos][1],HouseInfo[i][EnterPos][2]))
                 {
                   houseid=i;
                   break;
                 }
                }
                HouseInfo[houseid][SellPrice] = strval(inputtext);
                new pName[24];
                GetPlayerName(playerid,pName,sizeof(pName));
                new string[250];
                HouseInfo[houseid][hSell] = 1;
                format(HouseInfo[houseid][Owner],24,"%s",pName);
                format(string,sizeof(string),"{FOR SELL}\nOwner:%s\nSell price:%d$",HouseInfo[houseid][Owner],HouseInfo[houseid][SellPrice]);
                Update3DTextLabelText(HouseInfo[houseid][hText],COLOR_BLUE,string);
                new INI:hFile = INI_Open(HousesDB(houseid));
                INI_SetTag(hFile,"HouseInfo");
                INI_WriteString(hFile,"Owner",pName);
                INI_WriteInt(hFile,"SellPrice",HouseInfo[houseid][SellPrice]);
                INI_WriteInt(hFile,"Interior",HouseInfo[houseid][Interior]);
                INI_WriteFloat(hFile,"TeleX",HouseInfo[houseid][TelePos][0]);
                INI_WriteFloat(hFile,"TeleY",HouseInfo[houseid][TelePos][1]);
                INI_WriteFloat(hFile,"TeleZ",HouseInfo[houseid][TelePos][2]);
                INI_WriteFloat(hFile,"EnterX",HouseInfo[houseid][EnterPos][0]);
                INI_WriteFloat(hFile,"EnterY",HouseInfo[houseid][EnterPos][1]);
                INI_WriteFloat(hFile,"EnterZ",HouseInfo[houseid][EnterPos][2]);
                INI_WriteFloat(hFile,"ExitX",HouseInfo[houseid][ExitPos][0]);
                INI_WriteFloat(hFile,"ExitY",HouseInfo[houseid][ExitPos][1]);
                INI_WriteFloat(hFile,"ExitZ",HouseInfo[houseid][ExitPos][2]);
                INI_WriteInt(hFile,"ForSell",HouseInfo[houseid][hSell]);
                INI_Close(hFile);
                SendClientMessage(playerid,COLOR_PURPLE,"Your house is for sale now!");
            }
     }
      if(dialogid==14)
      {
         if(response==0) return SendClientMessage(playerid,COLOR_RED,"Action aborted");
         if(response==1)
         {
                new houseid;
                for(new i=0;i<=MAX_HOUSES;i++)
                {
                  if(IsPlayerInRangeOfPoint(playerid,3.0,HouseInfo[i][EnterPos][0],HouseInfo[i][EnterPos][1],HouseInfo[i][EnterPos][2]))
                  {
                    houseid=i;
                    break;
                  }
                }
                new pName[24];
                GetPlayerName(playerid,pName,sizeof(pName));
                new string[250];
                HouseInfo[houseid][hSell] = 0;
                format(string,sizeof(string),"Owner:%s",HouseInfo[houseid][Owner]);
                Update3DTextLabelText(HouseInfo[houseid][hText],COLOR_GREEN,string);
                HouseInfo[houseid][SellPrice] = 0;
                new INI:hFile = INI_Open(HousesDB(houseid));
                INI_SetTag(hFile,"HouseInfo");
                INI_WriteString(hFile,"Owner",pName);
                INI_WriteInt(hFile,"SellPrice",HouseInfo[houseid][SellPrice]);
                INI_WriteInt(hFile,"Interior",HouseInfo[houseid][Interior]);
                INI_WriteFloat(hFile,"TeleX",HouseInfo[houseid][TelePos][0]);
                INI_WriteFloat(hFile,"TeleY",HouseInfo[houseid][TelePos][1]);
                INI_WriteFloat(hFile,"TeleZ",HouseInfo[houseid][TelePos][2]);
                INI_WriteFloat(hFile,"EnterX",HouseInfo[houseid][EnterPos][0]);
                INI_WriteFloat(hFile,"EnterY",HouseInfo[houseid][EnterPos][1]);
                INI_WriteFloat(hFile,"EnterZ",HouseInfo[houseid][EnterPos][2]);
                INI_WriteFloat(hFile,"ExitX",HouseInfo[houseid][ExitPos][0]);
                INI_WriteFloat(hFile,"ExitY",HouseInfo[houseid][ExitPos][1]);
                INI_WriteFloat(hFile,"ExitZ",HouseInfo[houseid][ExitPos][2]);
                INI_WriteInt(hFile,"ForSell",HouseInfo[houseid][hSell]);
                INI_Close(hFile);
                gHouseSell[playerid] = 0;
         }
    }
 return 1;
}
"I would be really thankful if you help me related to both problems,houseid,and the fact that house deletes at restart,it's my first ownership,so,even if I followed a good tutorial I am not that kind of copy-paste guy,so I am sure I missed a few things...:P"
Reply
#2

Anybody,please?I really wanna know what is my noob mistake
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)