Scripts / Moving Vehicles ( Script Help Needed )

Author
Message
Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 6th Mar 2015 00:17 Edited at: 6th Mar 2015 00:25
As you can see from the video, using Avram's planes script I modified it
to get the Vehicles to simply move along the ground.


The problem I am having is to get them to stop aiming at player and just follow
a path formation, but ever thing I try causes GG to crash now.
All credits for script to Avram

Had to put script in second post as it would not fit on this page for some reason
The script is below,
PM
Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 6th Mar 2015 00:26 Edited at: 6th Mar 2015 00:30
--Script credits to Avram (modified planes script )

-- save as cars.lua

attached as for some reason it will not fit page

Attachments

Login to view attachments
PM
Avram
GameGuru TGC Backer
18
Years of Service
User Offline
Joined: 3rd Sep 2006
Location: Serbia
Posted: 6th Mar 2015 09:56 Edited at: 6th Mar 2015 09:57
Well, my script is based on RotateToPlayer so the planes always fly above the player's head. I doubt you can make them follow waypoints if you have based the script on my plane script. I also have troubles getting entities to follow paths.

Good job though, I like what you've made with the cars
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 6th Mar 2015 20:20 Edited at: 6th Mar 2015 20:21
set them to characters in the fpe and try this script

civilian.lua (note you will need to place waypoints for them to follow)
Quote: "-- LUA Script - precede every function and global member with lowercase name of script

-- globals
local aniplaying = 0
ai_newdest_time = {}
ai_cover_on = {}
-- init when level first runs
function civilian_init(e)
ai_soldier_state[e] = "patrol";
ai_soldier_pathindex[e] = -1;
ai_start_x[e] = nil
ai_starting_heath[e] = nil
ai_ran_to_cover[e] = 0
ModulateSpeed(e,1.0)
ai_old_health[e] = 0
--CharacterControlStand(e)
ai_returning_home[e] = 0
ai_newdest_time[e] = -1
ai_cover_on[e] = 0
ai_alerted_spoken[e] = 0

end

function civilian_main(e)
EntObjNo = g_Entity[e]['obj'];
MoveUp(e,1)
-- Detect player distance (note: possible optimization here)
PlayerDX = g_Entity[e]['x'] - g_PlayerPosX;
PlayerDY = g_Entity[e]['y'] - g_PlayerPosY;
PlayerDZ = g_Entity[e]['z'] - g_PlayerPosZ;
PlayerDist = math.sqrt(math.abs(PlayerDX*PlayerDX)+math.abs(PlayerDY*PlayerDY)+math.abs(PlayerDZ*PlayerDZ));

--if ai_ran_to_cover[e] ~= 1 then
-- Always looking at player
--if PlayerDist < 200 then
--LookAtPlayer(e)
--AIEntityGoToPosition(EntObjNo,g_Entity[e]['x'],g_Entity[e]['z'])
--else
-- Patrol Mode
if ai_soldier_state[e] == "patrol" then

-- Try and find a close path to patrol, just check once for it
if ai_soldier_pathindex[e] == -1 then

ai_soldier_pathindex[e] = -2

CharacterControlArmed(e)

-- find initial waypoint path to follow
PathIndex = -1;
pClosest = 99999;
for pa = 1, AIGetTotalPaths(), 1 do
for po = 1 , AIGetPathCountPoints(pa), 1 do
pDX = g_Entity[e]['x'] - AIPathGetPointX(pa,po);
pDZ = g_Entity[e]['z'] - AIPathGetPointZ(pa,po);
pDist = math.sqrt(math.abs(pDX*pDX)+math.abs(pDZ*pDZ));
if pDist < pClosest and pDist < 200 then
pClosest = pDist;
PathIndex = pa;
end
end -- po
end -- pa

-- follow found path
if PathIndex > -1 then
ai_soldier_pathindex[e] = PathIndex;
ai_path_point_index[e] = 2
ModulateSpeed(e,1.0)
SetCharacterToWalk(e)
ai_path_point_direction[e] = 1
ai_path_point_max[e] = AIGetPathCountPoints(ai_soldier_pathindex[e])
end

end
-- If we have a path then lets patrol it
if ai_soldier_pathindex[e] > -1 then

ai_patrol_x[e] = AIPathGetPointX(ai_soldier_pathindex[e],ai_path_point_index[e])
ai_patrol_z[e] = AIPathGetPointZ(ai_soldier_pathindex[e],ai_path_point_index[e])

