Jump to content
  • 0
NoOne

send item in all players in map

Question

hello can i ask for script

 

example

 

 i want to send 10pcs ESB and 10pcs Bubble Gum Box in all player in Geffen?

 

then a command @gatheringON to trigger it or a NPC that only lvl 99 GM can trigger?

 

 

thank you in advance

Share this post


Link to post
Share on other sites

9 answers to this question

Recommended Posts

  • 0

If you want to do it from a script, you would use getunits():

.@count = getunits(BL_PC, .@units, false, "geffen");

for (.@i = 0; .@i < .@count; ++.@i) {
	getitem(Bubble_Gum_Box_10, 1, .@units[.@i]);
}

 

Share this post


Link to post
Share on other sites
  • 0

Hello guys! thank you for reply! and it works! my only problem now is i want to send bind item is that possible? thank you!

 

//================= Hercules Script=======================================
//=       _   _                     _
//=      | | | |                   | |
//=      | |_| | ___ _ __ ___ _   _| | ___  ___
//=      |  _  |/ _ \ '__/ __| | | | |/ _ \/ __|
//=      | | | |  __/ | | (__| |_| | |  __/\__ \
//=      \_| |_/\___|_|  \___|\__,_|_|\___||___/
//================= License===============================================
//= This file is part of Hercules.
//= http: //herc.ws - http: //github.com/HerculesWS/Hercules
//=
//= Copyright (C)  Emistry
//= Copyright (C)  Ridley
//=
//= Hercules is free software: you can redistribute it and/or modify
//= it under the terms of the GNU General Public License as published by
//= the Free Software Foundation, either version 3 of the License, or
//= (at your option) any later version.
//=
//= This program is distributed in the hope that it will be useful,
//= but WITHOUT ANY WARRANTY; without even the implied warranty of
//= MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//= GNU General Public License for more details.
//=
//= You should have received a copy of the GNU General Public License
//= along with this program.  If not, see <http: //www.gnu.org/licenses/>.
//=========================================================================
//= @itemall to give item to all players online
//= @itemmap to give item to all players on same map as you
//================= Description===========================================
//= Use command to track a specific player
//================= Current Version=======================================
//= 1.0a
//=========================================================================

-	script	atcmd_item	FAKE_NPC,{

// configuration start
OnInit:
	bindatcmd("itemmap", strnpcinfo(NPC_NAME) +"::OnAtcommanda", 14, 99); // who can use it?
	bindatcmd("itemall", strnpcinfo(NPC_NAME) +"::OnAtcommandb", 14, 99); // who can use it?
	.max = 50; // max amount of items to give out at once
	end;
// configuration end

OnAtcommanda:
	.@type = 1; // @itemmap
	.@gmmap$ = strcharinfo(PC_MAP);
OnAtcommandb:
	if (.@atcmd_numparameters <= 1) { // need to input something
		message(strcharinfo(PC_NAME), sprintf(_$("Usage: %s <Item ID>, <Amount"), .@atcmd_command$));
		message(strcharinfo(PC_NAME), sprintf(_$("%s failed."), .@atcmd_command$));
		end;
	}
	.@itemid = atoi(.@atcmd_parameters$[0]); // check item
	.@amount = atoi(.@atcmd_parameters$[1]);
	if (getitemname(.@itemid) == "null") {
		message(strcharinfo(PC_NAME), "Item not found.");
		end;
	} else if (.@amount == 0 || .@amount > .max) {
		message(strcharinfo(PC_NAME), sprintf(_$("Invalid amount of Items. Needs to be between 1 and %d."), .max));
		end;
	}
	.@self_id = getcharid(CHAR_ID_ACCOUNT);
	if (!.@type)
		.@users = getusers(1);
	else
		.@users = getusers(0);
	while (.@count < .@users) { // Emistry Function
		query_sql("SELECT `account_id`, `name` FROM `char` WHERE `online` = 1 ORDER BY `account_id` LIMIT 128 OFFSET "+.@offset, .@aids, .@name$);
		.@i = 0;
		.@size = getarraysize(.@aids);
		while (.@i < .@size) {
			if (.@aids[.@i] != .@self_id) {
				if (.@type == 1) {
					getmapxy(.@map$, .@x, .@y, 0, .@name$[.@i]);
					if (.@map$ == .@gmmap$) {
						getitem(.@itemid, .@amount, .@aids[.@i]);
						.@gave++;
					}
				} else {
					getitem(.@itemid, .@amount, .@aids[.@i]);
					.@gave++;
				}
			}
			.@count++;
			.@i++;
		}
		.@offset = .@offset + .@size;
		deletearray(.@aids, .@size);
		deletearray(.@name$, .@size);
	}
	dispbottom(sprintf(_$("Gave %d x %s to %d Players."), .@amount, getitemname(.@itemid), .@gave));
}

 

