Hi I am lookin to add an AI and move them round a map purely by updating the script file. However I get an annoying error about nodes.
First I set up some origins:
spawn script_origin "targetname" "sp1pos1"
$sp1pos1.origin = ( -3203 -186 -47)
$sp1pos1.angle = 285
spawn script_origin "targetname" "sp1pos2"
$sp1pos2.origin = ( -2995 -216 -47)
spawn script_origin "targetname" "sp1pos3"
$sp1pos3.origin = ( -3001 -470 -47)
spawn script_origin "targetname" "sp1pos4"
$sp1pos4.origin = ( -3243 -459 -47)
I am spawning the AI as follows:
spawn "human/multiplayer_german_wehrmact_colonel.tik" "targetname" "Colonel"
level.SpawnNumber = 1
$Colonel.origin = $("sp" + level.SpawnNumber + "pos1").origin
$Colonel.angle = $("sp" + level.SpawnNumber + "pos1").angle
$Colonel ai_on
//$Colonel.mood "alert"
//$Colonel.enableEnemy
$Colonel physics_on
$Colonel resetleash
$Colonel leash 500
$Colonel weapon "Walter P38"
This all works fine. I then want to move the character between to point, I don't really need a whole patrol path, I jsut want to say move to point X. So I am currently doing this:
$Colonel thread global/walkto.scr::start $sp1pos2
$Colonel waittill movedone
However I'm getting the follwoing error:
Path not found in 'Actor::MoveToPatrolCurrentNode' for (entnum 155, radnum -1, targetname 'Colonel') from (-3203.000000 -186.000000 -47.875000) to (-2995.000000 -216.000000 -47.000000)
Reason: couldn't find start node
Can anyone help me!!??
How can I script an AI?
Moderator: Moderators
How can I script an AI?
[VS-UK]Capt.Parts[BnHQ]
I've got this to work now using only scripting! So in theory there is no reason we couldn't have bots in standard maps!
I appreciate that tis would be a lot of work in setting up all the waypoints but is possible. I've only tested this for spearhead.
Note I haven't gone to the impressive lengths in my code that jv_map has. Therefore at the moment when I turn on the EnableEnemy the AI will attack anyone it can see not only allies.
The code needs cleaning up a bit however it all works. I suspect I have a few lines of code that do anything from where I've been testing.
I appreciate that tis would be a lot of work in setting up all the waypoints but is possible. I've only tested this for spearhead.
Note I haven't gone to the impressive lengths in my code that jv_map has. Therefore at the moment when I turn on the EnableEnemy the AI will attack anyone it can see not only allies.
The code needs cleaning up a bit however it all works. I suspect I have a few lines of code that do anything from where I've been testing.
Code: Select all
SetupColonelPositions:
//spawn script_origin "targetname" "sp1pos1"
spawn info_waypoint "targetname" "sp1pos1"
$sp1pos1.origin = ( -3203 -186 -47)
$sp1pos1.angle = 285
$sp1pos1.target = $sp1pos2
spawn info_waypoint "targetname" "sp1pos2"
$sp1pos2.origin = ( -2995 -216 -47)
$sp1pos2.target = $sp1pos3
spawn info_waypoint "targetname" "sp1pos3"
$sp1pos3.origin = ( -3001 -470 -47)
$sp1pos3.target = $sp1pos4
spawn info_waypoint "targetname" "sp1pos4"
$sp1pos4.origin = ( -3243 -459 -47)
$sp1pos4.target = $sp1pos1
spawn script_origin "targetname" "sp1TurnTo"
$sp1TurnTo.origin = ( -3096 -502 0)
end
ColonelMovement:
/* justatest:
//$Colonel walkto $sp1pos2
//$Colonel.destination = $sp1pos2
$Colonel thread global/walkto.scr::start $sp1pos2
$Colonel waittill movedone
iprintlnbold "got to 2"
wait 5
$Colonel thread global/walkto.scr::start $sp1pos3
//$Colonel.destination = $sp1pos3
$Colonel waittill movedone
iprintlnbold "got to 3"
wait 5
$Colonel thread global/walkto.scr::start $sp1pos4
$Colonel waittill movedone
iprintlnbold "got to 4"
wait 5
$Colonel thread global/walkto.scr::start $sp1pos1
$Colonel waittill movedone
iprintlnbold "got to 1"
wait 5
goto justatest
*/
local.shortwaittime = 3 + randomint(3)
local.longwaittime = 10 + randomint(10)
local.longorshort = randomint(2)
if (local.longorshort == 1)
{
wait local.shortwaittime
}
else
{
wait local.longwaittime
}
local.pointtowalkto = randomint(3) + 1
if ( local.pointtowalkto != level.CurrentPosition)
{
$("sp" + level.SpawnNumber + "pos" + level.CurrentPosition).target = $("sp" + level.SpawnNumber + "pos" + local.pointtowalkto)
$("sp" + level.SpawnNumber + "pos" + local.pointtowalkto).target = null
println ("Walking to: " + "$sp" + level.SpawnNumber + "pos" + local.pointtowalkto)
println ($("sp" + level.SpawnNumber + "pos" + local.pointtowalkto).origin )
$Colonel walkto $( "sp" + level.SpawnNumber + "pos" + local.pointtowalkto)
$Colonel waittill movedone
level.CurrentPosition = local.pointtowalkto
}
thread ColonelMovement
end
CreateColonel:
waitthread SetupColonelPositions
spawn "human/multiplayer_german_wehrmact_colonel.tik" "targetname" "Colonel"
//level.SpawnNumber = randomint(4)
level.SpawnNumber = 1
level.CurrentPosition = 1
//$Colonel.origin = ( -2760 -620 -57)
//$Colonel.angle = 0
$Colonel.origin = $("sp" + level.SpawnNumber + "pos1").origin
$Colonel.angle = $("sp" + level.SpawnNumber + "pos1").angle
$Colonel ai_on
//$Colonel.mood "alert"
//$Colonel.enableEnemy
$Colonel physics_on
$Colonel resetleash
$Colonel leash 500
$Colonel weapon "Walter P38"
$Colonel.target = $("sp" + level.SpawnNumber + "pos1")
//$Colonel patrolpath $("sp" + level.SpawnNumber + "pos1")
$Colonel nosurprise 0
//sound_awareness
$Colonel.enableEnemy = 0
$Colonel thread ColonelDefendHimself
$Colonel thread ColonelKilled
thread ColonelMovement
end
ColonelDefendHimself:
$Colonel.enableEnemy = 0
KeepChecking:
local.FoundTarget = 0
for (local.i = 1; local.i <= player.size; local.i++)
{
if ($player[local.i])
{
if ($player[local.i].dmteam == allies)
{
if ($Colonel cansee $player[local.i])
{
$Colonel.enableEnemy = 1
local.FoundTarget = 1
}
}
}
}
if (local.FoundTarget == 0)
{
$Colonel.enableEnemy = 0
}
wait 0.2
goto KeepChecking
//$Colonel attackplayer
end
ColonelKilled:
self waittill death
iprintlnbold "Colonel has been assassinated"
wait 2
teamwin allies
end
[VS-UK]Capt.Parts[BnHQ]
