Manipulate data -
bruxo00 - 16.10.2013
Well, I'm trying to create a Roleplay server, and now I'm doing the car dealership.
Method for the server to load the car:
PHP код:
iCarInfo[i][cID] = CreateVehicle(iCarInfo[i][cModel], iCarInfo[i][cX], iCarInfo[i][cY], iCarInfo[i][cZ], iCarInfo[i][cAngle], iCarInfo[i][cCor1], iCarInfo[i][cCor2], 0);
And then programmed for when the player enters the car, if the variable
iPlayerInfo [playerid] [Chave1] key (1,2 or 3) was equal to
iCarInfo [Car] [cID] the player could stay in the car, otherwise would be expelled.
PS: Chave == Key in english
Then,
OnPlayerStateChange
PHP код:
new carro = GetPlayerVehicleID(playerid);
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
new arroz;
arroz = iCarInfo[carro][cID];
if(arroz == iPlayerInfo[playerid][Chave1] || arroz == iPlayerInfo[playerid][Chave2] || arroz == iPlayerInfo[playerid][Chave3] || arroz == iPlayerInfo[playerid][Chave4] || arroz == iPlayerInfo[playerid][ChaveEmp1] || arroz == iPlayerInfo[playerid][ChaveEmp2] || arroz == iPlayerInfo[playerid][ChaveEmp3])
{
SendClientMessage(playerid, -1, "This car is yours.");
}
else
{
RemovePlayerFromVehicle(playerid);
}
}
PS: variable
arroz was created to reduce the "visual" size of the variable.
But it simply did not work.
He said that the car was not mine, and ejectava me.
Then I tried something else. Go to
/dl and change the key for id "real" car. It worked perfectly!
I wanted to handle that "real" id that appears in the / dl. Someone?
OBS:
My load cars function:
pawn Код:
public CarregarCarros()
{
new ficheiro[64];
for(new i = 0; i < MAX_CARROS; i++)
{
format(ficheiro, sizeof(ficheiro), "iRP/Carros/%d.ini", i);
if(!DOF2_FileExists(ficheiro))
{
if(i == 0) continue;
DOF2_CreateFile(ficheiro);
DOF2_SetInt(ficheiro, "cX", 0);
DOF2_SetInt(ficheiro, "cY", 0);
DOF2_SetInt(ficheiro, "cZ", 0);
DOF2_SetInt(ficheiro, "cAngle", 0);
DOF2_SetInt(ficheiro, "cID", i);
DOF2_SetInt(ficheiro, "cModel", 0);
DOF2_SetInt(ficheiro, "cCor1", 0);
DOF2_SetInt(ficheiro, "cCor2", 0);
DOF2_SetInt(ficheiro, "cChave", i);
DOF2_SaveFile();
}
else
{
iCarInfo[i][cX] = DOF2_GetInt(ficheiro, "cX");
iCarInfo[i][cY] = DOF2_GetInt(ficheiro, "cY");
iCarInfo[i][cZ] = DOF2_GetInt(ficheiro, "cZ");
iCarInfo[i][cAngle] = DOF2_GetInt(ficheiro, "cAngle");
iCarInfo[i][cID] = DOF2_GetInt(ficheiro, "cID");
iCarInfo[i][cModel] = DOF2_GetInt(ficheiro, "cModel");
iCarInfo[i][cCor1] = DOF2_GetInt(ficheiro, "cCor1");
iCarInfo[i][cCor2] = DOF2_GetInt(ficheiro, "cCor2");
iCarInfo[i][cChave] = DOF2_GetInt(ficheiro, "cChave");
if(iCarInfo[i][cX] != 0 && iCarInfo[i][cY] != 0 && iCarInfo[i][cZ] != 0 && iCarInfo[i][cID] != 0)
{
iCarInfo[i][cID] = CreateVehicle(iCarInfo[i][cModel], iCarInfo[i][cX], iCarInfo[i][cY], iCarInfo[i][cZ], iCarInfo[i][cAngle], iCarInfo[i][cCor1], iCarInfo[i][cCor2], 0);
printf("\n Carro n %d carregado com sucesso!\n", i);
}
}
}
printf("\nCarros carregados com sucesso!\n");
}
Thank you everybody!
****** translator sucks
Re: Manipulate data -
park4bmx - 16.10.2013
Don't understand what you mean by "real id" ?
Also how " iCarInfo[carro][cID]; " is assigned, no one knows..
Re: Manipulate data -
bruxo00 - 17.10.2013
Hi. Thanks for the anwser.
I mean the real id that show in the /dl!
And the
iCarInfo[carro][cID] is at top of the post.
Thanks
Re: Manipulate data -
Misiur - 17.10.2013
You have to loop through your iCarInfo to get the right index
pawn Код:
new arroz;
arroz = iCarInfo[carro][cID];
//to
new
arroz = INVALID_VEHICLE_ID;
for(new i = 0; i != sizeof(iCarInfo); ++i) {
if(iCarInfo[i][cID] == carro) {
arroz = carro;
break;
}
}
if(arroz == INVALID_VEHICLE_ID) {
//This indicates that car is not in iCarInfo table
}
Re: Manipulate data -
bruxo00 - 17.10.2013
Hi. Thanks for the anwser.
That didn't work...
I put that like this on my gamemode:
pawn Код:
if(oldstate == PLAYER_STATE_ONFOOT && newstate == PLAYER_STATE_DRIVER)
{
new arroz = INVALID_VEHICLE_ID;
new carro = GetPlayerVehicleID(playerid);
for(new i = 0; i != sizeof(iCarInfo); ++i)
{
if(iCarInfo[i][cID] == carro)
{
arroz = carro;
break;
}
}
//if(arroz == iPlayerInfo[playerid][Chave1] || arroz == iPlayerInfo[playerid][Chave2] || arroz == iPlayerInfo[playerid][Chave3] || arroz == iPlayerInfo[playerid][Chave4] || arroz == iPlayerInfo[playerid][ChaveEmp1] || arroz == iPlayerInfo[playerid][ChaveEmp2] || arroz == iPlayerInfo[playerid][ChaveEmp3])
if(arroz == INVALID_VEHICLE_ID)
{
SendClientMessage(playerid, -1, "This is your car");
}
else
{
RemovePlayerFromVehicle(playerid);
}
}
Thanks!
Re: Manipulate data -
Konstantinos - 17.10.2013
It should be the opposite.
pawn Код:
if(arroz == INVALID_VEHICLE_ID)
{
RemovePlayerFromVehicle(playerid);
}
else
{
SendClientMessage(playerid, -1, "This is your car");
}
It's supposed you assign to arroz INVALID_VEHICLE_ID.
If the vehicleid matches with the vehicle's ID you entered, then it will change and it will no longer be INVALID_VEHICLE_ID.
Re: Manipulate data -
bruxo00 - 17.10.2013
Thanks you all!
I forgot to test that
But now I can get in the car, even if not the key.
Thanks!
Re: Manipulate data -
bruxo00 - 20.10.2013
BUMP...
Help me please ;3