Simple greeter bot: Difference between revisions

From Virtual Paradise Wiki
Jump to navigation Jump to search
mNo edit summary
mNo edit summary
Line 43: Line 43:
     vp_event_set(sdk, VP_EVENT_AVATAR_ADD, event_avatar_add);
     vp_event_set(sdk, VP_EVENT_AVATAR_ADD, event_avatar_add);
      
      
     while(1)
     vp_state_change(sdk);
     {
      
        vp_wait(sdk, 100);
    while(vp_wait(sdk, 1000) == 0){}
    }
     return 0;
     return 0;
}
}

Revision as of 21:57, 23 January 2008

<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);
   
   vp_state_change(sdk);
   
   while(vp_wait(sdk, 1000) == 0){}
   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>