Bug?

Posted By: oldschoolj

Bug? - 08/09/07 01:06

It seems that no matter what I do, when the player creates an entity, that entity is stuck at the players position. I wrote several codes, with varying degrees of functions, and even copied verbatum code from the magazines (AI code AUM55, and missle code) just to test it, and still it is stuck at the players position. Theoretically, if the player is the one that creates the entity, and it's IGNORE_YOU is set, it should do what it does, while ignoring the player. If I have it's ENABLE_IMPACT set, it is instantly destroyed at the players position. If I don't, the player is stuck. If the players origin is set to his feet, ormiddle, or even his head, the same results occur.... If his hull is narrow, or fat, no change. Also no effect with changing the entities hull. Please resolve this for me because it is really shutting my development down.

Here is a current code I am testing (lite-c): *the red highlights are pertinant*

Code:
#define MOUSE_SELECTION
#define PLAYER
#define ENEMIES
#define WHOAMI skill11

var enemy_switching = 0; // makes sure you can't select more than one enemy, and defines which enemy you can fight.
var anim_percentage_walk;
var anim_percentage_stand;
var anim_percentage_run; // animation percentage
var distance_to_ground; // the distance between player's origin and the ground
var anim_percentage_entwalk;
var run_toggle;
var dist = 0; // enemy 1 path variables
var vLastPos[3];
var vDir[3];
VECTOR spell_speed;
vec_zero (spell_speed);

var dist2 = 0; // enemy 2 path variables
var vLastPos2[3];
var vDir2[3];

var dist3 = 0; // enemy 3 path variables
var vLastPos3[3];
var vDir3[3];
var charge_bolt = 0; //spell toggle
var tremor = 0; //spell toggle
var anim_percentage = 0; // enemy 1's animation
var anim_percentage2 = 0; // enemy 2's animation
var anim_percentage3 = 0; // enemy 3's animation
function move_spell(); //function proto to move spell
function remove_spell(); //function proto to remove spell
function shoot_spell(); //function proto to shoot spell

ENTITY* marker_tga; // enemy 1's cursor
ENTITY* marker_tga2; // enemy 2's cursor
ENTITY* marker_tga3; // enemy 3's cursor
STRING* test_spell = "test_spell.mdl"; // defines the spells model to be used
VECTOR trace_dist; //tracing limites
vec_zero (trace_dist);
VECTOR movement_speed; // player's movement speed
vec_zero (movement_speed);
VECTOR temp2; //players tempz
vec_zero (temp2);
ENTITY* enemy01; //defines the ENTITY for enemy1
ENTITY* enemy02; //defines the ENTITY for enemy2
ENTITY* enemy03; //defines the ENTITY for enemy3
VECTOR enemy_temp; //enemeis temp direction
vec_zero (enemy_temp);

PANEL* spell_row01 = // the action panel where you can use spells, click a spell icon to cast a spell
{
scale_x = .8;
scale_y = .8;
bmap = "spells_pnl_main.tga";
pos_x = 112;
pos_y = 650;
button = (173, 18, "ui_optmenubtn_clk.tga", "ui_optmenubtn_nrml.tga", "ui_optmenubtn_ovr.tga", NULL, NULL, NULL);
button = (216, 18, "ui_skillmenubtn_clk.tga", "ui_skillmenubtn_nrml.tga", "ui_skillmenubtn_ovr.tga", NULL, NULL, NULL);
button = (259, 18, "ui_spellmenubtn_clk.tga", "ui_spellmenubtn_nrml.tga", "ui_spellmenubtn_ovr.tga", NULL, NULL, NULL);
button = (302, 18, "ui_splfold_button_chargebolt_clk.tga", "ui_splfold_button_chargebolt_nrml.tga", "ui_splfold_button_chargebolt_ovr.tga", charge_bolt_fired, NULL, NULL);
button = (345, 18, "ui_splfold_button_tremor_clk.tga", "ui_splfold_button_tremor_nrml.tga", "ui_splfold_button_tremor_ovr.tga", NULL, NULL, NULL);
flags = OVERLAY | VISIBLE;
}

