Page 1 of 1

Count a specific item

Posted: Tue Jul 17, 2018 1:51 am
by ghibli1983
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)

Re: Count a specific item

Posted: Tue Jul 17, 2018 3:11 am
by CWO
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.

Re: Count a specific item

Posted: Tue Jul 17, 2018 9:20 am
by Yukiko
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.

Re: Count a specific item

Posted: Tue Jul 17, 2018 9:26 am
by ghibli1983
Thnk's guys :cheesy:

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

is the right way?

Re: Count a specific item

Posted: Tue Jul 17, 2018 11:33 am
by Yukiko
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.

Re: Count a specific item

Posted: Tue Jul 17, 2018 11:47 am
by ghibli1983
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:

Re: Count a specific item

Posted: Tue Jul 17, 2018 4:06 pm
by Yukiko
Try searching for 0xeed.

Re: Count a specific item

Posted: Tue Jul 17, 2018 4:06 pm
by Yukiko
Try searching for 0xeed. Remember you are searching a text file. The strings have to match :)

Re: Count a specific item

Posted: Tue Jul 17, 2018 11:55 pm
by guialtran
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.

Re: Count a specific item

Posted: Wed Jul 18, 2018 3:11 am
by ghibli1983
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

Re: Count a specific item

Posted: Wed Jul 18, 2018 8:42 am
by Yukiko
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.

Re: Count a specific item

Posted: Thu Jul 19, 2018 7:44 am
by ghibli1983
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:
ALL GOLD COUNT IN THE SHARD
ALL GOLD COUNT IN THE SHARD
SOLVED.PNG (160.73 KiB) Viewed 42576 times

Re: Count a specific item

Posted: Fri Jul 20, 2018 8:35 am
by guialtran
you can modify this function and can count any item in the game. :whip:

Re: Count a specific item

Posted: Fri Jul 20, 2018 8:39 am
by Yukiko
Any possibility that you can post the function for others who might want to use it?

Re: Count a specific item

Posted: Fri Jul 20, 2018 11:12 am
by guialtran
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

Re: Count a specific item

Posted: Fri Jul 20, 2018 4:16 pm
by Yukiko
Thank you guialtran.