i figured i might as well put two guides into one, don't ask me why, i just did :P
Find Faction ID's
Before you find out how to get the faction ID's, you might be content with just having a list of them, why didn't i just post a list instead of the guide? because the list was made after the guide, anyway here it is, Hypersniper made a script which used my method to get the NPC faction ID's. http://pastebin.com/YUL2iWVF
ok so finding faction ID's, you might think this is as easy as looking in faction.dbc, but it's not, the faction ID's there only work for quests and items, they don't work for NPC's. but the client/server has to be pulling those NPC factions from somewhere right? well after a bit of testing i found out that -
"warning, this may confuse you, if it does don't panic, you don't actually need to know it"
the field1 in Factiontemplate.dbc corresponds to the ID in faction.dbc, so the client/server pulls the ID's and faction info from factiontemplate.dbc and then gets field1 in there and then uses that number to get the faction name (and perhaps other values) from faction.dbc
"confusing part over"
so if you want to get the ID for a for a faction you:
1. look in faction.dbc and get the ID # of the faction you want
2. find that # in field1 of factiontemplate.dbc
3. get the ID next to that field1, that ID is your NPC faction ID.
this may sound confusing but when you actually do this you will find out that it is actually just as easy as looking up the ID's in the DB if not easier and it is more reliable.
Making Guards
Now moving on to making guards, this is a very simple thing to do but i find that a lot of people have trouble figuring this out.
to make an NPC that is friendly to both Horde and Alliance, that does not attack PvPers nearby but does attack any nearby hostile NPC's (any NPC's that are hostile to all players) set their faction to 1857.
to make the ultimate guard that attacks anyone who PvPs nearby and attacks hostile NPC's simply set the NPC's guardtype to 2 in the creature_proto table. (this has only been tested for Arcemu, i don't know if there is a similar column in other cores)