PANEL* mob_information = //mob info panel 1
{
bmap = "mob_info.tga";
pos_x = 490;
pos_y = 10;
layer = 15;
flags = OVERLAY;
}

PANEL* mob_information2 = //mob info panel 2
{
bmap = "mob_info.tga";
pos_x = 490;
pos_y = 10;
layer = 16;
flags = OVERLAY;
}

PANEL* mob_information3 = //mob info panel 3
{
bmap = "mob_info.tga";
pos_x = 490;
pos_y = 10;
layer = 17;
flags = OVERLAY;
}

function charge_bolt_fired() //set to one if you clicked the icon for chargebolt
{
charge_bolt = 1;
}

function shoot_spell() //if player clicked the icon, and did it with the left mouse_button create the spell model
{
wait (1);
ent_create (test_spell,my.x,move_spell); // create me at the players origin, and then run the move spell function
}



function move_spell()// moves the spell
{
my.emask |= ENABLE_IMPACT; //i can impact with things
my.event = remove_spell; //if i hit something run the function remove spell
my.pan = your.pan; //match my pan to the players pan
my.tilt = your.tilt; //match my tilt to the players tilt
spell_speed.x = 10*time_step; // i can move at 10* step on the x axis
spell_speed.y = 0; //dont move in the y
spell_speed.z = 0; //or the z
while (my != NULL) // while i exist
{
c_move (my, spell_speed, nullvector, IGNORE_YOU); //move me at the variable "spell_speed" in the direction i was fired, and ignore the player
wait (1);
}
}

function remove_spell()
{
if (event_type = EVENT_IMPACT) //did i hit something?
{
wait (1);
ent_remove (my); //then remove me
}
}



function toggle_movemode ()
{
run_toggle = (run_toggle == 0); //toggle my movement from run to walk
}



function marker_orientation () // the positioning of the marker
{
while (1)
{
vec_set (my.x, you.x); // moves the marker wit hthe enemy
my.z = my.z - 30; // and puts it near the enemies feet, change based on enemy size. may need improving
set (my, PASSABLE); //may need fixing, but should make the marker passable
my.scale_x = .4; // markers size
my.scale_y = .4;
my.scale_z = .4;
my.tilt = 90; // make it parallel to the ground
wait (1);
}
}

function marker_orientation2() // the positioning of the marker
{
while (1)
{
vec_set (my.x, you.x);
my.z = my.z - 30;
set (my, PASSABLE);
my.scale_x = .4;
my.scale_y = .4;
my.scale_z = .4;
my.tilt = 90;
wait (1);
}
}

function marker_orientation3 () // the positioning of the marker
{
while (1)
{
vec_set (my.x, you.x);
my.z = my.z - 30;
set (my, PASSABLE);
my.scale_x = .4;
my.scale_y = .4;
my.scale_z = .4;
my.tilt = 90;
wait (1);
}
}

function enemy_selection() // the event that controls marker placement
{
if ((event_type == EVENT_CLICK) && (marker_tga == NULL) && (enemy_switching == 0))
{
marker_tga = ent_create ("marker.tga", vector (my.x, my.y, my.z -30), marker_orientation);
enemy_switching = 1;
}

if ((event_type == EVENT_SCAN) && (key_tab == 1) && (marker_tga == NULL) && (enemy_switching == 0))
{
marker_tga = ent_create ("marker.tga", vector (my.x, my.y, my.z -30), marker_orientation);
enemy_switching = 1;
}

if ((event_type == EVENT_CLICK) && (marker_tga != NULL) && (enemy_switching == 0))
{
vec_set (marker_tga.x, my.x);
vec_set (marker_tga.z, my.z -30);
reset (marker_tga, INVISIBLE);
enemy_switching = 1;
}

if ((event_type == EVENT_SCAN) && (key_tab == 1) && (marker_tga != NULL) && (enemy_switching == 0))
{
vec_set (marker_tga.x, my.x);
vec_set (marker_tga.z, my.z -30);
reset (marker_tga, INVISIBLE);
enemy_switching = 1;
}
if ((mouse_right == 1) && (marker_tga != NULL) && (enemy_switching == 1))
{
set (marker_tga, INVISIBLE);
enemy_switching = 0;
}
if ((event_type == EVENT_TOUCH) && (mob_information2 != VISIBLE) && (mob_information3 != VISIBLE))
{
set (mob_information, VISIBLE);
wait (-5);
reset (mob_information, VISIBLE);
}
}

