Simple greeter bot: Difference between revisions
Jump to navigation
Jump to search
mNo edit summary |
mNo edit summary |
||
| Line 1: | Line 1: | ||
__TOC__ | |||
==C/C++== | ==C/C++== | ||
In order to use the Virtual Paradise C SDK you must: | In order to use the Virtual Paradise C SDK you must: | ||
Revision as of 04:00, 22 November 2012
C/C++
In order to use the Virtual Paradise C SDK you must:
- Have Visual Studio, Visual C++ Express or another compatible C/C++ IDE+Compiler installed and configured
- Download the x86 SDK from the Developer Downloads page
<C>
- include <vpsdk/VP.h>
- include <stdio.h>
- include <stdlib.h>
- define Username "username"
- define Password "password"
- define Botname "greeterbot"
- 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, "universe.virtualparadise.org", 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>
C#
In order to use the Virtual Paradise .Net SDK you must:
- Have Visual Studio or Visual C# Express installed and configured
- Download the x86 SDK from the Developer Downloads page
- Download the .Net SDK from the VPNet SDK Download page
<CSharp> using System; using VpNet.Core; using VpNet.Core.EventData; using VpNet.Core.Structs;
namespace VPPainball {
class Program
{
//Virtual Paradise SDK Instance
public static Instance VPInstance;
static void Main(string[] args)
{
try
{
//Initalize the Virtual Paradise .Net SDK
VPInstance = new Instance();
//Register the events you wish to capture (Such as avatar entry)
//This must be done AFTER the initalization, but before connection
VPInstance.EventAvatarAdd += EventAvatarAdd;
VPInstance.EventAvatarDelete += EventAvatarDelete;
//Connect to the universe using the default server settings
VPInstance.Connect();
//Login to the universe using your username, password,
//and the desired bot name
VPInstance.Login("Username", "Password", "MyBotName");
//Enter the world
VPInstance.Enter("MyWorld");
//Set the bot's position in the world
VPInstance.UpdateAvatar(0.0f, 0.0f, 0.0f);
//in order to proccess any pending network events and data
//we must repeatedly call the Wait() function
//Here we use a wait of 50 Miliseconds
while (true)
{
VPInstance.Wait(50);
}
}
//This allows us to cleanly catch and handle
//any errors the SDK throws. In normal usage,
//you should handle specific errors, and not
//use a catch-all like the one below.
catch (VpException ex)
{
Console.WriteLine("{0}", ex.Message);
}
//This pauses the console on crash, so that
//you can review the error thrown by the SDK
Console.Read();
}
static void EventAvatarAdd(Instance Sender, Avatar AvatarData)
{
//A user has entered the world (or the bot's range)
//We print the user's name followed by a breif message
VPInstance.Say(AvatarData.Name + " Entered");
}
static void EventAvatarDelete(Instance Sender, Avatar AvatarData)
{
//A user has left the world (or the bot's range)
//We print the user's name followed by a breif message
VPInstance.Say(AvatarData.Name + " Left");
}
}
} </CSharp>
VB .Net
<VBNet> Coming Soon.. </VBNet>