Count a specific item
Moderator: POL Developer
- ghibli1983
- New User
- Posts: 27
- Joined: Mon Apr 23, 2018 1:36 pm
- Location: Italy
- Contact:
Count a specific item
Goodmorning everyone
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!
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!
Re: Count a specific item
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.
-
- Distro Developer
- Posts: 2825
- Joined: Thu Feb 02, 2006 1:41 pm
- Location: San Antonio, Texas
- Contact:
Re: Count a specific item
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.
- ghibli1983
- New User
- Posts: 27
- Joined: Mon Apr 23, 2018 1:36 pm
- Location: Italy
- Contact:
Re: Count a specific item
Thnk's guys
maybe use the ReadFile( filename ) for read a string in the items.txt
is the right way?
maybe use the ReadFile( filename ) for read a string in the items.txt
is the right way?
-
- Distro Developer
- Posts: 2825
- Joined: Thu Feb 02, 2006 1:41 pm
- Location: San Antonio, Texas
- Contact:
Re: Count a specific item
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.
- ghibli1983
- New User
- Posts: 27
- Joined: Mon Apr 23, 2018 1:36 pm
- Location: Italy
- Contact:
-
- Distro Developer
- Posts: 2825
- Joined: Thu Feb 02, 2006 1:41 pm
- Location: San Antonio, Texas
- Contact:
Re: Count a specific item
Try searching for 0xeed.
-
- Distro Developer
- Posts: 2825
- Joined: Thu Feb 02, 2006 1:41 pm
- Location: San Antonio, Texas
- Contact:
Re: Count a specific item
Try searching for 0xeed. Remember you are searching a text file. The strings have to match
Re: Count a specific item
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.
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.
- ghibli1983
- New User
- Posts: 27
- Joined: Mon Apr 23, 2018 1:36 pm
- Location: Italy
- Contact:
Re: Count a specific item
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
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
-
- Distro Developer
- Posts: 2825
- Joined: Thu Feb 02, 2006 1:41 pm
- Location: San Antonio, Texas
- Contact:
Re: Count a specific item
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.
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.
- ghibli1983
- New User
- Posts: 27
- Joined: Mon Apr 23, 2018 1:36 pm
- Location: Italy
- Contact:
Re: Count a specific item
SOLVED,
thank's to everywhone for help me and i want send a SPECIAL THANK'S to guialtran
I LEARNED MANY THINGS THANKS TO HIM
thank's to everywhone for help me and i want send a SPECIAL THANK'S to guialtran
I LEARNED MANY THINGS THANKS TO HIM
Re: Count a specific item
you can modify this function and can count any item in the game.
-
- Distro Developer
- Posts: 2825
- Joined: Thu Feb 02, 2006 1:41 pm
- Location: San Antonio, Texas
- Contact:
Re: Count a specific item
Any possibility that you can post the function for others who might want to use it?
Re: Count a specific item
this was done for an old core.
to run on the core 100 some modifications are required.
to run on the core 100 some modifications are required.
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
-
- Distro Developer
- Posts: 2825
- Joined: Thu Feb 02, 2006 1:41 pm
- Location: San Antonio, Texas
- Contact:
Re: Count a specific item
Thank you guialtran.