Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <zcmd>
- #define DIALOG_LIST_ITEM 1
- #define DIALOG_PAY_ITEM 2
- main(){
- print("Bai Test Desert");
- }
- new Actor247;
- enum ITEM_INFO {
- ItemName[20],
- ItemPrice
- }
- new ListItem[][ITEM_INFO] = {
- {"Coca Cola", 500},
- {"Pepsi", 250},
- {"Snack", 300},
- {"Hambuger", 600}
- };
- new Inventory[MAX_PLAYERS][sizeof(ListItem)];
- public OnGameModeInit() {
- DisableInteriorEnterExits();
- Actor247 = CreateActor(1, -23.6527,-57.3179,1003.5469,359.0366);
- return 1;
- }
- public OnPlayerConnect(playerid) {
- SetSpawnInfo(playerid, 0, 0, -26.691598,-55.714897,1003.546875, 0, 0, 0, 0, 0, 0, 0);
- for(new i; i < sizeof(ListItem); i++) {
- Inventory[playerid][i] = 0;
- }
- return 1;
- }
- public OnPlayerSpawn(playerid) {
- SetPlayerPos(playerid, -26.691598,-55.714897,1003.546875);
- SetPlayerFacingAngle(playerid, 0);
- SetPlayerInterior(playerid, 6);
- return 1;
- }
- public OnPlayerKeyStateChange(playerid, newkeys, oldkeys) {
- if(newkeys & KEY_WALK && newkeys & KEY_CTRL_BACK) {
- new listid[128], bill[2000];
- if(PlayerIsNearActor(playerid, Actor247)) {
- if(GetPVarInt(playerid, "TotalProduct") == 0) return SendClientMessage(playerid, 0xFF504AFF, "[!] Ban chua mua mat hang nao de thanh toan.");
- for(new i; i < sizeof(ListItem); i++) {
- format(listid, sizeof(listid), "ProductID_%d", i);
- if(GetPVarInt(playerid, listid) > 0) {
- format(bill, sizeof(bill), "%s\t%s: So luong %d (Don gia: $%d)\n", bill, ListItem[i][ItemName], GetPVarInt(playerid, listid), ListItem[i][ItemPrice]);
- }
- }
- format(bill, sizeof(bill), "Hoa don cua ban:\n%s\n==========================================\n\
- Tong san pham: %d\n\
- Tong so tien thanh toan: $%d",
- bill,
- GetPVarInt(playerid, "TotalProduct"),
- GetPVarInt(playerid, "TotalPrice"));
- ShowPlayerDialog(playerid, DIALOG_PAY_ITEM, DIALOG_STYLE_MSGBOX, "Thanh toan", bill, "Mua", "Huy");
- }
- }
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[]) {
- if(dialogid == DIALOG_LIST_ITEM) {
- if(response) {
- new listid[128];
- format(listid, sizeof(listid), "ProductID_%d", listitem);
- SetPVarInt(playerid, listid, GetPVarInt(playerid, listid) + 1);
- SetPVarInt(playerid, "TotalPrice", GetPVarInt(playerid, "TotalPrice") + ListItem[listitem][ItemPrice]);
- format(listid, sizeof(listid), "[+] Ban da chon mua san pham %s.", ListItem[listitem][ItemName]);
- SendClientMessage(playerid, 0xFDDE00FF, listid);
- SetPVarInt(playerid, "TotalProduct", GetPVarInt(playerid, "TotalProduct") + 1);
- }
- }
- if(dialogid == DIALOG_PAY_ITEM) {
- if(response) {
- 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.");
- GivePlayerMoney(playerid, -GetPVarInt(playerid, "TotalPrice"));
- SendClientMessage(playerid, 0xFDDE00FF, "[+] Ban da thanh toan san pham. /tuido de kiem tra.");
- new listid[128];
- for(new i; i < sizeof(ListItem); i++) {
- format(listid, sizeof(listid), "ProductID_%d", i);
- Inventory[playerid][i] += GetPVarInt(playerid, listid);
- DeletePVar(playerid, listid);
- }
- DeletePVar(playerid, "TotalProduct");
- DeletePVar(playerid, "TotalPrice");
- }
- }
- return 1;
- }
- PlayerIsNearActor(playerid, actorid)
- {
- new Float:x[2], Float:y[2], Float:z[2];
- GetPlayerPos(playerid, x[0], y[0], z[0]);
- GetActorPos(actorid, x[1], y[1], z[1]);
- if(IsPlayerInRangeOfPoint(playerid, 5.0, x[1], y[1], z[1])) return 1;
- return 0;
- }
- CMD:mua(playerid, params[]) {
- new itemlist[2000];
- for(new i; i < sizeof(ListItem); i++) {
- format(itemlist, sizeof(itemlist), "%s%s\t$%d\n", itemlist, ListItem[i][ItemName], ListItem[i][ItemPrice]);
- }
- format(itemlist, sizeof(itemlist), "Ten san pham\tGia ban\n%s", itemlist);
- ShowPlayerDialog(playerid, DIALOG_LIST_ITEM, DIALOG_STYLE_TABLIST_HEADERS, "San pham", itemlist, "Chon", "Huy");
- return 1;
- }
- CMD:trahang(playerid, params[]) {
- new listid[128];
- if(GetPVarInt(playerid, "TotalProduct") == 0) return SendClientMessage(playerid, 0xFF504AFF, "[!] Ban chua co mat hang nao trong gio do.");
- for(new i; i < sizeof(ListItem); i++) {
- format(listid, sizeof(listid), "ProductID_%d", i);
- DeletePVar(playerid, listid);
- }
- DeletePVar(playerid, "TotalProduct");
- DeletePVar(playerid, "TotalPrice");
- SendClientMessage(playerid, -1, "[-] Ban da tra lai toan bo mat hang.");
- return 1;
- }
- CMD:tuido(playerid, params[]){
- new inv[200];
- for(new i; i < sizeof(ListItem); i++) {
- format(inv, sizeof(inv), "%s%s: %d\n", inv, ListItem[i][ItemName], Inventory[playerid][i]);
- }
- ShowPlayerDialog(playerid, 0, DIALOG_STYLE_MSGBOX, "Tui do", inv, "Ok", "");
- return 1;
- }
- CMD:money(playerid, params[]) {
- ResetPlayerMoney(playerid);
- return GivePlayerMoney(playerid, strval(params));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement