15.07.2010, 00:47
(
Последний раз редактировалось Toni; 18.06.2012 в 19:12.
Причина: Updated terrible code.
)
Creating Dialog Vehicle Menu
Hello, This is a tutorial on how to create a dialog, that spawns vehicles at your location.
First off lets assign a ID to the dialog:
pawn Код:
#define vmenu 159156
pawn Код:
if(!strcmp(cmdtext, "/vmenu", true))
{
ShowPlayerDialog(playerid, vmenu, DIALOG_STYLE_LIST, "Vehicle Menu", "Andromada \nDodo \nSultan \nInfernus", "Spawn", "Cancel");
return 1;
}
Now lets create a declaration, and make it global so we don't have to keep creating more.
pawn Код:
new Float:X, Float:Y, Float:Z, Float:Angle, pInt;
pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
GetPlayerPos(playerid, X, Y, Z);
GetPlayerFacingAngle(playerid, Angle);
pInt = GetPlayerInterior(playerid);
switch(dialogid) {
case: vmenu
{
if(response)
{
if(listitem == 0) // The Andromada
{
CreateVehicle(592, X+5, Y, Z+1, Angle, random(100), random(100), -1); LinkVehicleToInterior(GetPlayerVehicleID(playerid), pInt);
}
if(listitem == 1) // Dodo
{
CreateVehicle(593, X+5, Y, Z+1, Angle, random(100), random(100), -1); LinkVehicleToInterior(GetPlayerVehicleID(playerid), pInt);
}
if(listitem == 2) // Sultan
{
CreateVehicle(560, X+5, Y, Z+1, Angle, random(100), random(100), -1); LinkVehicleToInterior(GetPlayerVehicleID(playerid), pInt);
}
if(listitem == 3) // Infernus
{
CreateVehicle(411, X+5, Y, Z+1, Angle, random(100), random(100), -1); LinkVehicleToInterior(GetPlayerVehicleID(playerid), pInt);
}
}
return 1;
}
return 0;
}
GetPlayerPos(playerid, X, Y, Z); - That function gets the player's X, Y, Z position, so the script knows where to create the vehicle.
GetPlayerFacingAngle(playerid, Angle); - That function will get your angle so it can spawn the vehicle the same angle as your angle.
pInt = GetPlayerInterior(playerid); - That function will get your interior so if you are somewhere else, it may be spawned there as well.
switch(dialogid) { }
case: vmenu - That function will check if the menu is the vehicle dialog.
if(response) - will check if the player responded to the dialog or not.
if(listitem == 0) - Will check the item id on the list (as the andromada is now the first one on the list, so it is item 0.
CreateVehicle(); - Will create the vehicle at your position. (The parameters are below)
pawn Код:
592 = Vehicle Model
X+5 = The Player's X position, + 5 X unit's
Y = The Player's Y position.
Z+1 = The Player's Z position, + 1 Z Unit
Angle = The Player's Angle.
random(100) = Vehicle Color 1, but random colors 0 through 100
random(100) = Vehicle Color 2, but random colors 0 through 100
-1 = Never Respawn again
GetPlayerVehicleID(playerid) = Get the players vehicle id that they spawned
pInt = The declaration that gets the player's interior
Thats it! Just repeat those if(listitem == ) id's the item's ID
and the Create vehicle function!
Hoped that help a lot
- Toni
Updated recently, I didn't have an editor to actually format it so it's a little derp and out dated. This is not a recommended tutorial for first off beginners that don't know basic coding.