diff --git a/docs/scripting/callbacks/OnPlayerRequestDownload.md b/docs/scripting/callbacks/OnPlayerRequestDownload.md index 699f3b45c..76b407830 100644 --- a/docs/scripting/callbacks/OnPlayerRequestDownload.md +++ b/docs/scripting/callbacks/OnPlayerRequestDownload.md @@ -10,11 +10,11 @@ tags: ["player"] This callback is called when a player request for custom model downloads. -| Name | Description | -| -------- | -------------------------------------------------------- | -| playerid | The ID of the player that request custom model download. | -| type | The type of the request (see below). | -| crc | The CRC checksum of custom model file. | +| Name | Description | +|-----------------------|------------------------------------------------------------| +| playerid | The ID of the player that request custom model download. | +| DOWNLOAD_REQUEST:type | The [type](../resources/download-requests) of the request. | +| crc | The CRC checksum of custom model file. | ## Returns @@ -25,29 +25,36 @@ This callback is called when a player request for custom model downloads. ## Examples ```c -#define DOWNLOAD_REQUEST_EMPTY (0) -#define DOWNLOAD_REQUEST_MODEL_FILE (1) -#define DOWNLOAD_REQUEST_TEXTURE_FILE (2) -new baseurl[] = "https://files.sa-mp.com/server"; +#define DOWNLOAD_REQUEST_EMPTY (DOWNLOAD_REQUEST:0) +#define DOWNLOAD_REQUEST_MODEL_FILE (DOWNLOAD_REQUEST:1) +#define DOWNLOAD_REQUEST_TEXTURE_FILE (DOWNLOAD_REQUEST:2) -public OnPlayerRequestDownload(playerid, type, crc) +new baseUrl[] = "https://assets.open.mp"; + +public OnPlayerRequestDownload(playerid, DOWNLOAD_REQUEST:type, crc) { - new fullurl[256+1]; - new dlfilename[64+1]; - new foundfilename=0; + if (!IsPlayerConnected(playerid)) + { + return 0; + } - if (!IsPlayerConnected(playerid)) return 0; + new fullUrl[256 + 1]; + new dlFileName[64 + 1]; + new foundFileName = 0; - if (type == DOWNLOAD_REQUEST_TEXTURE_FILE) { - foundfilename = FindTextureFileNameFromCRC(crc,dlfilename,64); + if (type == DOWNLOAD_REQUEST_TEXTURE_FILE) + { + foundFileName = FindTextureFileNameFromCRC(crc, dlFileName, 64); } - else if (type == DOWNLOAD_REQUEST_MODEL_FILE) { - foundfilename = FindModelFileNameFromCRC(crc,dlfilename,64); + else if (type == DOWNLOAD_REQUEST_MODEL_FILE) + { + foundFileName = FindModelFileNameFromCRC(crc, dlFileName, 64); } - if (foundfilename) { - format(fullurl,256,"%s/%s",baseurl,dlfilename); - RedirectDownload(playerid,fullurl); + if (foundFileName) + { + format(fullUrl, sizeof(fullUrl), "%s/%s", baseUrl, dlFileName); + RedirectDownload(playerid, fullUrl); } return 0; @@ -59,3 +66,7 @@ public OnPlayerRequestDownload(playerid, type, crc) The following callbacks might be useful, as they're related to this callback in one way or another. - [OnPlayerFinishedDownloading](OnPlayerFinishedDownloading): This callback is called when a player finishes downloading custom models. + +## Related Resources + +- [Download Request Types](../resources/download-requests)