|
Post by MonstaWolf on Jul 30, 2015 14:45:01 GMT
So, as you may or may not know, I am creating a huuuuge city full of traffic cars. each of them has 2 EventOnLocation for render-distance. One is attached to the moving car, and one is near it's spawn point. Basically, if you go out of the one attached to the car, it despawns and stops the script, and if you go into the other one it spawns the car and starts the script. It's all working fine, but, recently I've encountered heavy lag. What's wrong with it, and is there any fix?
|
|
|
Post by Power Supersport on Jul 30, 2015 14:58:29 GMT
Using iVectorLength() may solve your problem...
It's not very good keeping SOO many objects... I personally don't use EOL...
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on Jul 30, 2015 16:16:03 GMT
ya not a good idea to keep so many object,scripts are much faster, so iVectorLength() is a Vector 3 quantity right?
|
|
|
Post by Power Supersport on Jul 30, 2015 19:06:28 GMT
Yes...
the way that you use it is:
iVectorLength(Point1-Point2);
You just have the coords of the first point and the second point... Then a script:
if (iVectorLength(Point1-Point2) < distance) { do something }
distance is a float...
|
|
|
Post by MonstaWolf on Jul 30, 2015 19:33:35 GMT
Wait so would I add that into each of the ai scripts, or make a whole new script for each AI car?
|
|
|
Post by Power Supersport on Jul 30, 2015 19:44:46 GMT
Better making a whole script for all cars I think...
|
|
|
Post by MonstaWolf on Jul 30, 2015 20:13:04 GMT
Yes... the way that you use it is: iVectorLength(Point1-Point2); You just have the coords of the first point and the second point... Then a script: if (iVectorLength(Point1-Point2) < distance) { do something } distance is a float... What do you mean by 'point1 and point2?' do you mean the first 2 coords in the path? I need it to be that when the player gets far enough away from the traffic vehicle, it despawns. I suck at scripting, and may just give the hell up soon.
|
|
|
Post by Power Supersport on Jul 30, 2015 21:14:24 GMT
Point1 is the player's camera or car... Point2 is the AI Car...
So if the player is far away from the AI, stop it or hide it... whatsoever... That's scripted like that:
Vector3 Point1,Point2; void Main() {
iObjectLocation(OBJ_0,Point1); iObjectLocation(OBJ_22,Point2);
if (iVectorLength(Point1-Point2) > 20) { iObjectStop(OBJ_22); iObjectHide(OBJ_44); } } In our little script, we have:
OBJ_0 - Player's car OBJ_22 - CarAI OBJ_44 - AI Car Skinmesh
20 (meters) is how far the player's car has to be to stop the AI...
IMPORTANT! This is just an example... this may not work properly if implemented in a project...
|
|
|
Post by MonstaWolf on Jul 30, 2015 21:18:07 GMT
Point1 is the player's camera or car... Point2 is the AI Car... So if the player is far away from the AI, stop it or hide it... whatsoever... That's scripted like that: Vector3 Point1,Point2; void Main() {
iObjectLocation(OBJ_0,Point1); iObjectLocation(OBJ_22,Point2);
if (iVectorLength(Point1-Point2) > 20) { iObjectStop(OBJ_22); iObjectHide(OBJ_44); } } In our little script, we have: OBJ_0 - Player's car OBJ_22 - CarAI OBJ_44 - AI Car Skinmesh 20 (meters) is how far the player's car has to be to stop the AI... IMPORTANT! This is just an example... this may not work properly if implemented in a project... Omg thank you so muuuuuchhhhh
|
|
|
Post by Power Supersport on Jul 30, 2015 21:21:04 GMT
No problem... I just don't have the time right now to explain it a little bit more... sorry about that... (12:00AM here...)
|
|
|
Post by MonstaWolf on Jul 30, 2015 22:02:20 GMT
Ohhhh sry go tu sleep nao XD
|
|
|
Post by MonstaWolf on Jul 31, 2015 15:34:16 GMT
Vector3 Point1,Point2;
void Main() {
iObjectLocation(OBJ_0,Point1);
iObjectLocation(OBJ_88,Point2);
if (iVectorLength(Point1-Point2) > 150) {
iObjectStop(OBJ_22);
iObjectHide(OBJ_44);
iObjectHide(OBJ_66);
if (iVectorLength(Point1-Point2) < 150) {
iObjectStart(OBJ_22);
iObjectShow(OBJ_44);
iObjectShow(OBJ_66); Okay so I got the script to work, and now I'm trying to make it so that when you get back into range it starts the car again. Ths script didn't work... hopefully I'll find a solution soon
|
|
|
Post by Power Supersport on Jul 31, 2015 19:58:32 GMT
Ok let me transform it and it will work...
Vector3 Point1,Point2; int [] time(2); void Main() {
iObjectLocation(OBJ_0,Point1); iObjectLocation(OBJ_88,Point2);
if (iVectorLength(Point1-Point2) > 150) { if (time[0] < 3) time[0] += 1; if (time[0] == 1) { iObjectStop(OBJ_22); iObjectHide(OBJ_44); iObjectHide(OBJ_66); } time[1] = 0; }
else { if (time[1] < 3) time[1] += 1; if (time[1] == 1) { iObjectStart(OBJ_22); iObjectShow(OBJ_44); iObjectShow(OBJ_66); } time[0] = 0; }
}
This time it should work...
|
|
|
Post by MonstaWolf on Jul 31, 2015 20:48:48 GMT
Ok let me transform it and it will work... Vector3 Point1,Point2; int [] time(2); void Main() {
iObjectLocation(OBJ_0,Point1); iObjectLocation(OBJ_88,Point2);
if (iVectorLength(Point1-Point2) > 150) { if (time[0] < 3) time[0] += 1; if (time[0] == 1) { iObjectStop(OBJ_22); iObjectHide(OBJ_44); iObjectHide(OBJ_66); } time[1] = 0; }
else { if (time[1] < 3) time[1] += 1; if (time[1] == 1) { iObjectStart(OBJ_22); iObjectShow(OBJ_44); iObjectShow(OBJ_66); } time[0] = 0; }
} This time it should work... This stuff seems to come naturally to you XD is there anywhere i could learn it?
|
|
|
Post by Power Supersport on Aug 1, 2015 9:10:29 GMT
|
|