[SUGGESTION] Inventory System
#1

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
Reply
#2

@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]); 
Reply
#3

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;
}
Reply
#4

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.
Reply
#5

Use a global array for the inventories.
Reply
#6

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.
Reply
#7

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
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)