Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (degenerate_762, AbrahamR, AndrewAMD, ozgur), 667 guests, and 8 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
skills, spell damage question #358620
02/12/11 14:05
02/12/11 14:05
Joined: Jan 2011
Posts: 65
R
reknak Offline OP
Junior Member
reknak  Offline OP
Junior Member
R

Joined: Jan 2011
Posts: 65
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
}
}
}

Last edited by reknak; 02/12/11 16:56.
Re: skills, spell damage question [Re: reknak] #358623
02/12/11 14:16
02/12/11 14:16
Joined: Jan 2011
Posts: 797
Da wo du nicht bist! Muhahaha!
xxxxxxx Offline
User
xxxxxxx  Offline
User

Joined: Jan 2011
Posts: 797
Da wo du nicht bist! Muhahaha!
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

Last edited by xxxxxxx; 02/12/11 14:22.

Es ist immer wieder erstaunlich, dass Leute die riesen Scripte schreiben die einfachsten sachen nicht können zb. mich mit SIEBEN x zu schreiben! tongue
Re: skills, spell damage question [Re: xxxxxxx] #358660
02/12/11 17:07
02/12/11 17:07
Joined: Jan 2011
Posts: 65
R
reknak Offline OP
Junior Member
reknak  Offline OP
Junior Member
R

Joined: Jan 2011
Posts: 65
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


Re: skills, spell damage question [Re: reknak] #358666
02/12/11 17:50
02/12/11 17:50
Joined: Jan 2011
Posts: 120
United States
Logan Offline
Member
Logan  Offline
Member

Joined: Jan 2011
Posts: 120
United States
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.

Re: skills, spell damage question [Re: Logan] #358730
02/13/11 00:50
02/13/11 00:50
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
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;
}



Last edited by Widi; 02/13/11 00:55.
Re: skills, spell damage question [Re: Widi] #359094
02/15/11 16:45
02/15/11 16:45
Joined: Jan 2011
Posts: 65
R
reknak Offline OP
Junior Member
reknak  Offline OP
Junior Member
R

Joined: Jan 2011
Posts: 65
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


Gamestudio download | chip programmers | 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