I'm trying to make ai completly controlled by cog. Everything is working fine but Damaged and Killed messages are not working.
heres the cog if you can see whats wrong.
heres the cog if you can see whats wrong.
Code:
symbols thing ai thing victim local sound aigunfire template weaponshot vector randVec local vector forward local vector left local vector right local vector newVel local flex hp=100.0 flex reactionTime=0.5 flex aifov=160 flex aisightdist=5 flex fireRate=0.3 flex firePause=1.5 flex reload=3.0 flex attackdist=0.5 flex jumpRate=0.1 flex runningSpeed=1.0 flex jumpSpeed=0.4 flex damage_type local flex damage_amount local int debugMode=1 int weaponBurst=3 int shotsfired=0 local int magazine=0 local int oldvictim=-1 local message startup message pulse message damaged message timer message killed end # ========== code startup: CaptureThing(ai); SetThingPulse(ai, reactionTime); SetArmedMode(ai, 1); AISetMoveSpeed(ai, runningSpeed); if(debugMode = 1) { Print("startup"); } Return; # .......... pulse: # .......... # Looking # .......... victim = FirstThingInView(ai, aifov, aisightdist, 0x404); if((victim != -1) && (victim != ai) && (GetThingHealth(victim) != 0)) { Print("attacking1"); movement = GetThingThrust(victim); # .......... # Attack # .......... // SetThingLook(ai, VectorSub(GetThingPos(victim), GetThingPos(ai))); AiSetLookPos(ai, GetThingPos(victim)); oldvictim = victim; if(attacking == 0) { SetTimerEx(fireRate, 1, 0.0, 0.0); attacking = 1; } if(VectorDist(GetThingPos(ai), GetThingPos(victim)) > attackdist) { // AiSetMovePos(ai, GetThingPos(victim)); call attack_forward; } else if(VectorDist(GetThingPos(ai), GetThingPos(victim)) <= attackdist) { StopThing(ai); } // if(VectorX(movement) > 0.5) // { // call strafe_right; // } // else if(VectorX(movement) < -0.5) // { // call strafe_left; // } } else if((victim == -1) || (victim == ai) || (GetThingHealth(victim) || 0)) { attacking = 0; KillTimerEx(1); if((oldvictim != -1) && (VectorDist(GetThingPos(ai), GetThingPos(victim)) <= 2.0)) { SetThingVel(ai, VectorScale(GetThingLVec(ai), -0.5)); AiSetLookPos(ai, GetThingPos(victim)); oldvictim = -1; victim = -1; } } if(debugMode = 1) { Print("pulse"); } Return; # .......... damaged: damage_type = GetParam(1); damage_amount = GetParam(0); hp = (hp-damage_amount); if(hp <= 0) { SetPulse(0); DestroyThing(ai); } if(debugMode = 1) { Print("damaged"); } Return; # .......... timer: # .......... # Attack # .......... If(GetSenderID() == 1) { if(magazine < 30) { if(shotsfired < weaponBurst) { randVec = VectorSet((Rand()-0.5)*5, (Rand()-0.5)*5, 0.0); dummy = FireProjectile(ai, weaponshot, -1, -1, '0 0.02 0', randVec, 1.0, 0x30, 0, 0); shotsfired = (shotsfired + 1); magazine = (magazine + 1); SetTimerEx(fireRate, 1, 0.0, 0.0); } else if(shotsfired >= weaponBurst) { shotsfired = 0; SetTimerEx(firePause, 1, 0.0, 0.0); } } else if(magazine >= 30) { shotsfired = 0; magazine = 0; SetTimerEx(reload, 1, 0.0, 0.0); } if(debugMode = 1) { Print("timer"); } } Return; # .......... killed: StopThing(ai); SetPulse(0); KillTimerEx(1); if(debugMode = 1) { Print("killed"); } Return; # .......... attack_forward: forward = VectorScale(GetThingLVec(ai), runningSpeed); SetThingVel(ai, forward); if(Rand() < jumpRate) { DetachThing(ai); newVel = VectorAdd(VectorSet(0.0, 0.0, jumpSpeed), GetThingVel(ai)); SetThingVel(ai, newVel); } if(debugMode = 1) { Print("forward"); } Return; # .......... strafe_left: left = VectorScale(VectorSub(GetThingLVec(rbot), '-1 0 0'), runningSpeed); SetThingVel(ai, left); if(debugMode = 1) { Print("left"); } Return; # .......... strafe_right: right = VectorScale(VectorSub(GetThingLVec(rbot), '1 0 0'), runningSpeed); SetThingVel(ai, right); if(debugMode = 1) { Print("right"); } Return; end
I am _ Ace_1 _ , and I approve this message.