2 registered members (7th_zorro, dr_panther),
724
guests, and 3
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Weapon Code conversion, problem.
#290151
09/17/09 15:15
09/17/09 15:15
|
Joined: Jul 2009
Posts: 39 Chile!
Renard
OP
Newbie
|
OP
Newbie
Joined: Jul 2009
Posts: 39
Chile!
|
Ok, this is code creates an attach a weapon to a model, for thirth person shooter. It`s is supposed to fire bullets too. thanks to some of you the code is working but I`m having some problems: When firing the bullets the entity counter of the engine (F11) increases, but I can`t see the bullets, and it seems that they aren`t colliding with the walls as supposed. so they aren`t removed. The function wich calls the exposion sprite causes syntaxt errors that I can`t see. Here`s the code, can you give it a look?
action gun()
{
gatlin1 =my;
proc_mode = PROC_LATE;
set(my,PASSABLE); // the Gatlin shouldn't slow down the player
while(player != NULL)
{
vec_for_vertex (my.skill1, you, 1446);
vec_for_vertex (my.skill4, you, 1447); //special vertex made for this
vec_diff (my.skill7, my.skill4, my.skill1);// compute the vector that will be used by the Gatlin
vec_to_angle (my.pan, my.skill7); // rotate the Gatlin accordingly
// put the origin of the Gatlin in the vertex that is placed at the bottom of the arm
vec_set (my.x, my.skill1);
wait (1);
}
}
function fire_bullets()
{
proc_kill(4); // don't allow more than 1 copy of this function to run
while (mouse_left == 1) // this loop runs for as long as the left mouse button is pressed
{
vec_for_vertex (my.skill7, gatlin1, 75); // get the coordinates for the bullets' origin
// create the bullet at camera's position and attach it the "move_bullets" function
ent_create (bullet_mdl, my.skill7, move_bullets);
ent_create (muzzle_pcx, my.skill7, display_muzzle); // create the gun muzzle
snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100
wait (1*time_step); // fire 7 bullets per second (0.14 * 7 = 1 second)
}
}
function move_bullets()
{
var bullet_speed; // this var will store the speed of the bullet
set(my,ENABLE_IMPACT); // the bullet is sensitive to impact
my.emask |= ENABLE_IMPACT;
set(my,ENABLE_ENTITY); // and to other entities
set(my,ENABLE_BLOCK); // as well as to level blocks
my.event = remove_bullets; // when it collides with something, its event function (remove_bullets) will run
my.pan = camera.pan; // the bullet has the same pan
my.tilt = camera.tilt; // and tilt with the camera
my.x = 0.1 * time_step; // adjust the speed of the bullet here
my.y = 0; // the bullet doesn't move sideways
my.z = 0; // then don't allow the gravity to have its ways with the bullet
while (my != NULL) // this loop will run for as long as the bullet exists (it isn't "null")
{
// move the bullet ignoring the passable entities and store the result in distance_covered
c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE);
wait (1);
}
}
function remove_bullets() // this function runs when the bullet collides with something
{
wait (1); // wait a frame to be sure (don't trigger engine warnings)
ent_create (explosion_pcx, my.x, explosion_sprite); // create the explosion sprite
set(my, PASSABLE); // the bullets becomes passable and invisible now
set(my, INVISIBLE); // so it can't harm anyone anymore
wait (-2); // wait until the explosion_sprite() function is over
ent_remove (my); // and then remove the bullet
}
function display_muzzle()
{
set(my,PASSABLE); // the muzzle is passable
set(my,LIGHT); // make the black parts transparent even without using tga files (using a pcx file here)
set(my,BRIGHT); // the muzzle should be bright
my.ambient = 100; // and this line makes it even brighter
set(my,DECAL); // the sprite is oriented
my.pan = gatlin1.pan; // has the same pan and tilt
my.tilt = gatlin1.tilt; // with the weapon
my.roll = random(360); // and a random roll angle (looks nicer)
my.scale_x = 0.5; // we scale it down
my.scale_y = my.scale_x; // on all the axis
my.scale_z = my.scale_z; // this would only be needed for a 3D (model-based) muzzle
gatlin1.ambient = 100; // highlight the weapon (makes it look more realistic)
wait (2); // show the muzzle sprite for 2 frames
gatlin1.ambient = 0; // restore the normal weapon ambient value
ent_remove (my); // and then remove it
}
//function explosion_sprite() every line gives a syntaxt error, I donīt know why!!?!
//{
// set(my, PASSABLE); // the explosion sprite is passable
// my.scale_x = 0.15; // we scale it down to 0.15
// my.scale_y = my.scale_x; // on both axis
// set(my, LIGHT)// set its flare
// set(my,BRIGHT); // and bright flags
// my.ambient = 100; // and we give it an ambient of 100
// my.roll = random(360); // and has a random roll angle
// set(my,TRANSLUCENT); // and make it transparent
// my.alpha = 100; // but we set it to be completely opaque for now
// while (my.frame < 5) // go through all the animation frames
// {
// my.frame += 2 * time; // animation speed
// wait (1);
// }
// while (my.alpha > 0) // now fade the last frame quickly
// {
// my.alpha -= 50 * time; // 50 = fading speed
// wait (1);
// }
// ent_remove (my);
//}
WRYYYYYYYYYYYYYYYYYY!!!1!!ONE!!11
|
|
|
Re: Weapon Code conversion, problem.
[Re: bart_the_13th]
#290262
09/18/09 04:16
09/18/09 04:16
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
Expert
|
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Complete fix I think, compiled ok though. Also a few conversion improvements scattered throughout too.
action gun()
{ gatlin1 = me;
proc_mode = PROC_LATE;
set(my,PASSABLE); // the Gatlin shouldn't slow down the player
while(player != NULL)
{ vec_for_vertex(my.skill1, you, 1446); //
vec_for_vertex(my.skill4, you, 1447); //special vertex made for this
vec_diff(my.skill7, my.skill4, my.skill1); // compute the midpoint vector that will be used
vec_to_angle(my.pan, my.skill7); // align the Gatlin accordingly
// put the origin of the Gatlin in the vertex that is placed at the bottom of the arm
vec_set(my.x, my.skill1);
wait (1);
}
}
function fire_bullets()
{ proc_kill(4); // don't allow more than 1 copy of this function to run
while (mouse_left == 1) // this loop runs for as long as the left mouse button is pressed
{ vec_for_vertex (my.skill7, gatlin1, 75); // get the coordinates for the bullets' origin
// create the bullet at camera's position and attach it the "move_bullets" function
//!!!!! MAKE SURE that skill 7,8,9 contain the correct origin x,y,z
// and that nothing is "overwriting" these skill values
ent_create (bullet_mdl, my.skill7, move_bullets);
ent_create (muzzle_pcx, my.skill7, display_muzzle); // create the gun muzzle flash
snd_play (bullet_wav, 100, 0); // play the bullet sound at a volume of 100
//wait (1*time_step); // fire 7 bullets per second (0.14 * 7 = 1 second)
wait(-1/7); // fire 7 bullets per second [1second(-1) divided by 7]
}
}
function move_bullets()
{ VECTOR bullet_speed; // this var will store the speed of the bullet
// set the bullet to be sensitive to impact, entities and blocks
my.emask |= ( ENABLE_IMPACT | ENABLE_ENTITY | ENABLE_BLOCK);
my.event = remove_bullets; // when it collides with something, event "remove_bullets" will run
my.pan = camera.pan; // the bullet has the same pan
my.tilt = camera.tilt; // and tilt with the camera
bullet_speed.x = 0.1 * time_step; // adjust the FORWARD speed of the bullet here
bullet_speed.y = 0; // the bullet doesn't move sideways
bullet_speed.z = 0; // the bullet ignores gravity
while(my) // this loop will run for as long as the bullet exists (ie, isn't "null")
{ // move the bullet ignoring passable entities and the entity that called "fire_bullets"
c_move (my, bullet_speed, nullvector, IGNORE_PASSABLE|IGNORE_YOU);
wait (1);
}
}
function remove_bullets() // this function runs when the bullet collides with something
{ ent_create (explosion_pcx, my.x, explosion_sprite); // create the explosion sprite
set(my, PASSABLE); // the bullets becomes passable and invisible now
set(my, INVISIBLE); // so it can't harm anything anymore
wait(1); // wait a frame to be sure (don't trigger engine warnings)
ent_remove (my); // and then remove the bullet
}
function display_muzzle()
{ // the muzzle-flash is passable, bright, and oriented
set(my,PASSABLE|LIGHT|BRIGHT|DECAL);
// also make the black parts transparent even without using tga files (using a pcx file here)
my.ambient = 100; // and this line makes it even brighter
// muzzle-flash will pan and tilt with the weapon and a random roll angle (looks nicer)
vec_set(my.pan, vector(gatlin1.pan, gatlin1.tilt, random(360)));
vec_fill(my.scale_x, 0.5); // we scale it down on all the axis. This would only be needed for a 3D (model-based) muzzle
gatlin1.ambient = 100; // highlight the weapon (makes it look more realistic)
wait (2); // show the muzzle sprite for 2 frames
gatlin1.ambient = 0; // restore the normal weapon ambient value
ent_remove (my); // and then remove it
}
function explosion_sprite()
{
set(my, PASSABLE); // the explosion sprite is passable
my.scale_x = 0.15; // we scale it down to 0.15
my.scale_y = my.scale_x; // on both axis
set(my, LIGHT); // set its flare <<<this line was missing its ";"
set(my,BRIGHT); // and bright flags
my.ambient = 100; // and we give it an ambient of 100
my.roll = random(360); // and has a random roll angle
set(my,TRANSLUCENT); // and make it transparent
my.alpha = 100; // but we set it to be completely opaque for now
while (my.frame < 5) // go through all the animation frames
{ my.frame += 2 * time_step; // animation speed
wait (1);
}
while (my.alpha > 0) // now fade the last frame quickly
{ my.alpha -= 50 * time_step; // 50 = fading speed
wait (1);
}
ent_remove (my);
}
.
Last edited by EvilSOB; 09/18/09 04:49.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Weapon Code conversion, problem.
[Re: EvilSOB]
#290708
09/20/09 20:41
09/20/09 20:41
|
Joined: Jul 2009
Posts: 39 Chile!
Renard
OP
Newbie
|
OP
Newbie
Joined: Jul 2009
Posts: 39
Chile!
|
HO WOW Thxs a lot! i`ll give it a try!
WRYYYYYYYYYYYYYYYYYY!!!1!!ONE!!11
|
|
|
|