Count a specific item

Get Help on scripting in POL with configurations, config setups, script trouble shooting, etc.

Moderator: POL Developer

Post Reply
User avatar
ghibli1983
New User
Posts: 20
Joined: Mon Apr 23, 2018 1:36 pm
Location: Italy
Contact:

Count a specific item

Post by ghibli1983 » Tue Jul 17, 2018 1:51 am

Goodmorning everyone :D

I have a question, is possible count a specific item in the server,

exmple: count amount the gold coins in the server (objtype 0x0eed)?
What do you advise me to do?
thank you for your attention and your time! 8)

User avatar
CWO
POL Expert
Posts: 1139
Joined: Sat Feb 04, 2006 5:49 pm
Location: Chicago, IL USA
Contact:

Re: Count a specific item

Post by CWO » Tue Jul 17, 2018 3:11 am

POL has no direct function to list all of the items on the server and trying to do the set of functions to list everything would likely freeze your server for a while. The best thing you can do is write something that reads items.txt directly.

Yukiko
Distro Developer
Posts: 2452
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Count a specific item

Post by Yukiko » Tue Jul 17, 2018 9:20 am

If you only need to know about the items in the "physical world" reading items.txt is probably the most efficient way to get a count of a specific item. If the item you are counting is equipable you will also need to parse pcequip.txt and npcequip.txt. However if you also want to know if that item exists in bank boxes, backpacks, pouches, bags, crates, barrels, chests, and any other storage area you will also need to parse the storage.txt file as well.
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

User avatar
ghibli1983
New User
Posts: 20
Joined: Mon Apr 23, 2018 1:36 pm
Location: Italy
Contact:

Re: Count a specific item

Post by ghibli1983 » Tue Jul 17, 2018 9:26 am

Thnk's guys :cheesy:

maybe use the ReadFile( filename ) for read a string in the items.txt

is the right way?

Yukiko
Distro Developer
Posts: 2452
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Count a specific item

Post by Yukiko » Tue Jul 17, 2018 11:33 am

Yes but when you get my PM you will see you also have to parse the "equip" files as well, pcequip.txt and npcequip.txt.
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

User avatar
ghibli1983
New User
Posts: 20
Joined: Mon Apr 23, 2018 1:36 pm
Location: Italy
Contact:

Re: Count a specific item

Post by ghibli1983 » Tue Jul 17, 2018 11:47 am

Yukiko wrote:
Tue Jul 17, 2018 11:33 am
Yes but when you get my PM you will see you also have to parse the "equip" files as well, pcequip.txt and npcequip.txt.
i just reply , but in my pol in the data file don't match a gold coins (0x0eed) :grouphug:

Yukiko
Distro Developer
Posts: 2452
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Count a specific item

Post by Yukiko » Tue Jul 17, 2018 4:06 pm

Try searching for 0xeed.
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

Yukiko
Distro Developer
Posts: 2452
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Count a specific item

Post by Yukiko » Tue Jul 17, 2018 4:06 pm

Try searching for 0xeed. Remember you are searching a text file. The strings have to match :)
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

guialtran
Adept Poster
Posts: 84
Joined: Wed Jul 30, 2008 12:42 pm

Re: Count a specific item

Post by guialtran » Tue Jul 17, 2018 11:55 pm

you will have trouble reading the StorageAreas containers in the plural, ie all areas created to create virtual containers.

in the StorageAreas module there is no function to list these containers.

if you have created some system that when creating a StorageAreas it registers this same name in a datafile it would be possible, to sweep all the containers.

or look for the item that has the virtual container and look for this container in it.
example
a character has a StorageArea container
a boat (new), the old is a normal item, has a StorageArea
The guild pillar has a StorageArea.

taking this problem you just have to look for all the accounts look in their backpacks and then look for the whole map.

User avatar
ghibli1983
New User
Posts: 20
Joined: Mon Apr 23, 2018 1:36 pm
Location: Italy
Contact:

Re: Count a specific item

Post by ghibli1983 » Wed Jul 18, 2018 3:11 am

i need to count all gold coins in the world, i just modify the item array with an integer props,

now the props work, in all coin read a prop, now i need to write a system for search this prop and count the gold coin.

Is the right way?
thank's a lot to all

Yukiko
Distro Developer
Posts: 2452
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Count a specific item

Post by Yukiko » Wed Jul 18, 2018 8:42 am

If this is a new shard you could have an Create and Destroy script for gold coins. Every time a gold coin is created it would add the amount created to a Global Property and when they are destroyed it would subtract the amount from the Global Property. This would only work for a server that is new.

