First of all, thank you very much in advance to those who take the time to read and try to help.
I left the link of the original thread above. I tried to adapt the existing code here to gta samp 0.3.dl version but failed. Can anyone help?
Untagged - Release - CheckPoint Seeking Driver
This Cleo Template is a Basic Example of Auto-Driving using the Built-in Artificial Intelligence of GTA San Andreas. Inspiration of its creation and its publicity: Publicly Educate its readers about a way on manipulating the game's built-in AI to drive any vehicle. The Source Code Can be used...
ugbase.eu
C#:
{
* WILL ONLY WORK ON SAMP 0.3.7 R1
* If you want this script to work on other SAMP Versions, Modify the Memory Pointers of Snippet Named "GetCheckPointPositions" found at "Functions" Area
* Type "PLEASEDRIVE" to toggle autodriving
* SCM AI Manipulation is Based on:
- https://gtaforums.com/topic/403594-sa-~-cleo-script-tutorial-~/?tab=comments#comment-1059452423
}
// ~~~~~~~~~~~Used Headers~~~~~~~~~~~
{$CLEO}
// ~~~~~~~~~~~End of Used Headers~~~~~~~~~~~
// ~~~~~~~~~~~Script Initial Setup~~~~~~~~~~~
0000: CheckPoint Seeker Driver by AJOM
const
MYVEHICLE = 31@
MYPOSITIONX = 30@
MYPOSITIONY = 29@
MYPOSITIONZ = 28@
CHECKPOINTX = 27@
CHECKPOINTY = 26@
CHECKPOINTZ = 25@
CHECKPOINTRADIUS = 24@
IMPROVEDCHECKPOINTX = 23@
IMPROVEDCHECKPOINTY = 22@
IMPROVEDCHECKPOINTZ = 21@
OLDCHECKPOINTX = 20@
OLDCHECKPOINTY = 19@
OLDCHECKPOINTZ = 18@
DRIVINGSTYLE = 17@
end
// ~~~~~~~~~~~End of Script Initial Setup~~~~~~~~~~~
:initialization
wait 0
// ~~~~~~~~~~~Activation Stage~~~~~~~~~~~
if and
0ADC: test_cheat "PLEASEDRIVE"
00DF: actor $PLAYER_ACTOR driving
004D: jump_if_false @initialization
03C0: MYVEHICLE = actor $PLAYER_ACTOR car
046C: 4@ = car MYVEHICLE driver
if 07D6: 4@ == $PLAYER_ACTOR
004D: jump_if_false @initialization
/* if 0AB1: @GetCheckPointPositions 1 _Mode 4 _StoreXYZ CHECKPOINTX CHECKPOINTY CHECKPOINTZ _StoreXYRadius CHECKPOINTRADIUS
then
else
0ACD: show_text_highpriority "~r~No CheckPoints Found!~n~Try Again Later." time 2000
0002: jump @initialization
end */
// ~~~~~~~~~~~End of Activation Stage~~~~~~~~~~~
// ~~~~~~~~~~~Car Initialization Stage~~~~~~~~~~~
DRIVINGSTYLE = 0 // used for land vehicles
03CC: enable_car MYVEHICLE stuck_check_distance_to 2.0 time_to 500
00AE: set_car MYVEHICLE traffic_behaviour_to 2 // avoid obstacles + ignore traffic lights
// 0423: set_car MYVEHICLE improved_handling_to 5.0
00AD: set_car MYVEHICLE AI_max_speed_to 999999.0 // the AI will use its maximum allowable speed
// ~~~~~~~~~~~End of Car Initialization Stage~~~~~~~~~~~
0ACD: show_text_highpriority "~y~AJOM's Basic CheckPoint Driver:~g~ENABLED" time 2000
:doautodriving
wait 0
// ~~~~~~~~~~~Possible Deactivation Stage~~~~~~~~~~~
if or
0ADC: test_cheat "PLEASEDRIVE"
80DF: not actor $PLAYER_ACTOR driving
856E: not car MYVEHICLE defined
then
:disableutodriving
if 056E: car MYVEHICLE defined
then 03A2: set_car MYVEHICLE status_to 0 // Stop the AI and let us drive again
end
0ACD: show_text_highpriority "~y~AJOM's Basic CheckPoint Driver:~r~DISABLED" time 2000
0002: jump @initialization
end
if 8185: not car MYVEHICLE health >= 241
then
0622: AS_actor $PLAYER_ACTOR bail_car MYVEHICLE
0ACD: show_text_highpriority "~y~AJOM's Basic CheckPoint Driver:~r~DISABLED Bailed from Burning Car" time 2000
0002: jump @initialization
end
if 0AB1: @GetCheckPointPositions 1 _Mode 4 _StoreXYZ CHECKPOINTX CHECKPOINTY CHECKPOINTZ _StoreXYRadius CHECKPOINTRADIUS
then
else :manualdrivingoverride // while there are no checkpoints, temporarily allow us to drive our vehicle
if DRIVINGSTYLE <> 0
then DRIVINGSTYLE = 0 // Force the AI to reset the destination
end
03A2: set_car MYVEHICLE status_to 0
0002: jump @doautodriving
end
// ~~~~~~~~~~~End of Possible Deactivation Stage~~~~~~~~~~~
// ~~~~~~~~~~~Manual Driving Override Stage~~~~~~~~~~~ Allows us to drive if Game Control Keys are being pressed
for 0@ = 0xB73458 to 0xB73466 step 0x4
0A8D: 1@ = read_memory 0@ size 0x4 virtual_protect 0
if 1@ == 0
004D: jump_if_false @manualdrivingoverride
end
0A8D: 0@ = read_memory 0xB73474 size 0x4 virtual_protect 0
0A8D: 1@ = read_memory 0xB73478 size 0x4 virtual_protect 0
if and
0@ == 0
1@ == 0
004D: jump_if_false @manualdrivingoverride
if 04AB: actor $PLAYER_ACTOR driving_plane
then
0A8D: 0@ = read_memory 0xB7347E size 0x2 virtual_protect 0
if 0@ <> 0
then
wait 500 // submission delay before activation of autodriving once again
0002: jump @manualdrivingoverride
end
end
// ~~~~~~~~~~~End of Manual Driving Override Stage~~~~~~~~~~~
// ~~~~~~~~~~~Near CheckPoint Detection Stage~~~~~~~~~~~
00AA: store_car MYVEHICLE position_to MYPOSITIONX MYPOSITIONY MYPOSITIONZ
0509: 4@ = distance_between_XY CHECKPOINTX CHECKPOINTY and_XY MYPOSITIONX MYPOSITIONY
if 0035: CHECKPOINTRADIUS >= 4@ // if we are near to the checkpoint
then
if 0AB1: @GetCheckPointPositions 1 _Mode 2 _StoreXYZ 4@ 5@ 6@ _StoreXYRadius 7@ // try using next checkpoint
then
if or
4@ <> 0.0
5@ <> 0.0
6@ <> 0.0
then // use Next CheckPoint Position
0087: CHECKPOINTX = 4@
0087: CHECKPOINTY = 5@
0087: CHECKPOINTZ = 6@
0087: CHECKPOINTRADIUS = 7@
end
end
end
// ~~~~~~~~~~~End of Near CheckPoint Detection Stage~~~~~~~~~~~
// ~~~~~~~~~~~CheckPoint Position Improver Stage~~~~~~~~~~~
0AB1: @GetPointToPointTrueNorthAngles 6 _FromXYZ MYPOSITIONX MYPOSITIONY MYPOSITIONZ _ToXYZ CHECKPOINTX CHECKPOINTY CHECKPOINTZ _StoreAngleX 5@ _StoreAngleZ 6@
02E3: 7@ = car MYVEHICLE speed
if 0025: CHECKPOINTRADIUS > 7@ // speed is slower against the checkpoint radius
then 0087: 7@ = CHECKPOINTRADIUS // use the radius as excess distance
end
0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ CHECKPOINTX CHECKPOINTY CHECKPOINTZ _ZAngle 6@ _XAngle 5@ _Distance 7@ _ReturnXYZ IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ
// ~~~~~~~~~~~End of CheckPoint Position Improver Stage~~~~~~~~~~~
// ~~~~~~~~~~~AI Decision Stage~~~~~~~~~~~
if 04A7: actor $PLAYER_ACTOR driving_boat
then 02D3: boat MYVEHICLE sail_to IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ
else
if 04A9: actor $PLAYER_ACTOR driving_heli
then 0743: heli MYVEHICLE fly_then_land_to IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ altitude 60.0 to 120.0
else
if 04AB: actor $PLAYER_ACTOR driving_plane
then 04D2: set_plane MYVEHICLE fly_autopilot_around_point IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ altitude_between 60.0 and 120.0
else
/* For Tracing the Route, REQUIRES SAMPFUNCS
0B55: convert_3D_coords MYPOSITIONX MYPOSITIONY MYPOSITIONZ to_screen 0@ 1@
0B55: convert_3D_coords IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ to_screen 2@ 3@
0B68: render draw_line_point1 0@ 1@ point2 2@ 3@ width 1 color 0xFF00FF00
*/
if or // if we have a new checkpoint
8045: OLDCHECKPOINTX <> CHECKPOINTX
8045: OLDCHECKPOINTY <> CHECKPOINTY
8045: OLDCHECKPOINTZ <> CHECKPOINTZ
then
0087: OLDCHECKPOINTX = CHECKPOINTX
0087: OLDCHECKPOINTY = CHECKPOINTY
0087: OLDCHECKPOINTZ = CHECKPOINTZ
DRIVINGSTYLE = 0 // Force the AI to reset the destination
end
00AA: store_car MYVEHICLE position_to 4@ 5@ 6@
02E3: 7@ = car MYVEHICLE speed
if and
83CE: not car MYVEHICLE stuck
7@ > 1.0
06BD: no_obstacles_between IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ and 4@ 5@ 6@ solid 1 car 0 actor 0 object 1 particle 0
// 8AE3: 7@ = not random_object_near_point 4@ 5@ 6@ in_radius 10.0 find_next 0
then // do an obstacle free driving
if DRIVINGSTYLE <> 1 // avoids resetting the task variables of AI decision making
then
DRIVINGSTYLE = 1
00AF: set_car MYVEHICLE driver_behaviour_to 8 // ignore road-paths
04E0: car MYVEHICLE abandon_path_radius 999999 // always drive in straight line
// 00A7: car MYVEHICLE drive_basic_to IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ
02C2: car MYVEHICLE drive_accurate_to IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ
end
else // do an obstacle smart driving
if DRIVINGSTYLE <> 2 // avoids resetting the task variables of AI decision making
then
DRIVINGSTYLE = 2
00AF: set_car MYVEHICLE driver_behaviour_to 1 // follow road, drive back if way is blocked
04E0: car MYVEHICLE abandon_path_radius 0 // never-ever drive straight
0704: car MYVEHICLE racedrive_to IMPROVEDCHECKPOINTX IMPROVEDCHECKPOINTY IMPROVEDCHECKPOINTZ // use racing AI
end
end
end
end
end
// ~~~~~~~~~~~End of AI Decision Stage~~~~~~~~~~~
0002: jump @doautodriving
// ~~~~~~~~~~~Functions~~~~~~~~~~~
:GetPointToPointTrueNorthAngles // 0AB1: @GetPointToPointTrueNorthAngles 6 _FromXYZ 0@ 1@ 2@ _ToXYZ 3@ 4@ 5@ _StoreAngleX 31@ _StoreAngleZ 30@
// Snippet by AJOM
// ~~~~~~~~~~~get z-angle towards the target
0087: 30@ = 4@ // Y2
0063: 30@ -= 1@ // Y1
0087: 31@ = 3@ // X2
0063: 31@ -= 0@ // X1
0AA5: _atan2 | 0x4207C0 2 2 | _X 31@ _Y 30@
0AE9: pop_float 30@ // store result from above operation
30@ *= 57.295779817106167876798171061675 // radians to degrees
30@ -= 90.0 // TrueNorth's z-angle lags 90 degrees
//
// ~~~~~~~~~~~get x-angle towards the target
0087: 31@ = 5@ // Z2
0063: 31@ -= 2@ // Z1
0509: 29@ = distance_between_XY 0@ 1@ and_XY 3@ 4@ // adjacent side
0AA5: _atan2 | 0x4207C0 2 2 | _X 29@ _Y 31@
0AE9: pop_float 31@ // store result from above operation
31@ *= 57.295779817106167876798171061675 // radians to degrees
//
0AB2: cleo_return 2 _fAngleX 31@ _fAngleZ 30@
:get3DXYZInFrontOfTrueNorth // 0AB1: @get3DXYZInFrontOfTrueNorth 6 _XYZ 0@ 1@ 2@ _ZAngle 3@ _XAngle 4@ _Distance 5@ _ReturnXYZ 0@ 1@ 2@
{
Snippet By AJOM
Based on Source: http://danceswithcode.net/engineeringnotes/rotations_in_3d/rotations_in_3d_part2.html
But Using:
X0 = _Distance = 5@ , Y0 = 0.0 , Z0 = 0.0
Yaw = _ZAngle = 3@ , Pitch = _XAngle = 4@ , Roll = 0.0
}
// Use Opcode.eXe's Coordinate system
4@ += 180.0 // WorldXAngle = TrueNorthXAngle + 180.0
3@ += 270.0 // WorldZAngle = (TrueNorthZAngle + 90.0) + 180.0 // we add another 180.0 degrees because we halfy revolve over the World X angle
//
// Compute X Offset = Cos(Pitch)*Cos(Yaw)*X0
02F7: 31@ = cosine 4@ // (float)
02F7: 30@ = cosine 3@ // (float)
006B: 31@ *= 30@ // (float)
006B: 31@ *= 5@ // (float)
//
// Compute Y Offset = Cos(Pitch)*Sin(Yaw)*X0
02F7: 30@ = cosine 4@ // (float)
02F6: 29@ = sine 3@ // (float)
006B: 30@ *= 29@ // (float)
006B: 30@ *= 5@ // (float)
//
// Compute Z Offset = -Sin(Pitch)*X0
02F6: 29@ = sine 4@ // (float)
006B: 29@ *= 5@ // (float)
29@ *= -1.0
//
005B: 0@ += 31@ // New X
005B: 1@ += 30@ // New Y
005B: 2@ += 29@ // New Z
0AB2: ret 3 0@ 1@ 2@
// For SAMP Versions other than 0.3.7 R1, go to this link and replace GetCheckPointPositions Snippet into its respective version:
//
:GetCheckPointPositions
{
0AB1: @GetCheckPointPositions 1 _Mode 0@ _StoreXYZ 19@ 18@ 17@ _StoreXYRadius 16@
_Mode = 0 --> Normal Checkpoint
_Mode = 1 --> Primary/Current Race Checkpoint
_Mode = 2 --> Secondary/Next Race Checkpoint
_Mode = 3 --> ANY Checkpoint(Priority Normal CheckPoint)
_Mode = 4 --> ANY Checkpoint(Priority Current Race CheckPoint)
_Mode = 5 --> ANY Checkpoint(Priority Next Race CheckPoint)
}
if 0AA2: 31@ = load_dynamic_library "samp.dll"
then
31@ += 0x21A10C
0A8D: 31@ = read_memory 31@ size 4 virtual_protect 0 // pMiscnfo
31@ += 12
0A8D: 30@ = read_memory 31@ size 4 virtual_protect 0 // fCheckpointPosX
31@ += 4
0A8D: 29@ = read_memory 31@ size 4 virtual_protect 0 // fCheckpointPosY
31@ += 4
0A8D: 28@ = read_memory 31@ size 4 virtual_protect 0 // fCheckpointPosZ
31@ += 4
0A8D: 15@ = read_memory 31@ size 4 virtual_protect 0 // fCheckpointExtentX
31@ += 4
0A8D: 13@ = read_memory 31@ size 4 virtual_protect 0 // fCheckpointExtentY
005B: 15@ += 13@
15@ /= 2.0
31@ += 8
0A8D: 27@ = read_memory 31@ size 4 virtual_protect 0 // bCheckpointsEnabled
31@ += 8
0A8D: 26@ = read_memory 31@ size 4 virtual_protect 0 // fRaceCheckpointPosX
31@ += 4
0A8D: 25@ = read_memory 31@ size 4 virtual_protect 0 // fRaceCheckpointPosY
31@ += 4
0A8D: 24@ = read_memory 31@ size 4 virtual_protect 0 // fRaceCheckpointPosZ
31@ += 4
0A8D: 23@ = read_memory 31@ size 4 virtual_protect 0 // fRaceCheckpointNextX
31@ += 4
0A8D: 22@ = read_memory 31@ size 4 virtual_protect 0 // fRaceCheckpointNextY
31@ += 4
0A8D: 21@ = read_memory 31@ size 4 virtual_protect 0 // fRaceCheckpointNextZ
31@ += 4
0A8D: 14@ = read_memory 31@ size 4 virtual_protect 0 // m_fRaceCheckpointSize
31@ += 5
0A8D: 20@ = read_memory 31@ size 4 virtual_protect 0 // bRaceCheckpointsEnabled
if 0@ == 0 // Normal CheckPoint Only
then
:passnormalcheckpoint
if 27@ == true // Normal CheckPoint Exists Somewhere
then
0087: 19@ = 30@
0087: 18@ = 29@
0087: 17@ = 28@
0087: 16@ = 15@
0485: return_true
else 059A: return_false
end
else
if 0@ == 1 // Current Race CheckPoint Only
then
:passcurrentracecheckpoint
if 20@ == true // Primary/Secondary Race CheckPoint Exists Somewhere
then
0087: 19@ = 26@
0087: 18@ = 25@
0087: 17@ = 24@
0087: 16@ = 14@
0485: return_true
else 059A: return_false
end
else
if 0@ == 2 // Next Race CheckPoints Only
then
:passnextracecheckpoint
if 20@ == true // Primary/Secondary Race CheckPoint Exists Somewhere
then
0087: 19@ = 23@
0087: 18@ = 22@
0087: 17@ = 21@
0087: 16@ = 14@
0485: return_true
else 059A: return_false
end
else // Any checkpoints is acceptable
if or
27@ == true // Normal CheckPoint Exists Somewhere
20@ == true // Primary/Secondary Race CheckPoint Exists Somewhere
then
if 0@ == 5 // priority Next Race CheckPoint
then
if 20@ == true // Primary/Secondary Race CheckPoint Exists Somewhere
then 0002: jump @passnextracecheckpoint
else 0002: jump @passnormalcheckpoint
end
else
if 0@ == 4 // priority Current Race CheckPoint
then
if 20@ == true // Primary/Secondary Race CheckPoint Exists Somewhere
then 0002: jump @passcurrentracecheckpoint
else 0002: jump @passnormalcheckpoint
end
else
if 27@ == true // Normal CheckPoint Exists Somewhere
then 0002: jump @passnormalcheckpoint
else 0002: jump @passcurrentracecheckpoint
end
end
end
else 059A: return_false
end
end
end
end
else 059A: return_false
end
0AB2: cleo_return 4 _XYZ 19@ 18@ 17@ _Radius 16@
// ~~~~~~~~~~~End of Functions~~~~~~~~~~~