Advertisement
Guest User

Untitled

a guest
Apr 15th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 4.85 KB | None | 0 0
  1. #include <a_samp>
  2. #include <zcmd>
  3.  
  4. #define DIALOG_LIST_ITEM        1
  5. #define DIALOG_PAY_ITEM         2
  6.  
  7. main(){
  8.     print("Bai Test Desert");
  9. }
  10.  
  11. new Actor247;
  12.  
  13. enum ITEM_INFO {
  14.     ItemName[20],
  15.     ItemPrice
  16. }
  17.  
  18. new ListItem[][ITEM_INFO] = {
  19.     {"Coca Cola", 500},
  20.     {"Pepsi", 250},
  21.     {"Snack", 300},
  22.     {"Hambuger", 600}
  23. };
  24.  
  25. new Inventory[MAX_PLAYERS][sizeof(ListItem)];
  26.  
  27. public OnGameModeInit() {
  28.     DisableInteriorEnterExits();
  29.     Actor247 = CreateActor(1, -23.6527,-57.3179,1003.5469,359.0366);
  30.     return 1;
  31. }
  32.  
  33. public OnPlayerConnect(playerid) {
  34.     SetSpawnInfo(playerid, 0, 0, -26.691598,-55.714897,1003.546875, 0, 0, 0, 0, 0, 0, 0);
  35.     for(new i; i < sizeof(ListItem); i++) {
  36.         Inventory[playerid][i] = 0;
  37.     }
  38.     return 1;
  39. }
  40.  
  41. public OnPlayerSpawn(playerid) {
  42.     SetPlayerPos(playerid, -26.691598,-55.714897,1003.546875);
  43.     SetPlayerFacingAngle(playerid, 0);
  44.     SetPlayerInterior(playerid, 6);
  45.     return 1;
  46. }
  47.  
  48. public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
  49.     if(newkeys & KEY_WALK && newkeys & KEY_CTRL_BACK) {
  50.         new listid[128], bill[2000];
  51.         if(PlayerIsNearActor(playerid, Actor247)) {
  52.             if(GetPVarInt(playerid, "TotalProduct") == 0) return SendClientMessage(playerid, 0xFF504AFF, "[!] Ban chua mua mat hang nao de thanh toan.");
  53.             for(new i; i < sizeof(ListItem); i++) {
  54.                 format(listid, sizeof(listid), "ProductID_%d", i);
  55.                 if(GetPVarInt(playerid, listid) > 0) {
  56.                     format(bill, sizeof(bill), "%s\t%s: So luong %d (Don gia: $%d)\n", bill, ListItem[i][ItemName], GetPVarInt(playerid, listid), ListItem[i][ItemPrice]);
  57.                 }
  58.             }
  59.             format(bill, sizeof(bill), "Hoa don cua ban:\n%s\n==========================================\n\
  60.                                         Tong san pham: %d\n\
  61.                                         Tong so tien thanh toan: $%d",
  62.                                         bill,
  63.                                         GetPVarInt(playerid, "TotalProduct"),
  64.                                         GetPVarInt(playerid, "TotalPrice"));
  65.             ShowPlayerDialog(playerid, DIALOG_PAY_ITEM, DIALOG_STYLE_MSGBOX, "Thanh toan", bill, "Mua", "Huy");
  66.         }
  67.     }
  68.     return 1;
  69. }
  70.  
  71. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
  72.     if(dialogid == DIALOG_LIST_ITEM) {
  73.         if(response) {
  74.             new listid[128];
  75.             format(listid, sizeof(listid), "ProductID_%d", listitem);
  76.             SetPVarInt(playerid, listid, GetPVarInt(playerid, listid) + 1);
  77.             SetPVarInt(playerid, "TotalPrice", GetPVarInt(playerid, "TotalPrice") + ListItem[listitem][ItemPrice]);
  78.             format(listid, sizeof(listid), "[+] Ban da chon mua san pham %s.", ListItem[listitem][ItemName]);
  79.             SendClientMessage(playerid, 0xFDDE00FF, listid);
  80.             SetPVarInt(playerid, "TotalProduct", GetPVarInt(playerid, "TotalProduct") + 1);
  81.         }
  82.     }
  83.     if(dialogid == DIALOG_PAY_ITEM) {
  84.         if(response) {
  85.             if(GetPlayerMoney(playerid) < GetPVarInt(playerid, "TotalPrice")) return SendClientMessage(playerid, 0xFF504AFF, "[!] Ban khong du tien de thanh toan san pham. /trahang de tra lai toan bo mat hang.");
  86.             GivePlayerMoney(playerid, -GetPVarInt(playerid, "TotalPrice"));
  87.             SendClientMessage(playerid, 0xFDDE00FF, "[+] Ban da thanh toan san pham. /tuido de kiem tra.");
  88.             new listid[128];
  89.             for(new i; i < sizeof(ListItem); i++) {
  90.                 format(listid, sizeof(listid), "ProductID_%d", i);
  91.                 Inventory[playerid][i] += GetPVarInt(playerid, listid);
  92.                 DeletePVar(playerid, listid);
  93.             }
  94.             DeletePVar(playerid, "TotalProduct");
  95.             DeletePVar(playerid, "TotalPrice");
  96.         }
  97.     }
  98.     return 1;
  99. }
  100.  
  101. PlayerIsNearActor(playerid, actorid)
  102. {
  103.     new Float:x[2], Float:y[2], Float:z[2];
  104.     GetPlayerPos(playerid, x[0], y[0], z[0]);
  105.     GetActorPos(actorid, x[1], y[1], z[1]);
  106.     if(IsPlayerInRangeOfPoint(playerid, 5.0, x[1], y[1], z[1])) return 1;
  107.     return 0;
  108. }
  109.  
  110. CMD:mua(playerid, params[]) {
  111.     new itemlist[2000];
  112.     for(new i; i < sizeof(ListItem); i++) {
  113.         format(itemlist, sizeof(itemlist), "%s%s\t$%d\n", itemlist, ListItem[i][ItemName], ListItem[i][ItemPrice]);
  114.     }
  115.     format(itemlist, sizeof(itemlist), "Ten san pham\tGia ban\n%s", itemlist);
  116.     ShowPlayerDialog(playerid, DIALOG_LIST_ITEM, DIALOG_STYLE_TABLIST_HEADERS, "San pham", itemlist, "Chon", "Huy");
  117.     return 1;
  118. }
  119.  
  120. CMD:trahang(playerid, params[]) {
  121.     new listid[128];
  122.     if(GetPVarInt(playerid, "TotalProduct") == 0) return SendClientMessage(playerid, 0xFF504AFF, "[!] Ban chua co mat hang nao trong gio do.");
  123.     for(new i; i < sizeof(ListItem); i++) {
  124.         format(listid, sizeof(listid), "ProductID_%d", i);
  125.         DeletePVar(playerid, listid);
  126.     }
  127.     DeletePVar(playerid, "TotalProduct");
  128.     DeletePVar(playerid, "TotalPrice");
  129.     SendClientMessage(playerid, -1, "[-] Ban da tra lai toan bo mat hang.");
  130.     return 1;
  131. }
  132.  
  133. CMD:tuido(playerid, params[]){
  134.     new inv[200];
  135.     for(new i; i < sizeof(ListItem); i++) {
  136.         format(inv, sizeof(inv), "%s%s: %d\n", inv, ListItem[i][ItemName], Inventory[playerid][i]);
  137.     }
  138.     ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Tui do", inv, "Ok", "");
  139.     return 1;
  140. }
  141.  
  142. CMD:money(playerid, params[]) {
  143.     ResetPlayerMoney(playerid);
  144.     return GivePlayerMoney(playerid, strval(params));
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement