I need help
#1

Hello i started scripting a trunk system for my server.Everything is cool and all i just don't get how to save the trunk to the player.I added pTrunk in the pInfo enum and tried to go from there to make idx=GetPlayerVehicleID(playerid); and after that PlayerInfo[playerid][pTrunk] = idx; and stuff like that i tried and tried and i can't seem to find the way to save the trunk to the player.... :S
EDIT:Here is what i have till now...
pawn Код:
enum trunkInfo
{
    tOwner[32],
    tMaterials,
    tWeed,
    tCrack,
    tGun[2],
    tGunAmmo[2]
}
new TrunkInfo[MAX_VEHICLES][trunkInfo];

stock LoadTrunks()
{
    new binfo[21][32];
    new string[256];
    new File:file = fopen("trunks.cfg", io_read);
    if(file)
    {
        new idx = 1;
        while(idx < MAX_VEHICLES)
        {
            fread(file, string);
            split(string, binfo, '|');
            format(TrunkInfo[idx][tOwner], 32, "%s", binfo[3]);
            TrunkInfo[idx][tMaterials] = strval(binfo[8]);
            TrunkInfo[idx][tWeed] = strval(binfo[9]);
            TrunkInfo[idx][tCrack] = strval(binfo[10]);
            TrunkInfo[idx][tGun][0] = strval(binfo[11]);
            TrunkInfo[idx][tGunAmmo][0] = strval(binfo[12]);
            TrunkInfo[idx][tGun][1] = strval(binfo[13]);
            TrunkInfo[idx][tGunAmmo][1] = strval(binfo[14]);
            idx++;
        }
    }
    print("Trunks loaded successfully.");
    return 1;
}

stock SaveTrunks()
{
    new idx = 1, File:file;
    new string[256];
    while(idx < MAX_GARAGES)
    {
        format(string, sizeof(string), "%s|%d|%d|%d|%d|%d|%d|%d\r\n",
        TrunkInfo[idx][tOwner],
        TrunkInfo[idx][tMaterials],
        TrunkInfo[idx][tWeed],
        TrunkInfo[idx][tCrack],
        TrunkInfo[idx][tGun][0],
        TrunkInfo[idx][tGunAmmo][0],
        TrunkInfo[idx][tGun][1],
        TrunkInfo[idx][tGunAmmo][1]
        );
        if(idx == 1)
        {
            file = fopen("trunks.cfg", io_write);
        }
        else
        {
            file = fopen("trunks.cfg", io_append);
        }
        fwrite(file, string);
        fclose(file);
        idx++;
    }
    print("Trunks saved successfully.");
}

//and then the commands

