0 registered members (),
1,397
guests, and 7
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
State Transition
#203425
04/21/08 23:53
04/21/08 23:53
|
Joined: Oct 2007
Posts: 42 Minnesota, USA
Techd
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 42
Minnesota, USA
|
I have a NPC that comes close to the player stops and plays innocent animation. I need some help on getting the NPC to walk away from the player once clicked on so that the loop starts over. DEFINE _animframe, skill26;
DEFINE _angle, skill46; var stand_speed = 2;
var walk_speed = 12;
var innocent_speed = 2;
var follow_speed = 10;
var stand_speed = 2;
action follower
{
my.enable_click = on;
while (player == null) { wait(1); }
while(1)
{
you = null;
trace_mode = ignore_me + ignore_models;
temp = trace(my.x, player.x);
if (you != null)
{
if (you.transparent == on)
{
trace_mode += ignore_you;
temp = trace(my.x, player.x);
}
}
if (temp != 0)
{
my._animframe += time * stand_speed;
ent_cycle("stand", my._animframe);
}
else
{
vec_set (temp, nullvector);
temp.x = 1;
vec_rotate (temp, player.pan);
vec_set (temp, my.x);
vec_sub (temp, player.x);
if (my.skill10 < 200) // player comes closer than 200 quants to the npc
{
my._animframe += time * innocent_speed;
ent_cycle("innocent", my._animframe);
}
if (vec_dist (my.x, player.x) > 100)
{
temp.x = player.x - my.x;
temp.y = player.y - my.y;
temp.z = 0;
vec_to_angle(my.pan, temp); // rotate towards the player
my._animframe += time * walk_speed;
ent_cycle("run", my._animframe);
vec_set (temp, nullvector);
temp.x = time * follow_speed;
ent_move (temp, nullvector);
}
}
wait(1);
}
}
Last edited by Techd; 04/22/08 00:02. Reason: Typo's
Life is what you make it just like Games!
|
|
|
Re: State Transition
[Re: Techd]
#203808
04/24/08 11:06
04/24/08 11:06
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
The following is only an example. The example was created as diversion while waiting for the day to begin. After very light testing, it seems to work somewhat. Note that the actor or ai will return shortly after leaving. That may be a result of guesswork. Press key k to simulate clicking during innocence state. Adequate mouse behavior was not setup. The click test portion was not tested at all. Tag 'hackDbg' denotes quick hacks used for testing and time savings. Some details were not known. Some considerations were left out. Some better practices were not adhered to. Use of the example is neither advocated nor discouraged. No, it's not just a patching of pre-existing code. Use a smaller fixed font to view the source. Silly Jumbo Courier New type fonts, NO, not if screen real estate is precious. (i.e the source code box is over sized for the sample; horizontal scrolling is unnecessary; varies with resolution)
// tD example (ex) A6.6 C-Script
// slapped together / tested very lightly
// 2008-04-24
// goto 'school' parrot rhetoric not desired
// "I can do better in x min's bullsh!t" not desired
// --valid suggestions for better practices are desired
// --many better practices not used
// external (germ) analysis not desired
/*
http://www.coniserver.net/ubb7/ubbthreads.php?ubb=showflat&Number=203425#Post203425
Techd
I have a NPC that comes close to the player stops
and plays innocent animation.
I need some help on getting the NPC to walk away from the player
once clicked on so that the loop starts over.
*/
/*
conv:
_ = skill or local prefix
aif = ai functions prefix
B = boolean suffix
D = default suffix
e = entity prefix
gm = game suffix
id = identifier prefix
sp = speed suffix
st = state prefix
*/
// external ?_h.wdl
var mvDistR[3];
define _animframe, skill26;
define _angle, skill46;
define _id, skill47;
define idUndef = 0;
define idMap = 1;
define idEntity = 2;
define idObj = 3;
define idPlayer = 4;
define idActor = 17;
var gmState = 0;
define gmLive = 1;
var actorsB = 1;
// place these in false .wdl header
// ai1-ex_h.wdl
define _aiSt, skill48; // state of ai
define stWait = 1;
define stFollow = 2;
define stInnocent = 3;
define stLeave = 4;
// anim speeds
var innocentSp = 2;
var followSp = 10;
var standSp = 2;
var walkSp = 12;
// ai sight vars
var sightHitDist = 0; // dist to actor
var sightHitB = 0; // hit an actor
var sightNotActorB = 0; // if trace hit non actor
var sightObstB = 0;
var aiDistNearD = 100;
var aiDistYoD = 200;
entity* eSighted; // sighted actor
entity* eSightObst; // sighted obst, non-actor
// aif (ai functions)
function aifEvent1();
function aifMove1();
function aifNew1();
function aifNewClickable1();
function aifSightT1(&_pos);
function aifTurnSimple1();
var eventDbgK = 0; //hackDbg
// ai1-ex.wdl
// include <ai1-ex_h.wdl>;
function aifNew1() {
my._id = idActor;
my.event = aifEvent1;
}
function aifNewClickable1() {
aifNew1();
}
/*****************************
aifTurnSimple1
define better turn function later
*****************************/
function aifTurnSimple1(&_pos) {
vec_diff(temp, _pos, my.x);
vec_to_angle(temp, temp);
my.pan = ang(temp.pan);
}
/*****************************
aifSightT1
ai sight trace (uses me)
returns true or false (sightHitB)
_pos = position to trace to
eSighted = entity sighted or NULL
sighted entity should be an actor
eSightObst = non actor obst or NULL if actor or map hit
sightObstHit = 0, if actor hit, or idMap, idEntity otherwise
sightHitDist = 0 or dist to hit entity or map obj
*****************************/
function aifSightT1(&_pos) {
sightHitB = 0;
sightHitDist = 0;
sightObstB = 0;
eSightObst = NULL;
eSighted = NULL;
you = NULL;
trace_mode = ignore_me + ignore_passable;
sightHitDist = trace(my.x, _pos);
// if (sightHitDist == 0) { goto(fRetFalse); }
if (you == NULL) {
sightObstB = idMap;
goto(fRetFalse);
}
you._id = idActor; // hackDbg player must be set to idActor
if (you._id != idActor) {
sightObstB = idEntity;
eSightObst = you;
goto(fRetFalse);
}
eSighted = you;
goto(fRetTrue);
fRetFalse:
// false
return(0);
// true path
fRetTrue:
sightHitB = 1;
return(sightHitB);
}
/*****************************
aifMove1
*****************************/
function aifMove1() {
//printStr0("aifMove1");
my._animframe += time * walkSp;
ent_cycle("run", my._animframe);
mvDistR.x = followSp * time;
move_mode = ignore_me + ignore_passable;
ent_move(mvDistR, nullvector);
}
/*****************************
aifEvent1
*****************************/
function aifEvent1() {
if (event_type == event_click || eventDbgK) {
my._aiSt = stLeave;
vec_diff(temp, my.x, player.x); // reversed here
vec_to_angle(temp, temp);
my.pan = ang(temp.pan);
my.enable_click = off;
}
}
/*****************************
aAiFollower1
*****************************/
action aAiFollower1 {
aifNew1();
//aifNewClickable1();
gmState = gmLive; //hackDbg
while(gmState == gmLive) {
vec_set(mvDistR, nullvector);
if (player == NULL || actorsB == 0) { goto(fNext); }
if (my._aiSt == stLeave) { goto(fStLeave); }
aifTurnSimple1(player.x); //hackDbg
if (my._aiSt == stInnocent) { goto(fStInnocent); }
if (my._aiSt == stFollow) { goto(fStFollow); }
my.enable_click = off;
//wait
fStWait:
//printStr0("wait");
my._aiSt = stWait;
if (vec_dist(my.x, player.x) > aiDistYoD) {
if (aifSightT1(player.x) == 1) {
goto(fStFollow);
}
}
my._animframe += time * standSp;
ent_cycle("stand", my._animframe);
goto(fNext);
//follow
fStFollow:
//printStr0("follow");
my._aiSt = stFollow;
if (vec_dist(my.x, player.x) < aiDistNearD) {
goto(fStInnocent);
}
aifMove1();
goto(fNext);
//leave
fStLeave:
//printStr0("leave");
my._aiSt = stLeave;
my.enable_click = off;
if (vec_dist(my.x, player.x) > aiDistYoD * 2) {
goto(fStWait);
}
aifMove1();
goto(fNext);
//innocent
fStInnocent:
//printStr0("Innocent");
if (vec_dist(my.x, player.x) > aiDistYoD) {
goto(fStWait);
}
my._aiSt = stInnocent;
my._animframe += time * innocentSp;
ent_cycle("innocent", my._animframe);
my.enable_click = on;
if (key_k) { eventDbgK = 1; aifEvent1(); eventDbgK = 0;} // hackDbg
goto(fNext);
fNext:
wait(1);
}
}
|
|
|
Re: State Transition
[Re: testDummy]
#203852
04/24/08 15:35
04/24/08 15:35
|
Joined: Oct 2007
Posts: 42 Minnesota, USA
Techd
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 42
Minnesota, USA
|
Thank you for your reply, before I dive in is this code A6 or A7?
because I'm coding in A6 C-Script.
Life is what you make it just like Games!
|
|
|
Re: State Transition
[Re: Techd]
#203854
04/24/08 15:53
04/24/08 15:53
|
Joined: Oct 2007
Posts: 5,210 İstanbul, Turkey
Quad
Senior Expert
|
Senior Expert
Joined: Oct 2007
Posts: 5,210
İstanbul, Turkey
|
above code seems like c-script, i cant tell if the a7 is needed but there is high possiblity it will work with 6.6
3333333333
|
|
|
Re: State Transition
[Re: Quad]
#203855
04/24/08 16:00
04/24/08 16:00
|
Joined: Oct 2007
Posts: 42 Minnesota, USA
Techd
OP
Newbie
|
OP
Newbie
Joined: Oct 2007
Posts: 42
Minnesota, USA
|
Thankz Quadraxas I'll try it and see how it works out for me
Life is what you make it just like Games!
|
|
|
|