SA-MP Forums Archive
[Tutorial] Loot system + inventory - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Tutorials (https://sampforum.blast.hk/forumdisplay.php?fid=70)
+---- Thread: [Tutorial] Loot system + inventory (/showthread.php?tid=466964)

Pages: 1 2


Loot system + inventory - Voxel - 30.09.2013

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);



Re: Loot system + inventory - MBilal - 30.09.2013

Really Nice dude i Like it But how can i add object like hat ,Other Objects


Re: Loot system + inventory - Pottus - 30.09.2013

This is not really a good way to do it.


Re: Loot system + inventory - Voxel - 01.10.2013

Quote:
Originally Posted by MBilal
View Post
Really Nice dude i Like it But how can i add object like hat ,Other Objects
Under OnGameModeInit you add
LootObjects[0] = CreateObject(356, 2384.59448, -1674.36279, 13.74557, 87.72005, -23.87996, 0.00000); //M4A1

where 356 is the object id of the m4a1 to map it somewhere

you can simply add more objects just be creative


Re: Loot system + inventory - MBilal - 01.10.2013

how we can save them when player leave ?


Re: Loot system + inventory - Voxel - 01.10.2013

use this:
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{    
    SaveInventory(playerid);    
    return 1;
}



Re : Loot system + inventory - Naruto_Emilio - 03.10.2013

This is not a good looting system, because it has lack of good features (dynamic system, animations, timers...) so on


Re: Loot system + inventory - PT - 04.10.2013

that way don't is the better way to do this..

but result already, good job


Re: Loot system + inventory - Voxel - 04.10.2013

Im not a pro scripter, i made this 99% on my own. atleast it works =)


Re: Loot system + inventory - Jankingston - 04.10.2013

nice work bro


Re: Loot system + inventory - Voxel - 06.10.2013

Thanks!


Re: Loot system + inventory - FaceTutorialz - 14.10.2013

Can you add a download link? When I compile, I always get errors.


Re: Loot system + inventory - Pottus - 14.10.2013

Quote:
Originally Posted by FaceTutorialz
View Post
Can you add a download link? When I compile, I always get errors.
This doesn't really do what it's meant to do very well it's more of a example of what not to do


Re: Loot system + inventory - CrazyChoco - 14.10.2013

Wooow, this is actually pretty awesome


Re: Loot system + inventory - Voxel - 16.10.2013

yeah well, its a simple looting system i got working, there is nothing like this that i found so far on the internet and i think for people that just started with this sort of stuff its good for them to learn with.

be thank full i took the time out of my day to post this.


Respuesta: Loot system + inventory - Nitrome - 22.10.2013

Nice,


Re: Respuesta: Loot system + inventory - Voxel - 22.10.2013

Quote:
Originally Posted by Nitrome
View Post
Nice,
ty :3


Re: Loot system + inventory - Immortal_LTU - 23.10.2013

Does it save the items ? And it's in dialogs ?


Re: Loot system + inventory - Voxel - 23.10.2013

Quote:
Originally Posted by [FSaF]Jarno
View Post
I wouldn't say so. You used "SaveInventory" in your tutorial, but you never made the function for it!
It also barely does anything. TBH, i wouldn't make tutorials if i wouldn't even know how to script myself. Remember, a toddler has never teached an adult to do his job.
i suggest you learn to read, the SaveInventory is in the include that i provided a link for.

pls... check your facts before you "try" to insult some one.


Re: Loot system + inventory - Immortal_LTU - 25.10.2013

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
So these are the objects who are laying on the ground ?