2007.05.12, 03:21 PM
Fy Trooper, script with bug:
PROBLEMS/QS:
*solved*Do I need the ' and 's when I assign a variable something thats not true false or a number?
*solved*Does this work?: if (state!='fell') state='dead';
*solved*Error, No anim named idle
*solved*Engine freezes
*solved*They chase after eachother
The game runs less than one fps with a bunch of these characters (usually runs about 25-45 fps, though it can go down to 15 or up to 60 in different parts of the map)
Code:
var mood='guard';
var state='idle';
var secondaryState='';
var target;
var targetDistance='na';
function fyConstruct(obj)
{
obj.model.on=true;
obj.model.name='FY Trooper';
obj.model.lit=DIM3_MODEL_LIT_VERTEX;
obj.model.shadow.on=true;
obj.setting.team='UNSEEN';
obj.setting.openDoors=false;
obj.setting.damage=true;
obj.setting.ignorePickUpItems=true;
obj.size.x=1299;
obj.size.z=1318;
obj.size.y=4476;
obj.size.weight=230;
obj.health.maximum=15;
obj.health.start=15;
obj.setting.pushable=true;
obj.health.fallDamageMinimumHeight=5000;
obj.health.fallDamageFactor=15;
obj.turnSpeed.facingWalk=5;
obj.turnSpeed.motionWalk=5;
obj.turnSpeed.facingRun=5.2;
obj.turnSpeed.motionRun=5.2;
obj.turnSpeed.facingCrawl=4;
obj.turnSpeed.motionCrawl=4;
obj.turnSpeed.facingAir=4;
obj.turnSpeed.motionAir=4;
obj.forwardSpeed.walk=96;
obj.forwardSpeed.crawl=51;
obj.forwardSpeed.air=81;
obj.forwardSpeed.acceleration=5;
obj.forwardSpeed.deceleration=9;
obj.forwardSpeed.accelerationAir=2.0;
obj.forwardSpeed.decelerationAir=1.5;
obj.sideSpeed.walk=61;
obj.sideSpeed.run=121;
obj.sideSpeed.crawl=31;
obj.sideSpeed.air=51;
obj.sideSpeed.acceleration=5;
obj.sideSpeed.deceleration=9;
obj.sideSpeed.accelerationAir=2.0;
obj.sideSpeed.decelerationAir=1.5;
obj.verticalSpeed.normal=51;
obj.verticalSpeed.acceleration=11;
obj.verticalSpeed.deceleration=21;
obj.objectSpeed.bumpHeight=500;
// setup weapon
obj.weapon.add('pistol_bot');
}
function fySpawn(obj)
{
obj.model.animation.showMesh('BL15');
obj.model.animation.start('idle_guard');
obj.watch.start(50000);
}
function fyAnimation(obj)
{
if (mood=='guard') {
obj.motionVector.stop();
}
switch (state) {
case 'idle':
obj.model.animation.startThenChange('idle_'+mood+secondaryState,'idle_'+mood);
secondaryState='';
obj.motionVector.stop();
return;
case 'walk':
obj.forwardSpeed.walk=96;
obj.motionVector.walkToObject(target);
obj.model.animation.startThenChange('walk_agg'+secondaryState,'walk_agg');
secondaryState='';
return;
case 'run':
obj.forwardSpeed.walk=156;
obj.motionVector.walkToObject(target);
obj.model.animation.startThenChange('run_agg'+secondaryState,'run_agg');
secondaryState='';
return;
case 'fall':
secondaryState='';
obj.model.animation.startThenChange('trip_'+mood,'falling');
obj.motionVector.stop();
return;
case 'dead':
secondaryState='';
obj.model.animation.start('dead');
obj.motionVector.stop();
return;
case 'fell':
secondaryState='';
obj.model.animation.start('fell');
obj.motionVector.stop();
return;
}
}
function fyWatch(obj,subEvent)
{
if (obj.watch.objectTeam!='UNSEEN') {
switch (subEvent) {
case DIM3_EVENT_WATCH_OBJECT_NEAR:
fyDistanceSubtract(obj);
target=obj.watch.objectId;
mood='agg';
return;
case DIM3_EVENT_WATCH_OBJECT_FAR:
fyDistanceAdd(obj);
fyAnimation(obj);
return;
case DIM3_EVENT_WATCH_OBJECT_DEATH:
obj.motionVector.stop();
targetDistance='n/a'
state=idle;
fyAnimation;
return;
}
}
}
function fyDistanceSubtract(obj)
{
switch (targetDistance) {
case 'na':
targetDistance='far';
state='idle';
fyAnimation(obj);
obj.watch.start(40000);
return;
case 'far':
targetDistance='medium';
state='run';
fyAnimation(obj);
obj.watch.start(30000);
return;
case 'medium':
targetDistance='close';
state='walk';
fyAnimation(obj);
obj.watch.start(20000);
return;
case 'close':
targetDistance='closest';
state='idle';
fyAnimation(obj);
obj.watch.start(10000);
return;
}
}
function fyDistanceAdd(obj)
{
switch (targetDistance) {
case 'closest':
targetDistance='close';
state='idle';
fyAnimation(obj);
obj.watch.start(5000);
return;
case 'far':
targetDistance='na';
state='run';
fyAnimation(obj);
obj.watch.start(30000);
return;
case 'medium':
targetDistance='far';
state='walk';
fyAnimation(obj);
obj.watch.start(20000);
return;
case 'close':
targetDistance='medium';
state='idle';
fyAnimation(obj);
obj.watch.start(10000);
return;
}
}
function event(obj,mainEvent,subEvent,id,tick)
{
switch (mainEvent) {
case DIM3_EVENT_CONSTRUCT:
fyConstruct(obj);
return;
case DIM3_EVENT_SPAWN:
fySpawn(obj);
return;
case DIM3_EVENT_FALL:
state='fall';
return;
case DIM3_EVENT_LAND:
state='fell';
return;
case DIM3_EVENT_DIE:
if (state!='fell') state='dead';
return;
//case DIM3_EVENT_COLLIDE:
// fyCollide(obj);
// return;
//case DIM3_EVENT_DAMAGE:
// fyDamage(obj);
// return;
case DIM3_EVENT_WATCH:
fyWatch(obj,subEvent);
return;
}
}*solved*Do I need the ' and 's when I assign a variable something thats not true false or a number?
*solved*Does this work?: if (state!='fell') state='dead';
*solved*Error, No anim named idle
*solved*Engine freezes
*solved*They chase after eachother
The game runs less than one fps with a bunch of these characters (usually runs about 25-45 fps, though it can go down to 15 or up to 60 in different parts of the map)
