There is also a support add-on for max slots. Like, Sub's code, if you change that other than 5, the support add-on will fix the slot numbers to all the clients that use that certain datablock based on the slot count.
To find out how many items a player has, you could do something like:
for(%i=0;%i<%player.getDatablock().maxTools;%i++)
{
%tool = %player.tool[%i];
if(isObject(%tool))
%tools++;
}
return %tools;