Could someone help me decipher this a little?
#1

pawn Код:
//well point one: I gave a bad name to the function, it should better be called "GetWeaponTableIndex" or so...
//when we use the variables like "WepAmmo, WepModel" or whatever, we use the data that you read from the mysql table
//and stored in those variables... And there the Indizes are different to the IDs in the mysql
//so if we have a SQLID we first need to find the correct INDEX that is shadowing this SQLID
//As we have WepSQLID we can look at which Index WepSQLID matches to the SQLID we have at PlayerWeapon
//But all the time when we use some data that we pre-saved in the variables we need to use the Index of the serverside table
//instead of the SQLID
stock GivePlayerWeaponEx(playerid)
{
    for(new w = 0; w < 13; w++)
    {
        new id = GetWepIndexFromSQL(PlayerWeapons[playerid][w]);
        printf("WeaponID: %d", id);
        if(id < 0)
            continue;
        if(WepAmmo[id] > 0)
        {
            GivePlayerWeapon(playerid,WepModel[id],WepAmmo[id]);
            printf("Weapon: %d, Ammo: %d", WepModel[id], WepAmmo[id]);
        }
    }
    return 1;
}
Someone assisted me in writing this system, due to taking a break from SAMP and changing computers I've completely forgot. The comments have been written by them.

Basically

PlayerWeapons[playerid][w] saves the MySQLID of the weapon (not model).

So I don't understand the serverside index thing?

Any advice would be great.
Reply
#2

Show function GetWepIndexFromSQL, I think this function give all saved weapons to player.
Reply
#3

pawn Код:
stock GetWepIndexFromSQL(weapid)//returns the INDEX of the serverside database (PlayerWeapons[playerid][w] by giving the SQLID as parameter
{//needed when using WepVARIABLES
    new rst = -1;
    new string[40];
    format(string, sizeof(string), "SELECT `id` FROM `weapons`");
    mysql_query(string);
    mysql_store_result();
    new maxr = mysql_num_rows();
    mysql_free_result();
    for(new n=0; n<maxr; n++)
    {
        if(weapid == WepSQLID[n])   //at this point ==> weapid is the SQLID we have from PlayerWeapons
        {//and WepSQLID[n] is the SQL ID that is stored in the serverside table... n is the specific index (the number
            rst = n;//that we need)... Ahh. But if PlayerWeapons stores the SQLID? PlayerWeapons stores the SQLID, I don't
            break;// get your question:D
        }
    }
    return rst;
}
Reply
#4

All this is doing is storing the result from the MySQL database to a variable..

I suppose this is for assigning the weapon ID to a saving system.

As in, your table `weapons` will consist of a bunch of numbers that correspond to the weapon ID's within the name.

WepSQLID is looping through, making this

WepSQLID[0]
WepSQLID[1]
WepSQLID[2]
WepSQLID[3] etc..

So, until the if statement in the loop in GetIndexFromSQL looks like this(compiled ofc):

if(38 == WepSQLID[38]) which would be a minigun

Maybe I've got the entire wrong end of the stick
Reply
#5

Thanks for responding although the SQLID would be the id in the table!
Reply
#6

I advice u take an look on this: https://sampforum.blast.hk/showthread.php?tid=505081
Reply
#7

Thanks dude will check that out!

It's not entirely similar. Although vince may be able to help further.
Reply
#8

Quote:
Originally Posted by Dokins
Посмотреть сообщение
Thanks for responding although the SQLID would be the id in the table!
Show the table structure?
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)