SA-MP Forums Archive
Setting data incorrectly [Random] - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: Setting data incorrectly [Random] (/showthread.php?tid=574900)



Setting data incorrectly [Random] - Affan - 21.05.2015

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.


Re: Setting data incorrectly [Random] - rappy93 - 21.05.2015

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;




Re: Setting data incorrectly [Random] - Affan - 21.05.2015

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.


Re: Setting data incorrectly [Random] - Ghazal - 21.05.2015

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.


Re: Setting data incorrectly [Random] - Affan - 22.05.2015

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.


Re: Setting data incorrectly [Random] - Vince - 22.05.2015

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.