Setting data incorrectly [Random]
#1

So, I'm trying to load mb locations from the MySQL db and then when it's time to create mb in a random location, it chooses a random location from the mb locations which are loaded from the database.

Load MB from db
Код:
public loadMBs()
{
	print("loading moneybags initialized");
	for(new i = 0; i < cache_get_row_count(mysql); ++i)
	{
		cache_get_field_content(i, "mbloc", MBInfo[i][mbloc], mysql,128);
		MBInfo[i][mbX] = cache_get_field_content_float(i, "mbX", mysql);
		MBInfo[i][mbY] = cache_get_field_content_float(i, "mbY", mysql);
		MBInfo[i][mbZ] = cache_get_field_content_float(i, "mbZ", mysql);
		totalMoneyBags++;
	}
	printf("%d moneybags loaded!", totalMoneyBags);
	mbTimer[1] = SetTimer("MoneyBag", 300000, true);
	return 1;
}
Mb creating
Код:
		new randombag = random(sizeof(totalMoneyBags));
		printf("%d", randombag);
		MoneyBagPos[0] = MBInfo[randombag][mbX];
		MoneyBagPos[1] = MBInfo[randombag][mbY];
		MoneyBagPos[2] = MBInfo[randombag][mbZ];
		MBInfo[randombag][mbactive] = 1;
I tried printing the randombag, but it keeps randomizing at 0.
Reply
#2

Try this :

PHP код:
public loadMBs()
{
    print(
"loading moneybags initialized");
    for(new 
0cache_get_row_count(mysql); ++i)
    {
        
cache_get_field_content(0"mbloc"MBInfo[i][mbloc], mysql,128);
        
MBInfo[i][mbX] = cache_get_field_content_float(1"mbX"mysql);
        
MBInfo[i][mbY] = cache_get_field_content_float(2"mbY"mysql);
        
MBInfo[i][mbZ] = cache_get_field_content_float(3"mbZ"mysql);
        
totalMoneyBags++;
    }
    
printf("%d moneybags loaded!"totalMoneyBags);
    
mbTimer[1] = SetTimer("MoneyBag"300000true);
    return 
1;

Reply
#3

Now it doesn't create any moneybags. Do I have to change anything in the mb creation function?

Edit : Fixed it on my own, thanks anyways.
Reply
#4

Quote:
Originally Posted by Affan
Посмотреть сообщение
Now it doesn't create any moneybags. Do I have to change anything in the mb creation function?

Edit : Fixed it on my own, thanks anyways.
Please tell us how did you fix it so that newbies learn.
Reply
#5

Changed
PHP код:
new randombag random(sizeof(totalMoneyBags)); 
to
PHP код:
new randombag random(sizeof(MBInfo)); 
What MBInfo is
PHP код:
#define MAX_MBS    19
enum moneybagsystem
{
    
mbloc[30],
    
Float:mbX,
    
Float:mbY,
    
Float:mbZ,
    
mbactive
}
new 
MBInfo[MAX_MBS][moneybagsystem]; 
Info: I didn't use rappy93's suggestion, so the loadmb function is as it is at the first post.
Reply
#6

Question: why do you need to store all of them in memory if only one money bag is supposedly active at any time? Simply load a random row and create it when needed.
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)