Skip to content

Commit

Permalink
Update OnPlayerRequestDownload.md
Browse files Browse the repository at this point in the history
  • Loading branch information
adib-yg committed Feb 3, 2024
1 parent 296ced2 commit 3907a7e
Showing 1 changed file with 32 additions and 21 deletions.
53 changes: 32 additions & 21 deletions docs/scripting/callbacks/OnPlayerRequestDownload.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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;
Expand All @@ -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)

0 comments on commit 3907a7e

Please sign in to comment.