Bit.ly/sampwiki

Bit.ly/hoclamsamp

Dark Mode

Bài 5: Tạo Bảng Tele Với Dialog

Bài học số 5, chúng ta cùng tạo 1 bảng dịch chuyển interior house bằng dialog.

Đầu tiên chúng ta cần khai báo tên dialog trên đầu gamemode.


#define         HOUSES_INT                  (5200)
Tiếp theo chúng ta tạo 1 đoạn CMD để hiển thị Dialog.
CMD:houseint(playerid, params[])
{
    if (PlayerInfo[playerid][pAdmin] >= 2)
        {
  ShowPlayerDialog(playerid, HOUSES_INT, DIALOG_STYLE_LIST, "Noi That Houses","House 1\n House 2\n House 3\n House 4\n House 5\n House 6\n House 7\n House 8\n House 9\n House 10\n House 11\n House 12\n House 13\n House 14\n House 15\n House 16", "Select", "Cancel");
}
    else {
        SendClientMessageEx(playerid, COLOR_GREY, "Ban khong duoc phep su dung lenh nay.");
    }
    return 1;
Trên đây mình có sử dụng đoạn điều kiện phải là admin 2 trở lên mới có thể sử dụng được lệnh.

Rõ hơn về code gốc chúng ta sẽ cố đoạn Show Dialog như sau.


 ShowPlayerDialog(playerid, HOUSES_INT, DIALOG_STYLE_LIST, "Noi That Houses","House 1\n House 2\n House 3\n House 4\n House 5\n House 6\n House 7\n House 8\n House 9\n House 10\n House 11\n House 12\n House 13\n House 14\n House 15\n House 16", "Select", "Cancel");

Ở Bài học trước chúng ta đã hiểu sơ qua về công của các đoạn \n \t và tiêu dề dialog.
Chúng ta sẽ có 16 dòng và 2 Button, Chọn và Thoát.

Để code hoạt động chúng ta sẽ thêm code để khi chúng ta click vào dòng nào, dòng đó sẽ chạy tọa độ để tele.

Chúng ta tìm đến đoạn này:
public OnDialogResponse 

Add dưới nó đoạn này:
if(dialogid == HOUSES_INT)
{
if(response)
{
if(listitem == 0) // Burglary House #1
{
    SetPlayerPos(playerid,234.6087, 1187.8195, 1080.2578);
    SetPlayerInterior(playerid,3);
}
if(listitem == 1) // Burglary House #2
{
    SetPlayerPos(playerid,225.5707, 1240.0643, 1082.1406);
    SetPlayerInterior(playerid,2);
}
if(listitem == 2) // Burglary House #3
{
    SetPlayerPos(playerid,224.288, 1289.1907, 1082.1406);
    SetPlayerInterior(playerid,1);
}
if(listitem == 3) // Burglary House #4
{
    SetPlayerPos(playerid,239.2819, 1114.1991, 1080.9922);
    SetPlayerInterior(playerid,5);
}
if(listitem == 4) // Burglary House #5
{
    SetPlayerPos(playerid,295.1391, 1473.3719, 1080.2578);
    SetPlayerInterior(playerid,15);
}
if(listitem == 5) // Burglary House #6
{
    SetPlayerPos(playerid,261.1165, 1287.2197, 1080.2578);
    SetPlayerInterior(playerid,4);
}
if(listitem == 6) // Burglary House #7
{
SetPlayerPos(playerid,24.3769, 1341.1829, 1084.375);
    SetPlayerInterior(playerid,10);
}
if(listitem == 7) // Burglary House #8
{
    SetPlayerPos(playerid,-262.1759, 1456.6158, 1084.3672);
    SetPlayerInterior(playerid,4);
}
if(listitem == 8) // Burglary House #9
{
    SetPlayerPos(playerid,22.861, 1404.9165, 1084.4297);
    SetPlayerInterior(playerid,5);
}
if(listitem == 9) // Burglary House #10
{
    SetPlayerPos(playerid,140.3679, 1367.8837, 1083.8621);
    SetPlayerInterior(playerid,5);
}
    if(listitem == 10) // Burglary House #11
{
    SetPlayerPos(playerid,234.2826, 1065.229, 1084.2101);
    SetPlayerInterior(playerid,6);
}
if(listitem == 11) // Burglary House #12
{
    SetPlayerPos(playerid,-68.5145, 1353.8485, 1080.2109);
    SetPlayerInterior(playerid,6);
}
if(listitem == 12) // Burglary House #13
{
    SetPlayerPos(playerid,-285.2511, 1471.197, 1084.375);
    SetPlayerInterior(playerid,15);
}
if(listitem == 13) // Burglary House #14
{
    SetPlayerPos(playerid,-42.5267, 1408.23, 1084.4297);
    SetPlayerInterior(playerid,8);
}
if(listitem == 14) // Burglary House #15
{
    SetPlayerPos(playerid,84.9244, 1324.2983, 1083.8594);
    SetPlayerInterior(playerid,9);
}
if(listitem == 15) // Burglary House #16
{
    SetPlayerPos(playerid,260.7421, 1238.2261, 1084.2578);
    SetPlayerInterior(playerid,9);
}
}
return 1;


Trong đó: 

HOUSES_INT: là tên bạn đã khai báo.
Listitem: là danh sách mỗi dòng, chúng ta có 16 dòng thì ở đây chúng ta chạy từ 0 - 15, tức 16 dòng.

Mỗi dòng chúng ta chèn tọa độ tương ứng vs tọa độ chúng ta muốn tele tới.

SetPlayerInterior(playerid,9);: tức Interior ID 9

Ví Dụ Chúng Ta Có Dòng 16 Tên House 16
Chúng ta sẽ điền tọa độ để khi nhấn vào dòng 16 nó sẽ tele đến 260.7421, 1238.2261, 1084.2578
Chúng ta có:
if(listitem == 15) // Burglary House #16
{
    SetPlayerPos(playerid,260.7421, 1238.2261, 1084.2578);
        SetPlayerInterior(playerid,9);
}
Như Vậy Chúng Ta Đã Hoàn Thành Xong 1 Dialog Dịch Chuyển Inteior House Đơn Giản Rồi.

Bài Học Tiếp Theo Chúng Ta Sẽ Tạo 1 Câu Lệnh Chỉ Sử Dụng Được Ở 1 Địa Điểm

Nếu Bạn Có Thắc Mắc Gì Liên Quan Đến SA-MP, Vui lòng CMT Tại Đây!

Đăng nhận xét

Friends list