CMD:tdeposit(playerid, params[])
{
    new Float:x, Float:y, Float:z;
    new Float:vx, Float:vy, Float:vz;
    GetVehiclePos(PlayerInfo[playerid][pVeh], x, y, z);
    GetVehiclePos(PlayerInfo[playerid][pVVeh], vx, vy, vz);
    new string[128], option[32], amount, done;
    new idx = PlayerInfo[playerid][pVeh];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pVeh] && !PlayerInfo[playerid][pVVeh]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a vehicle.");
    if(!IsPlayerInRangeOfPoint(playerid, 4 , x, y, z) && !IsPlayerInRangeOfPoint(playerid, 4 , vx, vy, vz)) return SendClientMessage(playerid, COLOR_GREY, "You are not near your vehicle.");
    if(topened[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "You need to open your trunk first!");
        if(PlayerInfo[playerid][pVeh] || PlayerInfo[playerid][pVVeh])
        {
            if(sscanf(params, "s[32]", option))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /tdeposit [item]");
                SendClientMessage(playerid, COLOR_GREY, "ITEMS: weapon | weed | crack");
                format(string, sizeof(string), "Weapon 1: %s (%d Ammo) | Weapon 2: %s (%d Ammo)", RWN(TrunkInfo[idx][tGun][0]), TrunkInfo[idx][tGunAmmo][0], RWN(TrunkInfo[idx][tGun][1]), TrunkInfo[idx][tGunAmmo][1]);
                SendClientMessage(playerid, COLOR_WHITE, string);
                format(string, sizeof(string), " Weed: %d | Crack: %d", TrunkInfo[idx][tWeed], TrunkInfo[idx][tCrack]);
                SendClientMessage(playerid, COLOR_WHITE, string);
                return 1;
            }
            if(sscanf(params, "s[32]", option))
            {
                SendClientMessage(playerid, COLOR_WHITE, "USAGE: /tdeposit [item]");
                SendClientMessage(playerid, COLOR_GREY, "ITEMS: weapon | weed | crack");
                return 1;
            }
            if(!strcmp(option, "weapon", true, 4))
            {
                if(!GetPlayerWeapon(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You are not holding a weapon in your hand.");
                new tw[2], w[2];
                for(new i=0; i<13; i++)
                {
                    GetPlayerWeaponData(playerid, i, tw[0], tw[1]);
                    if(tw[0] == GetPlayerWeapon(playerid))
                    {
                        w[0] = tw[0];
                        w[1] = tw[1];
                    }
                }
                if(!TrunkInfo[idx][tGun][0])
                {
                    TrunkInfo[idx][tGun][0] = w[0];
                    TrunkInfo[idx][tGunAmmo][0] = w[1];
                    done = 1;
                }
                else if(!TrunkInfo[idx][tGun][1])
                {
                    TrunkInfo[idx][tGun][1] = w[0];
                    TrunkInfo[idx][tGunAmmo][1] = w[1];
                    done = 1;
                }
                if(done)
                {
                    format(string, sizeof(string), "* %s opens their vehicles trunk, puts a %s inside and closes it.", RPN(playerid), RWN(GetPlayerWeapon(playerid)));
                    SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
                    RemoveZaiatWeapon(playerid, w[0]);
                }
                else SendClientMessage(playerid, COLOR_GREY, "Your trunk doesn't have enough space.");
            }
            else if(!strcmp(option, "weed", true, 4))
            {
                if(sscanf(params, "s[32]i", option, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /tdeposit weed [ammount]");
                if(PlayerInfo[playerid][pWeed] < amount) return SendClientMessage(playerid, COLOR_GREY, "You don't have that much weed on you.");
                TrunkInfo[idx][tWeed] += amount;
                PlayerInfo[playerid][pWeed] -= amount;
                format(string, sizeof(string), "* %s opens their vehicles trunk, puts %d grams of weed inside and closes it.", RPN(playerid), amount);
                SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
            }
            else if(!strcmp(option, "crack", true, 4))
            {
                if(sscanf(params, "s[32]i", option, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /gdeposit crack [amount]");
                if(PlayerInfo[playerid][pCrack] < amount) return SendClientMessage(playerid, COLOR_GREY, "You don't have that much crack on you.");
                TrunkInfo[idx][tCrack] += amount;
                PlayerInfo[playerid][pCrack] -= amount;
                format(string, sizeof(string), "* %s opens their vehicles trunk, puts %d grams of crack inside and closes it.", RPN(playerid), amount);
                SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
            }
        }
    return 1;
}

CMD:twithdraw(playerid, params[])
{
    new Float:x, Float:y, Float:z;
    new Float:vx, Float:vy, Float:vz;
    GetVehiclePos(PlayerInfo[playerid][pVeh], x, y, z);
    GetVehiclePos(PlayerInfo[playerid][pVVeh], vx, vy, vz);
    new string[128], option[32], amount;
    new idx = PlayerInfo[playerid][pVeh];
    if(!IsPlayerLoggedIn(playerid)) return SendClientMessage(playerid, COLOR_GREY, "You need to login first before using any command.");
    if(!PlayerInfo[playerid][pVeh] && !PlayerInfo[playerid][pVVeh]) return SendClientMessage(playerid, COLOR_GREY, "You don't own a vehicle.");
    if(!IsPlayerInRangeOfPoint(playerid, 4 , x, y, z) && !IsPlayerInRangeOfPoint(playerid, 4 , vx, vy, vz)) return SendClientMessage(playerid, COLOR_GREY, "You are not near your vehicle.");
    if(topened[playerid] == 0) return SendClientMessage(playerid, COLOR_GREY, "You need to open your trunk first!");
    if(!strcmp(option, "weapon", true, 4))
    {
        if(sscanf(params, "s[32]i", option, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /twithdraw weapon [slot]");
        if(amount < 1 || amount > 2) return SendClientMessage(playerid, COLOR_GREY, "Weapon slots are between 1 and 2.");
        amount = amount-1;
        if(!TrunkInfo[idx][tGun][amount]) return SendClientMessage(playerid, COLOR_GREY, "You don't have a weapon in this slot.");
        GiveZaiatWeapon(playerid, TrunkInfo[idx][tGun][amount], TrunkInfo[idx][tGunAmmo][amount]);
        format(string, sizeof(string), "* %s takes a %s from their trunk.", RPN(playerid), RWN(TrunkInfo[idx][tGun][amount]));
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
        TrunkInfo[idx][tGun][amount] = 0;
        TrunkInfo[idx][tGunAmmo][amount] = 0;
    }
    else if(!strcmp(option, "weed", true, 4))
    {
        if(sscanf(params, "s[32]i", option, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /twithdraw weed [amount]");
        if(TrunkInfo[idx][tWeed] < amount) return SendClientMessage(playerid, COLOR_GREY, "You don't have that much weed in your trunk.");
        TrunkInfo[idx][tWeed] -= amount;
        PlayerInfo[playerid][pWeed] += amount;
        format(string, sizeof(string), "* %s takes %d grams of weed from their trunk.", RPN(playerid), amount);
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    }
    else if(!strcmp(option, "crack", true, 4))
    {
        if(sscanf(params, "s[32]i", option, amount)) return SendClientMessage(playerid, COLOR_WHITE, "USAGE: /twithdraw crack [amount]");
        if(TrunkInfo[idx][tCrack] < amount) return SendClientMessage(playerid, COLOR_GREY, "You don't have that much crack in your trunk.");
        TrunkInfo[idx][tCrack] -= amount;
        PlayerInfo[playerid][pCrack] += amount;
        format(string, sizeof(string), "* %s takes %d grams of crack from their trunk.", RPN(playerid), amount);
        SendNearbyMessage(playerid, 15, string, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE, COLOR_PURPLE);
    }
    return 1;
}
Basically what i am asking is how to set the player as trunk "owner" once and for all.
Reply
#2

nvm just saved everything in the playerinfo enum and it worked
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)