open.mp forum
[Server] How do you create a spawn selector? - Printable Version

+ open.mp forum (https://forum.open.mp)
-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
--- Forum: Support (https://forum.open.mp/forumdisplay.php?fid=12)
--- Thread: [Server] How do you create a spawn selector? (/showthread.php?tid=2577)



How do you create a spawn selector? - julio-jered - 2024-01-30

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.


RE: How do you create a spawn selector? - N0FeaR - 2024-03-16

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;