SA-MP Forums Archive
[SUGGESTION] Inventory System - 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)
+--- Thread: [SUGGESTION] Inventory System (/showthread.php?tid=605939)



[SUGGESTION] Inventory System - DavideFatman - 27.04.2016

Hello everyone!, i was scripting a gamemode and i wanted to do some nice inventory system, a little bit different from what you see around. I Recentley played in a server where you got your house, veh key and everything in your inventory. (I'm posting a screen a little bit down the thread) and i wanted to get some advice on how to make a similar system because i really liked it. I Don't need the whole script. Just a little example and some words should be enough.


Screen Here


Re: [SUGGESTION] Inventory System - GangstaSunny - 27.04.2016

@DavideFatman

I talk about the system showed on screen.
To build it you can use textdraws. Use strings and combine then to make sure all letters are showed (SA-MP Limits). You can use your player variables as you usualy do. Like:

PHP код:
format(string,sizeof(string),"Slot 1: %s~n~Slot 2: %s",PlayerInventory[pKalcor],PlayerInventory[pSpookie]); 



Re: [SUGGESTION] Inventory System - RedCounty - 27.04.2016

You will need to create a TextDraw and update the text, just like this example:

https://sampwiki.blast.hk/wiki/TextDrawCreate
https://sampwiki.blast.hk/wiki/TextDrawDestroy
https://sampwiki.blast.hk/wiki/TextDrawSetString

pawn Код:
#include <a_samp>
#include <zcmd>

new Text:invTD[MAX_PLAYERS], var[MAX_PLAYERS][3], invTimer[MAX_PLAYERS];

public OnPlayerConnect(playerid){
    invTD[playerid] = TextDrawCreate(240.0,580.0,"Inventory\n");
    UpdateInvTD(playerid);
    TextDrawShowForPlayer(playerid, invTD[playerid]);
   
    invTimer[playerid] = SetTimerEx("UpdateInvTD", 3000, true, "i", playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason){
    TextDrawHideForPlayer(playerid, invTD[playerid]);
    TextDrawDestroy(invTD[playerid]);
   
    KillTimer(invTimer[playerid]);
    return 1;
}

forward UpdateInvTD(playerid);
public UpdateInvTD(playerid){
    new longStr[300];
    if(var[playerid][1] == 1) //change to your vars
    {
        format(longStr, sizeof(longStr), "%sVar 1\n");
    }
   
    if(var[playerid][2] == 2) //change to your vars
    {
        format(longStr, sizeof(longStr), "%sVar 2");
    }
   
    TextDrawSetString(invTD[playerid], longStr);

    return 1;
}



Re: [SUGGESTION] Inventory System - DavideFatman - 27.04.2016

Quote:
Originally Posted by RedCounty
Посмотреть сообщение
You will need to create a TextDraw and update the text, just like this example:

https://sampwiki.blast.hk/wiki/TextDrawCreate
https://sampwiki.blast.hk/wiki/TextDrawDestroy
https://sampwiki.blast.hk/wiki/TextDrawSetString

pawn Код:
#include <a_samp>
#include <zcmd>

new Text:invTD[MAX_PLAYERS], var[MAX_PLAYERS][3], invTimer[MAX_PLAYERS];

public OnPlayerConnect(playerid){
    invTD[playerid] = TextDrawCreate(240.0,580.0,"Inventory\n");
    UpdateInvTD(playerid);
    TextDrawShowForPlayer(playerid, invTD[playerid]);
   
    invTimer[playerid] = SetTimerEx("UpdateInvTD", 3000, true, "i", playerid);
    return 1;
}

public OnPlayerDisconnect(playerid, reason){
    TextDrawHideForPlayer(playerid, invTD[playerid]);
    TextDrawDestroy(invTD[playerid]);
   
    KillTimer(invTimer[playerid]);
    return 1;
}

forward UpdateInvTD(playerid);
public UpdateInvTD(playerid){
    new longStr[300];
    if(var[playerid][1] == 1) //change to your vars
    {
        format(longStr, sizeof(longStr), "%sVar 1\n");
    }
   
    if(var[playerid][2] == 2) //change to your vars
    {
        format(longStr, sizeof(longStr), "%sVar 2");
    }
   
    TextDrawSetString(invTD[playerid], longStr);

    return 1;
}
I'm not so bad, i know how to use Textdraws, i mean the system to get the items like the vehicle keys.

Quote:
Originally Posted by GangstaSunny
Посмотреть сообщение
@DavideFatman

I talk about the system showed on screen.
To build it you can use textdraws. Use strings and combine then to make sure all letters are showed (SA-MP Limits). You can use your player variables as you usualy do. Like:

PHP код:
format(string,sizeof(string),"Slot 1: %s~n~Slot 2: %s",PlayerInventory[pKalcor],PlayerInventory[pSpookie]); 
I Was thinking of that method, but it would take a lot of variables for every player.


Re: [SUGGESTION] Inventory System - introzen - 27.04.2016

Use a global array for the inventories.


Re: [SUGGESTION] Inventory System - DavideFatman - 27.04.2016

Quote:
Originally Posted by introzen
Посмотреть сообщение
Use a global array for the inventories.
Thanks, What about if i wanna give the players the Vehicle Keys, how to assign them to a specific vehicle?. I can't figure it out.


Re: [SUGGESTION] Inventory System - introzen - 27.04.2016

I assume you have a vehicle array as well. Give each vehicle a unique key-code. In the inventory array, then define the correct key-code to the vehicle and check if they match on /lock etc.

E.g.
PHP код:
Inventory[playerid][vehiclekeys][0] = 1836736;
VehicleInfo[vehicleid][vKeyIdentifier] = 1836736