Problem with /accept car sistem. I give rep ! :D
#1

I have a problem with my /accept car command because a player can own 4 cars maximum and there are 4 slots.
If i sell my infernus (which is on SLOT 4) and the targetid( the person who type /accept car ) has too a car on SLOT 4 it's saying to him "You already own a vehicle." because he already has slot 4 occupied and the other slots not.
So i want to make a switch or helping me make a switch case who puts the car on an empty slot of the targetid when he accepts.
pawn Код:
else if(strcmp(params, "car", true) == 0) {
           
            new giveCarString[128],/*giveCarString2[128],*/x,giveCarPlayerName[2][MAX_PLAYER_NAME];
            if(primesccar[playerid] == 1)
            {
                if(IsPlayerConnectedEx(ofercar[playerid]))
                {
                    if(playerVariables[playerid][pCarModel1] < 1)
                    {
                        if(IsPlayerInRangeOfPlayer(playerid, ofercar[playerid], 5.0))
                        {
                            GetVehiclePos(playerVariables[ofercar[playerid]][pCarID1], playerVariables[playerid][pCarPos1][0], playerVariables[playerid][pCarPos1][1], playerVariables[playerid][pCarPos1][2]);
                            GetVehicleZAngle(playerVariables[ofercar[playerid]][pCarID1], playerVariables[playerid][pCarPos1][3]);

                            playerVariables[playerid][pCarModel1] = playerVariables[ofercar[playerid]][pCarModel1]; // Transfer the car model

                            playerVariables[playerid][pCarColour1][0] = playerVariables[ofercar[playerid]][pCarColour1][0]; // And the colours, and paint job
                            playerVariables[playerid][pCarColour1][1] = playerVariables[ofercar[playerid]][pCarColour1][1];
                            playerVariables[playerid][pCarPaintjob] = playerVariables[ofercar[playerid]][pCarPaintjob];

                            playerVariables[playerid][pCarKM] = playerVariables[ofercar[playerid]][pCarKM];

                            while(x < 13)
                            {
                                playerVariables[playerid][pCarMods1][x] = GetVehicleComponentInSlot(playerVariables[ofercar[playerid]][pCarID1], x); // Mods, too.
                                x++;
                            }
                            x = 0;
                            GetPlayerName(ofercar[playerid], giveCarPlayerName[1], MAX_PLAYER_NAME);
                            GetPlayerName(playerid, giveCarPlayerName[0], MAX_PLAYER_NAME);

                            playerVariables[playerid][pMoney] -= cardiff[playerid];
                            playerVariables[ofercar[playerid]][pMoney] += cardiff[playerid];
                            format(giveCarString, sizeof(giveCarString), "%s has accepted your offer, and is now the owner of this %s.", giveCarPlayerName[0], VehicleNames[playerVariables[playerid][pCarModel1] - 400]);
                            SendClientMessage(ofercar[playerid], COLOR_WHITE, giveCarString);

                            format(giveCarString, sizeof(giveCarString), "You have accepted %s's offer, and are now the owner of this %s.", giveCarPlayerName[1], VehicleNames[playerVariables[playerid][pCarModel1] - 400]);
                            SendClientMessage(playerid, COLOR_WHITE, giveCarString);
                           
                            new wakaname[25];
                            GetPlayerName(playerid,wakaname,25);
                            new str2[128];
                            format(str2,128,"UPDATE `playeraccounts` SET `playerCarModel`='%d' WHERE `playerName`='%s'",playerVariables[playerid][pCarModel1],wakaname);
                            mysql_tquery(handle,str2);
                           
                            new saveQuery[500];
                            format(saveQuery, sizeof(saveQuery), "UPDATE playeraccounts SET playerCarColour1 = '%d', playerCarColour2 = '%d', playerCarPosX = '%f', playerCarPosY = '%f', playerCarPosZ = '%f', playerCarPosZAngle = '%f' WHERE playerName = '%d'",playerVariables[playerid][pCarColour1][0],playerVariables[playerid][pCarColour1][1],
                            playerVariables[playerid][pCarPos1][0],playerVariables[playerid][pCarPos1][1],playerVariables[playerid][pCarPos1][2],playerVariables[playerid][pCarPos1][3], wakaname);
                            mysql_tquery(handle,saveQuery);

                            DestroyPlayerVehicle(ofercar[playerid]);
                            SpawnPlayerVehicle(playerid);
                            ofercar[playerid] = -1;
                            cardiff[playerid] = 0;
                            primesccar[playerid] = 0;
                           
                        }
                        else SendClientMessage(playerid, COLOR_GREY, "You're too far away.");
                    }
                    else SendClientMessage(playerid, COLOR_GREY, "You already own a vehicle.");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "The person offering the vehicle has disconnected.");
                }
            }
            else if(primesccar[playerid] == 2)
            {
                if(IsPlayerConnectedEx(ofercar[playerid]))
                {
                    if(playerVariables[playerid][pCarModel2] < 1)
                    {
                        if(IsPlayerInRangeOfPlayer(playerid, ofercar[playerid], 5.0))
                        {
                            GetVehiclePos(playerVariables[ofercar[playerid]][pCarID2], playerVariables[playerid][pCarPos2][0], playerVariables[playerid][pCarPos2][1], playerVariables[playerid][pCarPos2][2]);
                            GetVehicleZAngle(playerVariables[ofercar[playerid]][pCarID1], playerVariables[playerid][pCarPos2][3]);

                            playerVariables[playerid][pCarModel2] = playerVariables[ofercar[playerid]][pCarModel2]; // Transfer the car model

                            playerVariables[playerid][pCarColour2][0] = playerVariables[ofercar[playerid]][pCarColour2][0]; // And the colours, and paint job
                            playerVariables[playerid][pCarColour2][1] = playerVariables[ofercar[playerid]][pCarColour2][1];
                            playerVariables[playerid][pCarPaintjob2] = playerVariables[ofercar[playerid]][pCarPaintjob2];

                            playerVariables[playerid][pCarKM2] = playerVariables[ofercar[playerid]][pCarKM2];

                            while(x < 13)
                            {
                                playerVariables[playerid][pCarMods2][x] = GetVehicleComponentInSlot(playerVariables[ofercar[playerid]][pCarID2], x); // Mods, too.
                                x++;
                            }
                            x = 0;
                            playerVariables[playerid][pMoney] -= cardiff[playerid];
                            playerVariables[ofercar[playerid]][pMoney] += cardiff[playerid];                           
                            GetPlayerName(ofercar[playerid], giveCarPlayerName[1], MAX_PLAYER_NAME);
                            GetPlayerName(playerid, giveCarPlayerName[0], MAX_PLAYER_NAME);

                            format(giveCarString, sizeof(giveCarString), "%s has accepted your offer, and is now the owner of this %s.", giveCarPlayerName[0], VehicleNames[playerVariables[playerid][pCarModel2] - 400]);
                            SendClientMessage(ofercar[playerid], COLOR_WHITE, giveCarString);

                            format(giveCarString, sizeof(giveCarString), "You have accepted %s's offer, and are now the owner of this %s.", giveCarPlayerName[1], VehicleNames[playerVariables[playerid][pCarModel2] - 400]);
                            SendClientMessage(playerid, COLOR_WHITE, giveCarString);

                            new wakaname[25];
                            GetPlayerName(playerid,wakaname,25);
                            new str2[128];
                            format(str2,128,"UPDATE `playeraccounts` SET `playerCarModel2`='%d' WHERE `playerName`='%s'",playerVariables[playerid][pCarModel2],wakaname);
                            mysql_tquery(handle,str2);

                            new saveQuery[500];
                            format(saveQuery, sizeof(saveQuery), "UPDATE playeraccounts SET playerCarColour21 = '%d', playerCarColour22 = '%d', playerCarPosX2 = '%f', playerCarPosY2 = '%f', playerCarPosZ2 = '%f', playerCarPosZAngle2 = '%f' WHERE playerID = '%d'",playerVariables[playerid][pCarColour2][0],playerVariables[playerid][pCarColour2][1],
                            playerVariables[playerid][pCarPos2][0],playerVariables[playerid][pCarPos2][1],playerVariables[playerid][pCarPos2][2],playerVariables[playerid][pCarPos2][3], playerVariables[playerid][pInternalID]);
                            mysql_tquery(handle,saveQuery);
                            format(saveQuery, sizeof(saveQuery), "UPDATE playeraccounts SET playerCarPaintJob2 = '%d' WHERE playerID = '%d'",playerVariables[playerid][pCarPaintjob2],playerVariables[playerid][pInternalID]);
                            mysql_tquery(handle,saveQuery);

                            format(saveQuery, sizeof(saveQuery), "UPDATE playeraccounts SET playerCarKM2 = '%d' WHERE playerID = '%d'",playerVariables[playerid][pCarKM2],playerVariables[playerid][pInternalID]);
                            mysql_tquery(handle,saveQuery);
                           
                            DestroyPlayerVehicle2(ofercar[playerid]);
                            SpawnPlayerVehicle(playerid);
                            ofercar[playerid] = -1;
                            cardiff[playerid] = 0;
                            primesccar[playerid] = 0;
                           
                            //format(giveCarString2, sizeof(giveCarString2), "* %s has sold his %s to %s for %d$.", giveCarPlayerName[1], VehicleNames[playerVariables[playerid][pCarModel2]],giveCarPlayerName[0],cardiff[playerid]);
                            //submitToAdmins(giveCarString2,COLOR_RED);
                        }
                        else SendClientMessage(playerid, COLOR_GREY, "You're too far away.");
                    }
                    else SendClientMessage(playerid, COLOR_GREY, "You already own a vehicle.");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "The person offering the vehicle has disconnected.");
                }
            }
            else if(primesccar[playerid] == 3)
            {
                if(IsPlayerConnectedEx(ofercar[playerid]))
                {
                    if(playerVariables[playerid][pCarModel3] < 1)
                    {
                        if(IsPlayerInRangeOfPlayer(playerid, ofercar[playerid], 5.0))
                        {
                                GetVehiclePos(playerVariables[ofercar[playerid]][pCarID3], playerVariables[playerid][pCarPos3][0], playerVariables[playerid][pCarPos3][1], playerVariables[playerid][pCarPos3][2]);
                                GetVehicleZAngle(playerVariables[ofercar[playerid]][pCarID3], playerVariables[playerid][pCarPos3][3]);

                                playerVariables[playerid][pCarModel3] = playerVariables[ofercar[playerid]][pCarModel3]; // Transfer the car model

                                playerVariables[playerid][pCarColour3][0] = playerVariables[ofercar[playerid]][pCarColour3][0]; // And the colours, and paint job
                                playerVariables[playerid][pCarColour3][1] = playerVariables[ofercar[playerid]][pCarColour3][1];
                                playerVariables[playerid][pCarPaintjob3] = playerVariables[ofercar[playerid]][pCarPaintjob3];

                                playerVariables[playerid][pCarKM3] = playerVariables[ofercar[playerid]][pCarKM3];

                                while(x < 13)
                                {
                                    playerVariables[playerid][pCarMods3][x] = GetVehicleComponentInSlot(playerVariables[ofercar[playerid]][pCarID3], x); // Mods, too.
                                    x++;
                                }
                                x = 0;
                                GetPlayerName(ofercar[playerid], giveCarPlayerName[1], MAX_PLAYER_NAME);
                                GetPlayerName(playerid, giveCarPlayerName[0], MAX_PLAYER_NAME);
                                playerVariables[playerid][pMoney] -= cardiff[playerid];
                                playerVariables[ofercar[playerid]][pMoney] += cardiff[playerid];
                                format(giveCarString, sizeof(giveCarString), "%s has accepted your offer, and is now the owner of this %s.", giveCarPlayerName[0], VehicleNames[playerVariables[playerid][pCarModel3] - 400]);
                                SendClientMessage(ofercar[playerid], COLOR_WHITE, giveCarString);

                                format(giveCarString, sizeof(giveCarString), "You have accepted %s's offer, and are now the owner of this %s.", giveCarPlayerName[1], VehicleNames[playerVariables[playerid][pCarModel3] - 400]);
                                SendClientMessage(playerid, COLOR_WHITE, giveCarString);

                                new wakaname[25];
                                GetPlayerName(playerid,wakaname,25);
                                new str2[128];
                                format(str2,128,"UPDATE `playeraccounts` SET `playerCarModel3`='%d' WHERE `playerName`='%s'",playerVariables[playerid][pCarModel3],wakaname);
                                mysql_tquery(handle,str2);
                           
                                new saveQuery[500];
                                format(saveQuery, sizeof(saveQuery), "UPDATE playeraccounts SET playerCarColor31 = '%d', playerCarColour32 = '%d', playerCarPosX3 = '%f', playerCarPosY3 = '%f', playerCarPosZ3 = '%f', playerCarPosZAngle3 = '%f' WHERE playerName = '%d'",playerVariables[playerid][pCarColour3][0],playerVariables[playerid][pCarColour3][1],
                                playerVariables[playerid][pCarPos3][0],playerVariables[playerid][pCarPos3][1],playerVariables[playerid][pCarPos3][2],playerVariables[playerid][pCarPos3][3], wakaname);
                                mysql_tquery(handle,saveQuery);
                           
                                DestroyPlayerVehicle3(ofercar[playerid]);
                                SpawnPlayerVehicle(playerid);
                                ofercar[playerid] = -1;
                                cardiff[playerid] = 0;
                                primesccar[playerid] = 0;
                               
                                //format(giveCarString2, sizeof(giveCarString2), "* %s has sold his %s to %s for %d$.", giveCarPlayerName[1], VehicleNames[playerVariables[playerid][pCarModel3]],giveCarPlayerName[0],cardiff[playerid]);
                                //submitToAdmins(giveCarString2,COLOR_RED);
                        }
                        else SendClientMessage(playerid, COLOR_GREY, "You're too far away.");
                    }
                    else SendClientMessage(playerid, COLOR_GREY, "You already own a vehicle.");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "The person offering the vehicle has disconnected.");
                }
            }  
            else if(primesccar[playerid] == 4)
            {
                if(IsPlayerConnectedEx(ofercar[playerid]))
                {
                    if(playerVariables[playerid][pCarModel4] < 1)
                    {
                        if(IsPlayerInRangeOfPlayer(playerid, ofercar[playerid], 5.0))
                        {
                                GetVehiclePos(playerVariables[ofercar[playerid]][pCarID4], playerVariables[playerid][pCarPos4][0], playerVariables[playerid][pCarPos4][1], playerVariables[playerid][pCarPos4][2]);
                                GetVehicleZAngle(playerVariables[ofercar[playerid]][pCarID4], playerVariables[playerid][pCarPos4][3]);

                                playerVariables[playerid][pCarModel4] = playerVariables[ofercar[playerid]][pCarModel4]; // Transfer the car model

                                playerVariables[playerid][pCarColour4][0] = playerVariables[ofercar[playerid]][pCarColour4][0]; // And the colours, and paint job
                                playerVariables[playerid][pCarColour4][1] = playerVariables[ofercar[playerid]][pCarColour4][1];
                                playerVariables[playerid][pCarPaintjob4] = playerVariables[ofercar[playerid]][pCarPaintjob4];

                                playerVariables[playerid][pCarKM4] = playerVariables[ofercar[playerid]][pCarKM4];

                                while(x < 13)
                                {
                                    playerVariables[playerid][pCarMods4][x] = GetVehicleComponentInSlot(playerVariables[ofercar[playerid]][pCarID4], x); // Mods, too.
                                    x++;
                                }
                                x = 0;
                                playerVariables[playerid][pMoney] -= cardiff[playerid];
                                playerVariables[ofercar[playerid]][pMoney] += cardiff[playerid];                               
                                GetPlayerName(ofercar[playerid], giveCarPlayerName[1], MAX_PLAYER_NAME);
                                GetPlayerName(playerid, giveCarPlayerName[0], MAX_PLAYER_NAME);

                                format(giveCarString, sizeof(giveCarString), "%s has accepted your offer, and is now the owner of this %s.", giveCarPlayerName[0], VehicleNames[playerVariables[playerid][pCarModel4] - 400]);
                                SendClientMessage(ofercar[playerid], COLOR_WHITE, giveCarString);

                                format(giveCarString, sizeof(giveCarString), "You have accepted %s's offer, and are now the owner of this %s.", giveCarPlayerName[1], VehicleNames[playerVariables[playerid][pCarModel4] - 400]);
                                SendClientMessage(playerid, COLOR_WHITE, giveCarString);

                                new wakaname[25];
                                GetPlayerName(playerid,wakaname,25);
                                new str2[128];
                                format(str2,128,"UPDATE `playeraccounts` SET `playerCarModel4`='%d' WHERE `playerName`='%s'",playerVariables[playerid][pCarModel4],wakaname);
                                mysql_tquery(handle,str2);

                                new saveQuery[500];
                                format(saveQuery, sizeof(saveQuery), "UPDATE playeraccounts SET playerCarColor41 = '%d', playerCarColor42 = '%d', playerCarPosX4 = '%f', playerCarPosY4 = '%f', playerCarPosZ4 = '%f', playerCarPosZAngle4 = '%f' WHERE playerName = '%d'",playerVariables[playerid][pCarColour4][0],playerVariables[playerid][pCarColour4][1],
                                playerVariables[playerid][pCarPos4][0],playerVariables[playerid][pCarPos4][1],playerVariables[playerid][pCarPos4][2],playerVariables[playerid][pCarPos4][3], wakaname);
                                mysql_tquery(handle,saveQuery);
                               
                                DestroyPlayerVehicle4(ofercar[playerid]);
                                SpawnPlayerVehicle(playerid);
                                ofercar[playerid] = -1;
                                cardiff[playerid] = 0;
                                primesccar[playerid] = 0;
                               
                                //format(giveCarString2, sizeof(giveCarString2), "* %s has sold his %s to %s for %d$.", giveCarPlayerName[1], VehicleNames[playerVariables[playerid][pCarModel4]],giveCarPlayerName[0],cardiff[playerid]);
                                //submitToAdmins(giveCarString2,COLOR_RED);
                        }
                        else SendClientMessage(playerid, COLOR_GREY, "You're too far away.");
                    }
                    else SendClientMessage(playerid, COLOR_GREY, "You already own a vehicle.");
                }
                else
                {
                    SendClientMessage(playerid, COLOR_GREY, "The person offering the vehicle has disconnected.");
                }  
            }
            else SendClientMessage(playerid, COLOR_GREY, "Nobody has offered you a vehicle.");
        }
