• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Server] How do you create a spawn selector?
#1
Question 
I'm rather new to SA-MP scripting, but I'm trying to make a selector for spawnpoints (like the class one).
Does anyone know how? I've had a hard time finding it online.
  Reply
#2
Creating a spawnpoint selector in SA-MP scripting isn't too complex once you understand the basics. Here's a simplified explanation of how you could approach it:

Define Spawnpoints: First, you need to define spawnpoints in your game world. These could be coordinates where players will spawn when they select a particular spawnpoint.

Create a Dialog for Selection: You'll need to create a dialog box that shows the available spawnpoints and allows the player to select one.

Handle Dialog Response: Once the player selects a spawnpoint from the dialog, you'll need to handle that response in your script and set the player's spawnpoint accordingly.

Here's a basic example of how you could implement this:

PHP Code:
// Define your spawnpoints
new Float:spawnPoints[][3] = {
    {x1y1z1}, // coordinates of spawnpoint 1
    {x2y2z2}, // coordinates of spawnpoint 2
    // add more spawnpoints as needed
};

// Dialog ID for the spawnpoint selection dialog
#define DIALOG_SPAWNPOINT 1

// Create a function to show the spawnpoint selection dialog
ShowSpawnpointDialog(playerid) {
    ShowPlayerDialog(playeridDIALOG_SPAWNPOINTDIALOG_STYLE_LIST"Select a Spawnpoint""Select""Cancel", -1);
    // Add spawnpoint options to the dialog
    for (new 0sizeof(spawnPoints); i++) {
        AddDialogComponentString(DIALOG_SPAWNPOINT1"Spawnpoint " + (1));
    }
    // Show the dialog to the player
    SendDialog(playeridDIALOG_SPAWNPOINTDIALOG_STYLE_LIST"Select a Spawnpoint");
}

// Handle dialog response
public OnDialogResponse(playeriddialogidresponselistiteminputtext[]) {
    if (dialogid == DIALOG_SPAWNPOINT && response) {
        // Player selected a spawnpoint
        new spawnpointIndex listitem 1;
        SetPlayerPos(playeridspawnPoints[spawnpointIndex][0], spawnPoints[spawnpointIndex][1], spawnPoints[spawnpointIndex][2]);
        SendClientMessage(playeridCOLOR_YELLOW"You have been spawned at spawnpoint " + (spawnpointIndex 1));
        return 1;
    }
    return 0;

  Reply


Forum Jump: