Jump to content
  • 0

randitem in sql query?


HristDead

Question


  • Group:  Members
  • Topic Count:  66
  • Topics Per Day:  0.02
  • Content Count:  167
  • Reputation:   2
  • Joined:  08/01/12
  • Last Seen:  

Hey rAthena. I've been breaking my head about this for the past 2 hours. Someone care to take a look at it? 

I'm using the online peak NPC but want that, when a new peak is reached, every player gets 5x one type of the items in ".@RandItem[0]" array. I use a query to store the items in their storage but it simply isn't happening.

The announcement is working fine and the server doesn't return any kind of error. What am I doing wrong here? I've tried different combinations of ".@RandItem"

Thanks in advance :) 

-	script	Highest Peak	-1,{

OnPCLoginEvent:

// Assign current number of online players
sleep 1000;
.onlineusers = getusers(1);

// Today's date
.date$ = gettime(DT_YEAR)+"-"+gettime(DT_MONTH)+"-"+gettime(DT_DAYOFMONTH);

// Query for the highest peak in the database
query_sql("SELECT `users` FROM `" + .sqltable$ + "` ORDER BY `users` LIMIT 1",.@countusers);

if(getarraysize(.@countusers) == 0) {
	// There doesn't seem to be a row in our table, so lets create one
	query_sql("INSERT INTO `" + .sqltable$ + "` (`users`, `date`) VALUES (" + .onlineusers + ", '" + .date$ + "')");
} else {
	if(.onlineusers > .@countusers[0]) {
		// This is where we check if we want to announce a new peak
		if(.displaypeakannounce == 1){
			announce "[ Server ] We have reached a new population peak, we now have "+.onlineusers+" online players! Therefore we've decided to give you all a little surprise, re-log and check your storage to find out what it is!~ ",bc_all;

			// Replace the 

	query_sql "INSERT INTO `storage` (`id`, `account_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `expire_time`, `unique_id`) "+
			"SELECT  NULL, `login`.`account_id`, '.@RandItem', '5', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0' FROM `login` WHERE `account_id` > 1";
		}
		// Now lets update the table with our new player peak
		query_sql("UPDATE `" + .sqltable$ + "` SET `users` = '" + .onlineusers + "', `date` = '" + .date$ + "'");
	}
}
end;

OnInit:
// CONFIGS
	// We need an SQL table name first
	.sqltable$ = "cp_onlinepeak";
	
	// Would you like an announcement when you reach a higher peak?
	// 1 = Yes
	// 0 = No
	.displaypeakannounce = 1;

	// ITEM REWARD
	// 14534 = Medium life potion
	// 12299 = Mega resist potion
	// 12354 = Buche de Noel
	// 12196 = Plain Rice Cake
	// 12123 = Honey Pastry

	setarray .@RandItem[0],14534,12299,12354,12195,12123;
	set .@RandItemCount,getarraysize(.@RandItem);
	//getitem(.@Randitem[rand(.@RandItemCount)],5); - We will use SQL so this will not be important.

// END CONFIGS

}

 

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

  • Group:  Developer
  • Topic Count:  48
  • Topics Per Day:  0.01
  • Content Count:  1443
  • Reputation:   337
  • Joined:  10/17/12
  • Last Seen:  

11 hours ago, HristDead said:

Hey rAthena. I've been breaking my head about this for the past 2 hours. Someone care to take a look at it? 

I'm using the online peak NPC but want that, when a new peak is reached, every player gets 5x one type of the items in ".@RandItem[0]" array. I use a query to store the items in their storage but it simply isn't happening.

The announcement is working fine and the server doesn't return any kind of error. What am I doing wrong here? I've tried different combinations of ".@RandItem"

Thanks in advance :) 


-	script	Highest Peak	-1,{

OnPCLoginEvent:

// Assign current number of online players
sleep 1000;
.onlineusers = getusers(1);

// Today's date
.date$ = gettime(DT_YEAR)+"-"+gettime(DT_MONTH)+"-"+gettime(DT_DAYOFMONTH);

// Query for the highest peak in the database
query_sql("SELECT `users` FROM `" + .sqltable$ + "` ORDER BY `users` LIMIT 1",.@countusers);

if(getarraysize(.@countusers) == 0) {
	// There doesn't seem to be a row in our table, so lets create one
	query_sql("INSERT INTO `" + .sqltable$ + "` (`users`, `date`) VALUES (" + .onlineusers + ", '" + .date$ + "')");
} else {
	if(.onlineusers > .@countusers[0]) {
		// This is where we check if we want to announce a new peak
		if(.displaypeakannounce == 1){
			announce "[ Server ] We have reached a new population peak, we now have "+.onlineusers+" online players! Therefore we've decided to give you all a little surprise, re-log and check your storage to find out what it is!~ ",bc_all;

			// Replace the 

	query_sql "INSERT INTO `storage` (`id`, `account_id`, `nameid`, `amount`, `equip`, `identify`, `refine`, `attribute`, `card0`, `card1`, `card2`, `card3`, `expire_time`, `unique_id`) "+
			"SELECT  NULL, `login`.`account_id`, '.@RandItem', '5', '0', '1', '0', '0', '0', '0', '0', '0', '0', '0' FROM `login` WHERE `account_id` > 1";
		}
		// Now lets update the table with our new player peak
		query_sql("UPDATE `" + .sqltable$ + "` SET `users` = '" + .onlineusers + "', `date` = '" + .date$ + "'");
	}
}
end;

OnInit:
// CONFIGS
	// We need an SQL table name first
	.sqltable$ = "cp_onlinepeak";
	
	// Would you like an announcement when you reach a higher peak?
	// 1 = Yes
	// 0 = No
	.displaypeakannounce = 1;

	// ITEM REWARD
	// 14534 = Medium life potion
	// 12299 = Mega resist potion
	// 12354 = Buche de Noel
	// 12196 = Plain Rice Cake
	// 12123 = Honey Pastry

	setarray .@RandItem[0],14534,12299,12354,12195,12123;
	set .@RandItemCount,getarraysize(.@RandItem);
	//getitem(.@Randitem[rand(.@RandItemCount)],5); - We will use SQL so this will not be important.

// END CONFIGS

}

 

What's your client version I'll write you on real fast?

 

Just need to know if RoDex or old mail system.

Link to comment
Share on other sites

  • 0

  • Group:  Members
  • Topic Count:  66
  • Topics Per Day:  0.02
  • Content Count:  167
  • Reputation:   2
  • Joined:  08/01/12
  • Last Seen:  

42 minutes ago, Stolao said:

What's your client version I'll write you on real fast?

 

Just need to know if RoDex or old mail system.

Wow, thanks Stalao. That's really kind of you! My client version is 2013 08 07. It still supports the mail box system. :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...