As far as an existing server I think searching the world data files is the only way to get an accurate count but you will have to write a script to do it.
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

User avatar
ghibli1983
New User
Posts: 20
Joined: Mon Apr 23, 2018 1:36 pm
Location: Italy
Contact:

Re: Count a specific item

Post by ghibli1983 » Thu Jul 19, 2018 7:44 am

SOLVED,
:bacondance: :bacondance:
thank's to everywhone for help me and i want send a SPECIAL THANK'S to guialtran
I LEARNED MANY THINGS THANKS TO HIM :cheesy: :cheesy:
SOLVED.PNG
ALL GOLD COUNT IN THE SHARD
SOLVED.PNG (160.73 KiB) Viewed 174 times

guialtran
Adept Poster
Posts: 84
Joined: Wed Jul 30, 2008 12:42 pm

Re: Count a specific item

Post by guialtran » Fri Jul 20, 2018 8:35 am

you can modify this function and can count any item in the game. :whip:

Yukiko
Distro Developer
Posts: 2452
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Count a specific item

Post by Yukiko » Fri Jul 20, 2018 8:39 am

Any possibility that you can post the function for others who might want to use it?
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

guialtran
Adept Poster
Posts: 84
Joined: Wed Jul 30, 2008 12:42 pm

Re: Count a specific item

Post by guialtran » Fri Jul 20, 2018 11:12 am

this was done for an old core.
to run on the core 100 some modifications are required.
:deadhorse:

Code: Select all

//use storage;//old pol remove this
use uo;
use os;
//program textcommand(character, text, uc_text, langcode)
program my_countgold( chr )
	set_script_option(SCRIPTOPT_NO_INTERRUPT,1);
	set_script_option(SCRIPTOPT_DEBUG,0);
	set_script_option(SCRIPTOPT_NO_RUNAWAY,1);
	var slots := 5;
	var acct;
	var i;
	var countbank := 0;
	var countbackpack := 0;
	var countmap := 0;
	var countcontainer:= 0;
	var charref;
	var worldbank := FindStorageArea( "World Bank" );
	if(!worldbank)
		SendSysMessage(chr,"World Bank Error"+ worldbank );
		return;
	endif
	foreach nameacc in (ListAccounts())
		acct := FindAccount(nameacc);
		if( acct )
			i := slots;
			while( i )
				charref := acct.getcharacter(i);
				if( charref )
					//conta o banco
					var boxname  := ("Bankbox of "+charref.serial);
					var bankbox := FindRootItemInStorageArea( worldbank, boxname );
					if( bankbox )
						my_CountContainer( bankbox, countbank );
					endif
					//conta a backpack
					if(charref.backpack)
						my_CountContainer( charref.backpack, countbackpack );
					endif
				endif
				i:=i-1;//i+=1;
			endwhile
		endif
	endforeach
	//contar mapa
	foreach elem in (ListObjectsInBox( 0,0,-128, 6144,4096,127 ))//old pol
		if(elem.isa(POLCLASS_CONTAINER))
			my_CountContainer( elem, countcontainer );
		elseif(elem.objtype == 0xEED)
			countmap:=countmap+elem.amount;//countmap+=elem.amount;
		endif
	endforeach
	SendSysMessage(chr,"Total Gold Banks: "+ countbank );
	SendSysMessage(chr,"Total Gold Backpacks: "+ countbackpack );
	SendSysMessage(chr,"Total Gold Map: "+ countmap );
	SendSysMessage(chr,"Total Gold Container in Map: "+ countcontainer );
	var total := Cstr(countbank+countbackpack+countmap+countcontainer);
	for(i:=(len(total)-3);i>=1;i:=i-3)
		total[i]:=total[i]+".";
	endfor
	SendSysMessage(chr,"Total Total XD Gold: "+ total );
endprogram

function my_CountContainer( container, byref count )
	foreach elem in (EnumerateItemsInContainer( container ))
		if(elem.objtype == 0xEED)
			count:=count+elem.amount;//count+=elem.amount;
		endif
	endforeach
endfunction

Yukiko
Distro Developer
Posts: 2452
Joined: Thu Feb 02, 2006 1:41 pm
Location: San Antonio, Texas
Contact:

Re: Count a specific item

Post by Yukiko » Fri Jul 20, 2018 4:16 pm

Thank you guialtran.
Sincerely,
Yukiko

I would tell you a UDP joke but you might not get it.

Titus 2:13

Post Reply