[Tutorial] Loot system + inventory
#1

Loot system + inventory tutorial by Voxel

Welcome to my simple loot system tutorial, i hope you guys find this usefull!'
This is my second real tutorial so sorry if there are some mistakes.
(im not a pro scripter so there might be some false explinations!)
the inventory system was created by joestaff, ONLY THE LOOT WAS MADE BY ME!
for a better explantion of the inventory system and the include download look here:
https://sampforum.blast.hk/showthread.php?tid=130436

Okay so first we start with a define and a static and a include:
pawn Code:
#define PRESSED(%0)
#define MAX_LOOTS 100 //the amount of loot you allow in your world
static LootObjects[MAX_LOOTS] = { INVALID_OBJECT_ID, ... }; //if theres a invalid object
#include <j_inventory_v2>
Now for adding the loot, put this under public OnGameModeInit:
pawn Code:
LootObjects[0] = CreateObject(356, 2384.59448, -1674.36279, 13.74557,   87.72005, -23.87996, 0.00000); //M4A1
LootObjects[1] = CreateObject(355, 2409.01392, -1673.93286, 12.65986,   87.36000, -16.68000, 0.00000); //AK47
LootObjects[2] = CreateObject(358, 2362.54614, -1644.61816, 12.61388,   -101.64005, -18.41999, 0.00000); //Sniper Rifle
LootObjects[3] = CreateObject(357, 2393.15576, -1647.44202, 12.58709,   -94.92001, -69.59998, -58.37999); //Counry Rifle
LootObjects[4] = CreateObject(349, 2326.31885, -1646.21326, 13.87297,   -97.07997, -51.83994, -90.54002); //Shotgun
LootObjects[5] = CreateObject(351, 2324.06274, -1646.22961, 13.86012,   -94.55995, -61.14002, 0.00000); //Spas
LootObjects[6] = CreateObject(346, 2328.17944, -1681.76965, 13.70912,   88.20000, 23.28000, 0.00000); //9mm pistol
LootObjects[7] = CreateObject(347, 2413.82813, -1647.04639, 13.05190,   -84.78008, -118.08011, 0.00000); //9mm silenced
LootObjects[8] = CreateObject(348, 2306.93921, -1678.13745, 12.99543,   80.76003, 0.72000, 11.22000); //Desert Eagle
LootObject[lootnumber] = Createobject(objectid, x, y, z, rx, ry, rz);

