[Tutorial] Simple /buyskin command using dialogs/zcmd
#1

Tutorial Introduction
This tutorial was created for scripting beginners. In this tutorial in other words I will be showing how to create a very very simple /buyskin command using dialogs and zcmd. This command is used mostly in RP servers I believe.


Requirments
You will need:

Let's move on to scripting.

Scripting

First of all open your gamemode using pawno and include below (make sure zcmd.inc is in your include folder in pawno folder of your gamemode)
pawn Код:
#include <a_samp>
the ZCMD include.

pawn Код:
#include <zcmd> // ZCMD command proccessor
Search for

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    return 1;
}

and copy/paste the following:

pawn Код:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
    if(dialogid == 99999)
    {
        if(response)
        {
            new string[256];
            new skinid = strval(inputtext); // inputtext is the text that you will type in the black bar
            if(!strlen(inputtext)) return ShowPlayerDialog(playerid, 99999, DIALOG_STYLE_INPUT, "Select skin","Type a skinid below to choose a skin. \n (ID 0(CJ) is not included)","Select","Cancel"); // if you didnt type anything it will show the dialog again
            if(skinid < 1 || skinid > 299) // you can add more invalid skins. Example for skin id 4 to be invalid: if(skinid < 1 || skinid > 299 || skinid == 4)
            {
                SendClientMessage(playerid, -1, "Invalid skinid."); // Will display a message in chat box that the skin is invalid.
                ShowPlayerDialog(playerid, 99999, DIALOG_STYLE_INPUT, "Select skin","Type a skinid below to choose a skin. \n (ID 0(CJ) is not included)","Select","Cancel"); // If you picked an invalid skin it will show the dialog again.
                return 1;
            }
            else
            {
                SetPlayerSkin(playerid, skinid); // If it isn't an invalid skin it will be set.
                format(string, sizeof(string), "Picked skin: {FFD90F}%d", skinid); // Displays the skin id you picked.
                SendClientMessage(playerid, -1, string); // Displays the skin id you picked from the format function
                SendClientMessage(playerid, -1, "Cash spent: {FFD90F}$200"); // Displays the cash spent.
                GivePlayerMoney(playerid, -200); // Removes $200 from your money.
                return 1;
            }
        }
        else
        {
            SendClientMessage(playerid, -1, "Skin selection canceled."); // If you picked cancel / pressed ESC it will close the dialog.
        }
    }
    return 1;
}

We have now included the dialog that will let you pick your skin.

Let's move on. Creating the command using ZCMD proccessor.

At the last line of your gamemode add the following.

pawn Код:
CMD:buyskin(playerid, params[]) // ZCMD command /buyskin
{
    ShowPlayerDialog(playerid, 99999, DIALOG_STYLE_INPUT, "Select skin","Type a skinid below to choose a skin. \n (ID 0(CJ) is not included)","Select","Cancel"); // WIll show the dialog to buy a skin.
    SendClientMessage(playerid, -1, "New skin cost: {FFD90F}$200"); // Will display in chatbox the skin cost.
        //{FFD90F} is yellow 50% / -1 is the white color
    return 1;
}
And that is, you are done. As simple as walking ain't it?


Credits
ZeeX - <ZCMD> command proccessor
L.Hudson - Creator of the tutorial


NOTES
*If you had errors compiling or something didn't work please let me know right away.
*You can also set the /buyskin command to be in some locations to your liking. Example:
pawn Код:
CMD:buyskin(playerid, params[]) // ZCMD command /buyskin
{
    if(IsPlayerInRangeOfPoint(playerid, (range from the point), Position X, Position Y, Position Z))
    {
        ShowPlayerDialog(playerid, 99999, DIALOG_STYLE_INPUT, "Select skin","Type a skinid below to choose a skin. \n (ID 0(CJ) is not included)","Select","Cancel"); // WIll show the dialog to buy a skin.
        SendClientMessage(playerid, -1, "New skin cost: {FFD90F}$200"); // Will display in chatbox the skin cost.
    }
    else
    {
        SendClientMessage(playerid, -1, "You cannot buy a skin here.");
    }
    return 1;
}
Reply
#2

Its just setting the cash to decrease and setting the skin.
Would be better, if its saving on the file. so it will be more realistic shopping skin system.
Reply
#3

I will start working on a skin system with a timer and some animations and will try to do as realistic as I can thanks for the note
Reply
#4

Looks good for a newb like me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)