[PI/RUSE] Removing/Adding objects in Client
Well some people will probably say I stole this directly from RUSE Client that was released and only published it, but not really. Gabbe released the system for this but only adding objects (And not all objects only objects with type 10), so this will allow you to both remove and add objects from the client directly and only having to remove the objects from the server side and send it to the client(Incase you are using a movement check on players/npc walking/following you will have to remove the clipping for the object server side). Of course there is a better way to remove it from cache directly, but this is for the one who doesnt have a map editor.
You will need to create two Classes
GameObject
Code:
/**
* @author Gabriel Hannason
* @edit Marcus
*
*/
public class GameObject {
public GameObject(int id, int x, int y, int z, int face, int type) {
this.id = id;
this.x = x;
this.y = y;
this.z = z;
this.face = face;
this.type = type;
}
public int id, x, y, z, face, type;
}
CustomObjects
Code:
import java.util.ArrayList;
import java.util.List;
/**
* @author Gabriel Hannason
* @edit Gnakos
*/
public class CustomObjects {
public static void init() {
for(int i = 0; i < CUSTOM_OBJECTS.length; i++) {
int id = CUSTOM_OBJECTS[i][0];
int x = CUSTOM_OBJECTS[i][1];
int y = CUSTOM_OBJECTS[i][2];
int z = CUSTOM_OBJECTS[i][3];
int face = CUSTOM_OBJECTS[i][4];
int type = CUSTOM_OBJECTS[i][5];
CUSTOM_OBJECT_LIST.add(new GameObject(id, x, y, z, face, type));
}
}
public static final int[][] CUSTOM_OBJECTS = {
//{objectid (-1 to remove), objectX, objectY, objectHeight, objectFace, objectType},
};
public static List<GameObject> CUSTOM_OBJECT_LIST = new ArrayList<GameObject>();
}
Then in the Client file add these three functions (The clearObjectSpawnRequests() function can also be having the function name method63() for most clients)
Code:
private void handleRegionChange() {
int playerX = baseX + (myPlayer.x - 6 >> 7);
int playerY = baseY + (myPlayer.y - 6 >> 7);
for(GameObject customObject : CustomObjects.CUSTOM_OBJECT_LIST) {
if(customObject != null) {
if(plane == customObject.z && goodDistance(customObject.x, customObject.y, playerX, playerY, 50)) {
addObject(customObject.id, customObject.x, customObject.y, customObject.face, customObject.type, customObject.z);
}
}
}
clearObjectSpawnRequests();
}
public void addObject(int objectId, int x, int y, int face, int type, int height) {
if (type == 0 || type == 2) {
int mX = baseX;
int mY = baseY;
int x2 = x - mX;
int y2 = y - mY;
int kz = type >> 2;
int l17 = anIntArray1177[kz];
if (y2 >= 0 && y2 < 103 && x2 >= 0 && x2 < 103) {
createObjectSpawnRequest(-1, objectId, face, l17, y2, kz, height, x2, 0);
}
} else if (type == 1 || type == 10){
int mX = baseX;
int mY = baseY;
int x2 = x - mX;
int y2 = y - mY;
int i15 = 40 >> 2;
int l17 = anIntArray1177[i15];
if (y2 > 0 && y2 < 103 && x2 > 0 && x2 < 103) {
createObjectSpawnRequest(-1, objectId, face, l17, y2, type, height, x2, 0);
}
}
}
public static boolean goodDistance(int objectX, int objectY, int playerX,
int playerY, int distance) {
if (playerX == objectX && playerY == objectY)
return true;
for (int i = 0; i <= distance; i++) {
for (int j = 0; j <= distance; j++) {
if ((objectX + i) == playerX
&& ((objectY + j) == playerY
|| (objectY - j) == playerY || objectY == playerY)) {
return true;
} else if ((objectX - i) == playerX
&& ((objectY + j) == playerY
|| (objectY - j) == playerY || objectY == playerY)) {
return true;
} else if (objectX == playerX
&& ((objectY + j) == playerY
|| (objectY - j) == playerY || objectY == playerY)) {
return true;
}
}
}
return false;
}
And then in the loadRegion function (or method22 for most clients) after the
Code:
ObjectDef.mruNodes1.unlinkAll();
add this line
Code:
ObjectDef.mruNodes2.unlinkAll();
Credits to [Only registered and activated users can see links. Click Here To Register...] who released this in RUSE and thanks to me who fixed the removing of all objects instead of only object face 10
You will have to do the clipping control in the server your self incase you want the clipping to be working.