• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Pawn] [Help] - Park vehicle cmd issues
#1
Information 
Hello all, myself and a group of friends are working on a server and have noticed an issue with our park vehicle command.



The command only parks the car in Virtual World 0, we wanted to do dynamic garages, but when we /park in a garage with another VW other then 0 the car disappears and is parked in the VW 0 instead of the VW the garage is set too.



I've attached the command below if anyone can point out the issue, this is the command we had when we first started the project, I myself am still getting the hang of pawn so not sure what the problem is that's causing it to only park in VW 0.



Code:
CMD:park(playerid, params[])

{

if(PlayerInfo[playerid][pAdmin] >= 1 || PlayerInfo[playerid][pHelper] >= 2 || PlayerInfo[playerid][pDonateRank] == 5)

{

new playerpark;

if(!sscanf(params, "i", playerpark))

{

for(new d = 0; d < MAX_PLAYERVEHICLES; d)

{

if(IsPlayerInVehicle(playerid, PlayerVehicleInfo[playerpark][d][pvId]))

{

new Float:x, Float:y, Float:z, Float:angle, Float:health;

GetVehicleHealth(PlayerVehicleInfo[playerpark][d][pvId], health);

if(PlayerInfo[playerpark][pLockCar] == GetPlayerVehicleID(playerid)) PlayerInfo[playerpark][pLockCar] = INVALID_VEHICLE_ID;

GetVehiclePos(PlayerVehicleInfo[playerpark][d][pvId], x, y, z);

GetVehicleZAngle(PlayerVehicleInfo[playerpark][d][pvId], angle);

SurfingCheck(GetPlayerVehicleID(playerid));

UpdatePlayerVehicleParkPosition(playerpark, d, x, y, z, angle, health);

PutPlayerInVehicle(playerid, PlayerVehicleInfo[playerpark][d][pvId], 0);

SetPlayerArmedWeapon(playerid, 0);

new string[30  (MAX_PLAYER_NAME * 2)];

format(string, sizeof(string), "* %s has parked %s's vehicle for them.", GetPlayerNameEx(playerid), GetPlayerNameEx(playerpark));

new szMessage[128];

format(szMessage, sizeof(szMessage), "AdmCmd: %s has parked %s's vehicle for them", GetPlayerNameEx(playerid), GetPlayerNameEx(playerpark));

ABroadCast(COLOR_LIGHTRED,szMessage, 2);

ProxDetector(30.0, playerid, string, COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE,COLOR_PURPLE);

return 1;

}

}

SendClientMessageEx(playerid, COLOR_GRAD1, "You need to be in a player owned vehicle");

}

else

SendClientMessageEx(playerid, COLOR_WHITE, "USAGE: /park <playerid>");

}

else

SendClientMessageEx(playerid, COLOR_GRAD1, "Park is now an moderator command to combat abuse. /requesthelp or /am to an admin to get a car parked at your house.");

return 1;

}
  Reply
#2
Can you paste the code for the function "UpdatePlayerVehicleParkPosition"?
  Reply
#3
(2021-01-20, 01:49 AM)Behemoth Wrote: Can you paste the code for the function "UpdatePlayerVehicleParkPosition"?

Sure thing.

Code:
stock UpdatePlayerVehicleParkPosition(playerid, playervehicleid, Float:newx, Float:newy, Float:newz, Float:newangle, Float:health)

{

? ? new playername[MAX_PLAYER_NAME];

GetPlayerName(playerid, playername, sizeof(playername));

if(PlayerVehicleInfo[playerid][playervehicleid][pvId] != INVALID_PLAYER_VEHICLE_ID)

{

if(!isnull(PlayerVehicleInfo[playerid][playervehicleid][pvPlate])) {

SetVehicleNumberPlate(playervehicleid, PlayerVehicleInfo[playerid][playervehicleid][pvPlate]);

}

new Float:oldx, Float:oldy, Float:oldz, Float: oldfuel;

oldx = PlayerVehicleInfo[playerid][playervehicleid][pvPosX];

oldy = PlayerVehicleInfo[playerid][playervehicleid][pvPosY];

oldz = PlayerVehicleInfo[playerid][playervehicleid][pvPosZ];

if(oldx == newx && oldy == newy && oldz == newz) return 0;

PlayerVehicleInfo[playerid][playervehicleid][pvPosX] = newx;

PlayerVehicleInfo[playerid][playervehicleid][pvPosY] = newy;

PlayerVehicleInfo[playerid][playervehicleid][pvPosZ] = newz;

PlayerVehicleInfo[playerid][playervehicleid][pvPosAngle] = newangle;

oldfuel = Gas[PlayerVehicleInfo[playerid][playervehicleid][pvId]];

Gas[PlayerVehicleInfo[playerid][playervehicleid][pvId]] = 100.0;

for(new c=0; c<12; c) {

RemoveVehicleComponent(playervehicleid, c);

}

//UpdatePlayerVehicleMods(playerid, playervehicleid);

DestroyVehicle(PlayerVehicleInfo[playerid][playervehicleid][pvId]);

new carcreated = AddStaticVehicleEx(PlayerVehicleInfo[playerid][playervehicleid][pvModelId], PlayerVehicleInfo[playerid][playervehicleid][pvPosX], PlayerVehicleInfo[playerid][playervehicleid][pvPosY], PlayerVehicleInfo[playerid][playervehicleid][pvPosZ],

PlayerVehicleInfo[playerid][playervehicleid][pvPosAngle],PlayerVehicleInfo[playerid][playervehicleid][pvColor1], PlayerVehicleInfo[playerid][playervehicleid][pvColor2], -1);

? ? ? ? PlayerVehicleInfo[playerid][playervehicleid][pvId] = carcreated;

? ? ? ? Gas[carcreated] = oldfuel;

? ? ? ? // SetVehicleNumberPlate(carcreated, PlayerVehicleInfo[playerid][playervehicleid][pvNumberPlate]);

? ? ? ? SetVehicleHealth(carcreated, health);

if(PlayerVehicleInfo[playerid][playervehicleid][pvLocked] == 1) LockPlayerVehicle(playerid, PlayerVehicleInfo[playerid][playervehicleid][pvId], PlayerVehicleInfo[playerid][playervehicleid][pvLock]);

? ? ? ? //LoadPlayerVehicleMods(playerid, playervehicleid);

? ? ? ? return 1;

}

return 0;

}
  Reply
