Sign in to follow this  
LorianLA

Hilfe bei einer Query für den Clothingshop

Recommended Posts

Ich hab die Resource ClothingShop aus der RageMP Website auf den Server eingepackt. Standard mässig ist die Resource so eingestellt dass das Geld beim kleiderkaufen durch die currency-api abgezogen wird und dies wollte ich nun ändern und somit mit dem Geld aus der Datenbank ausführen. 

 

Dies ist mein Code momentan (kleidung wird gekauft und gespeichert das Geld wird aber nicht abgezogen):

 

mp.events.add("buyClothingItem", (player, type, slot, texture, drawable, price, money) => {
    // Extra spaghetti for verification
    if (typeof player.clothingShopType !== "string") {
        player.outputChatBox("You're not in a clothing shop marker.");
        return;
    }

    const key = allowedModels[player.model];
    if (typeof key !== "string") {
        player.outputChatBox("Your model is not allowed to use clothing shops.");
        return;
    }

    let item = shopData[player.clothingShopType][key];
    if (!Object.keys(item).includes(type)) {
        console.log(`[CLOTHES] Player ${player.name} sent invalid item type.`);
        return;
    }

    item = shopData[player.clothingShopType][key][type];
    if (!item.hasOwnProperty(slot)) {
        console.log(`[CLOTHES] Player ${player.name} sent invalid slot.`);
        return;
    }

    item = shopData[player.clothingShopType][key][type][slot];

    const itemIdx = item.findIndex(i => i.texture === texture && i.drawable === drawable && i.price === price);
    item = item[itemIdx];

    if (typeof item === "undefined") {
        console.log(`[CLOTHES] Player ${player.name} sent invalid item.`);
        return;
    }

    if (Number.isInteger(item.price)) {
        money = player.data.money;
        // Currency API is needed for this
        if (player.data.money < item.price) {
            player.notify("You can't afford this item.");
            return;
        }
        gm.mysql.handle.query('UPDATE `accounts` SET money = ? WHERE username = ?', [money, player.name], function(err, res){
            if(!err){
                money = money - item.price;
                giveClothingToPlayer(player, item.name, type, slot, item.drawable, item.texture);
            } else {
                console.log(err)
            }
        });
    } else {
        giveClothingToPlayer(player, item.name, type, slot, item.drawable, item.texture);
    }
});

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.