I give rep++ who will help me finish this.
Reply
#2

Up!!!
Reply
#3

pawn Код:
new carslot = -1;
for(new i = 0; i<4; i++)
{
    if(carvariable[playerid] == /*No car*/)
        carslot = i;
}
if(carslot == -1) /*No free car slot*/
I don't really have time to read all of that code, but that's a general idea for you.
Reply
#4

My car variabiles are:
playerVariables[playerid][pCarModel1]
playerVariables[playerid][pCarModel2]
playerVariables[playerid][pCarModel3]
playerVariables[playerid][pCarModel4]
I tried to add your code but i am getting problems.Can you insert your code into my script and post it. Thanks.
Reply
#5

UP!!!
Reply
#6

Up!!
Reply
#7

UPPPP!!!!
Reply
#8

If a vehicle is in slot 4 you don't have to put it in slot 4 again.
Try to check wich slot is free and put it into that.
Reply
#9

Quote:
Originally Posted by buburuzu19
Посмотреть сообщение
I have a problem with my /accept car command because a player can own 4 cars maximum and there are 4 slots.
If i sell my infernus (which is on SLOT 4) and the targetid( the person who type /accept car ) has too a car on SLOT 4 it's saying to him "You already own a vehicle." because he already has slot 4 occupied and the other slots not.
So i want to make a switch or helping me make a switch case who puts the car on an empty slot of the targetid when he accepts.