#4
You will need to add something for the VW in the enumerator for PlayerVehicleInfo (something like pvVW). In UpdatePlayerVehicleParkPosition you will then need to adjust it accordingly, by adding a VW parameter to it.

Code:
UpdatePlayerVehicleParkPosition(playerid, playervehicleid, Float:newx, Float:newy, Float:newz, Float:newangle, Float:health, vw)? // notice I've added VW on the end

Furthermore, I find the old coords for the vehicle pretty pointless as even the smallest movement will change it, so I'd remove that;
Code:
Float:oldx, Float:oldy, Float:oldz
oldx = PlayerVehicleInfo[playerid][playervehicleid][pvPosX];
oldy = PlayerVehicleInfo[playerid][playervehicleid][pvPosY];
oldz = PlayerVehicleInfo[playerid][playervehicleid][pvPosZ];

if(oldx == newx && oldy == newy && oldz == newz) return 0;

and keep just oldfuel (it should look like new Float:oldfuel);.

Moving on...

You will now want to save the new field in the enum PlayerVehicleInformation, to do this, you should set it with "GetPlayerVirtualWorld"
Something like;
Code:
PlayerVehicleInfo[playerid][playervehicleid][pvVW] = GetPlayerVirtualWorld(playerid);

..- should work fine.

(I should note, none of this is tested as I don't have all your files, but it should give you the general idea)

and that's basically it for logging the VW, for a start anyway. You'll need to update your enum so it saves to the database (ini, sql etc) by adding a field for VW. You'll also need to find where the vehicle spawns and make sure that the VW is called and set for that too.

I appreciate this isn't a step by step guide, but it should point you in the right direction.
  Reply
#5
(2021-01-20, 03:06 AM)Behemoth Wrote: You will need to add something for the VW in the enumerator for PlayerVehicleInfo (something like pvVW). In UpdatePlayerVehicleParkPosition you will then need to adjust it accordingly, by adding a VW parameter to it.



Code:
UpdatePlayerVehicleParkPosition(playerid, playervehicleid, Float:newx, Float:newy, Float:newz, Float:newangle, Float:health, vw)? // notice I've added VW on the end



Furthermore, I find the old coords for the vehicle pretty pointless as even the smallest movement will change it, so I'd remove that;

Code:
Float:oldx, Float:oldy, Float:oldz

oldx = PlayerVehicleInfo[playerid][playervehicleid][pvPosX];

oldy = PlayerVehicleInfo[playerid][playervehicleid][pvPosY];

oldz = PlayerVehicleInfo[playerid][playervehicleid][pvPosZ];



if(oldx == newx && oldy == newy && oldz == newz) return 0;



and keep just oldfuel (it should look like new Float:oldfuel);.



Moving on...



You will now want to save the new field in the enum PlayerVehicleInformation, to do this, you should set it with "GetPlayerVirtualWorld"

Something like;

Code:
PlayerVehicleInfo[playerid][playervehicleid][pvVW] = GetPlayerVirtualWorld(playerid);



..- should work fine.



(I should note, none of this is tested as I don't have all your files, but it should give you the general idea)



and that's basically it for logging the VW, for a start anyway. You'll need to update your enum so it saves to the database (ini, sql etc) by adding a field for VW. You'll also need to find where the vehicle spawns and make sure that the VW is called and set for that too.



I appreciate this isn't a step by step guide, but it should point you in the right direction.



Thank you for the help, I'll take a look at getting it set up tonight when the rest of the team is on.
  Reply


Forum Jump: