Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
2 registered members (AndrewAMD, TipmyPip), 13,353 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
ANET #286597
08/26/09 05:30
08/26/09 05:30
Joined: May 2009
Posts: 37
S
shiznitIII Offline OP
Newbie
shiznitIII  Offline OP
Newbie
S

Joined: May 2009
Posts: 37
Hi guys I need help on ANET. I read a the manual but I having a road block. This is my project:
I have a game where I have up to 5 players. It's an educational game for kids. Each player(kid) will select an animal from the option and then they will also select a color from the options. The other players can see each player's selected animal and color and when they point their mouse on the entity, there is a voice recording of the animal and color. (example brown dog). Here is what I did:

1. I initialized the server and client as localhost
2. for the players(kids), they have a different client program
3. When they click the option for the animal, the other players can already see but when they select the color, it doesnt update. only the player can see his color change not the others.
4. I'm using material to change the color of the entity.

I need help up to this point first. thank you

Re: ANET [Re: shiznitIII] #286600
08/26/09 06:23
08/26/09 06:23
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
you must create an user event, an example is in the "Simple 3D Chat" on the ANET Homepage.
With an userevent you can send events like "client connected" or "client synchronized" with an string and the id of the user.
I would send an user event with a string of the lenght of 1.
the string contains e.g. "y" for yellow or "r" for red.
Now you can change the color of the animal on all clients.


Visit my site: www.masterq32.de
Re: ANET [Re: MasterQ32] #286602
08/26/09 06:47
08/26/09 06:47
Joined: May 2009
Posts: 37
S
shiznitIII Offline OP
Newbie
shiznitIII  Offline OP
Newbie
S

Joined: May 2009
Posts: 37
Thanks. But players can change the color of the animals and they can change their animals anytime during the game. Like what i mentioned, there is no problem when they select or change the animals, its when they change the color. Also I added an event_touch but only the player can do that with their own animal. I also included event_click and same problem. This is some part of my code:

// Panel for color selection
PANEL* color_pan =
{
layer = 2;
pos_x = 500;
pos_y = 0;
button (0, 10, "blue.pcx", "blue.pcx", "blue.pcx", entity_color, NULL, func_over_color_sound);
button (55, 10, "brown.pcx", "brown.pcx", "brown.pcx", entity_color, NULL, func_over_color_sound);
button (110, 10, "black1.pcx", "black1.pcx", "black1.pcx",entity_color, NULL, func_over_color_sound);

// flags = OVERLAY | SHOW;
}

// Panel for animal selection
PANEL* charac_pan =
{
layer = 3;
pos_x = 0;
pos_y = 0;
button (10, 0, "horse1.tga", "horse1.tga", "horse3.tga", create_entity, NULL, func_over_entity_sound);
button (120, 0, "pig1.tga", "pig1.tga", "pig2.tga", create_entity, NULL, func_over_entity_sound);
button (230, 0, "bat1.tga", "bat1.tga", "bat2.tga", create_entity, NULL, func_over_entity_sound);
// flags = OVERLAY | SHOW;
}
// Initiate client-server connection
void start_clientserver()
{
enet_init(); //ENet is initialized

enet_svset_event(EVENT_CONNECTED,_str("client_connected"));
// enet_svset_event(EVENT_DISCONNECTED,_str("client_disconnected"));

enet_server = enet_init_server(2300,5,_str("")); //initializes the server with port 2300,
enet_client = enet_init_client(_str("127.0.0.1"),2300,_str("")); //Initializes a client
}

// character entity 1 event
void char_ent1_event()
{
if (event_type == EVENT_TOUCH)
{
my.ambient = 100;
my.lightrange = 20;
}

else
{
if (event_type == EVENT_RELEASE)
{
my.ambient = 0;
my.lightrange = 0;
}
}

if (event_type == EVENT_CLICK)
{
active_entity = 1;
media_stop(soundhandle1);
str_cpy(sound1,"horse effect1.mp3");
soundhandle1 = media_play(sound1,NULL,50);

move_percentage = 0;
str_cpy(action_str, "gallop");

while (1)
{
ent_animate(my,action_str,move_percentage, ANM_CYCLE);
move_percentage += speed * time_step;
move_percentage %= 100;
wait (1);
}
}
}

// character entity 2 event
void char_ent2_event()
{
if (event_type == EVENT_TOUCH)
{
my.ambient = 100;
my.lightrange = 20;
}

else
{
if (event_type == EVENT_RELEASE)
{
my.ambient = 0;
my.lightrange = 0;
}
}

if (event_type == EVENT_CLICK)
{
active_entity = 2;
media_stop(soundhandle1);
str_cpy(sound1,"pig effect1.mp3");
soundhandle1 = media_play(sound1,NULL,50);

move_percentage = 0;
str_cpy(action_str, "kosma");

while (1)
{
ent_animate(my,action_str,move_percentage, ANM_CYCLE);
move_percentage += speed * time_step;
move_percentage %= 100;
wait (1);
}
}
}

// character entity 3 event
void char_ent3_event()
{
if (event_type == EVENT_TOUCH)
{
my.ambient = 100;
my.lightrange = 20;
}

else
{
if (event_type == EVENT_RELEASE)
{
my.ambient = 0;
my.lightrange = 0;
}
}

if (event_type == EVENT_CLICK)
{
active_entity = 3;
media_stop(soundhandle1);
str_cpy(sound1,"bat2.mp3");
soundhandle1 = media_play(sound1,NULL,100);

move_percentage = 0;
str_cpy(action_str, "fly");

while (1)
{
ent_animate(my,action_str,move_percentage, ANM_CYCLE);
move_percentage += speed * time_step;
move_percentage %= 100;
wait (1);
}
}
}


// animal 1 action
void char_ent1_action()
{
//wait until the entity has a global pointer:
while(enet_ent_globpointer(my) == -1) {wait(1);}

my.pan = 280;
ent_setskin(my,NULL,0);
media_stop(soundhandle1);

my.emask |= (ENABLE_TOUCH | ENABLE_RELEASE | ENABLE_CLICK);
my.event = char_ent1_event;
}

// animal 2 action
void char_ent2_action()
{
//wait until the entity has a global pointer:
while(enet_ent_globpointer(my) == -1) {wait(1);}

my.pan = 200;
ent_setskin(my,NULL,0);
media_stop(soundhandle1);

my.emask |= (ENABLE_TOUCH | ENABLE_RELEASE | ENABLE_CLICK);
my.event = char_ent2_event;
}

// animal 3 action
void char_ent3_action()
{
//wait until the entity has a global pointer:
while(enet_ent_globpointer(my) == -1) {wait(1);}

my.pan = 200;
ent_setskin(my,NULL,0);
media_stop(soundhandle1);

my.emask |= (ENABLE_TOUCH | ENABLE_RELEASE | ENABLE_CLICK);
my.event = char_ent3_event;
}

// Function when mouse is over button. Entity sounds
void func_over_entity_sound(var butt)
{
if (butt == 1)
{
str_cpy(sound2,"horse.mp3");
soundhandle2 = media_play(sound2,NULL,100);
}

if (butt == 2)
{
str_cpy(sound2,"pig.mp3");
soundhandle2 = media_play(sound2,NULL,100);
}

if (butt == 3)
{
str_cpy(sound2,"bat.mp3");
soundhandle2 = media_play(sound2,NULL,100);
}
}

// Function when mouse is over button. color sounds
void func_over_color_sound(var butt)
{
if (butt == 1)
{
str_cpy(sound2,"blue.mp3");
soundhandle2 = media_play(sound2,NULL,100);
}

if (butt == 2)
{
str_cpy(sound2,"brown.mp3");
soundhandle2 = media_play(sound2,NULL,100);
}

if (butt == 3)
{
str_cpy(sound2,"black.mp3");
soundhandle2 = media_play(sound2,NULL,100);
}
}

// create first animal
void create_entity(var butt)
{
if (active_entity == 1)
{
enet_ent_remove(enet_ent_globpointer(char_ent1));
//ptr_remove(char_ent1);
}

if (active_entity == 2)
{
enet_ent_remove(enet_ent_globpointer(char_ent2));
// ptr_remove(char_ent2);
}

if (active_entity == 3)
{
enet_ent_remove(enet_ent_globpointer(char_ent3));
// ptr_remove(char_ent3);
}

if (butt == 1)
{
char_ent1 = enet_ent_create(_str("horse.mdl"),vector(200,-50,-50),_str("char_ent1_action"));
str_cpy(action_str, "gallop");
active_entity = 1;
}

if (butt == 2)
{
char_ent2 = enet_ent_create(_str("boar.mdl"),vector(300,50,-75),_str("char_ent2_action"));
str_cpy(action_str, "kosma");
active_entity = 2;
}

if (butt == 3)
{
char_ent3 = enet_ent_create(_str("bat.mdl"),vector(400,50,50),_str("char_ent3_action"));
str_cpy(action_str, "fly");
active_entity = 3;
}
}

// set animal color 1
void entity_color(var butt)
{
if (butt == 1)
{
if (active_entity == 1)
{
ent_mtlset (char_ent1, mtlcolor1, 0);
}
if (active_entity == 2)
{
ent_mtlset (char_ent2, mtlcolor1, 0);
}
if (active_entity == 3)
{
ent_mtlset (char_ent3, mtlcolor1, 0);
}
}

if (butt == 2)
{
if (active_entity == 1)
{
ent_mtlset (char_ent1, mtlcolor2, 0);
}
if (active_entity == 2)
{
ent_mtlset (char_ent2, mtlcolor2, 0);
}
if (active_entity == 3)
{
ent_mtlset (char_ent3, mtlcolor2, 0);
}
}

if (butt == 3)
{
if (active_entity == 1)
{
ent_mtlset (char_ent1, mtlcolor3, 0);
}
if (active_entity == 2)
{
ent_mtlset (char_ent2, mtlcolor3, 0);
}
if (active_entity == 3)
{
ent_mtlset (char_ent3, mtlcolor3, 0);
}
}
}

Re: ANET [Re: shiznitIII] #286603
08/26/09 06:50
08/26/09 06:50
Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
MasterQ32 Offline
Expert
MasterQ32  Offline
Expert

Joined: Nov 2007
Posts: 2,568
Germany, BW, Stuttgart
you can use the system also to changing the color!


Visit my site: www.masterq32.de
Re: ANET [Re: MasterQ32] #286641
08/26/09 09:27
08/26/09 09:27
Joined: May 2009
Posts: 37
S
shiznitIII Offline OP
Newbie
shiznitIII  Offline OP
Newbie
S

Joined: May 2009
Posts: 37
could you please show me how to do that. thanks

Re: ANET [Re: shiznitIII] #286902
08/28/09 07:04
08/28/09 07:04
Joined: Jul 2005
Posts: 1,930
Austria
Dark_samurai Offline
Serious User
Dark_samurai  Offline
Serious User

Joined: Jul 2005
Posts: 1,930
Austria
Everytime you change the color you send the event function:

Code:
//Do it on the player that changed the color!

//I used event number 20 for the change color event:
enet_svset_event(20,_str("change_color_event"));
enet_clset_event(20,_str("change_color_event"));

//do this for changing into yellow:
enet_clsend_event(20,_str("y"),-1);
//do this for changing into blue:
enet_clsend_event(20,_str("b"),-1);
//and so on.

//This function will be called on all participants when you use the enet_clsend_event(20,...); function:
function change_color_event(var sender, STRING* msg)
{
   if(str_cmp(msg,"y") == 1)
   {//yellow
   }
   if(str_cmp(msg,"b") == 1)
   {//blue
   }
   //and so on
}



Btw. you should read through the ANet HowTos of the manual and the 3d chat example tutorial, it explains everything you need for a multiplayer game with ANet.


ANet - A stable and secure network plugin with multi-zone, unlimited players, voip, server-list features,... (for A7/A8)!
get free version

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1