0 registered members (),
1,397
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: c_scan and a big world
[Re: alibaba]
#445047
08/26/14 21:36
08/26/14 21:36
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
Dont create particles in events, neither create / remove ents in events !!! bad, 2 scriptcrash leading ( somehow...sometime ), idea. btw. calling c_scan in a while, isnt a good idea aswell. at least, use some interval to perform the c_scan. "c_scanning" every frame is a very slow solution. About the questions ( hope it helps, just written it not tested )
// -------------------------------------------------------------------------------------------------------------------------
#define spawn_blood_particle skill96 // 1 = spawn particles ( like below ) / ents whatever...
#define id skill95 // 4ex: my.id = id_cat; ... my.id = id_healthpack; ... my.id = id_explosion;
#define id_explosion 1001 // identification - markers. "#define id_2ndmarker 1002" ... and so on
// -------------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
action AnyExplodingEnt_WED(){ // entity that performs the c_scan, the explosion, the gas - barrel 4ex ^^
my.id = id_explosion; // identification of this entity, in this case, its marked as explosion
while (my){ // main - while of "explosion - creating entity"
.
..
...
// ---=[ !!! CAREFULL, BAD IDEA: PERFORMING C_SCAN EVERY FRAME : SLOW = S*** ^^ !!! ]=--------------------------------
if (c_scan (...)){ // c_scan's result > 0 means: we've found something
draw_point3d (target.x, vector (50, 50, 255), 100, 3); // draw red dot ( one frame only )
if (you){ // scan detected valid entity? then you = detected ent!
you.health = 0; // 4ex: kill the scanned entity, whatever u want 2 do
//effect (blood_effect, 10, you.x, nullvector); // <- normally, good place 2 spawn particles here, btw
}
}
...
..
.
wait (1);
}
wait (1);
ptr_remove (me);
}
// -------------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
// -------------------------------------------------------------------------------------------------------------------------
void blood_effect (PARTICLE *p) { ... } // your particle effect startup function
// -------------------------------------------------------------------------------------------------------------------------
void _myevent_scan(){ // example event that spawns particles when triggered
if (event_type == EVENT_SCAN) if (you) if (you.id == id_explosion) // only react 2 scans from explosion-ents (+id-check)
my.spawn_blood_particle = 1; // as u can see, we spawn parts outside the event :O
}
// -------------------------------------------------------------------------------------------------------------------------
action Way2CreateParts_WED(){ // dont exceed ( +- [not sure atm] ) 19 chars! yes, this sucks ... confirmed.
set (my, POLYGON); // use polygonal hull ( why not? )
my.emask |= ENABLE_SCAN; // react on c_scan - requests
my.event = _myevent_scan; // force this event / void 2 run, triggered by any performed c_scan in range
while (my){ // the main - while of the "cow, monster, hero ... whatever" - example
.
..
...
if (my.spawn_blood_particle){ // set to 1 in the event, thats the magic trick
my.spawn_blood_particle = 0; // without this our entity wouldnt stop 2 blood ^^
VECTOR _temp; // local temp vector holding effect's direction
vec_set (_temp, vector (normal.x, 0, 0)); // part's direction correction, optional of course
effect (blood_effect, 10 + random (10), my.x, _temp); // finally, let blood spray / spawn the particles
}
...
..
.
wait (1);
}
wait (1);
ptr_remove (me);
}
// -------------------------------------------------------------------------------------------------------------------------
Peace
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: c_scan and a big world
[Re: rayp]
#445049
08/26/14 21:55
08/26/14 21:55
|
Joined: May 2008
Posts: 2,113 NRW/Germany
alibaba
Expert
|
Expert
Joined: May 2008
Posts: 2,113
NRW/Germany
|
There is no need for c_scan in a while loop. Just a cleve combining of EVENT_IMPACT and EVENT_DETECT plus what i´ve written before. Pseudocode:
void MissleEvent()
{
if(event_type==EVENT_IMPACT)
{
c_scan(my.x,my.pan,vector(360,0,400),whateveryouwanttoignore);´
wait(1);
my.event=NULL;
safe_remove(me);
}
if(event_type==EVENT_DETECT)
{
VECTOR temp;
vec_set(temp.x,you.x);
vec_to_ent(temp.x,you);
if(temp.z==0)
{
//KILL EVERYTHING AND CREATE PARTICLES
}
}
}
action Missle()
{
my.emask |= ENABLE_IMPACT | ENABLE_DETECT;
my.event=MissleEvent;
while(me)
{
//some ballistics code or something
wait(1);
}
}
|
|
|
Re: c_scan and a big world
[Re: alibaba]
#445052
08/26/14 22:29
08/26/14 22:29
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
Yes, as i said its a bad (in almost all cases) useless idea. But maybe he wants more then the simple chain - reaction - explosion, we dont know for sure yet. ^^ Another simple way ( if its up2 "barrel explosions" ), nearly the same script as Alibaba posted, in green
#define health skill100
#define id skill99
#define id_barrel 1234
void _event_barrel(){
if (event_type == EVENT_SCAN || event_type == EVENT_IMPACT) if (you) if (you.id == id_barrel) my.health = 0;
}
//skill1 BarrelHealth 100
action BarrelExplode_WED(){
set (my, POLYGON);
my.id = id_barrel;
my.emask |= (ENABLE_SCAN | ENABLE_IMPACT); // impact: 4ex use ents as bullets ( 4my taste better than using c_trace btw )
my.event = _event_barrel;
if (my.skill1) my.health = my.skill1 // takes value from WED's settings panel
else my.health = 50 + integer (random (50));
while (my.health){
// if u want, add more code here. maybe barrel's idle animation lol
wait (1);
}
my.event = NULL;
set (my, INVISIBLE | PASSABLE); // ghostmode
c_scan (my.x, my.pan, vector (360,0, 150 + random (250)), SCAN_ENTS | IGNORE_ME | IGNORE_PASSABLE);
// put your "BOOM - code" here ^^ ...like playing explosion sounds etc.
/*
// example: wait until sound was played ( via handle )
var _sndhandle = 0;
_sndhandle = ent_playsound (me, snd_explo, 200);
while (snd_playing (_sndhandle)) wait (1);
*/
wait (-1);
ptr_remove (me);
}
Greets
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: c_scan and a big world
[Re: rayp]
#445060
08/27/14 10:45
08/27/14 10:45
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Yes, as i said its a bad (in almost all cases) useless idea. But maybe he wants more then the simple chain - reaction - explosion, we dont know for sure yet. ^^ The code is for a disk sized projectile that the player can fire and that deals full damage to the main target and half in explosion damage in a circular zone. Next to damaging the enemy/entity + chance to stun, it needs to be able to create particles as gore (fountains of blood ). For the impact event I got everything working, but I still needed to get the explosion/event_scan part working correctly. I had trouble getting the draw_point3d code correctly to debug my c_scan. I now used this in the entity's event (its probably bad coding I know, I removed it now, it was only for testing):
if (event_type == EVENT_SCAN)
{
if (you.DAMAGE > 0 && is(you,FLAG2))
{
...damage etc...
wait(1);
while (1)
{
draw_point3d (my.x, vector (50, 50, 255), 100, 3);
wait(1);
}
}
}
... and that shows that the horizontal scan sector and vertical scan sector part part of the c_scan function is incredible buggy/inconsistent or something else is wrong with my map that makes it buggy. Cause often the dots don't get created when I hit an enemy in the explosion range. So I think I will just entirely ignore c_scan for this one and go with your before first mentioned trick Rayp; for + ent_next + vec_dist within a function that I call from the missile action. I will comment again as soon as I got it working. For some reason I always tend to mess things up with c_scans in projects no matter how many tutorials + examples I have read about it. Same goes a bit for c_trace, but to a lesser extent.
Last edited by Reconnoiter; 08/27/14 10:49.
|
|
|
Re: c_scan and a big world
[Re: Reconnoiter]
#445129
08/28/14 02:42
08/28/14 02:42
|
Joined: Jul 2008
Posts: 2,107 Germany
rayp
X
|
X
Joined: Jul 2008
Posts: 2,107
Germany
|
well dont know if i understood the problem with c_scan correct sry. i go in my bed now ^^ The code is for a disk sized projectile that the player can fire and that deals full damage to the main target and half in explosion damage in a circular zone. ...but if u combine all tips together, maybe it looks like this , a nice rocket - like projectile ( no c_scan used ):
#define health skill100
#define _lifetime skill99 // lifetime of the bullet, the flying projectile
#define _removeable skill98 // 1 = c_explode running 0 = ok, all done, remove now
void c_explode (ENTITY* _ent, _explorange){ // usage: c_explode (me, 300); <- explosion @ me's Position with range of 300
if (!_ent) return;
var _stored_you = 0; if (you) _stored_you = handle (you); // saves handle...
for (you = ent_next (NULL); you; you = ent_next (you)){
if (!_ent) break;
var _dist2ent = 0; _dist2ent = _explorange + 1; // always start "false"
_dist2ent = vec_dist (_ent.x, you.x);
if (you.health && !you._lifetime){
trace_mode = (IGNORE_ME | IGNORE_PASSABLE | USE_POLYGON);
if (_dist2ent < _explorange) if (c_trace (_ent.x, your.x, trace_mode)){
if (HIT_TARGET) draw_point3d (target.x, vector (50, 50, 255), 100, 3);
you.health -= dist2ent / 2; // less dist? more damage!
}
}
}
if (_stored_you) you = ptr_for_handle (_stored_you); // ...restores handle
if (_ent) _ent._removeable = 1;
}
void _event_flying_bullet(){
if (event_type == EVENT_IMPACT || event_type == EVENT_ENTITY) my.health = 0; // BOOOM!
}
void _flying_bullet(){
my.group = 1; // we'll ignore, bullets wont block each other
my.health = 1;
my._lifetime = 100;
my.emask |= (ENABLE_IMPACT | ENABLE_ENTITY);
my.event = _event_flying_bullet;
if (you) vec_set (my.pan, you.pan); // you = entity that spawned this bullet
set (my, POLYGON); // or use custom hull, often the better choice
while (my.health && my._lifetime){
move_mode = (IGNORE_ME | IGNORE_PASSABLE | IGNORE_YOU);
c_ignore (1, 0); // bullets ignore bullets
c_move (me, vector (20 * time_step, 0, 0), nullvector, move_mode);
my._lifetime -= time_step;
wait (1);
}
my.event = NULL;
set (my, INVISIBLE | PASSABLE);
c_explode (me, 300); // init explosion
while (!my.removeable) wait (1); // wait until c_explode is done
wait (1);
ptr_remove (me); // finally, remove projectile
}
action Hero_WED(){ // example how to create a bullet from player
my.health = 100;
my.group = 1; // the bullets ignore the player
var _snd_shoot = 0; // simply holds handle of sound file later
while (my.health){
.
..
...
if (key_ctrl || mouse_left) if (!snd_playing (_snd_shoot)){
_snd_shoot = snd_play (sound_playerfires_rocket, 80, 0);
ent_create ("bullet.mdl", vector (my.x, my.x, my.z), _flying_bullet);
}
...
..
.
wait (1);
}
}
did not test, looks like it works. but finally, i need some sleep. ^^ edit: you.health -= _dist2ent / 2 is bullshit atm, will add working line, in near future. Greets
Acknex umgibt uns...zwischen Dir, mir, dem Stein dort... "Hey Griswold ... where u gonna put a tree that big ?" 1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected rayp.flags |= UNTOUCHABLE;
|
|
|
Re: c_scan and a big world
[Re: rayp]
#445142
08/28/14 13:43
08/28/14 13:43
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
Hi, I wrote some new code which doesn't use c_scan or c_trace and it almost works perfectly and it seems fairly fps friendly. There is still 1 problem, I can't seem to get the c_scan-like horizontal and vertical sector check working. The code is below, thanks alot by the way for all your time so far. I call the function once when the missile explodes:
//*CUSTOM explosion hit event*//
//for player weapons explosions//
function enemy_hitexplosion()
{
VECTOR scan_sector, enemypos_vec;
for (you = ent_next (NULL); you; you = ent_next (you))
{
if (you.group == 3) // == ENEMY
{
if (you.STATE != 5) //NOT DEAD
{
if (vec_dist(my.x, you.x) < my.AREAOFEFFECT) //WITHIN DISTANCE
{
//simulates c_scan sector scan
vec_set(scan_sector, vector(my.AREAOFEFFECT, my.AREAOFEFFECT, my.AREAOFEFFECT));
if (my.WEAPONSELECTED == 5) scan_sector.z = 50;
vec_set(enemypos_vec, you.x);
vec_to_ent(enemypos_vec, my);
//WITHIN SECTOR RANGE
if (enemypos_vec.x < my.x + scan_sector.x && enemypos_vec.x > my.x - scan_sector.x &&
enemypos_vec.y < my.y + scan_sector.y && enemypos_vec.y > my.y - scan_sector.y &&
enemypos_vec.z < my.z + scan_sector.z && enemypos_vec.z > my.z - scan_sector.z)
{
//damage + effect + sound
effect(BloodGreen_Effect_base,6 + integer(random(4)),you.x,nullvector);
...
//stun + death (on server)
...
}
}
}
}
}
}
ps: the vec_dist check could be ommitted but I purely put it there to save fps (less vec_to_ent and vec_set has to be triggerred than).
|
|
|
Re: c_scan and a big world
[Re: Reconnoiter]
#445198
08/30/14 13:24
08/30/14 13:24
|
Joined: Mar 2012
Posts: 927 cyberspace
Wjbender
User
|
User
Joined: Mar 2012
Posts: 927
cyberspace
|
can you not just rotate a geometric box wich is as long as the radius of affect ,around the explosion centre ,then for every entity it touches during the 360 sweep , check the distance to the entity from the explosion centre , based on the distance then act accordingly ...
just a theoretical answer..
Compulsive compiler
|
|
|
Re: c_scan and a big world
[Re: Wjbender]
#445200
08/30/14 14:04
08/30/14 14:04
|
Joined: May 2008
Posts: 2,113 NRW/Germany
alibaba
Expert
|
Expert
Joined: May 2008
Posts: 2,113
NRW/Germany
|
i guss this line
//WITHIN SECTOR RANGE
if (enemypos_vec.x < my.x + scan_sector.x && enemypos_vec.x > my.x - scan_sector.x &&
enemypos_vec.y < my.y + scan_sector.y && enemypos_vec.y > my.y - scan_sector.y &&
enemypos_vec.z < my.z + scan_sector.z && enemypos_vec.z > my.z - scan_sector.z)
should look more like this:
//WITHIN SECTOR RANGE
if (you.x < my.x + scan_sector.x && you.x > my.x - scan_sector.x &&
you.y < my.y + scan_sector.y && you.y > my.y - scan_sector.y &&
enemypos_vec.z < 10&& enemypos_vec.z > -10)
I guess this should work. This will check all ents between -10 and 10 of height. You problem was (i guess) that you compared the relative x and y coordinates with absolute x and y coordinates.
|
|
|
Re: c_scan and a big world
[Re: alibaba]
#445206
08/30/14 18:39
08/30/14 18:39
|
Joined: Dec 2011
Posts: 1,823 Netherlands
Reconnoiter
OP
Serious User
|
OP
Serious User
Joined: Dec 2011
Posts: 1,823
Netherlands
|
@Wjbender, funny solution. What I am wondering is though if the collision would be good enough. If I can do it as an almost sphere collision than that would be nice (a retangle block would be less precise on 2 sides when rotating). Maybe the NARROW flag.
@alibaba, yes that code was indeed the problem. But I need to compare the position relatively. Cause otherwise, if I e.g. do "my.tilt = 60;", the explosion's angle does not change. While I want it to rotate properly with the missile's angle. Its for a fps game.
Last edited by Reconnoiter; 08/30/14 18:40.
|
|
|
Moderated by mk_1, Perro, rayp, Realspawn, Rei_Ayanami, rvL_eXile, Spirit, Superku, Tobias, TSG_Torsten, VeT
|