SA-MP Forums Archive
[Tutorial] How to create a simple Dialog Car Spawner. - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] How to create a simple Dialog Car Spawner. (/showthread.php?tid=273055)



How to create a simple Dialog Car Spawner. - Shockey HD - 31.07.2011

Hey SAMP users. Im going to show you how to create a Dialog Car Spawner and its pretty simple but it tends to take some time. Im going to start you off with the Basics of it, then you should be able to catch on. So here we go.

Im going to give you a little "Resource Table so you can grab these helpful post to help you out on this.

Vehicles
Car Colors (Optional)
ChangeVehicleColor(For Car Colors)

Okay, So lets get started

Were going to make a simple command for this.

ZCMD:

pawn Код:
CMD:spawncar(playerid,params[])
{
    ShowPlayerDialog(playerid,12,DIALOG_STYLE_LIST,"Cars:","Infernus\nElegy\nTurismo\n","Select","Cancel");
    return 1;
}
strcmp:

pawn Код:
if(strcmp("/spawncar", cmdtext, true) == 0)
{
    ShowPlayerDialog(playerid,12,DIALOG_STYLE_LIST,"Cars:","Infernus\nElegy\nTurismo\n","Select","Cancel");
    return 1;
}
DCMD:

pawn Код:
dcmd(spawncar,7,cmdtext);
pawn Код:
dcmd_spawncar(playerid,params[])
{
    #pragma unused params
    ShowPlayerDialog(playerid,12,DIALOG_STYLE_LIST,"Cars:","Infernus\nElegy\nTurismo\n","Select","Cancel");
    return 1;
}
Okay, these are the basic command. ShowPlayerDialog Is the dialog itself. It shows for the player (playerid). The Dialog ID is current 12 you can change that. and its a dialog_Style_List Format. Cars is the head of the Dialog and Infernus Elegy and Turismo are cars that we are going to add.
So, Now were going to go to OnDialogResponse.

pawn Код:
if(dialogid == 12)
        {
                if(response == 1)
                {
                   if(listitem == 0)
                        {
                            new Float:x, Float:y, Float:z, Float:a;
                            GetPlayerPos(playerid, x,y,z);
                            GetPlayerFacingAngle(playerid, a);
                            new vehicleid = CreateVehicle(411, x+3,y,z, a, -1, -1, -1);
                            PutPlayerInVehicle(playerid, vehicleid, 0);
                         }
                         if(listitem == 1)
                           {
                             new Float:x, Float:y, Float:z, Float:a;
                            GetPlayerPos(playerid, x,y,z);
                            GetPlayerFacingAngle(playerid, a);
                            new vehicleid = CreateVehicle(562, x+3,y,z, a, -1, -1, -1);
                            PutPlayerInVehicle(playerid, vehicleid, 0);
                                   
                         }
                        if(listitem == 2)
                           {
                               new Float:x, Float:y, Float:z, Float:a;
                               GetPlayerPos(playerid, x,y,z);
                               GetPlayerFacingAngle(playerid, a);
                               new vehicleid = CreateVehicle(451, x+3,y,z, a, -1, -1, -1);
                               PutPlayerInVehicle(playerid, vehicleid, 0);
                                }
                            }
                        }
I will tell you what this does. This will get the coordinates of where you are X,Y,Z and it will get your faceing Angle.
This will create the vehicle desired and it will spawn it move you 3 time on the X axis. Then, this will put you into the vehicle.



Thanks pretty much it guys, pretty simple but great for a stunt or admin script. :]

Thanks for reading!



Re: How to create a simple Dialog Car Spawner. - [HiC]TheKiller - 31.07.2011

That code will not actually put the player in the vehicle because you are using GetVehicleID before you are putting the player in the vehicle.

You should do this:
pawn Код:
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x,y,z);
GetPlayerFacingAngle(playerid, a);
new vehicleid = CreateVehicle(411, x+3,y,z, a, -1, -1, -1);
PutPlayerInVehicle(playerid, vehicleid, 0);
Otherwise, not a bad tutorial .


Re: How to create a simple Dialog Car Spawner. - Shockey HD - 31.07.2011

Quote:
Originally Posted by [HiC]TheKiller
Посмотреть сообщение
That code will not actually put the player in the vehicle because you are using GetVehicleID before you are putting the player in the vehicle.

You should do this:
pawn Код:
new Float:x, Float:y, Float:z, Float:a;
GetPlayerPos(playerid, x,y,z);
GetPlayerFacingAngle(playerid, a);
new vehicleid = CreateVehicle(411, x+3,y,z, a, -1, -1, -1);
PutPlayerInVehicle(playerid, vehicleid, 0);
Otherwise, not a bad tutorial .
Okay, thank you updating


Re: How to create a simple Dialog Car Spawner. - Basicz - 31.07.2011

I would make something like this
pawn Код:
stock createVehForPlayer( playerid, vehmodel )
{
    new
        Float: pos[ 4 ]
    ;

    GetPlayerPos( playerid, pos[ 0 ], pos[ 1 ], pos[ 2 ] );

    GetPlayerFacingAngle( playerid, pos[ 3 ] );

    new
        iVeh = CreateVehicle( vehmodel, pos[ 0 ], pos[ 1 ], pos[ 2 ], pos[ 3 ], -1, -1, -1 )
    ;

    SetVehicleVirtualWorld( iVeh, GetPlayerVirtualWorld( playerid ) );

    LinkVehicleToInterior( iVeh, GetPlayerInterior( playerid ) );

    PutPlayerInVehicle( playerid, iVeh, 0 );

    return 1;
}

public OnDialogResponse( playerid, dialogid, response, listitem, inputtext[ ] )
{
    if ( dialogid == 12 )
    {
        if ( response )
        {
            new
                iList[ ] = { 411, 562, 451 };

            createVehForPlayer( playerid, iList[ listitem ] );
        }
   }

   return 1;
}
Not a bad tutorial.


Re: How to create a simple Dialog Car Spawner. - Chrillzen - 02.08.2011

Код:
D:\Allt\SAMP RPG\gamemodes\stunt.pwn(106) : warning 203: symbol is never used: "spawncar"
?


Re: How to create a simple Dialog Car Spawner. - Shockey HD - 02.08.2011

Quote:
Originally Posted by Chrillzen
Посмотреть сообщение
Код:
D:\Allt\SAMP RPG\gamemodes\stunt.pwn(106) : warning 203: symbol is never used: "spawncar"
?
You must of forget the C in CMD


Re: How to create a simple Dialog Car Spawner. - XphosKill3r - 10.04.2012

My pwn code... in game it says "Unknown Command"

code:

http://pastebin.com/TVSdQC1C


Re: How to create a simple Dialog Car Spawner. - Jonny5 - 10.04.2012

I like how you included strcmp dcmd zcmd !!!

heres the YCMD
pawn Код:
YCMD:spawncar(playerid, params[], help)
{
#pragma unused params
    if (help)   {SendClientMessage(playerid, 0xFFCC33AA, "/spawncar : Spawn a Car");}
    else        {ShowPlayerDialog(playerid,12,DIALOG_STYLE_LIST,"Cars:","Infernus\nElegy\nTurismo\n","Select","Cancel");}
    return 1;
}

nice tut! simple 8/10


@XphosKill3r

your onPlayerCommandText function is missing
pawn Код:
return 0;
}
at the bottom


from what i can see