global string ?
#1

hi all.
my and some friends (6) are working on a new GM.
we are almost 20% done but we are having a problem here.
first , we are using this player inventory include
https://sampforum.blast.hk/showthread.php?tid=130436

what we want to do is a /sell and /accept command.
the commands works , but we have the item name in command params.
sscanf take it there is no problem.
but how do we put the item name (string ) GLOBAL so i can add the item in the inventory of the player that do /accept ?
we already tried pvars with no luck.

here are the code we actually have for that

command /sellitem
pawn Код:
CMD:sellitem(playerid, params[])
{
    new id;
    new itemname[30];
    new amount;
    new price;
    if(sscanf(params, "uiis[30]", id, amount, price, itemname))
    {
         SendClientMessage(playerid, COLOR_WHITE, "[USAGE] /sellitem [playerid] [amount] [price] [itemname]"); //-1 stands for white, change that with your colors if wanted.
    }
    else
    {
        new targetname[MAX_PLAYER_NAME];
        new playername[MAX_PLAYER_NAME];
        new string[128];
        new string2[128];
        GetPlayerName(id,targetname,sizeof(targetname));
        GetPlayerName(playerid,playername,sizeof(playername));
        Player[id][AmountHD] = amount;
        Player[id][PriceHD] = price;
        format(string, sizeof(string), "Player {808000}%s{FFFFFF}(%i) want to sell you %i %s for $%i. Use /acceptitem [sellerid] to accept.", playername, playerid, amount, itemname, price);
        SetPVarString(id,"ItemToAccept", itemname);
        SendClientMessage(id, -1, string);
        Player[id][PendingHD] = 1;
        Player[playerid][OfferingHD] = 1;
        format(string2, sizeof(string2), "Transaction sent to %s(%i)", targetname, id);
        SendClientMessage(playerid, -1, string2);
    }
    return 1;
}
command /acceptitem
pawn Код:
CMD:acceptitem(playerid, params[])
{
    new id;
    new itemname[30];
    new amount;
    new price;
    if(sscanf(params, "u", id))
    {
         SendClientMessage(playerid, COLOR_WHITE, "[USAGE] /acceptitem [seller id]");
    }
    else
    {
        new targetname[MAX_PLAYER_NAME];
        new playername[MAX_PLAYER_NAME];
        GetPlayerName(playerid,playername,sizeof(playername));
        GetPlayerName(id,targetname,sizeof(targetname));
        new string[128];
        amount = Player[id][AmountHD];
        price = Player[id][PriceHD];
        if(GetPlayerMoney(playerid) <price)
        {
            SendClientMessage(playerid, COLOR_RED, "Not enought cash.");
            Player[playerid][PendingHD] = 0;
            Player[id][OfferingHD] = 0;
        }
        else
        {
            if(Player[playerid][PendingHD] == 1)
            {
                if(Player[id][OfferingHD] == 1)
                {
                    GetPVarString(playerid, "ItemToAccept", itemname, 30);
                    format(string, sizeof(string), "Player %s(%i) accepted the transaction.", playername, playerid);
                    SendClientMessage(id, COLOR_GREEN, string);
                   
                    Player[id][PendingHD] = 0;
                    Player[playerid][OfferingHD] = 0;
                    AddItem(playerid,itemname,amount);
                    AC_BS_GivePlayerMoney(playerid, -price);
                    AC_BS_GivePlayerMoney(id, price);
                   
                    new string2[128];
                    format(string2, sizeof(string2), "%i %s have been added to your inventory and $%i have been given to %s(%i)", amount, itemname, price, targetname, id);
                    SendClientMessage(playerid, COLOR_GREEN, string2);
                    SendClientMessage(playerid, COLOR_GREEN, itemname);
                }
            }
        }
    }
    return 1;
}
the id , amount , price are all working perfect as they are Int and stored in enum ( global ).
now how can we do it for a string ( item name , which is text , undefined lenght )

we also tried new thestring[MAX_PLAYERS][30]; and new thestring[MAX_PLAYERS][] = "NULL"; and everything similar with no luck.

you can see we also tried using pvars.

thank you
Reply
#2

ii did another fast test and this one seem to work. at least for me.

pawn Код:
CMD:setstring(playerid, params[])
{
    new pvarstring[128];
    new string[30];
    if(sscanf(params, "s[30]", pvarstring))
    {
        SendClientMessage(playerid, COLOR_WHITE, "[USAGE] /setstring [string]");
    }
    else
    {
        format(string, sizeof(string), "%s", pvarstring);
        SendClientMessage(playerid, COLOR_PINK, string);
        SetPVarString(playerid, "sellingitem", string);
    }
    return 1;
}


CMD:getstring(playerid, params[])
{
    new string[30];
    new pvarstring[128];
    GetPVarString(playerid, "sellingitem", pvarstring, 128);
    format(string, sizeof(string), "%s", pvarstring);
    SendClientMessage(playerid, COLOR_PINK, string);
    AddItem(playerid, string, 1);
    return 1;
}
the item ( entered in /setstring command ) is added to the inventory.
but i still need to wait my team to test i with some players because we had a script that was working for 1 player not the other.

if you have suggestion , other way , or anything tell me! it's gonna help my whole team.

thanks
Reply
#3

there is no way they could get it working.

the pvarstring part is working great ( player 2 can get player 1 pvarstring )
but the item wont add to inventory.
exactly like if the pvarstring was empty but it is NOT.

anyone can help us ?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)