Could someone explain me a thing?[Urgently]
#1

Hello everyone,
im made my first vehicle system but im having some problems.
Could someone explain me a thing?How the system should work ?I mean,mine have this bug:
When a player sells his vehicle,all the players have a wrong vehicle .
Example:


Код:
VehicleID:1------------VehicleID:2
|||||||||||------------|||||||||||
Owner:Justin-----------Owner:Bruno
Justin sells his vehicle and then:

Код:
----<_____________________<
----\/--------------------/\
----||--------------------||
VehicleID:1------------VehicleID:2
|||||||||||------------|||||||||||
Owner:Justin-----------Owner:Bruno
And everything will look like this:

Код:
VehicleID:1(bruno's vehicle)-------------Wrong Vehicle
|||||||||||------------------------------|||||||||||
Owner:Noone------------------------------Owner:Bruno
9999-No vehicle

Bruno's vehicle takes justins vehicle id and then Bruno will have a wrong vehicle
If this didn't explain you enough,just ask.

PS:After selling a vehicle,it gets distroyed.I forgot this
Reply
#2

As i said,the script destroys the vehicles after selling them and after restart a vehicle is missing so all the vehicles will get a lower ID.

The sell code is long but ill put here the "/asellcar".

pawn Код:
if(!strcmp(cmdtext, "/asellcar", true))
    {
        if(IsPlayerConnected(playerid))
        {
            if(gPlayerLogged[playerid] == 0)
            {
                SendClientMessage(playerid, COLOR_GREY, "Login first!");
                return 1;
            }
            if(PlayerInfo[playerid][pAdmin] >= 5)
            {
                new vehid = GetPlayerVehicleID(playerid);
                CarInfo[vehid][cOwned] = 0;

                new ye,m,d;
                new h,mi,s;
                getdate(ye,m,d);
                gettime(h,mi,s);

                for(new i = 0; i < MAX_PLAYERS; i ++)
                {
                    if(IsPlayerConnected(i))
                    {
                        if(PlayerInfo[i][pPcarkey] == vehid || PlayerInfo[i][pPcarkey2] == vehid)
                        {
                            if(PlayerInfo[i][pPcarkey] == vehid) PlayerInfo[i][pPcarkey] = 999;
                            else if(PlayerInfo[i][pPcarkey2] == vehid) PlayerInfo[i][pPcarkey2] = 9999;

                            GivePlayerMoney(i, GetVehiclePrice(vehid) / 2);
                        }
                        else
                        {
                            format(string, sizeof(string),"INTELRP/Accounts/%s.ini",CarInfo[vehid][cOwner]);
                            new totalcash = dini_Int(string,"Money") + GetVehiclePrice(vehid);
                            dini_IntSet(string,"Money",totalcash);

                            if(dini_Int(string,"CarKey") == vehid)
                            {
                                dini_IntSet(string,"CarKey",9999);
                            }
                            else if(dini_Int(string,"CarKey2") == vehid)
                            {
                                dini_IntSet(string,"CarKey2",9999);
                            }
                        }
                    }
                }
                PlayerPlaySound(playerid, 1052, 0.0, 0.0, 0.0);
                RemovePlayerFromVehicle(playerid);
                TogglePlayerControllable(playerid, 1);
                DestroyVehicle(vehid);
                format(string, sizeof(string),"INTELRP/Vehicles/%d.ini",vehid);
                fremove(string);
                return 1;
            }
            else
            {
                SendClientMessage(playerid, COLOR_GREY, "INTEL:Not authorized.");
                return 1;
            }
        }
        return 1;
    }
I was thinking to do something like:

When a player sells his vehicle,i will Dini_IntSet all the accounts.
pawn Код:
format(file,sizeo(file),"INTELRP/Accounts/%s.ini");
dini_IntSet(file,"CarKey",dini_Int(file,"CarKey")-1);
or something like this.But i guess it will be really buggy
Reply
#3

Quote:
Originally Posted by ******
Посмотреть сообщение
Ahh, you're complaining about after a restart - that's different. In that case why are you storing the ID in the first place? As you've seen IDs are meaningless over server restarts. Just store the data on the vehicle such as model, colour etc and recreate the vehicle every mode start, saving the returned ID in a global for that run only.
Ohh,facepalm.I didn't even think about that .
So this would be ok?

Command /buyvehicle
pawn Код:
/* PS: every vehicle has a file [1.ini;2.ini;3.ini...].*/


new veh;
for(new h = 1; h < sizeof(CarInfo); h++)//This will count the last vehicle created
{
    if(CarInfo[h][cOwned] == 1)
    {
        veh = h + 1;
        }
}
CarInfo[veh][vID] = veh;
PlayerInfo[playerid][pckey] = veh;
That's what you meant?xD
Reply
#4

Quote:
Originally Posted by WikiSamp
Посмотреть сообщение
Returns The ID of the vehicle created.
...im really embarassed now.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)