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
1 registered members (TipmyPip), 18,633 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
Page 1 of 2 1 2
movement not working :( #93445
10/07/06 10:34
10/07/06 10:34
Joined: Sep 2006
Posts: 108
J
Jered Offline OP
Member
Jered  Offline OP
Member
J

Joined: Sep 2006
Posts: 108
hey guys, going to post my entire script here. For some reason the character will turn, and aninamte, but when I try to go forward or backward, all I get is the animation and no movement. Everything i got is from Locoweeds tutorial. I know the code is a mess, and this is just trial error right now, as I am trying to learn how to script from the multiplayer perspective....however I can not seem to get to get the character to move.

please note that functions, and actions and stuff may not be in the proper order (they all work, but I have moved things around here recently to try and take care of other bugs I have ran into...I will get everything back in the proper place probably tomorrow (I have a backup copy with the functions, actions, and such in the proper order if you need that..can just post it if need be)..as I do not have time to before I post this...any help would be great!



// anything that you need to find QUICKLY (most needed areas) will be a box that looks like this:

/*************************
* *
* something in here *
* *
*************************/

not sure why it has all the star boxes screwed up ( in this post)...they all look like this in my script:

/****************
* ........................ *
* something in here *
* ........................ *
****************/

(without the periods)

// things that fit fit below the important categories are broke down using this:

//----------------------------------------------------------------------------

// anything that is important that is not in the star box can be found by looking through the sections that are seperated with
// the dotted line. (kind of like the submenu of the words in the star box.)

//I am doing this to make this code as easy as possible to find what you need to fix, easier to follow the logic
//of the script, and keep up with what is going on.






/************
* *
* Paths *
* *
************/

path ".\\wads";

path ".\\Sounds";

path ".\\Models";

path ".\\Entities";

path ".\\Bitmaps";


//---------------------------------------------------------------------------------------------------------------------------------










/***************
* *
* Defines *
* *
***************/

//------------------------------------------------------------------------------------------------------------------------------
//Boolean....instead of using 1 for true and 0 for false...we make it easier to read the script...tyoing false will equel 0 now.
define FALSE, 0;
define TRUE, 1;



//------------------------------------------------------------------------------------------------------------------------------
//Animation states
define ANIMATION_STATE_STAND, 0;
define ANIMATION_STATE_WALK, 1;
define ANIMATION_STATE_RUN, 2;
define ANIMATIONE_STATE_ATTACK, 3;




//------------------------------------------------------------------------------------------------------------------------------
//Animation speeds
define PLAYER_ANIM_WALK_SPEED, 6; // animation speed for "walk"
define PLAYER_ANIM_RUN_SPEED, 8; // " " run
define PLAYER_ANIM_BLEND_SPEED, 10; // " " blending the animation


//------------------------------------------------------------------------------------------------------------------------------

// Number of players aloud on the server at one time?
define MAX_CONNECTIONS, 4; // With the comercial version the max is 4.




//------------------------------------------------------------------------------------------------------------------------------

// Define PROFESSION Types below here ( whatever profesions you will have in your game....like a cop, or burgler, or carpentor)
// EXAMPLE define for a profession: define Pro_Carpenter, 1;
// second EXAMPLE: define Metal_Worker, 2;
// setup: define variable_name, identification_number;








//------------------------------------------------------------------------------------------------------------------------------

//below here add the defines for SKILL defienitions
// EXAMPLE: define armor_class, skill30; // armor class of the entity
// setup: define variable_name, skill#;

define player_number, skill1; // player number that this entity is owned by.
define profession, skill2; // entity's prefession.
define speed, skill3; // entity's run speed.
define health, skill4; // entity's health.
define max_health, skill5; // Maximum health of the entity.
define armor_class, skill6; // Armor class of the entity.
define power_pool, skill7; // entity's power.
define max_power, skill8; // Maximum power for the entity.
define class, skill9; // the class that the player chose
define force_x, skill10; // current forces for this entity
define force_y, skill11; // " "
define force_z , skill12; // " "
define current_anim_percent, skill13; //current animation percent
define blend_anim_percent, skill14; //blending animation percent
define animation_state, skill15; //animation state
define prev_anim_state, skill16;
define weapon, skill17; // weapon ID that this ent wields






//------------------------------------------------------------------------------------------------------------------------------
// in this section you should define any CLASSES that you may have
//EXAMPLE: define Templar, skill23;
// setup: define variable_name, skill#
//EXAMPLE 2: define Wizard, 3;
//setup: define cariable_name, value;


define cleric, 10;
define wizzard, 11;





//------------------------------------------------------------------------------------------------------------------------------
// Class speeds

define wizzard_speed, 11; // speed of a vizzard
define cleric_speed, 12; // speed of a cleric
define officer_speed, 13; // speed of an officer



//Class's max health

define wizzard_max_hp, 50;
define cleric_max_hp, 34;
define ooficer_max_hp, 63;


// Class's Armor class

define wizzard_ac, 7;
define cleric_ac, 5;
define officer_ac, 9;



//Movement defines
define PLAYER_SPEED_TURN, 6; // how fast a player rotates


// weapong types
define cleric_waund, 1; // clerics fighting stick
define wizzard_stick, 2; // wizzards fighting stick
define officer_bar, 3; // officers fighting stick













/*****************
* *
* Resources *
* Strings *
*****************/

//-------------------------------------------------------------------------------------------------------------------------------
// Place all STRINGS declerations below here...that do not have a submenu option below...usually levels and such

string fighting_chance_str = <fighting_chance.wmb>; // This will be our levalage!!







//-------------------------------------------------------------------------------------------------------------------------------
// Any MODELS that will be added to the game go in this section

string str_cbabe = <cbabe.mdl>; // this is the cbabe model

string str_wizzard_mdl = <blue_warlock.mdl>;

string str_warrior_mdl = <red_guard.mdl>;








//-------------------------------------------------------------------------------------------------------------------------------
// any DISPLAYED strings go in this section

string str_people_connected; // used to show the number of people currently connected.

string str_temp; // temp string ..um duh!

string str_player_num; // string to hold the player number

string str_number_of_players; // sting to hold the number of players








//-------------------------------------------------------------------------------------------------------------------------------
// any FONTS go in this area...yes Font is a resource lol

font arial_font = "arial", 1, 10; //standord font




/***************
* *
* Bitmaps *
* *
***************/
//------------------------------------------------------------------------------------------------------------------------------
//pannels
//choosing a class


bmap cleric_tga = <cleric.tga>;
bmap wizzard_tga = <wizzard.tga>;
bmap class_selection_tga = <class_selection.tga>;


//-------------------------------------------------------------------------------------------------------------------------------















/*****************
* *
* Varaibles *
* *
*****************/
//------------------------------------------------------------------------------------------------------------------------------





//------------------------------------------------------------------------------------------------------------------------------
// ENGINE variables go here

var fps_max = 65; //locking it down! no one is allowed to go over 65 frames per second..actually you can have any fps right now.

var fps_lock = ON; // no more freedom for the frames... muuhhaahahaa..no one has an advantage now..so there!








//------------------------------------------------------------------------------------------------------------------------------
// RESOLUTIONS and DISPLAY variables

var video_mode = 7; //screen size will be 800X600..can change this later or whatever..maybe make it to where the player chooses

var video_screen = 2; // Start settings for full screen (2 sets it to windowed mode.......1 sets it to full screen)

var mouse_mode = 2; // with 2 you can use the mouse, but it does not have an effect on forces. ( the force keyword))








//------------------------------------------------------------------------------------------------------------------------------
// GAME variables go in this section

var people_connected = 0; // how many people are connected to the server right now?

var number_of_players = 0; //how many players are actually in the game? ... both of these start with 0 when servers starts up.

var server_says_start = FALSE; // client holds creating entity until server says go.

var class_ID; // used in the main function to hold the players class ID.

var temp_loc[3];

var vecFrom[3];

var vecTo[3];

var class_not_set = TRUE;

var force[3]; // temp for "forces" in the player_move action





//------------------------------------------------------------------------------------------------------------------------------















/******************
* *
* Text stuff *
* *
******************/

//-----------------------------------------------------------------------------------------------------------------------------
// text to display the number of people connected


text txt_people_connected

{
pos_x = 0; //possition cordinates on the screen

pos_y = 65;

layer = 15; //what layer you want it in?

font arial_font; // Type of font to use

string str_people_connected; // what will be displayed....whatever the variable contains.

}





//------------------------------------------------------------------------------------------------------------------------------
// Text to display this particular players_number.




//--------------------------------------------------------------------------------------------------------------------------------
// Text to display the current number of people in the game

text txt_number_of_playerss // number pf plaers in the game
{

pos_x = 0; // again it is set in the function init_display()

pos_y = 0;

layer = 15;

font arial_font;

string str_number_of_players;

}





text number_for_player
{

pos_x = 0; // we set it in init_display() down below this point in the script

pos_y = 0;

layer = 15;

font arial_font;

string str_player_num;

}











/**************
* *
* Panels *
* *
**************/






// next is the two class pannels that we have so far

panel = cleric_class
{
bmap = cleric_tga;

layer = 21;

pos_x = 0;

pos_y = 0;

on_click = set_class_cleric;

flags = overlay, transparent, refresh;

}






panel = wizzard_class
{
bmap = wizzard_tga;

layer = 21;

pos_x = 0;

pos_y = 0;

on_click = set_class_wizzard;

flags = overlay, transparent, refresh;

}





//----------------------------------------------------------------------------------------------------------------------------
// class selection panel
panel selection_class
{

bmap = class_selection_tga;

layer = 20;

pos_x = 0;

pos_y = 0;

//on_click = set_class; // this is not used right now...but will be during a real game

flags = overlay, transparent, refresh;

}











//------------------------------------------------------------------------------------------------------------------------------





function animate()
{

proc_late(); // make sure force is set before we run the animation




while(my)
{

if (my.animation_state == ANIMATION_STATE_RUN)
{


my.current_anim_percent += PLAYER_ANIM_RUN_SPEED *time;


}

else
{


my.current_anim_percent += PLAYER_ANIM_WALK_SPEED * time;


}





if (my.current_anim_percent >100)
{


my.current_anim_percent -= 100;


}





//do animation of current animation state
if (my.animation_state == ANIMATION_STATE_WALK)
{



if (my.prev_anim_state != my.animation_state)
{


my.blend_anim_percent += PLAYER_ANIM_BLEND_SPEED *time;

my.blend_anim_percent = min (my.blend_anim_percent, 100);



ent_blend ("walk", 0, my.blend_anim_percent);

if (my.blend_anim_percent == 100)
{

my.current_anim_percent = 0;




ent_animate (me, "walk", my.current_anim_percent, ANM_CYCLE);

my.prev_anim_state = my.animation_state;

my.blend_anim_percent = 0;


}

}


else
{


ent_animate (me, "walk", my.current_anim_percent, ANM_CYCLE);


}
}


else
{

if (my.animation_state == ANIMATION _STATE_STAND)
{


if (my.prev_anim_state != my.animation_state)
{


my.blend_anim_percent += PLAYER_ANIM_BLEND_SPEED * time;

my.blend_anim_percent = min (my.blend_anim_percent, 100);



ent_blend ("stand", my.current_anim_percent, my.blend_anim_percent);

if (my.blend_anim_percent == 100)
{


my.current_anim_percent = 0;




ent_animate (me, "stand", my.current_anim_percent, ANM_CYCLE);

my.prev_anim_state = my.animation_state;

my.blend_anim_percent = 0;


}


}


else
{


ent_animate (me, "stand", my.current_anim_percent, ANM_CYCLE);


}


}



else
{

if (my.animation_state == ANIMATION_STATE_RUN)

{

if(my.prev_anim_state != my.animation_state)
{

my.blend_anim_percent += PLAYER_ANIM_BLEND_SPEED * time;

my.blend_anim_percent = min(my.blend_anim_percent,100);



ent_blend("run",my.current_anim_percent,my.blend_anim_percent);

if(my.blend_anim_percent == 100)
{

my.current_anim_percent=0;



ent_animate(me,"run",my.current_anim_percent,ANM_CYCLE );

my.prev_anim_state = my.animation_state;

my.blend_anim_percent = 0;

}



}



else
{

ent_animate( me, "run", my.current_anim_percent, ANM_CYCLE );

}


}




else // attack
{

if(my.prev_anim_state != my.animation_state)
{

my.blend_anim_percent += PLAYER_ANIM_BLEND_SPEED * time;

my.blend_anim_percent = min(my.blend_anim_percent,100);



ent_blend("attack",my.current_anim_percent,my.blend_anim_percent);



if (my.blend_anim_percent == 100)
{

my.current_anim_percent=0;



ent_animate(me,"attack",my.current_anim_percent,ANM_CYCLE );

my.prev_anim_state = my.animation_state;

my.blend_anim_percent = 0;

}

}




else
{

ent_animate( me, "attack", my.current_anim_percent, ANM_CYCLE );

}



}




}




}





wait(1);




}
}

















/***************
* *
* Actions *
* *
***************/

//-------------------------------------------------------------------------------------------------------------------------------
//move the player

action move_player
{


my.pan = random(360); // face a random direction


// We need the server to give the player his unique player_number...in the same order that the player logs in
number_of_players += 1; // the player has been created and is in the world...so we add one to the number of players
// on the server

send_var (number_of_players); //send the new number of players to all clients that are connected to the server

my.player_number = number_of_players; // This sets the player_number skill --> skill 1 --> see defines at top of script

send_skill (my.player_number, SEND_ALL); // send player_number skill to all clients



//this code helps solves issues with high latency between the server and the client.
sleep (.3);
ent_sendnow(my);
sleep (3); // solves high latency issues for right now.





//if not client...making sure that only the dedicated server reads throug this...not the client
if (connection != 2)
{


if(my.class == cleric)
{


my.speed = cleric_speed; // set players speed

my.health = cleric_max_hp; //set health

my.max_health = cleric_max_hp; // set max health

my.armor_class = cleric_ac; //set AC

//send health, max health, and armor class
send_skill(my.health, SEND_VEC + SEND_ALL);

my.weapon = cleric_waund; // set weaopon


}




if (my.class == wizzard)
{


my.speed = wizzard_speed; //set players speed

my.health = wizzard_max_hp; //set health

my.max_health = wizzard_max_hp; // set max health

my.armor_class = wizzard_ac; // set armor class


//send health, max health and armor class
send_skill (my.health, SEND _VEC + SEND_ALL);

my.weapon = wizzard_stick; //set weapons


}

//if (my.class == officer) // point here is that you can keep on going with them if you have more.


}




// animate if it is not the SERVER
if ((connection == 2) || (connection == 0) || (connection == 3))
{

animate(); // animate the entity


}


while(1)
{


//initiall set animation to WALK, this can be changed s neccesary as it goes through the code.
my.animation_state = ANIMATION_STATE_WALK;


//if moving forward or backward at walking rate, set animation to walk
if ((abs(my.force_x) >0) && (abs(my.force_x) <=1))
{


my.animation_state = ANIMATION_STATE_WALK;


}



else
{


//if moving forward or backward at run, set animation to run
if (abs(my.force_x) >1)
{


my.animation_state = ANIMATION_STATE_RUN;


}


else
{


//if entity is not turning, then all that is left is standing
if (my.force_y == 0)
{


my.animation_state = ANIMATION _STATE_STAND;


}




//get new pan
my.pan = my.force_y * PLAYER_SPEED_TURN * time + my.pan;



//use time and speed_forwards_factor
force.x = my.force_x * my.speed * time;

force.y = 0;

force.z = 0;



//move_mode = glide +ignore_passable;

//result = ent_move (force.x, nullvector);



// move the player
c_move (my, force.x , nullvector, ignore_me + ignore _sprites + glide + ignore_passable);





//A6.3 feature..and after

if (my.floor_dist > (my.max_z - my.min_z) / 2)
{


my.z -= my.floor_dist - (my.max_z - my.min_z) / 2;


}





}


}



wait(1);


}



}

//-------------------------------------------------------------------------------------------------------------------------------
//move camera..3rd person

function move_camera()
{


var distance;

var adj_cam_tilt;

var camera_next[3];



restart_camera:

//wait for player to be created

while (player == NULL)
{


wait(1);


}



while (player != NULL) // player exist?
{


camera_next.x = player.x - cos (player.pan) * 200;

camera_next.y = player.y - sin (player.pan) * 200;

camera_next.z = player.z + 10;



you = player;



//make sure camera has unobstructed view
trace_mode = ignore_sprites + ignore_you + ignore_passable +use_box;

distance = trace (player.x, camera_next.x);

if (distance)
{


distance -= 2;

camera.x = player.x - cos (player.pan) * 200;

camera.y = player.x - sin (player.pan) * 200;


}


else
{


camera.x = player.x - cos (player.pan) * 200;

camera.y = player.y - sin (player.pan) * 200;


}


camera.z = player.z +75;

camera.pan = player.pan;

if (distance == 0)
{


distance = 200;


}


//if players back is close to a wall...tilt camera

// away from player while still being able to see the play field


adj_cam_tilt = (100 / distance);


if (adj_cam_tilt > 1.75)
{


adj_cam_tilt = 1.75;


}



camera.tilt = -10;

camera.tilt += (camera.tilt * adj_cam_tilt);

adj_cam_tilt = 0;

camera.roll = 0;




wait (1);


}


goto (restart_camera);


}





//-------------------------------------------------------------------------------------------------------------------------------
//move_officer

action move_officer
{


//my.profession = whatever_profession_ you_make
move_player();



}



//--------------------------------------------------------------------------------------------------------------------------------
// move_cleric

action move_cleric
{

my.class = cleric;

move_player();


}



//--------------------------------------------------------------------------------------------------------------------------------
// move_wizzard

action move_wizzard
{

my.class = wizzard;

move_player();


}












//---------------------------------------------------------------------------------------------------------------------------------
// Function set class: Cleric

function set_class_cleric
{

class_ID = cleric;

class_not_set = FALSE;

}






//---------------------------------------------------------------------------------------------------------------------------------
// Function set class: Wizzard

function set_class_wizzard
{

class_ID = wizzard;

class_not_set = FALSE;

}







//---------------------------------------------------------------------------------------------------------------------------------
//Function to set up the class selection pannels, and move the people connected text to the right some

function init_display()
{

selection_class.pos_x = 144 ;

selection_class.pos_y = 200;

selection_class.alpha = 50;



cleric_class.pos_x = 144;

cleric_class.pos_y = 232;

cleric_class.alpha = 50;




wizzard_class.pos_x = 400;

wizzard_class.pos_y = 232;

wizzard_class.alpha = 50;



txt_people_connected.pos_x = 600;

txt_people_connected.pos_y = 32;




txt_number_of_playerss.pos_x = 600;

txt_number_of_playerss.pos_y = 48;



number_for_player.pos_x = 600;

number_for_player.pos_y = 62;



}






//------------------------------------------------------------------------------------------------------------------------------
//Input Scan() ... check the input from the player and let the server do it's work


function input_scan()
{

//only send changed skill values to the server...we need a way to store old values to check if they have changed
var force_x_old;

var force_y_old;

var force_z_old;





while(1)
{

//if player has been created, get input from him or her

if (player)
{

force_x_old = player.force_x; //store the old force values

force_y_old = player.force_y;





player.force_x = 0;

player.force_y = 0;





//<w> or else <curser up> moves the character forward

if ((key_w == 1) || (key_cuu == 1))
{

player.force_x = 1;


}



//if <a> or else <curser left>....... turn the player to the left

if ((key_a == 1) || (key_cul == 1))
{

player.force_y = 1;


}





//if <d> or else <curser right> .... turn the player to the left

if ((key_d == 1) || (key_cur == 1))
{

player.force_y = -1;


}





//if <s> or else <curser down> ......player moves back

if ((key_s == 1) || (key_cud == 1))
{

player.force_x = -1;


}


//if <shift> is pressed....player will runage! (run!)

if (key_shift == 1)
{

player.force_x = player.force_x * 1.5; // run speed is 1.5 times faster then walk


}





// The Code below uses 3DGS's force protocol

// get new force values (gruadually speed up force)

// uses more bandwidth until reaches min or max force

// but does work




//player.force_x = key_force.y; // get force x

//player.force_y = -key_force.x; // get force y

//player.force_z = 0; // force z always 0 for now



//if any forces have changed, then we need to send the new forces to the server to updte the client

if ((player.force_x != force_x_old) || (player.force_y != force_y_old) || (player.force_z != force_z_old))
{

//if we are a single player, host or server...we don't need to update anything
if (connection == 2) || (connection == 3)
{

send_skill (player.force_x, SEND_VEC); // send the force vector to the server


}


}


}


wait(1);

}


}








//---------------------------------------------------------------------------------------------------------------------------------
//switch the mouse mode so we can click panels and what not

function mouse_on()
{

mouse_mode = 2;

while (mouse_mode > 0)
{

mouse_pos.x = pointer.x;

mouse_pos.y = pointer.y;

wait(1);

}


mouse_map = null;

}





//turn the mouse back off when not needed
function mouse_off()
{

mouse_mode = 0;


}


//--------------------------------------------------------------------------------------------------------------------------------






/************
* *
* Main *
* *
************/

function main()
{



randomize(); //set random seed









//---------------------------------------------------------------------------------------------------------------------------
// if this is not a single player game we need to wait for the connection to be established.
ifdef server;

while(connection == 0)
{

wait(1);

}
endif;





ifdef client;

while(connection == 0)
{

wait (1);


}


endif;


//---------------------------------------------------------------------------------------------------------------------------
// time to load the level that we stored in a string above! WOOT it starts!
sleep (1);
level_load(varrahs_world_str); // load the level
sleep (1); // just making sure the level is actually loaded
camera.visible = on;




//---------------------------------------------------------------------------------------------------------------------------
// checking stuff in this area



// check to see if this is a client or not

if (connection == 2) // is this the client?
{
//beep();

while (server_says_start == FALSE)
{

wait(1);

}


}







// if we are the host, we need to count ourself as a player!

if (connection == 3)
{

people_connected = 1;

}


//------------------------------------------------------------------------------------------------------------------------------
// display the text that shows how many people are connected......show it to the user
// if this was a dedicated server, we would want it to skip all this part...no one is playing the server

if (connection != 1)
{








display_info(); // continuely display any information we want to show




init_display(); // Initialize the text posistions if neccesary



mouse_on(); //turn mouse on!






//Display class panel on the screen so the player can choose a class!
selection_class.visible = on;
wizzard_class.visible = on;
cleric_class.visible = on;





//if not in single player mode, display the players
if (connection)
{

txt_people_connected.visible = ON;

txt_number_of_playerss.visible = ON;

number_for_player.visible = ON;

}






//wait for a class to be selected by the player


while (class_not_set)
{

wait(1);

}








// now time to turn off the mouse..since they selected a class
mouse_off(); // turn off the mouse.





// also it is now time to make the pannels go away

selection_class.visible = off;
cleric_class.visible = off;
wizzard_class.visible = off;






create_player(); // create the player by calling this function...located bellow this place


move_camera(); // call simple 3rd person chase camera



input_scan(); // get the input from the user

}


}





/*****************
* *
* Functions *
* *
*****************/

//--------------------------------------------------------------------------------------------------------------------------------
// Function Server Called(): the server was called..maybe from a client?

function server_called()
{

//If a new player connected, incriment the people connected variable
// and tell the computer it is ok to continue

if ((event_type == event_join) && (people_connected < MAX_CONNECTIONS))

{
ifdef server;


server_says_start = TRUE; // let client know that it is ok to start up now

people_connected += 1; //another person connected


send_var(people_connected); // send number of people connected

send_var(server_says_start); // actually send it to the client now....send start message



endif;
}


// Someone just disconnected!!! how darn them!

if (event_type == event_leave)

{

ifdef server;

people_connected -= 1; //one less person connected to the server

number_of_players -= 1;
send_var(people_connected); // send the number of people connected

endif;
}


send_var_to (you, number_of_players);
}

on_server = server_called; // on server event, call server_called()








//---------------------------------------------------------------------------------------------------------------------------------
//DISPLAY INFO --> continuously displays game information

function display_info()

{

while(1)
{

str_cpy (str_people_connected, "People currently connected to the server: ");

str_for_num (str_temp,people_connected);

str_cat (str_people_connected, str_temp);



str_cpy (str_number_of_players, "number of players currently in the world: ");

str_for_num (str_temp, number_of_players);

str_cat (str_number_of_players, str_temp);



if (player != NULL) // make sure the player exists
{

str_cpy (str_player_num, "You are Player Number: ");

str_for_num (str_temp, player.player_number);

str_cat (str_player_num, str_temp);



}

wait(1);

}

}








//---------------------------------------------------------------------------------------------------------------------------------
// CREATE PLAYER ... crate a player entity and place it at a random location.

function create_player()

{

var position_found = FALSE;


while (position_found == FALSE)
{

//get a random start vector around center of level

vecFrom.x = -400 + random(800);

vecFrom.y = -400 + random(800);

vecFrom.z = 200;




vec_set(vecTo, vecFrom);
vecTo.z = -200;



trace_mode = ignore_sprites + ignore_passents + ignore_passable + ignore_models + use_box + scan_texture;
trace(vecFrom, vecTo);



//check for floor textures, if there is a floor, create entity

if ((str_stri (tex_name, "Grass_07")!= FALSE) || (str_stri (tex_name, "crator") != FALSE))
{

vec_set(temp_loc, vecTo);

temp_loc.z = target.z +35;



//create player's entity depending on his or her class
if (class_ID == wizzard)
{

player = ent_create (str_wizzard_mdl, temp_loc, move_wizzard);


}



if (class_ID == cleric)
{

player = ent_create (str_cbabe, temp_loc, move_cleric);
}








position_found = TRUE; //found the floor to create the player on!

}


}

}



again the animations work ( the character animates the walk), but he does not actually move...can't figure out if I am missing something, or if I have something out of place, or just have something completely wrong...I am new to multiplayer..thanks for any help you can send my way....all this is just practice...not the actuall game I am making...just trying to get the hang of of how c-script + multiplayer works...still do not understand the client / server fully..so any help in how they communicate would also be appreciated!


3DGS (6.4) Commercial
Re: movement not working :( [Re: Jered] #93446
10/07/06 20:46
10/07/06 20:46
Joined: Aug 2003
Posts: 7,440
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,440
Red Dwarf
i dont see you are sending the player's position in your move function:

send_skill(my.x,send_vec);


"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: movement not working :( [Re: Michael_Schwarz] #93447
10/07/06 22:10
10/07/06 22:10
Joined: Sep 2006
Posts: 108
J
Jered Offline OP
Member
Jered  Offline OP
Member
J

Joined: Sep 2006
Posts: 108
Michael,

This script is designed to be able to be host, server, or single player. Even without a send_skill, the single player part should have no issues. However even in the single player part, all I get is the animation of walking, but no actual walking.

however, there is a lot that I do not now about multiplayer right now, so if I may ask:

where would I put the send_skill? after the c_move(.... in the move_player()? or when exactly do you send it? Again this script is based on Lucoweeds tutorial on multiplayer....and I dont see where he sends the skill either...I understand why we have to send it..so it will update in multiplayer, but I do not understand when to send it..after I do what?

again, the issue in not moving is not in sending it ( though I need to know how), as a single player ( not multiplayer) should be able to walk without a send...so the walk code ( found in player move() ) is not functioning correctly. I have tried both C-move and ent_move...neither seem to do the job..I am missing something...but not sure what.


3DGS (6.4) Commercial
Re: movement not working :( [Re: Jered] #93448
10/07/06 22:35
10/07/06 22:35
Joined: Aug 2003
Posts: 7,440
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,440
Red Dwarf
i've taken a deeper look into your code ( it was very messy in the forum (next time, use the code tag)

basically, the move function made the player "move" when he should stand, and stand when he should move, ive reworked it for you, not perfect, but what i could do in 1 minute of spare time you still have to improve it though

Code:
  action move_player
{
my.pan = random(360); // face a random direction
// We need the server to give the player his unique player_number...in the same order that the player logs in
number_of_players += 1; // the player has been created and is in the world...so we add one to the number of players
// on the server
send_var (number_of_players); //send the new number of players to all clients that are connected to the server
my.player_number = number_of_players; // This sets the player_number skill --> skill 1 --> see defines at top of script
send_skill (my.player_number, SEND_ALL); // send player_number skill to all clients
//this code helps solves issues with high latency between the server and the client.
sleep (.3);
ent_sendnow(my);
sleep (3); // solves high latency issues for right now.
//if not client...making sure that only the dedicated server reads throug this...not the client
if (connection != 2)
{
if(my.class == cleric)
{
my.speed = cleric_speed; // set players speed
my.health = cleric_max_hp; //set health
my.max_health = cleric_max_hp; // set max health
my.armor_class = cleric_ac; //set AC
//send health, max health, and armor class
send_skill(my.health, SEND_VEC + SEND_ALL);
my.weapon = cleric_waund; // set weaopon
}

if (my.class == wizzard)
{
my.speed = wizzard_speed; //set players speed
my.health = wizzard_max_hp; //set health
my.max_health = wizzard_max_hp; // set max health
my.armor_class = wizzard_ac; // set armor class
//send health, max health and armor class
send_skill (my.health, SEND _VEC + SEND_ALL);
my.weapon = wizzard_stick; //set weapons
}
//if (my.class == officer) // point here is that you can keep on going with them if you have more.
}
// animate if it is not the SERVER
if ((connection == 2) || (connection == 0) || (connection == 3))
{
animate(); // animate the entity
}
while(1)
{
//initiall set animation to WALK, this can be changed s neccesary as it goes through the code.
my.animation_state = ANIMATION_STATE_WALK;
//if moving forward or backward at walking rate, set animation to walk
if ((abs(my.force_x) >0) && (abs(my.force_x) <=1))
{
my.animation_state = ANIMATION_STATE_WALK;
}
else
{
//if moving forward or backward at run, set animation to run
if (abs(my.force_x) >1)
{
my.animation_state = ANIMATION_STATE_RUN;
//get new pan
my.pan = my.force_y * PLAYER_SPEED_TURN * time + my.pan;
//use time and speed_forwards_factor
force.x = my.force_x * my.speed * time;
force.y = 0;
force.z = 0;
//move_mode = glide +ignore_passable;
//result = ent_move (force.x, nullvector);
// move the player
c_move (my, force.x , nullvector, ignore_me + ignore _sprites + glide + ignore_passable);

//A6.3 feature..and after

if (my.floor_dist > (my.max_z - my.min_z) / 2)
{
my.z -= my.floor_dist - (my.max_z - my.min_z) / 2;
}
}
else
{
//if entity is not turning, then all that is left is standing
if (my.force_y == 0)
{
my.animation_state = ANIMATION _STATE_STAND;
}
//get new pan
my.pan = my.force_y * PLAYER_SPEED_TURN * time + my.pan;
//use time and speed_forwards_factor
force.x = my.force_x * my.speed * time;
force.y = 0;
force.z = 0;
//move_mode = glide +ignore_passable;
//result = ent_move (force.x, nullvector);
// move the player
c_move (my, force.x , nullvector, ignore_me + ignore _sprites + glide + ignore_passable);

//A6.3 feature..and after

if (my.floor_dist > (my.max_z - my.min_z) / 2)
{
my.z -= my.floor_dist - (my.max_z - my.min_z) / 2;
}
}
}
wait(1);
}
}




"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: movement not working :( [Re: Michael_Schwarz] #93449
10/07/06 23:36
10/07/06 23:36
Joined: Sep 2006
Posts: 108
J
Jered Offline OP
Member
Jered  Offline OP
Member
J

Joined: Sep 2006
Posts: 108

ok I fixed the location of the c_move to where you said. However that did nothing but you made me look at the logic, and I noticed even where you put it, was not quite right....I know that is not your fault...my code looked like..well you know the word. Thanks for telling me about the code thing..I have it working for right now...the code is below....how it should be. thanks you so much for the help...was getting frustrated with it


I do have one question though. I have ran it as host, and fired up a client as well. I watched as the client did it's thing...from the host I watched. this means that the code is taking place on the server? Again I am learning from the locoweed tutorial, so i am also trying to understand what goes on as I adjust things. Am I correct in saying thiss code is taking place on the server? I can't seem to see where the server is sending it to the client, nor do i see where the client might be sending it to the server...I done went and got confused lol.



this is the CORRECT CODE for the function..move_player()...thanks again Michael

Code:
 
//-------------------------------------------------------------------------------------------------------------------------------
//move the player

function move_player
{


my.pan = random(360); // face a random direction


// We need the server to give the player his unique player_number...in the same order that the player logs in
number_of_players += 1; // the player has been created and is in the world...so we add one to the number of players
// on the server

send_var (number_of_players); //send the new number of players to all clients that are connected to the server

my.player_number = number_of_players; // This sets the player_number skill --> skill 1 --> see defines at top of script

send_skill (my.player_number, SEND_ALL); // send player_number skill to all clients



//this code helps solves issues with high latency between the server and the client.
sleep (.3);
ent_sendnow(my);
sleep (3); // solves high latency issues for right now.





//if not client...making sure that only the dedicated server reads throug this...not the client
if (connection != 2)
{


if(my.class == cleric)
{


my.speed = cleric_speed; // set players speed

my.health = cleric_max_hp; //set health

my.max_health = cleric_max_hp; // set max health

my.armor_class = cleric_ac; //set AC

//send health, max health, and armor class
send_skill(my.health, SEND_VEC + SEND_ALL);

my.weapon = cleric_waund; // set weaopon


}




if (my.class == wizzard)
{


my.speed = wizzard_speed; //set players speed

my.health = wizzard_max_hp; //set health

my.max_health = wizzard_max_hp; // set max health

my.armor_class = wizzard_ac; // set armor class


//send health, max health and armor class
send_skill (my.health, SEND _VEC + SEND_ALL);

my.weapon = wizzard_stick; //set weapons


}

//if (my.class == officer) // point here is that you can keep on going with them if you have more.


}




// animate if it is not the SERVER
if (connection != 1)
{

animate(); // animate the entity


}


while(1)
{


//initiall set animation to WALK, this can be changed s neccesary as it goes through the code.
my.animation_state = ANIMATION_STATE_WALK;


//if moving forward or backward at walking rate, set animation to walk
if ((abs(my.force_x) >0) && (abs(my.force_x) <=1))
{


my.animation_state = ANIMATION_STATE_WALK;


}



else
{


//if moving forward or backward at run, set animation to run
if (abs(my.force_x) >1)
{


my.animation_state = ANIMATION_STATE_RUN;


}


else
{


//if entity is not turning, then all that is left is standing :P
if (my.force_y == 0)
{


my.animation_state = ANIMATION _STATE_STAND;


}



}


}



//get new pan
my.pan = my.force_y * PLAYER_SPEED_TURN * time + my.pan;



//use time and speed_forwards_factor
force.x = my.force_x * my.speed * time;

force.y = 0;

force.z = 0;



//move_mode = glide +ignore_passable;

//ent_move (force.x, nullvector);



// move the player
c_move (me, force.x , nullvector, ignore_me | ignore _sprites | glide | ignore_passable | use_box);







//A6.3 feature..and after

if (my.floor_dist > (my.max_z - my.min_z) / 2)
{


my.z -= my.floor_dist - (my.max_z - my.min_z) / 2;


}


wait(1);


}



}




3DGS (6.4) Commercial
Re: movement not working :( [Re: Jered] #93450
10/07/06 23:43
10/07/06 23:43
Joined: Aug 2003
Posts: 7,440
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,440
Red Dwarf
yes, the code is taking place on the server.
And sorry for my mistakes. Its quite late at night

In any case, movement should take place on the client side and NOT on the server, as this can produce severe problems such as snapping-back(rubber band effect).


"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: movement not working :( [Re: Michael_Schwarz] #93451
10/08/06 12:24
10/08/06 12:24
Joined: Sep 2006
Posts: 108
J
Jered Offline OP
Member
Jered  Offline OP
Member
J

Joined: Sep 2006
Posts: 108
No problem about the mistake...actually kind of glad you didn't get it right ( wasn't your fault...my code was hard to read with the way I posted it without the code tags lol). I was able to lock down what the problem was based on your fix, and that was a great help.

couple questions if you don't mind answering them.

When I code in the actual game, I want the movement to be on the client like you mentioned. With that in mind, can you give me an example of how it would work?

I don't want a whole slew of code, but basicly I just want an idea of how the client would update the server, and how the server would update all the clients that are connected to it.

I am not quit sure at this point how or exactly when it is time to update the server..or when it is time to update the clients from the info the server has.

So my questions is:

how would I send the info from the client to the server and from the server back to all clients?

Is this all done using send_skill, or is there other ways to go about this? What I am looking for, or would like to learn, is the best and moost effeint way to keep the server updated and all clients updated. Thanks again for all your help...you will be added to the credits when I get to work on the actuall game itself. Right now I am just doing practices of what the actual game would be doing...so i get a feel for how c-script and multiplayer operate together.

if you want to use code to explain this, that's cool, but if you don't want to, or don't have to, that's just cool by me.


3DGS (6.4) Commercial
Re: movement not working :( [Re: Jered] #93452
10/08/06 14:18
10/08/06 14:18
Joined: Aug 2003
Posts: 7,440
Red Dwarf
Michael_Schwarz Offline
Senior Expert
Michael_Schwarz  Offline
Senior Expert

Joined: Aug 2003
Posts: 7,440
Red Dwarf
Of course - It seems im becoming one of the Multiplayer gurus anyway -

The most effective method for me right now(without getting lag and/or snap-back) is to have a LOCAL entity(on client) that updates to a global entity(on server):

Code:

entity* player2; // create a entity pointer
player=ent_createlocal("player.mdl",nullvector,player_action); // local entity
player2=ent_create("player.mdl",player.x,null); // global entity, visible to other clients
player2.invisible=on; // make it invisible so you dont see it on the local PC



Updating is a difficult thing, you have to find the right amount of updates without getting too much data that is sent per frame.

Actually I am doing this by making a seperate loop that hat a wait(3); instead of a wait(1); at the end so the position of the player is sent every 3 frames instead of every frame, this saves bandwidth.
Code:

while(1)
{
vec_set(player2.x,player.x); // set the player2 position to the actual player position
send_skill(player2.x,send_vec); // send_vec to send the 2 following skills aswell
// player2.x, .y and .z
wait(3); // wait 3 frames to save bandwidth
}



this is heavily simplified, but you should get a idea of what i am talking about.

about the server sending this information back to all clients you dont have to worry about, as it is a global entity, the server automatically sends the positions to all clients.

I hope you got the idea. Dont hesitate to ask if you've got any further questions


"Sometimes JCL reminds me of Notch, but more competent" ~ Kiyaku
Re: movement not working :( [Re: Michael_Schwarz] #93453
10/08/06 20:06
10/08/06 20:06
Joined: Sep 2006
Posts: 108
J
Jered Offline OP
Member
Jered  Offline OP
Member
J

Joined: Sep 2006
Posts: 108
I do have the idea that was a sweet explination! I do have a question though. The way I am understadning it, is that there are two different entities of the same model. One that is sent to all clients ( including the one your on) and the one that is shown on your screen ( the local one). The one that is sent to the client you said was invisible...so that you do not see it.

If that is all correct, why have a player on your screen? why not use the invisable one? or is the invisible one not realy there? I know I am missing a piece of knoledge here...what am I not seeing?

here is where my confusion. We create the entity localy ( on the client) we then update the server that this character exists. is the entity that is now on the server, that is being sent to all the clients nothing but the pointer itself?


3DGS (6.4) Commercial
Re: movement not working :( [Re: Jered] #93454
10/08/06 20:19
10/08/06 20:19
Joined: Sep 2006
Posts: 108
J
Jered Offline OP
Member
Jered  Offline OP
Member
J

Joined: Sep 2006
Posts: 108
oh ok. I think I got it now...we are sending the pointer to the entity that we created localy. If we removed the model we created localy then the model that is sent to all clients would also be gone...correct? So we have to create it local first, point to it send the pointer ( which does not really exist..it's a copy of what we made already), and the pointer displays across the clients, but would not exist without creating the local entity...and that is why we have to make it invisible on our client..this correct?


3DGS (6.4) Commercial
Page 1 of 2 1 2

Moderated by  HeelX, Spirit 

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