function enemy_selection2() // the event that controls marker placement
{
if ((event_type == EVENT_CLICK) && (marker_tga2 == NULL) && (enemy_switching == 0))
{
marker_tga2 = ent_create ("marker.tga", vector (my.x, my.y, my.z -30), marker_orientation2);
enemy_switching = 2;
}

if ((event_type == EVENT_SCAN) && (key_tab == 1) && (marker_tga == NULL) && (enemy_switching == 0))
{
marker_tga2 = ent_create ("marker.tga", vector (my.x, my.y, my.z -30), marker_orientation2);
enemy_switching = 2;
}

if ((event_type == EVENT_CLICK) && (marker_tga != NULL) && (enemy_switching == 0))
{
vec_set (marker_tga2.x, my.x);
vec_set (marker_tga2.z, my.z -30);
reset (marker_tga2, INVISIBLE);
enemy_switching = 2;
}

if ((event_type == EVENT_SCAN) && (key_tab == 1) && (marker_tga2 != NULL) && (enemy_switching == 0))
{
vec_set (marker_tga2.x, my.x);
vec_set (marker_tga2.z, my.z -30);
reset (marker_tga2, INVISIBLE);
enemy_switching = 2;
}
if ((mouse_right == 1) && (marker_tga2 != NULL) && (enemy_switching == 2))
{
set (marker_tga2, INVISIBLE);
enemy_switching = 0;
}
if ((event_type == EVENT_TOUCH) && (mob_information != VISIBLE) && (mob_information3 != VISIBLE))
{
set (mob_information2, VISIBLE);
wait (-5);
reset (mob_information2, VISIBLE);
}
}

function enemy_selection3() // the event that controls marker placement
{
if ((event_type == EVENT_CLICK) && (marker_tga3 == NULL) && (enemy_switching == 0))
{
marker_tga3 = ent_create ("marker.tga", vector (my.x, my.y, my.z -30), marker_orientation3);
enemy_switching = 3;
}

if ((event_type == EVENT_SCAN) && (key_tab == 1) && (marker_tga == NULL) && (enemy_switching == 0))
{
marker_tga3 = ent_create ("marker.tga", vector (my.x, my.y, my.z -30), marker_orientation3);
enemy_switching = 3;
}

if ((event_type == EVENT_CLICK) && (marker_tga3 != NULL) && (enemy_switching == 0))
{
vec_set (marker_tga3.x, my.x);
vec_set (marker_tga3.z, my.z -30);
reset (marker_tga3, INVISIBLE);
enemy_switching = 3;
}

if ((event_type == EVENT_SCAN) && (key_tab == 1) && (marker_tga3 != NULL) && (enemy_switching == 0))
{
vec_set (marker_tga3.x, my.x);
vec_set (marker_tga3.z, my.z -30);
reset (marker_tga3, INVISIBLE);
enemy_switching = 3;
}
if ((mouse_right == 1) && (marker_tga3 != NULL) && (enemy_switching == 3))
{
set (marker_tga3, INVISIBLE);
enemy_switching = 0;
}
if ((event_type == EVENT_TOUCH) && (mob_information2 != VISIBLE) && (mob_information != VISIBLE)) //ive touched an enemy?
{
set (mob_information3, VISIBLE); //make the infopanel visible
wait (-5);
reset (mob_information3, VISIBLE); //wait 5 seconds, then turn it off
}
}