Now under public OnPlayerDisconect were gonna save the inventory of the player.
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{
    SaveInventory(playerid);
    return 1;
}
Now were gonna add it when you press LALT you will open your inventory and when you press C you will pick up the item with a debug message when your not close enough:
pawn Code:
public OnPlayerKeyStateChange(playerid, newkeys, oldkeys)
{
    if (newkeys & KEY_WALK)
    {
        ShowInventory(playerid);
        return 1;
    }
    if (newkeys & KEY_CROUCH)
    {
        if(IsValidObject(LootObjects[0]) && IsPlayerInRangeOfPoint(playerid,2.0,2384.59448,-1674.36279,13.74557))
        {
            AddItem(playerid,"M4A1",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 M4A1 has been added to your inventory");
            DestroyObject(LootObjects[0]);
        }
        if(IsValidObject(LootObjects[1]) && IsPlayerInRangeOfPoint(playerid,2.0,2409.01392, -1673.93286, 12.65986))
        {
            AddItem(playerid,"AK47",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 AK47 has been added to your inventory");
            DestroyObject(LootObjects[1]);
        }
        if(IsValidObject(LootObjects[2]) && IsPlayerInRangeOfPoint(playerid,2.0,2362.54614, -1644.61816, 12.61388))
        {
            AddItem(playerid,"Sniper Rifle",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 Sniper Rifle has been added to your inventory");
            DestroyObject(LootObjects[2]);
        }
        if(IsValidObject(LootObjects[3]) && IsPlayerInRangeOfPoint(playerid,2.0,2393.15576, -1647.44202, 12.58709))
        {
            AddItem(playerid,"Country Rifle",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 Country Rifle has been added to your inventory");
            DestroyObject(LootObjects[3]);
        }
        if(IsValidObject(LootObjects[4]) && IsPlayerInRangeOfPoint(playerid,2.0,2326.31885, -1646.21326, 13.87297))
        {
            AddItem(playerid,"Shotgun",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 Shotgun has been added to your inventory");
            DestroyObject(LootObjects[4]);
        }
        if(IsValidObject(LootObjects[5]) && IsPlayerInRangeOfPoint(playerid,2.0,2324.06274, -1646.22961, 13.86012))
        {
            AddItem(playerid,"Spas",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 Spas has been added to your inventory");
            DestroyObject(LootObjects[5]);
        }
        if(IsValidObject(LootObjects[6]) && IsPlayerInRangeOfPoint(playerid,2.0,2328.17944, -1681.76965, 13.70912))
        {
            AddItem(playerid,"9mm Pistol",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 9mm Pistol has been added to your inventory");
            DestroyObject(LootObjects[6]);
        }
        if(IsValidObject(LootObjects[7]) && IsPlayerInRangeOfPoint(playerid,2.0,2413.82813, -1647.04639, 13.05190))
        {
            AddItem(playerid,"9mm Silenced",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 9mm Silenced has been added to your inventory");
            DestroyObject(LootObjects[7]);
        }
        if(IsValidObject(LootObjects[8]) && IsPlayerInRangeOfPoint(playerid,2.0,2306.93921, -1678.13745, 12.99543))
        {
            AddItem(playerid,"Desert Eagle",1);
            SendClientMessage(playerid, COLOR_GREEN, "* 1 Desert Eagle has been added to your inventory");
            DestroyObject(LootObjects[8]);
        }
        else
        {
            //DEBUG MESSAGE
            SendClientMessage(playerid, COLOR_RED, "Your not close enough!");
            return 1;
        }
    }
    return 0;
}
Now were gonna make all the items we need (you can add your new items here)
pawn Code:
public OnPlayerUseItem(playerid,ItemName[])
{
    if(!strcmp(ItemName,"Full Medkit",true))
    {
        new Float:hp;
        GetPlayerHealth(playerid,hp);
        if(hp>=100)return SendClientMessage(playerid,COLOR_RED,"* You already have full health!");
        SetPlayerHealth(playerid,100);
        RemoveItem(playerid,ItemName,1);
        return SendClientMessage(playerid,COLOR_WHITE,"* You used a medkit.");
    }
    if(!strcmp(ItemName,"Small Medkit",true))
    {
        new Float:hp;
        GetPlayerHealth(playerid,hp);
        if(hp>=50)return SendClientMessage(playerid,COLOR_RED,"* You already have more then half health!");
        SetPlayerHealth(playerid,50);
        RemoveItem(playerid,ItemName,1);
        return SendClientMessage(playerid,COLOR_WHITE,"* You used a small medkit.");
    }
    if(!strcmp(ItemName,"Full Armour",true))
    {
        new Float:armour;
        GetPlayerArmour(playerid,armour);
        if(armour>=100)return SendClientMessage(playerid,COLOR_RED,"* You already have full armour!");
        SetPlayerArmour(playerid,100);
        RemoveItem(playerid,ItemName,1);
        return SendClientMessage(playerid,COLOR_WHITE,"* You used your full armour.");
    }
    if(!strcmp(ItemName,"Small Armour",true))
    {
        new Float:armour;
        GetPlayerArmour(playerid,armour);
        if(armour<=50)return SendClientMessage(playerid,COLOR_RED,"* You already have more then half armour!");
        SetPlayerArmour(playerid,50);
        RemoveItem(playerid,ItemName,1);
        return SendClientMessage(playerid,COLOR_WHITE,"* You used your small armour.");
    }
    if(!strcmp(ItemName,"Sniper Rifle",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 34, 25);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your Sniper Rifle.");
    }
    if(!strcmp(ItemName,"Country Rifle",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 33, 30);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your Country Rifle.");
    }
    if(!strcmp(ItemName,"M4A1",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 31, 100);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your M4A1.");
    }
    if(!strcmp(ItemName,"AK47",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 30, 100);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your AK47.");
    }
    if(!strcmp(ItemName,"MP5",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 29, 150);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your MP5.");
    }
    if(!strcmp(ItemName,"Spas",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 27, 40);
        ApplyAnimation(playerid,"BUDDY","buddy_reload",4.1,0,1,1,1,1);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your Spas.");
    }
    if(!strcmp(ItemName,"Shotgun",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 25, 70);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your Shotgun.");
    }
    if(!strcmp(ItemName,"9mm Pistol",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 22, 60);
        ApplyAnimation(playerid,"COLT45","colt45_reload",4.1,0,1,1,1,1);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your 9mm Pistol.");
    }
    if(!strcmp(ItemName,"9mm Silenced",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 23, 70);
        ApplyAnimation(playerid,"SILENCED","Silence_reload",4.1,0,1,1,1,1);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your 9mm Silenced.");
    }
    if(!strcmp(ItemName,"Desert Eagle",true))
    {
        RemoveItem(playerid,ItemName,1);
        GivePlayerWeapon(playerid, 24, 40);
        return SendClientMessage(playerid,COLOR_WHITE,"* You have taken out your Desert Eagle.");
    }
    return 0;
}
and now add this under public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{

pawn Code:
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
InventoryOnDialogResponse(playerid, dialogid, response, inputtext);
//rest of your code
And this under your code where your player logged in:
pawn Code:
LoadInventory(playerid);
Reply


Messages In This Thread
Loot system + inventory - by Voxel - 30.09.2013, 15:14
Re: Loot system + inventory - by MBilal - 30.09.2013, 18:29
Re: Loot system + inventory - by Pottus - 30.09.2013, 18:34
Re: Loot system + inventory - by Voxel - 01.10.2013, 06:42
Re: Loot system + inventory - by MBilal - 01.10.2013, 07:03
Re: Loot system + inventory - by Voxel - 01.10.2013, 08:32
Re : Loot system + inventory - by Naruto_Emilio - 03.10.2013, 21:23
Re: Loot system + inventory - by PT - 04.10.2013, 02:47
Re: Loot system + inventory - by Voxel - 04.10.2013, 16:13
Re: Loot system + inventory - by Jankingston - 04.10.2013, 16:41
Re: Loot system + inventory - by Voxel - 06.10.2013, 13:16
Re: Loot system + inventory - by FaceTutorialz - 14.10.2013, 20:43
Re: Loot system + inventory - by Pottus - 14.10.2013, 20:51
Re: Loot system + inventory - by CrazyChoco - 14.10.2013, 20:53
Re: Loot system + inventory - by Voxel - 16.10.2013, 09:15
Respuesta: Loot system + inventory - by Nitrome - 22.10.2013, 15:20
Re: Respuesta: Loot system + inventory - by Voxel - 22.10.2013, 16:10
Re: Loot system + inventory - by Immortal_LTU - 23.10.2013, 12:47
Re: Loot system + inventory - by Voxel - 23.10.2013, 13:10
Re: Loot system + inventory - by Immortal_LTU - 25.10.2013, 16:06
Re: Loot system + inventory - by Voxel - 26.10.2013, 08:28
Re: Loot system + inventory - by J4mmyHD - 18.11.2013, 20:54
Re: Loot system + inventory - by Voxel - 19.11.2013, 16:41
Re: Loot system + inventory - by [WA]iRonan - 01.12.2013, 15:18
Re: Loot system + inventory - by Voxel - 01.12.2013, 16:50
Re: Loot system + inventory - by [WA]iRonan - 02.12.2013, 17:33
Re: Loot system + inventory - by Voxel - 02.12.2013, 20:14
Re: Loot system + inventory - by [WA]iRonan - 03.12.2013, 12:42
Re: Loot system + inventory - by Voxel - 03.12.2013, 13:33
Re: Loot system + inventory - by Toxik - 16.02.2014, 16:01
Re: Loot system + inventory - by Voxel - 18.02.2014, 05:17
Re: Loot system + inventory - by Unfriendly - 19.02.2014, 04:23
Re: Loot system + inventory - by Voxel - 19.02.2014, 06:09
Re: Loot system + inventory - by darkhunter332 - 30.08.2015, 09:33
Re: Loot system + inventory - by Voxel - 12.10.2015, 15:12

Forum Jump:


Users browsing this thread: 1 Guest(s)