SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help > Tutorials

Reply
 
Thread Tools Display Modes
Old 30/09/2013, 04:14 PM   #1
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 580
Reputation: 70
Default Loot system + inventory

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:
http://forum.sa-mp.com/showthread.php?t=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);
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 30/09/2013, 07:29 PM   #2
MBilal
Gangsta
 
MBilal's Avatar
 
Join Date: May 2013
Posts: 811
Reputation: 57
Default Re: Loot system + inventory

Really Nice dude i Like it But how can i add object like hat ,Other Objects
MBilal is offline   Reply With Quote
Old 30/09/2013, 07:34 PM   #3
Pottus
High-roller
 
Pottus's Avatar
 
Join Date: Jun 2012
Posts: 4,842
Reputation: 1312
Default Re: Loot system + inventory

This is not really a good way to do it.
Pottus is offline   Reply With Quote
Old 01/10/2013, 07:42 AM   #4
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 580
Reputation: 70
Default Re: Loot system + inventory

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
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 01/10/2013, 08:03 AM   #5
MBilal
Gangsta
 
MBilal's Avatar
 
Join Date: May 2013
Posts: 811
Reputation: 57
Default Re: Loot system + inventory

how we can save them when player leave ?
MBilal is offline   Reply With Quote
Old 01/10/2013, 09:32 AM   #6
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 580
Reputation: 70
Default Re: Loot system + inventory

use this:
pawn Code:
public OnPlayerDisconnect(playerid, reason)
{    
    SaveInventory(playerid);    
    return 1;
}
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 03/10/2013, 10:23 PM   #7
Naruto_Emilio
Banned
 
Join Date: Apr 2011
Location: North Africa
Posts: 1,297
Reputation: 365
Default Re : Loot system + inventory

This is not a good looting system, because it has lack of good features (dynamic system, animations, timers...) so on
Naruto_Emilio is offline   Reply With Quote
Old 04/10/2013, 03:47 AM   #8
PT
Godfather
 
PT's Avatar
 
Join Date: Nov 2012
Location: Europe
Posts: 7,168
Reputation: 801
Default Re: Loot system + inventory

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

but result already, good job
PT is offline   Reply With Quote
Old 04/10/2013, 05:13 PM   #9
Voxel
Gangsta
 
Voxel's Avatar
 
Join Date: Sep 2013
Location: The Netherlands
Posts: 580
Reputation: 70
Default Re: Loot system + inventory

Im not a pro scripter, i made this 99% on my own. atleast it works =)
__________________
My Work:
[GameMode]The Nether Survival
[Filterscript]SQLite Database Start
[Tutorial]SQLite Commands
[Tutorial]Loot/ Inventory System
[Tutorial]Simple Hunger/Thirst System
[Tutorial]Converting Binary
[Map]Tropical Island + Pier
[Map]San Fierro Apocalypse
Voxel is offline   Reply With Quote
Old 04/10/2013, 05:41 PM   #10
Jankingston
Banned
 
Join Date: Oct 2013
Location: New York, Albany.
Posts: 399
Reputation: 30
Default Re: Loot system + inventory

nice work bro
Jankingston is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
loot system Legend_Of_War Scripting Help 2 15/08/2013 04:05 AM
How does a loot system works? CrazyChoco Scripting Help 5 05/06/2013 11:57 AM
Loot system. iHaze. Scripting Help 7 30/03/2013 12:40 PM
Loot System Kitten Scripting Help 0 16/01/2013 03:45 AM


All times are GMT. The time now is 02:00 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.