How to Check if a Player Owns a Certain Vehicle -
Ox1gEN - 15.12.2014
Welp, I have tried it myself and I couldn't figure out a solution to the problem, I tried to solve it by myself but I just don't know how.
The code is clearly not working since I am getting run time error 4 (Array index out of bounds).
Code:
pawn Код:
YCMD:v_park(playerid, params[], help) {
new query[500];
if(IsPlayerInAnyVehicle(playerid)) {
if(PR[playerid][VehiclesOwned] == 0) return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] You don't even have a vehicle yet!");
else {
new vehicleid = GetPlayerVehicleID(playerid);
if(PR[vehicleid][Name] == PR[playerid][Name]) {
if(PR[vehicleid][UserID] == PR[playerid][UserID]) {
new Float:x, Float:y, Float:z, Float:angle;
GetVehicleZAngle(vehicleid, angle);
GetVehiclePos(vehicleid, x, y, z);
x = PR[playerid][parkX];
y = PR[playerid][parkY];
z = PR[playerid][parkZ];
angle = PR[playerid][Angle];
mysql_format(dbHandle, query, sizeof(query), "UPDATE `playerrelated` SET `parkX` = %f, `parkY` = %f, `parkZ` = %f, `Angle` = %f WHERE `Name` = '%s'", x, y, z, angle, GetName(playerid));
mysql_tquery(dbHandle, query);
DestroyVehicle(vehicleid);
} else {
return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] This isn't your vehicle! Therefore you can not park it!");
}
}
else {
return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] This isn't your vehicle! Therefore you can not park it!");
}
}
} else return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] You are not in any vehicle!");
return 1;
}
I am pretty sure this:
if(PR[vehicleid][Name] == PR[playerid][Name]) {
if(PR[vehicleid][UserID] == PR[playerid][UserID]) {
causes the problem because I am using vehicleid instead of something else.
I used that because I thought that'd be the way of figuering out of that vehicle is owned by a certain player.
Re: How to Check if a Player Owns a Certain Vehicle -
ikey07 - 15.12.2014
These two lines looks like something wrong
if(PR[vehicleid][Name] == PR[playerid][Name]) {
if(PR[vehicleid][UserID] == PR[playerid][UserID])
RP[... is it vehicle or player enum ?
Re: How to Check if a Player Owns a Certain Vehicle -
Mic_H - 16.12.2014
Can you show the enums?
Re: How to Check if a Player Owns a Certain Vehicle -
Quickie - 16.12.2014
add vehicle model collumn to your database
pawn Код:
YCMD:v_park(playerid, params[], help)
{
new query[500];
if(IsPlayerInAnyVehicle(playerid))
{
if(PR[playerid][VehiclesOwned] == 0) return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] You don't even have a vehicle yet!");
new vehicleid = GetPlayerVehicleID(playerid);
if(!strcmp(PR[vehicleid][Name],PR[playerid][Name])&&(PR[vehicleid][UserID]==playerid)) //<<<<<<<<<<<
{
new Float:x, Float:y, Float:z, Float:angle,vehmodel;
GetVehicleZAngle(vehicleid, angle);
GetVehiclePos(vehicleid, x, y, z);
x = PR[playerid][parkX];
y = PR[playerid][parkY];
z = PR[playerid][parkZ];
angle = PR[playerid][Angle];
mysql_format(dbHandle, query, sizeof(query), "UPDATE `playerrelated` SET `parkX` = %f, `parkY` = %f, `parkZ` = %f, `Angle` = %f WHERE `Name` = '%s'", x, y, z, angle, GetName(playerid)); // add collumn to your SQL for vehicle model
mysql_tquery(dbHandle, query);
DestroyVehicle(vehicleid);
//also destroy the PR[vehicleid][UserID] and PR[vehicleid][Name]
}
else
{
return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] This isn't your vehicle! Therefore you can not park it!");
}
}
else return SendClientMessage(playerid, 0xFF0000FF, "[ ! ] You are not in any vehicle!");
return 1;
}
Re: How to Check if a Player Owns a Certain Vehicle -
Mic_H - 16.12.2014
Its better to store/load/delete data of playervehicle using his UniqueID.. i.e., DataBase ID.. Load the ID when he joins.. If you compare it with his name, it may/might cause issues if his name was changed IG and his login name was different etc etc.. Unique wont change, so better..
PHP код:
if(VehInfo[VehID][OwnDBID]==pInfo[playerid][DBID])
{
DoRest
}
else
{
Vehicle: Bro, you dont own me.
}
Re: How to Check if a Player Owns a Certain Vehicle -
Ox1gEN - 16.12.2014
Thanks but I think because of your help I figured out a solution and btw I have everything fetched and stored in a database so I am not worried about that part since it's working fine.
Thanks.
Edit:
Btw if anyone wonders, I just finished v_park and v_get, both work, I guess my solution worked out, but two of you guys above gave me an idea how to work this out.
(I bassicly created a variable in the enum to store the vehicle that is created and just used that wherever.)