--Snipped Code--

I give rep++ who will help me finish this.
Alright, there's a problem in your code, that seems apparent by your results that you explain.

Now, [HiC]TheKiller, has explained what you need to read, to get this sorted, yet you're still stuck on a simple fix, where there is none. You need to integrate that check, in the code, when it decides on who is getting the vehicle. then use that found slot, to put the vehicle in.


What your script is doing is it's ONLY checking the same slot for each person, when it does the trade, when it's not doing a check for those empty slots.
Reply
#10

Quote:
Originally Posted by Sew_Sumi
Посмотреть сообщение
Alright, there's a problem in your code, that seems apparent by your results that you explain.

Now, [HiC]TheKiller, has explained what you need to read, to get this sorted, yet you're still stuck on a simple fix, where there is none. You need to integrate that check, in the code, when it decides on who is getting the vehicle. then use that found slot, to put the vehicle in.


What your script is doing is it's ONLY checking the same slot for each person, when it does the trade, when it's not doing a check for those empty slots.
I understand what you have told me , i am stucked at this because i don't know how to integrate the check .. if you could give me an example for car slot 1 i will easly understand.
Reply
#11

Integrate the check into the accept command.

just before where it checks, and says that the slot is full..

if(playerVariables[playerid][pCarModel1] < 1)

