Thread

projector bot (Sdk)

projector bot // Sdk

1  |  

swe

Sep 13, 2003, 12:00am
aight, well heres some code for a projecter bot i made for aw-europe. ya'll
might it find helpful. isnt commented and is quite messy but hey, better
then nothing! oh, this isnt the same code i posted before! alittle better :)
fixed a few things, and added a back option! to get it to work you will need
2 text files, samples are shown below, under the code! :)

================[Code]========================

//SWE's projector bot!


#include <iostream>
#include <fstream.h>
#include "aw.h"

void citLogin();
void getUrl();

void chatHandle();
void objectClick();
char Speaker[100];
char urls[256][256];
char uniUrl[256];
int uniPort,count;

int screenNumber,screenX,screenZ;
int frameNum = 0;

int main(){

citLogin();
std::cout<<"\nBack in main from citLogin\n";
getUrl();
std::cout<<"\nback in main from getUrl\n";




while (!aw_wait (-1))
;


return 0;
}

void citLogin(){

int citnum,NS,EW,Alt,Av,i,rc;
char password[256],world[256],botName[256];
fstream file;
file.open("cit.txt",ios::in);
if (file.is_open()){
std::cout<<"opened";
}

else{
std::cout<<"failed";
}


file >> citnum >> password >> botName >> world >> NS >> EW >> Alt >> Av >>
Speaker >> uniUrl >> uniPort;

if (rc=aw_init(AW_BUILD)){
std::cout << "unable to login, reason :" <<rc;
}
aw_event_set(AW_EVENT_CHAT,chatHandle);

aw_event_set(AW_EVENT_OBJECT_CLICK,objectClick);

std::cout<<"\ncreated\n";

if (rc=aw_create(uniUrl,uniPort,0)){
std::cout << "unable to login, reason :" <<rc;
}

std::cout<<"\nloging in uni\n";

aw_int_set (AW_LOGIN_OWNER, citnum);
aw_string_set (AW_LOGIN_PRIVILEGE_PASSWORD, password);
aw_string_set (AW_LOGIN_APPLICATION, "SWE's projector bot");
aw_string_set (AW_LOGIN_NAME, botName);

if (rc = aw_login ()) {
printf ("Unable to login (reason %d)\n", rc);
exit (1);
}
std::cout<<"logged in";

if (rc = aw_enter (world)) {
printf ("Unable to enter world (reason %d)\n", rc);
exit (1);
}
std::cout<<"\nentered world\n";

/* announce our position in the world */
aw_int_set (AW_MY_X, EW*1000); /* 1W */
aw_int_set (AW_MY_Z, NS*1000); /* 1N */
aw_int_set (AW_MY_YAW, 0); /* face towards GZ */
if (rc = aw_state_change ()) {
printf ("Unable to change state (reason %d)\n", rc);
exit (1);
}
std::cout<<"\nmoved to position\n";
file.close;
/* main event loop */
}

void chatHandle(){
//std::cout <<"\nchat handle\n";
char newAction[256];
char outMessage[256];
int rc;
if(stricmp(aw_string(AW_CHAT_MESSAGE),"next")==0){
//std::cout <<"message is next";
if(stricmp(aw_string(AW_AVATAR_NAME),Speaker)==0){
//std::cout <<"the right speaker"<<"\n";
frameNum++;
if(frameNum > count)
frameNum=1;
sprintf(newAction,"create picture %s",urls[frameNum]);
std::cout<<newAction<<"\n";
aw_int_set (AW_OBJECT_OLD_NUMBER, screenNumber);
aw_int_set (AW_OBJECT_OLD_X, screenX);
aw_int_set (AW_OBJECT_OLD_Z, screenZ);
aw_string_set (AW_OBJECT_ACTION, newAction);
if (rc = aw_object_change ())
printf ("Unable to change screen (reason %d)\n", rc);
else {
printf ("screen changed.\n");
screenNumber = aw_int (AW_OBJECT_NUMBER);
}

}
}
if (stricmp(aw_string(AW_CHAT_MESSAGE),"last")==0){
if(stricmp(aw_string(AW_AVATAR_NAME),Speaker)==0){
frameNum--;
if(frameNum <= 0)
frameNum=count;
sprintf(newAction,"create picture %s",urls[frameNum]);
std::cout<<newAction<<"\n";
aw_int_set (AW_OBJECT_OLD_NUMBER, screenNumber);
aw_int_set (AW_OBJECT_OLD_X, screenX);
aw_int_set (AW_OBJECT_OLD_Z, screenZ);
aw_string_set (AW_OBJECT_ACTION, newAction);
if (rc = aw_object_change ())
printf ("Unable to change screen (reason %d)\n", rc);
else {
printf ("screen changed.\n");
screenNumber = aw_int (AW_OBJECT_NUMBER);
}

}
}

}

void objectClick(){
std::cout<<"\nobject clicked\n";
if(stricmp(aw_string(AW_AVATAR_NAME),Speaker)==0){
std::cout<<"object clicked by speaker\n";
if(stricmp(aw_string(AW_OBJECT_DESCRIPTION),"screen")==0){
screenNumber = aw_int(AW_OBJECT_NUMBER);
screenX = aw_int(AW_OBJECT_X);
screenZ = aw_int(AW_OBJECT_Z);
std::cout<<"description is screen. object number taken : "<<screenNumber;
aw_say("New projection screen selected!\n");
screenNumber = aw_int(AW_OBJECT_NUMBER);
}
}
}
void getUrl(){

fstream url;
int i;
i = 1;

url.open("pictures.txt",ios::in);


url >> count;

while (count >= i){
url >> urls[i];
i++;
}
url.close();
}


/*=====================[cit.txt]===============================
141 password BotName eu-bots 1 1 1 0 SWE auth.activeworlds.com 5702



=====================[pictures.txt]============================
2 www.kkw.com/hhe01.jpg www.kkw.com/hhe02.jpg



in pictures.txt, the first number is the amount of pictures to show.

in cit.txt, heres how it works: [Citnum] [PPW] [Botname] [World] [NS coord]
[EW coord] [Altitude] [Speaker Citname] [Universe URL] [Universe port]

hope you find it useful.
-SWE

1  |  
Awportals.com is a privately held community resource website dedicated to Active Worlds.
Copyright (c) Mark Randall 2006 - 2024. All Rights Reserved.
Awportals.com   ·   ProLibraries Live   ·   Twitter   ·   LinkedIn