AIEntityGoToPosition(EntObjNo,ai_patrol_x[e],ai_patrol_z[e])

tDistX = g_Entity[e]['x'] - ai_patrol_x[e]
tDistZ = g_Entity[e]['z'] - ai_patrol_z[e]

DistFromPath = math.sqrt(math.abs(tDistX*tDistX)+math.abs(tDistZ*tDistZ))

if DistFromPath < 50 then
if ai_path_point_direction[e] == 1 then
ai_path_point_index[e] = ai_path_point_index[e] + 1
if ( ai_path_point_index[e] > ai_path_point_max[e] ) then
ai_path_point_index[e] = ai_path_point_max[e] -1
ai_path_point_direction[e] = 0
end
else
ai_path_point_index[e] = ai_path_point_index[e] - 1
if ( ai_path_point_index[e] < 1 ) then
ai_path_point_index[e] = 2
ai_path_point_direction[e] = 1
end
end
end
else
CharacterControlFidget(e)
end
end

-- end
--if g_Entity[e]['health'] < 100 then
-- SetCharacterToRun(e)
-- ModulateSpeed(e,1.3)
-- ai_ran_to_cover[e] = 1
-- AISetEntityControl(EntObjNo,AI_MANUAL);
-- AIEntityMoveToCover(EntObjNo,g_PlayerPosX,g_PlayerPosZ);
-- end
end
"
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 7th Mar 2015 01:51 Edited at: 7th Mar 2015 03:36
Hi smallg, thanks I will give this a try.

Is there anyway to speed them up without them becoming jerky moving?

I set ModulateSpeed(e,5.0)

but it not fast and the cars are very jerky moving

Attachments

Login to view attachments
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 7th Mar 2015 12:57
interesting, i dont think i've seen any jerky movement except in the animations when using that, is that what you're referring to?
did you adjust the modulatespeed call already in the main part of the script or just add a new call? (note not the init part, must be the main script)
are the cars hitting each other by any chance as physics will be working for characters?
you may also want to remove the moveup(e,1) call, i didnt notice that was in there (doubt it has any effect though)

i dont think there is any way to speed them up besides that call using the AI commands, it should work for simple movement without animations fine though
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 7th Mar 2015 16:31 Edited at: 7th Mar 2015 16:48
Hi smallg, see video this is the best it will go before the van starts shaking everywhere,
it stalls all time along the way and does a 180 at some points along the path




Script set-up
PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 7th Mar 2015 17:26
i played around and the problem is directly linked to the modulatespeed call, can you use a lower value and get them to work normally?
are they still too slow even at say 3?
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 8th Mar 2015 00:39
Yep still slow at 3, also they keep spinning around, I also tried the script on a train engine but it
keeps making the train go half way through the floor even setting off = Z or X in fpe.

Is there anyways of combining my Cars script with yours to get faster speeds?
PM
Dany
14
Years of Service
User Offline
Joined: 14th Nov 2010
Location:
Posted: 8th Mar 2015 08:23
from where did you get all the cars you built yourself or that such a package for sale?
Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 8th Mar 2015 08:40
I got them few year ago from a friend he bought them with other stuff
but he never used them so he gave his stuff to me instead.

I have no idea who created them apart from there is a name on the
number plate 'PSIONIC' so I can not sell them as I do not have the
permission to do so Sorry ,

If I was able to give them I would not charge for them anyways
I would simply put them as freebies.


PM
smallg
Community Leader
19
Years of Service
User Offline
Joined: 8th Dec 2005
Location:
Posted: 8th Mar 2015 18:04
im afraid i dont have avrams add on so maybe he can help you expand your original script.

not sure why they would spin around when using waypoints - i dont notice any such behaviour when i use it but it's possible they get confused with the angle of the next point or something i guess, those are just using the AI code so not much i can do about it.
life\'s one big game

windows vista ultimate

i5 @3.3ghz, 4gb ram, geforce gtx460, directx 11
Super Clark
GameGuru TGC Backer
13
Years of Service
User Offline
Joined: 4th Apr 2011
Location: UK
Posted: 8th Mar 2015 20:17
ok smallg thanks for your help much appreciated.
PM

Login to post a reply

Server time is: 2024-12-30 16:49:10
Your offset time is: 2024-12-30 16:49:10