SA-MP Forums Archive
saving over all ATMs? - 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: saving over all ATMs? (/showthread.php?tid=664393)



saving over all ATMs? - TheLeech - 27.02.2019

for some reason it saves over all ATMs the last ATMs stats I create.

Код:
stock ATM_Create(playerid)
{
    new
	    Float:x,
	    Float:y,
	    Float:z,
	    Float:angle;

	if (GetPlayerPos(playerid, x, y, z) && GetPlayerFacingAngle(playerid, angle))
	{
		for (new i = 0; i < MAX_ATM_MACHINES; i ++) if (!ATMData[i][atmExists])
		{
		    ATMData[i][atmExists] = true;

		    x += 1.0 * floatsin(-angle, degrees);
			y += 1.0 * floatcos(-angle, degrees);

            ATMData[i][atmPos][0] = x;
            ATMData[i][atmPos][1] = y;
            ATMData[i][atmPos][2] = z;
            ATMData[i][atmPos][3] = angle;

            ATMData[i][atmInterior] = GetPlayerInterior(playerid);
            ATMData[i][atmWorld] = GetPlayerVirtualWorld(playerid);

			ATM_Refresh(i);
   			mysql_tquery(g_iHandle, "INSERT INTO `atm` (`atmID`) VALUES(0)", "OnATMCreated", "d", i);
   			EditDynamicObject(playerid, ATMData[i][atmObject]);
   			IDforEditing[playerid] = i;
   			SetPVarInt(playerid, "EditorMode", 1); // 1 for ATM's, 2 for speed cameras, 3 for house objects, 4 for business, 5 for car.
			return i;
		}
	}
	return -1;
}

stock ATM_Save(atmid)
{
	new
	    query[200];

	format(query, sizeof(query), "UPDATE `atm` SET `atmX` = '%.4f', `atmY` = '%.4f', `atmZ` = '%.4f', `atmA` = '%.4f', `atmInterior` = '%d', `atmWorld` = '%d' WHERE `atmID` = '%d'",
	    ATMData[atmid][atmPos][0],
	    ATMData[atmid][atmPos][1],
	    ATMData[atmid][atmPos][2],
	    ATMData[atmid][atmPos][3],
	    ATMData[atmid][atmInterior],
	    ATMData[atmid][atmWorld],
	    ATMData[atmid][atmID]
	);
	return mysql_tquery(g_iHandle, query);
}

stock ATM_Refresh(atmid)
{
	if (atmid != -1 && ATMData[atmid][atmExists])
	{
	    if (IsValidDynamicObject(ATMData[atmid][atmObject]))
	        DestroyDynamicObject(ATMData[atmid][atmObject]);

	    if (IsValidDynamic3DTextLabel(ATMData[atmid][atmText3D]))
	        DestroyDynamic3DTextLabel(ATMData[atmid][atmText3D]);

		new
	        string[64];

		format(string, sizeof(string), "/atm to use this machine\nOr press H.", atmid);

		ATMData[atmid][atmObject] = CreateDynamicObject(2942, ATMData[atmid][atmPos][0], ATMData[atmid][atmPos][1], ATMData[atmid][atmPos][2] - 0.4, 0.0, 0.0, ATMData[atmid][atmPos][3], ATMData[atmid][atmWorld], ATMData[atmid][atmInterior]);
        ATMData[atmid][atmText3D] = CreateDynamic3DTextLabel(string, 0xFFFFFFFF, ATMData[atmid][atmPos][0], ATMData[atmid][atmPos][1], ATMData[atmid][atmPos][2], 15.0, INVALID_PLAYER_ID, INVALID_VEHICLE_ID, 0, ATMData[atmid][atmWorld], ATMData[atmid][atmInterior]);

		return 1;
	}
	return 0;
}

forward OnATMCreated(atmid);
public OnATMCreated(atmid)
{
    if (atmid == -1 || !ATMData[atmid][atmExists])
		return 0;

	ATMData[atmid][atmID] = cache_insert_id(g_iHandle);
 	ATM_Save(atmid);

	return 1;
}

public OnPlayerEditDynamicObject(playerid, objectid, response, Float:x, Float:y, Float:z, Float:rx, Float:ry, Float:rz)
{
    new Float:oldX, Float:oldY, Float:oldZ, Float:oldRotX, Float:oldRotY, Float:oldRotZ;
	GetObjectPos(objectid, oldX, oldY, oldZ);
	GetObjectRot(objectid, oldRotX, oldRotY, oldRotZ);
    if(response != 1) return 1;
    if(response == EDIT_RESPONSE_FINAL)
	{
	    switch(GetPVarInt(playerid, "EditorMode"))
		{
		    case 1:
		    {
		        new atmid = IDforEditing[playerid];
		        ATMData[atmid][atmPos][0] = x;
			    ATMData[atmid][atmPos][1] = y;
			    ATMData[atmid][atmPos][2] = z;
			    ATMData[atmid][atmPos][3] = rz;
			    ATMData[atmid][atmInterior]= GetPlayerInterior(playerid);
			    ATMData[atmid][atmWorld] = GetPlayerVirtualWorld(playerid);
			    ATMData[atmid][atmID] = IDforEditing[playerid];
			    ATM_Save(IDforEditing[playerid]);
			    DeletePVar(playerid,"EditorMode");
			}
		}
	}
	if(response == EDIT_RESPONSE_CANCEL)
	{
	    return 1;
	}
	return 1;
}



Re: saving over all ATMs? - SymonClash - 01.03.2019

I don't understand, does it save just the last created ATM? If so, try:

pawn Код:
stock ATM_Save()
{
    for(new i = 0; i < MAX_ATM_MACHINES; i ++) if(ATMData[i][atmExists])
    {
        new query[200];

        format(query, sizeof(query), "UPDATE `atm` SET `atmX` = '%.4f', `atmY` = '%.4f', `atmZ` = '%.4f', `atmA` = '%.4f', `atmInterior` = '%d', `atmWorld` = '%d' WHERE `atmID` = '%d'",
        ATMData[i][atmPos][0],
        ATMData[i][atmPos][1],
        ATMData[i][atmPos][2],
        ATMData[i][atmPos][3],
        ATMData[i][atmInterior],
        ATMData[i][atmWorld],
        ATMData[i][atmID]);
        mysql_tquery(g_iHandle, query);
    }
    return 1;
}