View Full Version : Creating a easy Copsystem
Marco1
16th August 2009, 14:11
Hi guys/Programmers,
I need bit help at my copsystems ive done now all conditions and fines ect but i have a simple maybe easy problem
how i can "Chase" a other guy ?
i mean
if i type "!chase" that it "Chases" the player who is ca.200meters away from me
like if a players is in the 200meter area i can chase everybody in these 200meters like.
!chase
>Marco1 is chasing Scawen
an if no one is near 200meters to me
!chase
>No Player in Chase area.
i need only this code that it shows me this 2 usernames/lfswnames.
the other things i have allready:thumb:
Best Regarts Marco1.
DarkTimes
16th August 2009, 14:33
You need to store the X, Y and Z coordinates of each driver in the race, and when someone types !chase you will need to loop through them all and check how far away they are. The X, Y and Z coordinates are contained in the IS_MCI packet. In order to determine the distance between 2 points you can use some code like this:
double GetDistance(int aX, int aY, int aZ, int bX, int bY, int bZ)
{
int xDistance = bX - aX;
int yDistance = bY - aY;
int zDistance = bZ - aZ;
return Math.Sqrt(
(xDistance * xDistance )+
(yDistance * yDistance) +
(zDistance * zDistance));
}
The result of this method will need to be divided by 65536 in order to convert it into meters.
A quick search of the forum for "distance" presented these threads converting similar subjects.
http://www.lfsforum.net/showthread.php?t=51092
http://www.lfsforum.net/showthread.php?t=40901
http://www.lfsforum.net/showthread.php?t=35935
http://www.lfsforum.net/showthread.php?t=28077
Marco1
16th August 2009, 14:37
Thanks Darktimes
and ive solved the other problem whit the 2 usernames :thumb: just use it like in the !send cmd
Maths puhhh :smileypul ^^
anyway Thank you :D
Greez Heiko
have a nice HOT sunday 36° .... :schwitz::
Heiko1
16th August 2009, 14:40
so it is if i understand it right and codet it right in C#:
//DFO = DistanceFromOfficer
int DFO = ((int)Math.Sqrt(Math.Pow(MCI.Info[i].X - (X * 196608), 2) + Math.Pow(MCI.Info[i].Y - (Y * 196608), 2)) / 65536);
//distance in meters
if (DFO <= 200)
{
foreach (clsPlayers ChaseIdx in Players)
{
Message(YouUsername+" is chasing "ChaseIdx.Username);
}
}
else
{
Message("No Playout found within 200meters");
}
Now ive got an problem to:
But how to find out the Players X-Y coordinates
MariusMM
16th August 2009, 15:16
Now ive got an problem to:
But how to find out the Players X-Y coordinates
Well, this show's my X & Y coordinates + Nods in 2 buttons on track. I don't know if it will help, but it should explain something.
if (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].Username == "MariusMM")
{
InSim.Send_BTN_CreateButton("^1X: " + MCI.Info[i].X / 196608 + " ^2Y: " + MCI.Info[i].Y / 196608, Flags.ButtonStyles.ISB_DARK, 5, 15, 6, 90, 6, (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID), 2, false);
InSim.Send_BTN_CreateButton("^3Node: " + MCI.Info[i].Node, Flags.ButtonStyles.ISB_DARK, 5, 15, 12, 90, 170, (Connections[GetConnIdx(Players[GetPlyIdx(MCI.Info[i].PLID)].UniqueID)].UniqueID), 2, false); // Spare Button
}
Marco1
16th August 2009, 15:27
@ Mrius he means the x-y coordinates from a other player not from himself
DarkTimes
16th August 2009, 15:40
The X, Y and Z coordinates are contained in the IS_MCI packet.
:)
Marco1
16th August 2009, 15:43
so its then the code
MCI.Info[ChaseIdx].X
MCI.Info[ChaseIdx].Y
?
vBulletin® v3.8.6, Copyright ©2000-2012, Jelsoft Enterprises Ltd.