Posted By: reknak
skills, spell damage question - 02/12/11 14:05
Hi, I was trying to create system where you could fire a projectile and the projectile flies forward and as soon as it collides with something it explodes and it deals damage to the entity. Now my problem is how do I let the projectile damage the entity? At the moment I use skills for the damage and health. For setting the damage I use;
c_scan(my.x,my.pan,vector(360,0,10),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
your.HEALTH -= my.DAMAGE;
, but the 'your.HEALTH -=my.DAMAGE' makes the game crash on startup when the function runs because both use skills. Could someone tell me how I could do it (without crashes ^^)?
My script for the spell action (red are the important lines);
action spell_fly()
{
my.DAMAGE = 22;
my.ambient = 120; // medium bright
my.lightrange = 100; // activate dynamic light
vec_set(my.blue,vector(255,0,0)); // bluish light color
set(me,BRIGHT); // additive blending
vec_scale(my.scale_x,0.12); // small size
c_setminmax(me); // set my bounding box to my real size
my.pan = your.pan; // face same direction as player
my.tilt = your.tilt;
// set FLAG2 to make the spell detectable by c_scan,
// and store the spell creator (you) in a skill
// so that the detecting entity gets its enemy pointer
set(my,FLAG2);
my.CREATOR = you;
my.STATE = 1;
while(1)
{
// state 1: flying ///////////////////////////////////////////
if (my.STATE == 1)
{
my.roll += 20*time_step;
c_move(me,vector(80*time_step,0,sin(my.tilt)),NULL,IGNORE_YOU);
if (HIT_TARGET) // collided?
my.STATE = 2; // go to next state
}
// state 2: exploding ////////////////////////////////////////
if (my.STATE == 2)
{
set(me,ZNEAR); // render in front of close objects\
ENTITY* enemy = NULL;
c_scan(my.x,my.pan,vector(360,0,10),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
your.HEALTH -= my.DAMAGE;
my.roll = random(360);
my.lightrange *= 1+ (0.5*time_step + ); // increase light range
vec_scale(my.scale_x,1+0.8*time_step); // inflate size
if (my.scale_x > 0.2) { // explosion finished?
ent_remove(me);
return;
}
}
wait(1);
}
}
-EDIT; before the "your.HEALTH -= my.DAMAGE;" I used this code (it worked perfectly except that if you change your weaponslot the damage isn't correct anymore ofcourse):
// hit event
function wizard_hit()
{
if (my.STATE != 4)
{
healthplayer -= 25;
if (healthplayer <= 0)
{
my.ANIMATION = 0;
my.STATE = 4; // 4 = dead
}
}
}
function corruptedmage_hit()
{
if (my.STATE != 4)
{
if (weaponslot == 1)
{
my.HEALTH -= 22;
}
if (weaponslot == 2)
{
my.HEALTH -= 25;
}
if (my.HEALTH <= 0)
{
my.ANIMATION = 0;
my.STATE = 4; // 4 = dead
}
}
}
c_scan(my.x,my.pan,vector(360,0,10),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
your.HEALTH -= my.DAMAGE;
, but the 'your.HEALTH -=my.DAMAGE' makes the game crash on startup when the function runs because both use skills. Could someone tell me how I could do it (without crashes ^^)?
My script for the spell action (red are the important lines);
action spell_fly()
{
my.DAMAGE = 22;
my.ambient = 120; // medium bright
my.lightrange = 100; // activate dynamic light
vec_set(my.blue,vector(255,0,0)); // bluish light color
set(me,BRIGHT); // additive blending
vec_scale(my.scale_x,0.12); // small size
c_setminmax(me); // set my bounding box to my real size
my.pan = your.pan; // face same direction as player
my.tilt = your.tilt;
// set FLAG2 to make the spell detectable by c_scan,
// and store the spell creator (you) in a skill
// so that the detecting entity gets its enemy pointer
set(my,FLAG2);
my.CREATOR = you;
my.STATE = 1;
while(1)
{
// state 1: flying ///////////////////////////////////////////
if (my.STATE == 1)
{
my.roll += 20*time_step;
c_move(me,vector(80*time_step,0,sin(my.tilt)),NULL,IGNORE_YOU);
if (HIT_TARGET) // collided?
my.STATE = 2; // go to next state
}
// state 2: exploding ////////////////////////////////////////
if (my.STATE == 2)
{
set(me,ZNEAR); // render in front of close objects\
ENTITY* enemy = NULL;
c_scan(my.x,my.pan,vector(360,0,10),SCAN_ENTS | SCAN_FLAG2 | IGNORE_ME);
your.HEALTH -= my.DAMAGE;
my.roll = random(360);
my.lightrange *= 1+ (0.5*time_step + ); // increase light range
vec_scale(my.scale_x,1+0.8*time_step); // inflate size
if (my.scale_x > 0.2) { // explosion finished?
ent_remove(me);
return;
}
}
wait(1);
}
}
-EDIT; before the "your.HEALTH -= my.DAMAGE;" I used this code (it worked perfectly except that if you change your weaponslot the damage isn't correct anymore ofcourse):
// hit event
function wizard_hit()
{
if (my.STATE != 4)
{
healthplayer -= 25;
if (healthplayer <= 0)
{
my.ANIMATION = 0;
my.STATE = 4; // 4 = dead
}
}
}
function corruptedmage_hit()
{
if (my.STATE != 4)
{
if (weaponslot == 1)
{
my.HEALTH -= 22;
}
if (weaponslot == 2)
{
my.HEALTH -= 25;
}
if (my.HEALTH <= 0)
{
my.ANIMATION = 0;
my.STATE = 4; // 4 = dead
}
}
}