The vast majority of the headgears in the game should already have costume equivalents in renewal's item-db, you can simply copy these into pre-re's item-db if your server is pre-re and they will work. Similarly, these ones should already be present in iteminfo.lua.
It is only necessary to add them manually for the handful of headgears that aren't already there. If you're getting "unknown item", check that the id number in the lua matches the id number of the item in the item-db. For example, slotted jacket is id number 2304, so the entry in the lua file must be [2304]. If you're adding new items to the item-db, make sure the id numbers in both locations match up.
For that script error you're getting, it's complaining that it doesn't recognize the "costume" function. I'm not familiar with that code (it's not from my implementation), but it would need to be declared in script.hpp and script.cpp so scripts can use it.