// ******************************************************************************** // // **Creator: Dazzle Licence: Diku Merc Rom Terms ** // // **Difficulty: 3 Snippet: Check Functions ** // // ******************************************************************************** // // ** Contact Information ** // // **Yahoo: ldevil.geo Msn: ldevil@hotmail.com ** // // **Aim: pocketweasle Email: sandstorm@arthmoor.com ** // // **Webpage: http://sandstorm.arthmoor.com ** // // ******************************************************************************** // // **Terms of Usage: ** // // **Follow the Diku, Merc, Rom Licences, also, if you have a snippet helpfile ** // // **Put my name in there, if not, leave my name in the source. ** // // **Also, this code is given AS-IS, straight from my mud, so there will be some ** // // **Effort required to make this work in your mud. ** // // **Install at your own risk, if you have any comments or questions on this ** // // **Visit the website mentioned above, and enter the forum, post and bugs or ** // // **suggestions there. ** // // ******************************************************************************** // Okay, these functions here are rather simple in nature, put them into your merc.h file // *leave the function* // #define CheckCh(ch) \ if(!ch) \ { \ nlogf("%s: null ch!", __FUNCTION__); \ return; \ } // *Use on non_npc commands* // #define CheckNpc(ch) \ if(ch && IsNpc(ch)) \ { \ ch->Send("%s\n\r", "Huh?"); \ return; \ } // *Check if ch exists, and if ch is a npc (both checks from above in 1)* // #define CheckNpcCh(ch) \ if(ch) \ { \ if(IsNpc(ch)) \ { \ ch->Send("%s\n\r", "Huh?"); \ return; \ } \ } \ else \ { \ nlogf("%s: null ch!", __FUNCTION__); \ return; \ } Now, if you want to check if the ch exists first, we recommend putting CheckCh(ch) at the top of the function, before anything todo with the ch, Now, if you want to stop npc's from using the command, you can put this. You simply put it in CheckNpc(ch); after the initial setup of the function, before it does anything else with the ch variable. If you are going to put both of the above in a function, we'd recommend using this one instead CheckNpcCh(ch); Because this function checks for both npc and if the ch is infact a valid, and not null. My mud uses these functions not only in commands, but in other functions, solong as the function is void whatever, these will work in them, if say you use CheckCh(ch); on a int function, it will complain that it is not returing a variable. You can simply make fixes for that by creating functions for each type, which i recommend doing if you use these functions allot, or have allot of int variables which you wish to check first with the functions.