Share this post


Link to post
Share on other sites
  • 0

*getitembound(<item id>, <amount>, <bound type>{, <account ID>})

*getitembound("<item name>", <amount>, <bound type>{, <account ID>})

This command behaves identically to getitem(), but the items created will be bound to the target character as specified by the bound type. All items created in this manner cannot be dropped, sold, vended, auctioned, or mailed, and in some cases cannot be traded or stored.

Valid bound types are:

1 - Account Bound

2 - Guild Bound

3 - Party Bound

4 - Character Bound

Edited by heroji

Share this post


Link to post
Share on other sites
  • 0

thank you sir!

 

one more thing can i remove the limit? because theres 160 players on the map and only 120+ receive the item when i use @itemmap

Share this post


Link to post
Share on other sites
  • 0

this is untested but you could do something similar to:

-	script	mapitem	FAKE_NPC,{
end;

OnCall:
	// @mapitem <nameid> <amount>{, <map>}
	.@nameid$ = .@atcmd_parameters$[0];
	.@amount = atoi(.@atcmd_parameters$[1]);
	.@map$ = strcharinfo(PC_MAP);

	if (.@atcmd_parameters == 3) {
		.@map$ == .@atcmd_parameters$[2];
	} else if (.@atcmd_parameters != 2) {
		dispbottom("mapitem: illegal number of arguments.");
		dispbottom("Usage:");
		dispbottom("@mapitem <nameid> <amount> for the current map");
		dispbottom("@mapitem <nameid> <amount> <map> for another map");
		end;
	}

	if (getmapinfo(MAPINFO_ID, .@map$) < 0) {
		dispbottom(sprintf("mapitem: map `%s` not found.", .@map$));
		end;
	}

	.@itemid = getiteminfo(.@nameid$, ITEMINFO_ID) < 0
		? getiteminfo(atoi(.@nameid$), ITEMINFO_ID)
		: getiteminfo(.@nameid$, ITEMINFO_ID);

	if (.@itemid < 0) {
		dispbottom(sprintf("mapitem: item `%s` does not exist.", .@nameid$));
		end;
	}

	.@nameid$ = getiteminfo(.@itemid, ITEMINFO_AEGISNAME);

	if (.@amount < 0 || .@amount > .max) {
		dispbottom(sprintf("mapitem: trying to give %d `%s`, while the maximum allowed is %d.", .@amount, .@nameid$, .max));
		end;
	}

	.@count = getunits(BL_PC, .@units, false, .@map$);

	freeloop(true);
	for (.@i = 0; .@i < .@count; ++.@i) {
		if (.bound != false) {
			getitembound(.@itemid, .@amount, .bound, .@units[.@i]);
		} else {
			getitem(.@itemid, .@amount, .@units[.@i]);
		}
	}
	freeloop(false);

	.@players = ++.@i; .@total = .@amount * .@players;
	dispbottom(sprintf("mapitem: gave %d `%s` (%d total) to %d players on map `%s`", .@amount, .@nameid$, .@total, .@players, .@map$));
	end;

OnInit:
	bindatcmd("itemmap", "mapitem::OnCall", 14, 99);
	.max = 100;
	.bound = IBT_ACCOUNT; // set to false to disable
}

 

Share this post


Link to post
Share on other sites
  • 0
33 minutes ago, NoOne said:

thank you sir!

 

one more thing can i remove the limit? because theres 160 players on the map and only 120+ receive the item when i use @itemmap

query_sql("SELECT `account_id`, `name` FROM `char` WHERE `online` = 1 ORDER BY `account_id` LIMIT 128 OFFSET "+.@offset, .@aids, .@name$);

or  try change the limit to 200 offset..

Share this post


Link to post
Share on other sites
  • 0

Keep in mind that performing SQL queries is slow, especially when there's 200 rows of results so you should be using getunits() when possible.

If you do not provide a map to getunits() it will search the whole server, just like the SQL query that is used in Ridleys script.

Share this post


Link to post
Share on other sites
  • 0
Just now, meko said:

Keep in mind that performing SQL queries is slow, especially when there's 200 rows of results so you should be using getunits() when possible.

If you do not provide a map to getunits() it will search the whole server, just like the SQL query that is used in Ridleys script.

i see does it also affects your server performance?

Share this post


Link to post
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.   Restore formatting

  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.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.