Saving problem :x
#1

Hello guys!

I made an easy carownership system but there is one little problem that i can't solve...
Here is the post:
pawn Код:
new file[128];
    new Float:x,Float:y,Float:z;
    new pName[MAX_PLAYER_NAME];
    GetPlayerName(playerid,pName,30);
    format(file,sizeof(file),"Server/Cars/%s.ini",pName);
    if(dini_Exists(file))
    {
    for(new i; i<MAX_VEHICLES; i++)
    if(i == CarOwner[playerid])
    {
    new Float:Healthh;
    Healthh = GetPlayerVehicleID(playerid);
    new Float:angl;
    GetVehiclePos(i,x,y,z);
    dini_IntSet(file,"LastID", i);
    dini_IntSet(file,"CModel", CarInfo[i][CModel]);
    dini_FloatSet(file,"PosX", x);
    dini_FloatSet(file,"PosY", y);
    dini_FloatSet(file,"PosZ", z);
    dini_IntSet(file,"Angle", GetVehicleZAngle(i,angl));
    dini_FloatSet(file,"Health", Healthh);
    CarOwner[playerid] = i;
    DestroyVehicle(i);
    }
    }
This script is added in: OnPlayerDisconnect(playerid)
and the problem is it doesn't save anything if i do GMX
- yes i also tried on OnPlayerGameModeExit
Reply
#2

Well your code really doesn't make any sense, there's several problems with it. First of all, you're creating a string for the playername with a length of MAX_PLAYER_NAME (24), and then you're specifying the length of the string as 30 in your GetPlayerName function? You should change that to:

pawn Код:
GetPlayerName(playerid, pname,30);
The next part doesn't make sense at all, this is assuming that CarOwner[playerid] has stored the ID of the vehicle that they own. So why do you need a loop at all to find what car they own? Then you're storing the ID of the vehicle in a float and storing it as the health of the vehicle!? Also you're trying to store the return value of the GetVehicleZAngle function, which won't work since the return value is not the angle.

Either way I suggest you store the ID of the vehicle they own in the CarOwner variable. Then you can simply do this:

pawn Код:
if(dini_Exists(file))
{
    new Float:Healthh, Float:angl;
    GetVehicleHealth(CarOwner[playerid],Healthh);
    GetVehicleZAngle(CarOwner[playerid],angl);
    GetVehiclePos(CarOwner[playerid],x,y,z);
    dini_IntSet(file,"LastID", CarOwner[playerid]);
    dini_IntSet(file,"CModel", CarInfo[CarOwner[playerid]][CModel]);
    dini_FloatSet(file,"PosX", x);
    dini_FloatSet(file,"PosY", y);
    dini_FloatSet(file,"PosZ", z);
    dini_FloatSet(file,"Angle", angl);
    dini_FloatSet(file,"Health", Healthh);
    DestroyVehicle(CarOwner[playerid]);
}
Doesn't that make more sense? Or am I missing the point of your code?
Reply
#3

Yes you're right ... lol
but the server still doesn't save ...
it's just:
pawn Код:
LastID=0
CModel=0
PosX=0.000000
PosY=0.000000
PosZ=0.000000
Angle=0
Health=0.000000
Reply
#4

Well like I said, are you sure you're storing the ID of the vehicle in that variable? Otherwise my code will not work, and neither will yours because it makes no sense

Show me where you are storing the ID of the vehicle in the CarOwner variable.
Reply
#5

I made what you said but ... it's still the same problem
if i leave and join again my car respawns at the same position but if i do GMX it's away...
Reply
#6

So it does work when disconnecting normally? Did you check the files to see if they saved correctly with a normal disconnect that wasn't forced by a GMX?
Reply
#7

with a normal disconnecting the file saves the cords (i looked) etc. but with a GMX they get lost
Reply
#8

Well I suspect that the vehicles are destroyed by the server too quickly to gather the required information for each player. Although I'm not sure about that, so lets do some debugging to be 100% sure:

pawn Код:
if(dini_Exists(file))
{
    new Float:Healthh, Float:angl;
    GetVehicleHealth(CarOwner[playerid],Healthh);
    GetVehicleZAngle(CarOwner[playerid],angl);
    GetVehiclePos(CarOwner[playerid],x,y,z);
    printf("CarOwner: %d | Health: %f | X: %f | Y: %f | Z: %f | A: %f",CarOwner[playerid],Healthh,x,y,z,angl); // Add this line.
    dini_IntSet(file,"LastID", CarOwner[playerid]);
    dini_IntSet(file,"CModel", CarInfo[CarOwner[playerid]][CModel]);
    dini_FloatSet(file,"PosX", x);
    dini_FloatSet(file,"PosY", y);
    dini_FloatSet(file,"PosZ", z);
    dini_FloatSet(file,"Angle", angl);
    dini_FloatSet(file,"Health", Healthh);
    DestroyVehicle(CarOwner[playerid]);
}
Add the print into the code like I did.
Reply
#9

Why did you use printf ? lol
and it's still not working
Reply
#10

That's how we're going to debug the code, it's not supposed to fix the problem at all, it's supposed to find out what's wrong with the code. You need to look in your server console to see what was printed so we can debug the code, the information is also available in the server_log.txt so you can copy and paste it in here.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)