action players_code ()
{
on_alt = toggle_movemode; // this will trigger the togglemovemode function for running, or walking
player = me; // I'm the player
while (1)
{
my.pan += 6 * (key_a - key_d) * time_step; // rotate the player using the "A" and "D" keys
vec_set (temp2.x, my.x); // copy player's position to temp2
temp2.z -= 5000; // set temp2.z 5000 quants below player's origin
distance_to_ground = c_trace (my.x, temp2.x, IGNORE_ME | USE_AABB);
if ((key_w == 0) && (key_s == 0))// the player isn't moving?
{
movement_speed.x = 7 * (key_w - key_s) * time_step; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value
movement_speed.z = maxv (-35 * time_step, movement_speed.z); // 35 = falling speed
c_move (my, movement_speed.x, nullvector, GLIDE);
ent_animate(my, "stand", anim_percentage_stand, ANM_CYCLE); // play the "stand" animation
}
if ((run_toggle == 1) && (key_s == 1))
{
movement_speed.x = 15 * (key_w - key_s) * time_step; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value
movement_speed.z = maxv (-35 * time_step, movement_speed.z); // 35 = falling speed
c_move (my, movement_speed.x, nullvector, GLIDE);
ent_animate(my, "run", anim_percentage_run, ANM_CYCLE); // play the "run" animation
}
if ((run_toggle == 1) && (key_w == 1))
{
movement_speed.x = 15 * (key_w - key_s) * time_step; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value
movement_speed.z = maxv (-35 * time_step, movement_speed.z); // 35 = falling speed
c_move (my, movement_speed.x, nullvector, GLIDE);
ent_animate(my, "run", anim_percentage_run, ANM_CYCLE); // play the "run" animation
}
if ((run_toggle == 0) && (key_w == 1))// the player is moving?
{
movement_speed.x = 7 * (key_w - key_s) * time_step; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value
movement_speed.z = maxv (-35 * time_step, movement_speed.z); // 35 = falling speed
c_move (my, movement_speed.x, nullvector, GLIDE);
ent_animate(my, "walk", anim_percentage_walk, ANM_CYCLE); // play the "walk" animation
}
if ((run_toggle == 0) && (key_s == 1))// the player is moving?
{
movement_speed.x = 7 * (key_w - key_s) * time_step; // move the player using "W" and "S"
movement_speed.y = 0; // don't move sideways
movement_speed.z = - (distance_to_ground - 17); // 17 = experimental value
movement_speed.z = maxv (-35 * time_step, movement_speed.z); // 35 = falling speed
c_move (my, movement_speed.x, nullvector, GLIDE);
ent_animate(my, "walk", anim_percentage_walk, ANM_CYCLE); // play the "walk" animation
}
if (mouse_left == 1) //ive pressed the left mouse button?
{
wait (1);
if (charge_bolt == 1) //and ive pressed the menu icon for chargebolt?
{
shoot_spell(); //run the shoot spell function
}
}

anim_percentage_entwalk += 5 * time_step; // begin walk speed
anim_percentage_stand += 4 * time_step; // stand speed
anim_percentage_walk += 5 * time_step; //walk speed
anim_percentage_run += 6 * time_step; //run speed
// move the player
c_scan(player.x, player.pan, vector(100, 100, 1000), IGNORE_ME | SCAN_ENTS |SCAN_LIMIT); //scan while i move
wait (1);
}
}

/////--- Enemies walk around on paths

action test_enemy1 ()
{
enemy01 = my;
my.emask = ENABLE_SCAN | ENABLE_CLICK | ENABLE_RIGHTCLICK | ENABLE_TOUCH | ENABLE_RELEASE | USE_AABB | ENABLE_IMPACT;
my.event = enemy_selection;
path_set(my, "path_1");
while(1)
{
path_spline(me,my.x,dist);
dist += 5*time_step;
vec_diff(vDir,my.x,vLastPos);
vec_to_angle(my.pan,vDir);
vec_set(vLastPos,my.x);
ent_animate(my, "walk", anim_percentage, ANM_CYCLE);
anim_percentage += 5 * time_step;
wait(1);
}
}

