Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 2 additions & 33 deletions frontend/docs/scripting/functions/PutPlayerInVehicle.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
```
Expand Down