[Tutorial] How to make a drug system.
#1

Hello,

Welcome to my seventh tutorial.
In this tutorial you will learn how to make a simple drug system.

Here is the full code with explanation:
pawn Код:
#include <a_samp>//you all know that.
#include <zcmd>//including a zcmd include in the script.
#include <sscanf2>//including sscanf2 include in the script.

enum pInfo
{
    drugs//the variable that will store the player's amount of drugs he have.
}
new PlayerInfo[MAX_PLAYERS][pInfo];

CMD:checkweed(playerid,params[])//creating a checkweed cmd.
{
    new string[128];//this is the variable which will store the info of the message we will send to the player.
    format(string,sizeof(string),"You have %d drugs on you!",PlayerInfo[playerid][drugs]);//formating the message we will send to the player the info of his drugs.
    SendClientMessage(playerid,-1,string);//sending the formated message.
    return 1;
}

CMD:giveweed(playerid,params[])//creating a giveweed cmd.
{
    new targetid,type;//these are the variables which will store the id of the person we want to give the weed and the amount of weed he want's to give to the person.
    if(sscanf(params, "ud", targetid, type)) return SendClientMessage(playerid, -1, "[Usage]: /giveweed [Part of Name/Player ID] [Amount]");//will check that if the information entered is right or in the right format.
    if(type > PlayerInfo[playerid][drugs])return SendClientMessage(playerid,-1,"ERROR: You do not have that much amount of drugs!");//if the person is entering the big amount of weed than he has or entering a higher amount of weed then he acctually have,it will send him an error message.
    if(targetid == playerid)return SendClientMessage(playerid,-1,"ERROR: You cannot give drugs to your self!");//An error message will appear if the person will try to give weed to himself.
    PlayerInfo[playerid][drugs] -= type;//this will minus player's weed.Will reduce the amount of the player.
    PlayerInfo[targetid][drugs] +=type;//this will give the target player the amount of weed he want's to give.
    return 1;
}
CMD:useweed(playerid,params[])//creating a use weed cmd.
{
    if(PlayerInfo[playerid][drugs] > 1)//this will check if the player has the weed or not.
    {
        new Float:Health;//the variable which will store player's health.
        GetPlayerHealth(playerid, Health);//this will get player's health and store it in the variable Health.(new Float:Health).
        SetPlayerHealth(playerid, Health+20);//this will add 20+ health to player's current health.
        SetPlayerWeather(playerid, -66);//this will set player's weather to -66.You can check for weather ids by searching on the samp wiki.
        PlayerInfo[playerid][drugs] -= 1;//this will minus player's amount of weed because he used some of it.
        SetTimerEx("Usedrugs", 10000, false, "d", playerid);//setting timer for the player for like 10 seconds.
        SendClientMessage(playerid, -1, "INFO: You have used one gram of Weed.");//this will send the player a message that he use one gram of weed.
    }
    else
    {
        SendClientMessage(playerid, -1, "ERROR: You need at least one gram of Weed to use it.");//this error message will appear if he does not have weed to use.
    }
    return 1;
}
/*==============================this is the timer we made in the useweed cmd==============================*/
forward Usedrugs(playerid);
public Usedrugs(playerid)
{
    SetPlayerWeather(playerid, 2);//setting player's weather to 2.
    return 1;
}
/*=========================================================================================================*/
Hope I helped you.
Reply
#2

i am testing looks nice
Reply
#3

nice , but with the smoking anim it would look better :d
Reply
#4

Flawed. Forgot to add sscanf to giveweed command.
Reply
#5

Quote:
Originally Posted by Vince
Посмотреть сообщение
Flawed. Forgot to add sscanf to giveweed command.
LOL! ThAnKs! edited.
Reply
#6

Any more comments?
Reply
#7

Well Not bad but let's say it's "too simple" drugs system but good one.
Reply
#8

Hmm.ThAnKs!
Reply
#9

Simple and good tutorial. Good work
Reply
#10

Nice work but in future please explain(Thats why is tutorial)
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)