SA-MP Forums Archive
Multiple owned cars identification problem - 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: Multiple owned cars identification problem (/showthread.php?tid=429376)



Multiple owned cars identification problem - dusk - 09.04.2013

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.


Re: Multiple owned cars identification problem - dusk - 10.04.2013

Bump


Re: Multiple owned cars identification problem - Coltmaster - 10.04.2013

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.


Re: Multiple owned cars identification problem - dusk - 10.04.2013

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


Re: Multiple owned cars identification problem - dusk - 10.04.2013

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


Re: Multiple owned cars identification problem - iJumbo - 10.04.2013

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


Re: Multiple owned cars identification problem - Faisal_khan - 10.04.2013

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


Re: Multiple owned cars identification problem - dusk - 10.04.2013

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


Re: Multiple owned cars identification problem - Faisal_khan - 10.04.2013

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


Re: Multiple owned cars identification problem - Riddick94 - 10.04.2013

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.


Re: Multiple owned cars identification problem - dusk - 26.04.2013

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?


Re: Multiple owned cars identification problem - dusk - 29.04.2013

Bump


Re: Multiple owned cars identification problem - dusk - 01.05.2013

bump


Re: Multiple owned cars identification problem - dusk - 03.05.2013

Bump


Re: Multiple owned cars identification problem - Scenario - 03.05.2013

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


Re: Multiple owned cars identification problem - dusk - 05.05.2013

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 ..?


Re: Multiple owned cars identification problem - dusk - 07.05.2013

bump


Re: Multiple owned cars identification problem - dusk - 08.05.2013

bump...i really need a new way to bump my threads..


Re: Multiple owned cars identification problem - dusk - 10.05.2013

pmub