diff --git a/frontend/docs/scripting/functions/PutPlayerInVehicle.md b/frontend/docs/scripting/functions/PutPlayerInVehicle.md index 735e199e663..1e307d92ed2 100644 --- a/frontend/docs/scripting/functions/PutPlayerInVehicle.md +++ b/frontend/docs/scripting/functions/PutPlayerInVehicle.md @@ -24,40 +24,9 @@ Puts a player in a vehicle. ## Examples ```c -// Global array to track which vehicle belongs to each player. -// INVALID_VEHICLE_ID is used as a placeholder for players without a vehicle. -static s_PlayerVehicle[MAX_PLAYERS] = { INVALID_VEHICLE_ID, ... }; - -public OnPlayerSpawn(playerid) -{ - // Check if the player already has a valid vehicle. - if (!IsValidVehicle(s_PlayerVehicle[playerid])) - { - // If not, create a new vehicle for the player and store its ID. - s_PlayerVehicle[playerid] = CreateVehicle(411, 0.0, 0.0, 3.5, 0.0, -1, -1, -1); - } - - // Mark that the player should be placed in their vehicle once it is fully loaded. - // This avoids issues where the vehicle might not yet be loaded on the client's side. - SetPVarInt(playerid, "PutPlayerInVehicle", 1); - - return 1; -} - -public OnVehicleStreamIn(vehicleid, forplayerid) +public OnPlayerEnterVehicle(playerid, vehicleid, ispassanger) { - // This callback is triggered when a vehicle streams in for the player (i.e. when it is loaded into memory). - // Check if the streamed-in vehicle is the player's and if they need to be placed in it. - if (vehicleid == s_PlayerVehicle[forplayerid] && GetPVarInt(forplayerid, "PutPlayerInVehicle")) - { - // Put the player into the vehicle. - PutPlayerInVehicle(forplayerid, vehicleid, 0); - - // Clear the marker to prevent repeatedly putting the player into the vehicle - // (e.g., if the player leaves the vehicle and it streams in again later). - DeletePVar(forplayerid, "PutPlayerInVehicle"); - } - + PutPlayerInVehicle(playerid, vehicleid, 0); return 1; } diff --git a/frontend/i18n/fa/docusaurus-plugin-content-docs/current/scripting/functions/PutPlayerInVehicle.md b/frontend/i18n/fa/docusaurus-plugin-content-docs/current/scripting/functions/PutPlayerInVehicle.md index 15ccb049b07..823ad68a297 100644 --- a/frontend/i18n/fa/docusaurus-plugin-content-docs/current/scripting/functions/PutPlayerInVehicle.md +++ b/frontend/i18n/fa/docusaurus-plugin-content-docs/current/scripting/functions/PutPlayerInVehicle.md @@ -24,40 +24,9 @@ tags: ["player", "vehicle"] ## مثال‌ها ```c -// Global array baraye radgirigiye inke kodum vehicle motealeq be har player hast. -// INVALID_VEHICLE_ID baraye placeholder playerhayi ke vehicle nadarand estefade mishe. -static s_PlayerVehicle[MAX_PLAYERS] = { INVALID_VEHICLE_ID, ... }; - -public OnPlayerSpawn(playerid) -{ - // Check mikonim age player ghablan vehicle dashteh ya na. - if (!IsValidVehicle(s_PlayerVehicle[playerid])) - { - // Age nadareh, ye vehicle jadid barash misazim va ID esh ro zakhire mikonim. - s_PlayerVehicle[playerid] = CreateVehicle(411, 0.0, 0.0, 3.5, 0.0, -1, -1, -1); - } - - // Moshakhas mikonim ke player bayad dar vehicle gharar begireh vaghti ke kamel load shod. - // In az moshkelat jologirigiri mikone ke vehicle hanuz dar samte client load nashode bashe. - SetPVarInt(playerid, "PutPlayerInVehicle", 1); - - return 1; -} - -public OnVehicleStreamIn(vehicleid, forplayerid) +public OnPlayerEnterVehicle(playerid, vehicleid, ispassanger) { - // In callback vaghti ejra mishe ke ye vehicle baraye player stream in mishe (yaani dar hafeze load mishe). - // Check mikonim age vehicle ke stream in shode motealeq be hamun player bashe va lazem bashe dar un gharar begire. - if (vehicleid == s_PlayerVehicle[forplayerid] && GetPVarInt(forplayerid, "PutPlayerInVehicle")) - { - // Player ro dar vehicle gharar midim. - PutPlayerInVehicle(forplayerid, vehicleid, 0); - - // Marker ro pak mikonim ta az tekrar gharar dadan player dar vehicle - // jologirigiri konim (meslan age player az vehicle biyad birun va dobre stream in beshe). - DeletePVar(forplayerid, "PutPlayerInVehicle"); - } - + PutPlayerInVehicle(playerid, vehicleid, 0); return 1; } ```