action test_enemy2 ()
{
enemy02 = my;
path_set(my, "path_2");
my.emask = ENABLE_SCAN | ENABLE_CLICK | ENABLE_RIGHTCLICK | ENABLE_TOUCH | ENABLE_RELEASE | USE_AABB | ENABLE_IMPACT;
my.event = enemy_selection2;
while(1)
{
path_spline(me,my.x,dist2);
dist2 += 5*time_step;
vec_diff(vDir2,my.x,vLastPos2);
vec_to_angle(my.pan,vDir2);
vec_set(vLastPos2,my.x);
ent_animate(my, "walk", anim_percentage2, ANM_CYCLE);
anim_percentage2 += 5 * time_step;
wait(1);
}
}

action test_enemy3 ()
{
enemy03 = my;
path_set(my, "path_3");
my.emask = ENABLE_SCAN | ENABLE_CLICK | ENABLE_RIGHTCLICK | ENABLE_TOUCH | ENABLE_RELEASE | USE_AABB | ENABLE_IMPACT;
my.event = enemy_selection3;
while(1)
{
path_spline(me,my.x,dist3);
dist3 += 5*time_step;
vec_diff(vDir3,my.x,vLastPos3);
vec_to_angle(my.pan,vDir3);
vec_set(vLastPos3,my.x);
ent_animate(my, "walk", anim_percentage3, ANM_CYCLE);
anim_percentage3 += 5 * time_step;
wait(1);
}
}




PS. On a further note. I cannnot set anythign more than ENABLE_IMPACT for the freshly created spell entity, or it gives me a syntax error....
Posted By: Uhrwerk

Re: Bug? - 08/09/07 01:12

There are some errors in your code. For example you're not allowed to use the vec_zero macro outside a function. Only one of many, that catched my eye...

Check even the way you define strings. STRING* x = "blabla" is horribly wrong. This has been discussed many times in the forum. Have a look at the Lite-C forums.
Posted By: oldschoolj

Re: Bug? - 08/09/07 01:15

i have to disagree bud, I use this alot

VECTOR whatever;
vec_zero (whatever);

and it works perfectly fine, in alot of different ways.

Also, defining the model to be used as an entity in a string is no problem either. But thats not the problem here. The entire code runs as it should without any issues, EXCEPT the current problem with the spell being destroyed or stuck at the player. But, thanks for trying to help, and please remember that this is a question about the code highlighted in red
Posted By: oldschoolj

Re: Bug? *DELETED* - 08/09/07 01:17

Post deleted by oldschoolj
Posted By: oldschoolj

Re: Bug? - 08/09/07 01:34

Ust to show that the code works, here is a demo level
Controls:
w-forward
s-back
a-left
d-right
Left Mouse-select
Right Mouse-deselect
Zoom wheel- zoom in out
Press the ALT key once to toggle run or walk mode
Hold middle mouse button and move mouse to pan camera

The error: if you press the chargebolt icon, u can see it is made but instantly destroyed.

Have fun

download the demo
download the code

PS there is a copywrite notice included. You are allowed to use this code commercially or privately with no credit. You MAY NOT use any of the sprites, icons, selection cursor, menu bar or otherwise for any reason other then testing.

Jesse
Posted By: jcl

Re: Bug? - 08/09/07 06:52

There can be many reasons for such a problem, for instance you're probably creating several entities and they are stuck in each other. Also ENABLE_IMPACT is the wrong event to use here, you'd need ENABLE_BLOCK, _ENTITY and so on.

However it usually won't work on the forum that you post a huge bunch of code for others to fix. Most users just don't have the time. Better make yourself familiar with the movement functions and collision events, step through your code line by line, and reduce the problem to a few lines of code. I'm moving this to the scripting forum, maybe you'll get help there.
© 2023 lite-C Forums