Posted: 18th Mar 2021 9:03
now i have an array of checkpoints global and positions as part of a vehicle type
and i have a current and next pointervariable to keep track of where you are in relation to the checkpoints
now that part works for laps and the placing of crashed vehicles etc

1>The problem is there is up to a maximum of 9 positions a player can be at any one time which is a different number to the number of checkpoints
the array positions has an array of position textures and im not sure how i can add that to work preferably update at each checkpoint

2> a minor issue is detecting the wrong way at the bottom of function

+ Code Snippet
function trackCheckpointCheck(vehicle ref as vehicle,id as integer)
	p1 as tPoint :i as integer
	p1.x=getObjectWorldX(vehicle.hit)
	p1.z=getObjectWorldZ(vehicle.hit)
	d1 as float:d1 = abs(DistanceXZXZ(p1.x,p1.z,lpaths[0].nodes[vehicle.CurrentCheck.counter].x,lpaths[0].nodes[vehicle.CurrentCheck.counter].z))
	d2 as float:d2 = abs(DistanceXZXZ(p1.x,p1.z,lpaths[0].nodes[vehicle.nextCheck.counter].x,lpaths[0].nodes[vehicle.nextCheck.counter].z))
	print(vehicle.currentCheck.counter)
if  vehicle.checkPoints[vehicle.nextCheck.counter]=0  and d2<d1
    vehicle.place = places[vehicle.nextCheck.counter].no[vehicle.laps]
	//SetObjectImage(vehicle.position,positions[1],1)    //set the texture positions is an array of textures 
    inc vehicle.place
    places[vehicle.nextCheck.counter].no[vehicle.laps] = vehicle.place
    dec vehicle.checkPoints[vehicle.currentCheck.counter] //= 1 //now becomes a past checkpoint

	//save the location for when you go off track so you can return to previos checkpoint
	///////////////////////////////////////////////////////////////////////////////////////////
	vehicle.savePos = 1
    vehicle.lastGoodX[vehicle.savePos] =GetObjectX(vehicle.hit)
	vehicle.lastGoodY[vehicle.savePos] =GetObjectY(vehicle.hit)
	vehicle.lastGoodZ[vehicle.savePos] =GetObjectZ(vehicle.hit)
	vehicle.lastGoodAY[vehicle.savePos] = GetObjectAngleY(vehicle.hit)
	/////////////////////////////////////////////////////////////////////////////////////////
	vehicle.currentCheck.counter =vehicle.nextCheck.counter 
	if vehicle.nextCheck.counter < lpaths[0].nodes.length
		vehicle.nextCheck.counter = vehicle.currentCheck.counter+1
	else
			inc vehicle.laps:vehicle.currentCheck.counter=0: vehicle.nextCheck.counter=1  
			for i=0 to places.length
				vehicle.checkPoints[i]=0
				i2 as integer:for i2 = 0 to places[i].no.length
					places[i].no[i2]=0
				next i2
			next i
			if vehicle.laps=totalLaps  /// loop cutback this way
				  winner.name= vehicle.Name
				  winner.flag=1
			endif	
    endif
elseif d1<d2 and vehicle.checkPoints[vehicle.currentCheck.counter]=1
	SetObjectImage(vehicle.position,wrongwayImg,1)
	//dec vehicle.currentCheck.counter
	//if vehicle.currentCheck.counter<=0 then vehicle.currentCheck.counter=vehicle.checkpoints.length
endif


Thanks for any help anyone can give
Posted: 18th Mar 2021 20:03
What does it show for the position now?
Posted: 18th Mar 2021 23:00
ive got that commented out in the above function because if i make it show the position using the checkpoints it errors
there are more checkpoints than cars/rankings

and im trying to keep the for/next loops minimal
Posted: 19th Mar 2021 0:40
I could take a look at the code if you want
Posted: 19th Mar 2021 13:56
what i needed was an array of positions where at each chekpoint
but allot more checkpoints, i now use the built in function sort

+ Code Snippet
function trackCheckpointCheck(vehicle ref as vehicle,id as integer,placings ref as integer[])
	p1 as tPoint :i as integer:num as integer
	p1.x=getObjectWorldX(vehicle.hit)
	p1.z=getObjectWorldZ(vehicle.hit)
	d1 as float:d1 = abs(DistanceXZXZ(p1.x, p1.z, lpaths[0].nodes[vehicle.CurrentCheck.counter].x,lpaths[0].nodes[vehicle.CurrentCheck.counter].z))
	d2 as float:d2 = abs(DistanceXZXZ(p1.x, p1.z, lpaths[0].nodes[vehicle.nextCheck.counter].x,lpaths[0].nodes[vehicle.nextCheck.counter].z))
	print(vehicle.currentCheck.counter)
	if  vehicle.checkPoints[vehicle.nextCheck.counter] = 0  and d2<d1
	    vehicle.place = places[vehicle.nextCheck.counter].no[vehicle.laps]
print(id)
		placings[id]=vehicle.currentCheck.counter  + vehicle.laps
		num=placings.length-getPosition(vehicle.currentCheck.counter+ vehicle.laps,placings)
		SetObjectImage(vehicle.position,positions[num],1)    //set the texture positions is an array of textures 
	    inc vehicle.place
	    places[vehicle.nextCheck.counter].no[vehicle.laps] = vehicle.place
	    
	    dec vehicle.checkPoints[vehicle.currentCheck.counter] //= 1 //now becomes a past checkpoint
	
		//save the location for when you go off track so you can return to previos checkpoint
		///////////////////////////////////////////////////////////////////////////////////////////
		if mod(vehicle.currentCheck.counter,4) //only save every 4 checkpoint
			vehicle.savePos = 1
			vehicle.lastGoodX[vehicle.savePos] =GetObjectX(vehicle.hit)
			vehicle.lastGoodY[vehicle.savePos] =GetObjectY(vehicle.hit)
			vehicle.lastGoodZ[vehicle.savePos] =GetObjectZ(vehicle.hit)
			vehicle.lastGoodAY[vehicle.savePos] = GetObjectAngleY(vehicle.hit)
		endif
		/////////////////////////////////////////////////////////////////////////////////////////
		vehicle.currentCheck.counter = vehicle.nextCheck.counter 
		if vehicle.nextCheck.counter < lpaths[0].nodes.length
			vehicle.nextCheck.counter = vehicle.currentCheck.counter+1
		else
			inc vehicle.laps:vehicle.currentCheck.counter=0: vehicle.nextCheck.counter=1  
			for i=0 to places.length
				vehicle.checkPoints[i]=0
					i2 as integer:for i2 = 0 to places[i].no.length
						places[i].no[i2]=0
					next i2
			next i
			if vehicle.laps=totalLaps  /// loop cutback this way
				  winner.name=vehicle.Name
				  winner.flag=1
			endif	
	    endif
	elseif d1 > 1000
		SetObjectImage(vehicle.position,wrongwayImg,1)
		//dec vehicle.currentCheck.counter
		//if vehicle.currentCheck.counter<=0 then vehicle.currentCheck.counter=vehicle.checkpoints.length
	endif
endfunction

function getPosition(cur as integer,pos as integer[])
		result as integer
		//cur=pos[id]
		pos.sort()
		result=pos.find(cur)
endfunction result