|
Re: sword/fist fighting a.i code....
[Re: testDummy]
#222410
08/19/08 08:33
08/19/08 08:33
|
Joined: Jan 2006
Posts: 2,157 Connecticut, USA
Blink
OP

Expert
|
OP

Expert
Joined: Jan 2006
Posts: 2,157
Connecticut, USA
|
thanks tD, i will give it a try and let you know what the results are.
My Famous Quotes: "Hip hop is like a virus, infecting everyone and everything around it. Every form of media has some way,shape or form, assimilated hip hop into it." It has also mutated into other strains like, trip hop, house, rap, gangster, and conscious forms. Once you are infected with it, its with you for life."
|
|
|
Re: sword/fist fighting a.i code....
[Re: testDummy]
#222508
08/19/08 18:00
08/19/08 18:00
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
This is 'your' thread. If issue feedback is / was desired, a separate thread would have been more appropriate. There are three parts (files): rsr1.wdl
font standard_font = <ackfont.pcx>, 6, 9; // panel font
/*******************************
images
*******************************/
bmap imSpark = <spkpart.pcx>; // for spark particles
bmap imBlood = <bloodspray.pcx>; // for blood particles
/*******************************
sounds
*******************************/
sound sdBeep = <msg.wav>;
sound sdSword = <knife.wav>;
/*******************************
levels
*******************************/
STRING lvl_s1 = <testswordlvl1.wmb>; // level string
sword-fight.wdl
/*
sword-fight.wdl
2008.08.15
tD
pseudo-auto generated from src: Blink
---trimmed!?
---made more flexible!?
---but no additional functionality added;
*/
/*******************************
skills
*******************************/
define _wpBase, skill12; // vertex sword base (override)
define _wpTip, skill15; // vertex sword tip (override)
define _hp, skill18; // hit points
define _st1, skill21;
define _anip, skill23; // ani percent
define _atkTm, skill24; // not active, gave problems
/*******************************
animation strings
*******************************/
var _STAND = 0;
var _WALK = 1;
var _ATK1 = 2;
var _DEAD = 3;
// for dummies (comment these out)
TEXT ani_t1 {
strings = 4;
string = "standB";
string = "walkA";
string = "slashR";
string = "dieA";
}
// below are the original ani strings
// uncomment these
/*
TEXT ani_t1 {
strings = 4;
string = "stand";
string = "walk";
string = "attack";
string = "death";
}*/
var ani_nSpAtk = 5; // ani sp attack
var ani_nSpDie = 3; // ani sp die
var ani_nSpStand = 2; // ani sp stand
var ani_nSpWalk = 4; // ani sp walk
var pl_vDist[3]; // moves the player
var pl_nHpD = 100;
string hp_s1 = "STRENGTH: "; // hitpoints string
/*******************************
ai
*******************************/
ENTITY* ai_e1; //
var ai_vDist[3]; // moves the enemy
var ai_nAlertDist = 5; // alert distance; multiple of entity size x
var ai_nAtkDist = 1.5; // attack distance; multiple of entity size x
var ai_nHpD = 20; // default enemy hit points
/*******************************
weapon
*******************************/
// originals; uncomment these
//var wp_nBaseD = 601; // vertex sword base default
//var wp_nTipD = 5; // vertex sword tip default
// for dummies; comment these out
var wp_nBaseD = 138;
var wp_nTipD = 145;
var wp_nResult = 0; // a temp for wp trace result
var wp_nSwordDamage = 10; // sword damage multiplier
panel hp_p1 { // sux compared to alternatives
pos_x = 0;
pos_y = 0;
digits =120, 575, 4, standard_font, 1, player._hp;
flags = refresh, visible;
}
text hp_t1 { // sux compared to alternatives
pos_x = 30;
pos_y = 550;
font = standard_font;
string = hp_s1;
flags = visible;
}
/*******************************
temps
*******************************/
var v1[3];
var v2[3];
/*******************************
function prototypes
*******************************/
function particle_sparks();
function particle_blood();
function fade_particle();
/*******************************
cam3f_1
camera 3rd person function
player only for now
*******************************/
function cam3f_1() {
// camera
camera.x = player.x - 200 * cos(player.pan); // 200 = distance between the player and the camera
camera.y = player.y - 200 * sin(player.pan); // same value here
camera.z = player.z + 50; // above the player
camera.pan = player.pan; // looks in the same direction with the player
camera.tilt = -10; // look down at the player
}
/*******************************
plf_input
player input function
*******************************/
function plf_input() {
my.pan += -20 * mouse_force.x * time_step; // rotates with the mouse
pl_vDist.x = 10 * ((key_w || key_cuu) - (key_s || key_cud)) * time_step; // moves forward / backward with W / S
pl_vDist.y = 5 * ((key_a || key_cul) - (key_d || key_cur)) * time_step; // move side to side
pl_vDist.z = 0;
}
/*******************************
zotf_ani
zot ~= actor
*******************************/
function zotf_ani(_nAniSp, _bLoop) {
ent_animate(me, ani_t1.string[my._st1], my._anip, ANM_CYCLE);
my._anip += _nAniSp;
if (_bLoop) {
my._anip %= 100;
return(0);
} else {
my._anip = min(my._anip, 100);
}
if (my._anip >= 100) {
return(100);
}
}
/*******************************
zotf_die
*******************************/
function zotf_die() {
zotf_st(_DEAD);
while (my._anip < 90) { // the player is dead
zotf_ani(ani_nSpDie, 0);
wait (1);
}
my.passable = ON; // the corpse can't be hit by the enemy sword from now on
}
/*******************************
zotf_st
reset ani on state change
*******************************/
function zotf_st(_st) {
if (my._st1 == _st) {
return(0);
}
my._st1 = _st;
my._anip = 0;
return(1);
}
/*******************************
zotf_new
*******************************/
function zotf_new() {
c_setminmax(me);
wait(1);
my._wpBase = wp_nBaseD;
my._wpTip = wp_nTipD;
}
/*******************************
wpf_trace
weapon trace function
*******************************/
function wpf_trace() {
vec_for_vertex(v1, ME, my._wpBase); // sword tip vertex coords - get the value in Med
vec_for_vertex(v2, ME, my._wpTip); // sword base vertex coords - get the value in Med
trace_mode = ignore_me + ignore_passable; // ignore me (the player) and all the entities that are passable
wp_nResult = trace(v1, v2); // trace between these sword positions
if (wp_nResult != 0) { // the player has hit something
effect (particle_sparks, 10, target, normal);
if (you != null) {you._hp -= wp_nSwordDamage * time_step;} // if it hasn't hit a wall, decrease health
ent_playsound (me, sdSword, 500); // sword sound
}
}
}
/*******************************
player_fight
pl_a1
player action
*******************************/
action player_fight { // attached to the player
player = ME; // I'm the player
player._hp = pl_nHpD; // and I have 100 health points
zotf_new();
while (ME != NULL) { // as long as I'm alive
if (my._hp <= 0) { break; }
plf_input();
//move
cam3f_1();
var pl_bWalk; pl_bWalk = (abs(pl_vDist.x) > 0) || (abs(pl_vDist.y) > 0);
if (pl_bWalk) { // the player is walking
zotf_st(_WALK);
zotf_ani(ani_nSpWalk, 1);
} else { // not walking
zotf_st(_STAND);
zotf_ani(ani_nSpStand, 1);
}
ent_move(pl_vDist, nullvector);
if (mouse_left) {// if we press the left mouse button
zotf_st(_ATK1);
while (my._anip < 100) {
zotf_ani(ani_nSpAtk, 0);
wpf_trace();
wait (1);
}
//k_st[k_ml] = !mouse_left; // can't use autofire on a sword
}
str_for_num(hp_s1, my._hp);
wait (1);
}
zotf_die();
}
/*******************************
enemy_fight
ai_a1
enemy / ai action
*******************************/
action enemy_fight { // attached to the enemy
ai_e1 = me; // I'm the enemy
ai_e1._hp = ai_nHpD; // and I have 100 _hp
zotf_new();
while (ME != NULL) { // as long as I'm alive
if (my._hp <= 0) { break; }
if ((vec_dist (my.x, player.x) < ((my.max_x - my.min_x) * ai_nAlertDist))
&& player._hp > 0) {// the player approaches the enemy
vec_diff(temp, player.x, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac
ai_vDist.x = 5 * time_step;
ai_vDist.y = 0;
ai_vDist.z = 0;
zotf_st(_WALK);
ent_move(ai_vDist, nullvector);
zotf_ani(ani_nSpWalk, 1);
if (vec_dist (my.x, player.x) < (my.max_x * ai_nAtkDist)) { // if the player comes closer than 50 quants attack him
zotf_st(_ATK1);
while (my._anip < 100){
//if (my._atkTm <= 0) {
wpf_trace();
//my._atkTm = 16 * 6;
//}
zotf_ani(ani_nSpAtk, 0);
wait (1);
}
}
} else { // the player is farther than 200 quants away
zotf_st(_STAND);
zotf_ani(ani_nSpStand, 1);
}
wait (1);
}
zotf_die();
}
function particle_sparks() {
temp.x = random(2) - 1;
temp.y = random(2) - 1;
temp.z = random(1) - 1.5;
vec_add (my.vel_x, temp);
my.alpha = 30 + random(50);
my.bmap = imSpark;
my.size = 5;
my.flare = on;
my.bright = on;
my.move = on;
my.lifespan = 20;
my.function = fade_particle;
my.gravity =0;
my.beam = on;
my.streak = on;
}
function particle_blood() {
temp.x = random(2) - 1;
temp.y = random(2) - 1;
temp.z = random(1) - 1.5;
vec_add (my.vel_x, temp);
my.alpha = 70 + random(30);
my.bmap = imBlood;
my.size = 6;
my.flare = on;
my.bright = on;
my.move = on;
my.lifespan = 20;
my.function = fade_particle;
}
function fade_particle() {
my.alpha -= 5 * time_step;
if (my.alpha < 0) {my.lifespan = 0;}
}
main1.wdl
path "images";
path "models";
path "sounds";
include <rsr1.wdl>;
include <sword-fight.wdl>;
var video_mode = 7; // 800x600
var video_depth = 32; // 16 bit mode
function main() {
level_load(lvl_s1);
wait(2); // wait for the level to be loaded
clip_size = 0; // show all the triangles for all the models
on_d = null; // disable the debug panel (key "D") because it is used for movement
fps_max = 40; // lock the frame rate to 40 fps
wait(1);
} see comments. Right about now would be a good time to complain about browser-specific code text box copy-n-paste functionality!?
|
|
|
Re: sword/fist fighting a.i code....
[Re: testDummy]
#222540
08/19/08 21:19
08/19/08 21:19
|
Joined: Jan 2006
Posts: 2,157 Connecticut, USA
Blink
OP

Expert
|
OP

Expert
Joined: Jan 2006
Posts: 2,157
Connecticut, USA
|
i tested, but i got a bunch of errors. i had to add the font, so that error was fixed, and then when the level ran, i got this error in a dialog box:
Empty Pointer in enemy fight:
((vec_dist(my.x,player.x)<((my.max_x-my.min_x)*ai_nAlertDist))&&player._hp>0)
My Famous Quotes: "Hip hop is like a virus, infecting everyone and everything around it. Every form of media has some way,shape or form, assimilated hip hop into it." It has also mutated into other strains like, trip hop, house, rap, gangster, and conscious forms. Once you are infected with it, its with you for life."
|
|
|
Re: sword/fist fighting a.i code....
[Re: Blink]
#222543
08/19/08 21:20
08/19/08 21:20
|
Joined: Jan 2006
Posts: 2,157 Connecticut, USA
Blink
OP

Expert
|
OP

Expert
Joined: Jan 2006
Posts: 2,157
Connecticut, USA
|
i am still running A6.60, if that helps at all.
My Famous Quotes: "Hip hop is like a virus, infecting everyone and everything around it. Every form of media has some way,shape or form, assimilated hip hop into it." It has also mutated into other strains like, trip hop, house, rap, gangster, and conscious forms. Once you are infected with it, its with you for life."
|
|
|
Re: sword/fist fighting a.i code....
[Re: Blink]
#222546
08/19/08 21:44
08/19/08 21:44
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
Perhaps, if the player is added first in WED, before the enemies, the error is not produced. Regardless, there should be a check against NULL for the player pointer. trade out the entire function:
/*******************************
enemy_fight
ai_a1
enemy / ai action
*******************************/
action enemy_fight { // attached to the enemy
ai_e1 = me; // I'm the enemy
my._hp = ai_nHpD; // and I have 100 _hp
zotf_new();
while (ME != NULL) { // as long as I'm alive
if (my._hp <= 0) { break; }
if (player == NULL) { goto(fNullPlayer); }
if ((vec_dist (my.x, player.x) < ((my.max_x - my.min_x) * ai_nAlertDist))
&& player._hp > 0) {// the player approaches the enemy
vec_diff(temp, player.x, my.x);
vec_to_angle(my.pan, temp);
my.tilt = 0; // I'm a maniac
ai_vDist.x = 5 * time_step;
ai_vDist.y = 0;
ai_vDist.z = 0;
zotf_st(_WALK);
ent_move(ai_vDist, nullvector);
zotf_ani(ani_nSpWalk, 1);
if (vec_dist (my.x, player.x) < (my.max_x * ai_nAtkDist)) { // if the player comes closer than 50 quants attack him
zotf_st(_ATK1);
while (my._anip < 100){
//if (my._atkTm <= 0) {
wpf_trace();
//my._atkTm = 16 * 6;
//}
zotf_ani(ani_nSpAtk, 0);
wait (1);
}
}
} else { // the player is farther than 200 quants away
zotf_st(_STAND);
zotf_ani(ani_nSpStand, 1);
}
fNullPlayer:
wait (1);
}
zotf_die();
} If the player pointer is NULL, or becomes NULL, execution should skip to label fNullPlayer, over the rest of the code, then to wait(1), and back to the while evaluation. This should remove the error. Perhaps, that 'solution' is superior to a one time check (while(player == NULL) { wait(1); }). i had to add the font, so that error was fixed The font had to be added to the images folder here also. The source of the original snippet in this thread, probably wasn't found here. It was assumed, that resource file and others were already added there. If error solved, well done, all the same.
|
|
|
Re: sword/fist fighting a.i code....
[Re: testDummy]
#222572
08/19/08 23:33
08/19/08 23:33
|
Joined: Jan 2006
Posts: 2,157 Connecticut, USA
Blink
OP

Expert
|
OP

Expert
Joined: Jan 2006
Posts: 2,157
Connecticut, USA
|
works perfectly! wow, how many times have you saved me from myself, trying to write a script and failing,lol? i really appreciate your efforts as usual, and already have you down for credits in my other projects. you are amazing, tD.
My Famous Quotes: "Hip hop is like a virus, infecting everyone and everything around it. Every form of media has some way,shape or form, assimilated hip hop into it." It has also mutated into other strains like, trip hop, house, rap, gangster, and conscious forms. Once you are infected with it, its with you for life."
|
|
|
|