SA-MP Forums Archive
How to make a permanant variable - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: How to make a permanant variable (/showthread.php?tid=509185)



How to make a permanant variable - AphexCCFC - 25.04.2014

Hello. How do I make it so when someone uses /createhouse it adds one more onto the id variable, but when I restart the server, the id variable goes back to 0.

pawn Код:
stock CreateHouse(price, Float:PosX, Float:PosY, Float:PosZ)
{
    new string[140], query[300];
    new id = 0; // Here is the ID variable. I want it to save even on game mode restart

    HouseInfo[id][hHouseID] = id;
    HouseInfo[id][hEnterPos][0] = PosX;
    HouseInfo[id][hEnterPos][1] = PosY;
    HouseInfo[id][hEnterPos][2] = PosZ;
    HouseInfo[id][hExitPos][0] = 266.9708;
    HouseInfo[id][hExitPos][1] = 304.9378;
    HouseInfo[id][hExitPos][2] = 999.1484;
    HouseInfo[id][hExitPos][3] = 273.4171;
    HouseInfo[id][hInterior] = 2;
    format(HouseInfo[id][hAddress], 32, "1 San Fierro Drive");
    HouseInfo[id][hPrice] = price;

    format(query, sizeof(query), "INSERT INTO `Houses` (`HouseID`, `Address`, `Price`, `EnterX`, `EnterY`, `EnterZ`, `ExitX`, `ExitY`, `ExitZ`, `ExitA`, `Interior`) VALUES (%d, \'%s\', %d, %f, %f, %f, %f, %f, %f, %f, %d)",
    HouseInfo[id][hHouseID],
    HouseInfo[id][hAddress],
    HouseInfo[id][hPrice],
    HouseInfo[id][hEnterPos][0],
    HouseInfo[id][hEnterPos][1],
    HouseInfo[id][hEnterPos][2],
    HouseInfo[id][hExitPos][0],
    HouseInfo[id][hExitPos][1],
    HouseInfo[id][hExitPos][2],
    HouseInfo[id][hExitPos][3],
    HouseInfo[id][hInterior]
    );

    mysql_function_query(g_Handle, query, false, "", "");

    HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, PosX, PosY, PosZ, -1, -1, -1, 100.0);
    format(string,sizeof(string),"HouseID: %d\nAddress: %s\nPrice: %d", HouseInfo[id][hHouseID], HouseInfo[id][hAddress], HouseInfo[id][hPrice]);
    HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, -1, PosX, PosY, PosZ, 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
    id ++; // Here it adds one on each time a house is created
}



AW: How to make a permanant variable - Nero_3D - 25.04.2014

Save the value to a file / database and load it afterwards


Re: How to make a permanant variable - AphexCCFC - 25.04.2014

Ahh found another way so it adds one on when it loads the house rows, thanks.

One more question, how does one make it so when a player exits the house, it sets their facing angle 180 degrees (half turn)?
Tried this but doesn't work:

pawn Код:
SetPlayerFacingAngle(playerid, HouseInfo[i][hEnterPos][3]-180);



Re: How to make a permanant variable - Galletziz - 25.04.2014

you give a value of id to global variable like this..

pawn Код:
//global variable above on GameModeInit()
new housecount;

stock CreateHouse(price, Float:PosX, Float:PosY, Float:PosZ)
{
    new string[140], query[300];
    new id = housescount;

    HouseInfo[id][hHouseID] = id;
    HouseInfo[id][hEnterPos][0] = PosX;
    HouseInfo[id][hEnterPos][1] = PosY;
    HouseInfo[id][hEnterPos][2] = PosZ;
    HouseInfo[id][hExitPos][0] = 266.9708;
    HouseInfo[id][hExitPos][1] = 304.9378;
    HouseInfo[id][hExitPos][2] = 999.1484;
    HouseInfo[id][hExitPos][3] = 273.4171;
    HouseInfo[id][hInterior] = 2;
    format(HouseInfo[id][hAddress], 32, "1 San Fierro Drive");
    HouseInfo[id][hPrice] = price;

    format(query, sizeof(query), "INSERT INTO `Houses` (`HouseID`, `Address`, `Price`, `EnterX`, `EnterY`, `EnterZ`, `ExitX`, `ExitY`, `ExitZ`, `ExitA`, `Interior`) VALUES (%d, \'%s\', %d, %f, %f, %f, %f, %f, %f, %f, %d)",
    HouseInfo[id][hHouseID],
    HouseInfo[id][hAddress],
    HouseInfo[id][hPrice],
    HouseInfo[id][hEnterPos][0],
    HouseInfo[id][hEnterPos][1],
    HouseInfo[id][hEnterPos][2],
    HouseInfo[id][hExitPos][0],
    HouseInfo[id][hExitPos][1],
    HouseInfo[id][hExitPos][2],
    HouseInfo[id][hExitPos][3],
    HouseInfo[id][hInterior]
    );

    mysql_function_query(g_Handle, query, false, "", "");

    HouseInfo[id][hPickup] = CreateDynamicPickup(1273, 23, PosX, PosY, PosZ, -1, -1, -1, 100.0);
    format(string,sizeof(string),"HouseID: %d\nAddress: %s\nPrice: %d", HouseInfo[id][hHouseID], HouseInfo[id][hAddress], HouseInfo[id][hPrice]);
    HouseInfo[id][hText] = CreateDynamic3DTextLabel(string, -1, PosX, PosY, PosZ, 25, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 1, -1, -1, -1, 100);
    id++; // Here it adds one on each time a house is created
}
obviusly when you restart the server if you don't use any system for save this informations the count back to 0.