Multiple owned cars identification problem
#1

Okay let's get straight to it. I load the info from my DB(no problem here) and then I create a vehicle like this:
pawn Код:
Keys[VehicleKeys[playerid]][PlayerVehiclesSpawned[playerid]+1] = CreateVehicle(VehicleInfo[VehicleKeys[playerid]][model],VehicleInfo[VehicleKeys[playerid]][X],VehicleInfo[VehicleKeys[playerid]][Y],VehicleInfo[VehicleKeys[playerid]][Z],VehicleInfo[VehicleKeys[playerid]][R],VehicleInfo[VehicleKeys[playerid]][CColor1],VehicleInfo[VehicleKeys[playerid]][CColor2],-1);
That works,the car appears.
The problem is in my park function:
pawn Код:
if(!strcmp(tmp,"park",true,4))
    {
        new currentveh;
        if(IsPlayerInAnyVehicle(playerid))
        {
            currentveh = GetPlayerVehicleID(playerid);
            GetPlayerName(playerid,Name,sizeof(Name));
            if(IsPlayerInRangeOfPoint(playerid,5,VehicleInfo[VehicleKeys[playerid]][X],VehicleInfo[VehicleKeys[playerid]][Y],VehicleInfo[VehicleKeys[playerid]][Z]))
            {
                for(new i=0; i<MAX_PLAYER_SPAWNED_VEHICLES; i++)
                {
                    if(currentveh == Keys[VehicleKeys[playerid]][i])
                    {
                        DestroyVehicle(currentveh);
                        PlayerVehiclesSpawned[playerid]--;
                        SendClientMessage(playerid,0x00FF00,"Masina priparkuota");
                    }
                }
            }
        }
    }
And when i test it IG, i spawn 2 cars, and i can only park the last one spawned.

That should loop trough max player spawned vehicles,which is 2. That works I think.
At first i=0. So and that shouldn't be the currentveh,because PlayerVehiclesSpawned[playerid] is by deffault 0 and on spawn it add 1 to it. So the loop does i=1, that SHOULD park the vehicle because on spawn PlayerVehiclesSpawned[playerid] was 1. So what is the problem?

I really hope you understand what I mean.
Reply
#2

Bump
Reply
#3

Alright I'm not an expert here but I think most servers have it so you can only spawn one car at a time, maybe that would be simpler.
Reply
#4

I saw that kind of system in action myself.so it must be possible somehow..
Reply
#5

Other question: or maybe someone knows a way to have multiple cars with the same ID? Or,is it immposible?
Reply
#6

I think not becouse everything should be numerated if you put another veh with the same ID the older will be bugged
Reply
#7

You will have to store each car data in an array.
Reply
#8

could you tell more more? I don't have an idea how to use them in my case
Reply
#9

Use this tutorial to store it https://sampforum.blast.hk/showthread.php?tid=193491
Reply
#10

https://sampwiki.blast.hk/wiki/CreateVehicle

Look:
Quote:

Returns
The vehicle ID of the vehicle created (1 - MAX_VEHICLES).
INVALID_VEHICLE_ID (65535) if vehicle was not created (vehicle limit reached or invalid vehicle model ID passed).

When you create vehicle, you can return it's ID, it's gonna be much simpler then. And try this tutorial from Faisal_khan, which gave you.
Reply
#11

Hey, thanks for answering, but...

My way of trying to do this has changed...although you gave me some great (i thought) ideas.

So my current problem is this:
pawn Code:
stock FindEmptyPlayerSlot(playerid)
{
    for(new i; i<2; i++)
    {
        if(PlayerInfo[playerid][PVehicle][i] == INVALID_VEHICLE_ID)
        {
            return i;
        }
    }
    return -1;
}
This always returns -1.

That array is just PlayerInfo[playerid][PVehicle][2]. So if PlayerInfo[playerid][PVehicle][0] is invalid vehicle id it should just return that 0? shoudn't it?
Reply
#12

Bump
Reply
#13

bump
Reply
#14

Bump
Reply
#15

It should, yes. Use print statements to determine the values of your array. Also, show where you're using the FindEmptyPlayerSlot() function.
Reply
#16

Here
pawn Code:
new veh;
    veh=FindEmptyPlayerSlot(playerid);
    printf("Empty player veh slot: %d",veh);
-1 was printed.

BUT, here
pawn Code:
stock FindEmptyPlayerSlot(playerid)
{
    for(new i; i<2; i++)
    {
        if(PlayerInfo[playerid][PVehicle][i] == INVALID_VEHICLE_ID)
        {
            printf("%d",i);
            return i;
        }
    }
    return -1;
}
0 was printed, so what the ..?
Reply
#17

bump
Reply
#18

bump...i really need a new way to bump my threads..
Reply
#19

pmub
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)