Address wont save
#1

Hello,

I cannot find my bug why my address shows "1", while I gave it the address "4th palin street"

pawn Код:
enum HouseData
{
    hInteriorID,
    hAddress[255],
    Float: hInteriorX,
    Float: hInteriorY,
    Float: hInteriorZ,
    Float: hInteriorA,
    hExteriorID,
    Float: hExteriorX,
    Float: hExteriorY,
    Float: hExteriorZ,
    Float: hExteriorA,
    hSpawnID,
    Float: hSpawnX,
    Float: hSpawnY,
    Float: hSpawnZ,
    Float: hSpawnA,
    HPickupID,
    hOwner[255],
    HousePrice,
    LockStatus,
    hType[255],
    LastLoginDay,
    LastLoginMonth,
    LastLoginYear,
};
pawn Код:
command(sethouseaddress, playerid, params[])
{
    new address[255], string[128];
    if(sscanf(params, "z", address))
    {
        if(Player[playerid][AdminLevel] >= 6)
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /sethouseaddress [address]");
        }
    }
    else
    {
        if(Player[playerid][AdminLevel] >= 6)
        {
            for(new h = 0; h < MAX_HOUSES; h++)
            {
                if(strcmp(Houses[h][hAddress], address, true))
                {
                    if(IsPlayerInRangeOfPoint(playerid, 2, Houses[h][hExteriorX], Houses[h][hExteriorY], Houses[h][hExteriorZ]))
                    {
                        format(Houses[h][hAddress], 255, "%s", address);
                        format(string, sizeof(string), "You succesfully renamed house id: %d's address to: %s", h, address);
                        SCM(playerid, YELLOW, string);
                        SaveHouse(h);
                        break;
                    }
                }
                else
                {
                    SCM(playerid, RED, "This address already exists");
                }
            }
        }
    }
    return 1;
}
pawn Код:
stock InitHouses()
{
    new FileName[128];
    for(new i = 0; i < MAX_HOUSES; i++)
    {
        format(FileName, sizeof(FileName), "Houses/House_%d.ini", i);
        if(fexist(FileName))
        {
            Houses[i][hAddress] = dini_Get(FileName, "hAddress");
            Houses[i][hType] = dini_Get(FileName, "hType");
            Houses[i][hInteriorID] = dini_Int(FileName, "InteriorID");
            Houses[i][hInteriorX] = dini_Float(FileName, "InteriorX");
            Houses[i][hInteriorY] = dini_Float(FileName, "InteriorY");
            Houses[i][hInteriorZ] = dini_Float(FileName, "InteriorZ");
            Houses[i][hInteriorA] = dini_Float(FileName, "InteriorA");

            Houses[i][hExteriorID] = dini_Int(FileName, "ExteriorID");
            Houses[i][hExteriorX] = dini_Float(FileName, "ExteriorX");
            Houses[i][hExteriorY] = dini_Float(FileName, "ExteriorY");
            Houses[i][hExteriorZ] = dini_Float(FileName, "ExteriorZ");
            Houses[i][hExteriorA] = dini_Float(FileName, "ExteriorA");

            Houses[i][hSpawnID] = dini_Int(FileName, "SpawnID");
            Houses[i][hSpawnX] = dini_Float(FileName, "SpawnX");
            Houses[i][hSpawnY] = dini_Float(FileName, "SpawnY");
            Houses[i][hSpawnZ] = dini_Float(FileName, "SpawnZ");
            Houses[i][hSpawnA] = dini_Float(FileName, "SpawnA");

            Houses[i][hOwner] = dini_Get(FileName, "Owner");
            Houses[i][HousePrice] = dini_Int(FileName, "HousePrice");
            Houses[i][LockStatus] = dini_Int(FileName, "LockStatus");
            Houses[i][LastLoginDay] = dini_Int(FileName, "LastLoginDay");
            Houses[i][LastLoginMonth] = dini_Int(FileName, "LastLoginMonth");
            Houses[i][LastLoginYear] = dini_Int(FileName, "LastLoginYear");

            if(strcmp(Houses[i][hOwner], "Nobody", true) == 0)
            {
                Houses[i][LockStatus] = 1;
                Houses[i][HPickupID] = CreateDynamicPickup(1273, 23, Houses[i][hExteriorX], Houses[i][hExteriorY], Houses[i][hExteriorZ], 0, -1, -1, 150.0);
            }
            else
            {
                Houses[i][HPickupID] = CreateDynamicPickup(1318, 23, Houses[i][hExteriorX], Houses[i][hExteriorY], Houses[i][hExteriorZ], 0, -1, -1, 150.0);
            }

            printf("[system] House %d spawned.", i);
            SpawnedHouses++;
       }
    }
    return 1;
}
pawn Код:
stock SaveHouse(i)
{
    new FileName[23];
    format(FileName, sizeof(FileName), "Houses/House_%d.ini", i);
    if(fexist(FileName))
    {
        dini_IntSet(FileName, "InteriorID", Houses[i][hInteriorID]);
        dini_FloatSet(FileName, "InteriorX", Houses[i][hInteriorX]);
        dini_FloatSet(FileName, "InteriorY", Houses[i][hInteriorY]);
        dini_FloatSet(FileName, "InteriorZ", Houses[i][hInteriorZ]);
        dini_FloatSet(FileName, "InteriorA", Houses[i][hInteriorA]);

        dini_IntSet(FileName, "ExteriorID", Houses[i][hExteriorID]);
        dini_FloatSet(FileName, "ExteriorX", Houses[i][hExteriorX]);
        dini_FloatSet(FileName, "ExteriorY", Houses[i][hExteriorY]);
        dini_FloatSet(FileName, "ExteriorZ", Houses[i][hExteriorZ]);
        dini_FloatSet(FileName, "ExteriorA", Houses[i][hExteriorA]);

        dini_IntSet(FileName, "SpawnID", Houses[i][hSpawnID]);
        dini_FloatSet(FileName, "SpawnX", Houses[i][hSpawnX]);
        dini_FloatSet(FileName, "SpawnY", Houses[i][hSpawnY]);
        dini_FloatSet(FileName, "SpawnZ", Houses[i][hSpawnZ]);
        dini_FloatSet(FileName, "SpawnA", Houses[i][hSpawnA]);

        dini_Set(FileName, "Owner", Houses[i][hOwner]);
        dini_Set(FileName, "hAddress", Houses[i][hAddress]);
        dini_Set(FileName, "hType", Houses[i][hType]);
        dini_IntSet(FileName, "HousePrice", Houses[i][HousePrice]);
        dini_IntSet(FileName, "LockStatus", Houses[i][LockStatus]);
        dini_IntSet(FileName, "LastLoginDay", Houses[i][LastLoginDay]);
        dini_IntSet(FileName, "LastLoginMonth", Houses[i][LastLoginMonth]);
        dini_IntSet(FileName, "LastLoginYear", Houses[i][LastLoginYear]);

        printf("[system] House %d saved.", i);
    }
    return 1;
}
Reply
#2

