skills, spell damage question

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
}
}
}
Posted By: xxxxxxx

Re: skills, spell damage question - 02/12/11 14:16

c_scan does not always give a you pointer. make sure that you have a you pointer!
EDIT: do you have
#define HEALTH skill1
#define DAMAGE skill2
sorry for my english.
xxxxxxx
Posted By: reknak

Re: skills, spell damage question - 02/12/11 17:07

Quote:
c_scan does not always give a you pointer. make sure that you have a you pointer!
EDIT: do you have
#define HEALTH skill1
#define DAMAGE skill2
sorry for my english.
xxxxxxx
, I think it has got something to do with the pointer, since when I change your.HEALTH to my.HEALTH it doesn't crash anymore. I have defined both skills at the beginning of the script:

Quote:
#include <acknex.h>
#include <default.c>

#define STATE skill1
#define ANIMATION skill2
#define CREATOR skill3
#define HEALTH skill4
#define DAMAGE skill5

Posted By: Logan

Re: skills, spell damage question - 02/12/11 17:50

I'd recommend using events instead of c_scan. It is cleaner that way, and events are a feature hard-wired into Lite-C that accomplish the same purpose you're trying to here.

In the spells's function before the while loop:
Code:
my.emask |= ENABLE_ENTITY;
my.event = hit_enemy; // or some other function name--WITHOUT the ()



Now you write a small function called hit_enemy that subtracts the damage from the enemy, and erase the c_scan line in your enemy's function, as the event function will take care of everything.

Also, please, especially when posting long code chunks, use the [ code ] [/ code ] tags (without the spaces of course). It is very hard to read code that isn't formatted correctly, especially very long sections like this. laugh

Let me know if the events work/don't work, or if you need any clarification.
Posted By: Widi

Re: skills, spell damage question - 02/13/11 00:50

As xxxxxxx said, c_scan does not always give a you pointer !!!
Quote:

since when I change your.HEALTH to my.HEALTH it doesn't crash anymore.

...because you is empty at this moment, c_scan set you to zero.

Code:
c_scan(...)
if (you)
{
   you.HEALTH -= my.DAMAGE;
}


Posted By: reknak

Re: skills, spell damage question - 02/15/11 16:45

Thanks for all the usefull comments.

I got it working now, didn't know I could use the 'you.' in an event ^^.

ps: this forum is awesome wink
© 2024 lite-C Forums