Where you have these checks, should be checked by the empty slot checker, and based on that, it should start using the free slot.


With this script, there's nothing "wrong" with it, as it'll work, but the whole command can be done more efficiently. Instead of checking over and over if people are connected (Which they need to be to have typed the command), and rather than having an individual section for each car slot.

You just gotta read more of the script, and make it more efficient later on. If you keep making sloppy code, later on, it'll be harder and harder to read it to find the problems.
Reply
#12

Ok i will try and come back with teply. REP++ AND THANKS.
Reply
#13

Still can't fix it , i tried to integrate the check but i failed it's not working , can somebody help me a little bit by making a model or what to add and where..
Reply
#14

Switch out these lines
Код:
if(playerVariables[playerid][pCarModel1] < 1)
                    {
and integrate the check around there. If it will check for the free slots, it won't need that return if it checks. It will select the slot needed and create a new variable for the player accepting, for the free slot, as long as you use the variable in the correct spaces.

Now as for your over all coding... I'm sure it can be condensed, and more efficiently done.

Rather than having a full section for each slot, you should be able to work towards doing it in a shorter space, less lines, and with more functionality.
Reply
#15

I understand what you tried to told me but that's what i tried to do but i failed because i don't know how to integrate a check with some variables ( i tried to replace that variables but ... ) , if i would know i could paste them and finish this job.
| need someone to integrate the check for me to help me ...
Reply
#16

He gave you the check, and it made variables, I told you where to put it...


It's not as if we want to simply paste you the code so you can copy and paste... You should at least want to make effort and learn how to write it.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)