Simple greeter bot

From Virtual Paradise Wiki
Revision as of 16:26, 23 October 2007 by Edwin (talk | contribs)
Jump to navigation Jump to search

<C>

  1. include <vpsdk/VP.h>
  2. include <stdio.h>
  3. include <stdlib.h>
  1. define Username "username"
  2. define Password "password"
  3. define Botname "greeterbot"
  4. define Worldname "VP-Gate"

void event_avatar_add(VPInstance sdk);

int main(int argc, char ** argv) {

   int err;
   if(err = vp_init(VPSDK_VERSION))
   {
       printf("Couldn't initialize VP API(reason %d)", err);
       return 1;
   }
   VPInstance sdk;
   sdk = vp_create();
   if(err = vp_connect_universe(sdk, "virtualparadise.gotdns.com", 57000))
   {
       printf("Couldn't connect to universe(reason %d)", err);
       return 1;
   }
   
   if(err = vp_login(sdk, Username, Password, Botname))
   {
       printf("Couldn't login(reason %d)", err);
       return 1;
   }
   
   if(err = vp_enter(sdk, Worldname))
   {
       printf("Couldn't enter world(reason %d)", err);
       return 1;
   }
   
   vp_event_set(sdk, VP_EVENT_AVATAR_ADD, event_avatar_add);
   
   while(1)
   {
       vp_wait(sdk, 100);
   }
   return 0;

}

void event_avatar_add(VPInstance sdk) {

   char message[100];
   sprintf((char*)&message, "Hello, %s!", vp_string(sdk, VP_AVATAR_NAME));
   vp_say(sdk, (char*)&message);

} </C>