Does the message comes when you setadress "You succesfully renamed house id: %d's address to: %s"
Reply
#3

Quote:
Originally Posted by dr.lozer
Посмотреть сообщение
Does the message comes when you setadress "You succesfully renamed house id: %d's address to: %s"
Yes but on relog it is gone and it shows the house id i think (house id is 1 and it shows "1")
Reply
#4

I haven't really messed with scripting in a while but I do see your problem. I can't remember the correct way to fix it but I'll try to explain it.

You are only formatting hAddress, nowhere in that command do you set it. You should make a new string and format it to include only the address. Then set hAddress to that string. So you need something like;

Код:
format(str1,sizeof(str1),"%s",address);
Houses[i][hAddress] = str1;
At least, that's how I would handle it with Yini. Never really played with Dini but I imagine they're pretty similar.
Reply
#5

Add this on top and down of the #include <a_samp>

Код:
#if !defined isnull
	#define isnull(%1) \
				((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
then use this:

pawn Код:
command(sethouseaddress, playerid, params[])
{
    new string[128];
    if(isnull(params))
    {
        if(Player[playerid][AdminLevel] >= 6)
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /sethouseaddress [address]");
        }
    }
    else
    {
        if(Player[playerid][AdminLevel] >= 6)
        {
            for(new h = 0; h < MAX_HOUSES; h++)
            {
                if(strcmp(Houses[h][hAddress], address, true))
                {
                    if(IsPlayerInRangeOfPoint(playerid, 2, Houses[h][hExteriorX], Houses[h][hExteriorY], Houses[h][hExteriorZ]))
                    {
                        format(Houses[h][hAddress], 255, "%s", params);
                        format(string, sizeof(string), "You succesfully renamed house id: %d's address to: %s", h, params);
                        SCM(playerid, YELLOW, string);
                        SaveHouse(h);
                        break;
                    }
                }
                else
                {
                    SCM(playerid, RED, "This address already exists");
                }
            }
        }
    }
    return 1;
}
Reply
#6

Quote:
Originally Posted by zDevon
Посмотреть сообщение
Код:
format(str1,sizeof(str1),"%s",address);
Houses[i][hAddress] = str1;
format is for strings, Houses[i][hAddress] = for a number like 43 or 13 or something like that.
The address is like: 4th Palin Street
Reply
#7

Quote:
Originally Posted by dr.lozer
Посмотреть сообщение
Add this on top and down of the #include <a_samp>

Код:
#if !defined isnull
	#define isnull(%1) \
				((!(%1[0])) || (((%1[0]) == '\1') && (!(%1[1]))))
#endif
then use this:

pawn Код:
command(sethouseaddress, playerid, params[])
{
    new string[128];
    if(isnull(params))
    {
        if(Player[playerid][AdminLevel] >= 6)
        {
            SendClientMessage(playerid, WHITE, "SYNTAX: /sethouseaddress [address]");
        }
    }
    else
    {
        if(Player[playerid][AdminLevel] >= 6)
        {
            for(new h = 0; h < MAX_HOUSES; h++)
            {
                if(strcmp(Houses[h][hAddress], address, true))
                {
                    if(IsPlayerInRangeOfPoint(playerid, 2, Houses[h][hExteriorX], Houses[h][hExteriorY], Houses[h][hExteriorZ]))
                    {
                        format(Houses[h][hAddress], 255, "%s", params);
                        format(string, sizeof(string), "You succesfully renamed house id: %d's address to: %s", h, params);
                        SCM(playerid, YELLOW, string);
                        SaveHouse(h);
                        break;
                    }
                }
                else
                {
                    SCM(playerid, RED, "This address already exists");
                }
            }
        }
    }
    return 1;
}
Let me test
Reply
#8

Now the house wont wanna spawn :S
Reply
#9

Quote:
Originally Posted by Stefand
Посмотреть сообщение
format is for strings, Houses[i][hAddress] = for a number like 43 or 13 or something like that.
The address is like: 4th Palin Street
No..

By adding a character count to hAddress on your enum defines, you allowed declaring it as a string. So to speak. Just try what I suggested with your original code (before dr.lozer's suggestion) and see how it works out.

You actually don't even need a new string like I originally said. 'address' is the parameter for /sethouseaddress, yeah? So just use
Код:
Houses[i][hAddress] = address
Reply
#10

The save address works correct now but, it doesnt wanna spawn the house....
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)