Collision

You can detect height and width of your player in various ways.
You can set entity vars for example. then you've to set if condition and position...

this is an example:
Code:
        for (i = 0; i < openborconstant("MAX_ENTS"); ++i) {
            void opp = getentity(i);
            float x = getentityproperty(player, "x");
            float z = getentityproperty(player, "z");
            float a = getentityproperty(player, "a");

            float xo = getentityproperty(opp, "x");
            float zo = getentityproperty(opp, "z");
            float ao = getentityproperty(opp, "a");

	    
		for (p = 0; p < 4; ++p) { //is this entity a player???
			void player = getplayerproperty(p, "entity");
			if ( player != self && player == opp ) {
				
				// COLLIDE
				if ( x > xo-width && x < xo+width && z > zo-height && z < zo+height ) {
					// self is at left of the other player, so shifts self back
					if ( getentityproperty(self, "x") < xo ) changeentityproperty(self, "position", xo-width-1,z,a);
					else if.. etc etc
				}
			}
		}
	}
 
Unfortunately i haven't a complete script/char.txt
I wrote that script for an example...
However the:
if ( x > xo-width && x < xo+width && z > zo-height && z < zo+height ) {

is like a bbox ok?
 
OK. I'm curious about what could be the correct way to put script. Also could it be under character text or something?

Anyways I edited the script to see if I'm doing it right before running.

Code:
//COLLISION EDIT 2
        for (i = 0; i < openborconstant("MAX_ENTS"); ++i) {
            void opp = getentity(i);
            float x = getentityproperty(player, "x");
            float z = getentityproperty(player, "z");
            float a = getentityproperty(player, "a");

            float xo = getentityproperty(opp, "x");
            float zo = getentityproperty(opp, "z");
            float ao = getentityproperty(opp, "a");

	    
		for (p = 0; p < 4; ++p) { //is this entity a player???
			void player = getplayerproperty(p, "entity");
			if ( player != self && player == opp ) {
				
				// COLLIDE
				if ( x > xo-width && x < xo+width && z > zo-height && z < zo+height && a > ao-altitude && a < ao+altitude) {
					// self is at left of the other player, so shifts self back
					if ( getentityproperty(self, "x") < xo ) changeentityproperty(self, "position", xo-width-1,z,a);
					else if ( getentityproperty(self, "x") > xo) changeentityproperty(self, "position", xo+width+1,z,a);
					else if ( getentityproperty(self, "z") < zo) changeentityproperty(self, "position", x, zo-height-1,a);
					else if ( getentityproperty(self, "z") > zo) changeentityproperty(self, "position", x, zo+height+1,a);
					else if ( getentityproperty(self, "a") < ao) changeentityproperty(self, "position", x,z, ao-altitude-1);
					else if ( getentityproperty(self, "a") > ao) changeentityproperty(self, "position", x,z, ao+altitude+1);
				}
			}
		}
	}

Or is it like this?

Code:
//COLLISION EDIT 4
        for (i = 0; i < openborconstant("MAX_ENTS"); ++i) {
            void opp = getentity(i);
            float x = getentityproperty(player, "x");
            float z = getentityproperty(player, "z");
            float a = getentityproperty(player, "a");

            float xo = getentityproperty(opp, "x");
            float zo = getentityproperty(opp, "z");
            float ao = getentityproperty(opp, "a");

	    
		for (p = 0; p < 4; ++p) { //is this entity a player???
			void player = getplayerproperty(p, "entity");
			if ( player != self && player == opp ) {
				
				// COLLIDE
				if ( x > xo-width && x < xo+width && z > zo-height && z < zo+height && a > ao-altitude && a < ao+altitude) {
					// self is at left of the other player, so shifts self back
					if ( getentityproperty(self, "x") < xo ){ 
					changeentityproperty(self, "position", xo-width-1,z,a);
					}
					else if ( getentityproperty(self, "x") > xo){ 
					changeentityproperty(self, "position", xo+width+1,z,a);
					}
					else if ( getentityproperty(self, "z") < zo){
					changeentityproperty(self, "position", x, zo-height-1,a);
					}
					else if ( getentityproperty(self, "z") > zo){
					changeentityproperty(self, "position", x, zo+height+1,a);
					}
					else if ( getentityproperty(self, "a") < ao){
					changeentityproperty(self, "position", x,z, ao-altitude-1);
					}
					else if ( getentityproperty(self, "a") > ao){
					changeentityproperty(self, "position", x,z, ao+altitude+1);
					}
				}
			}
		}
	}

EDIT: Hmm... I wonder which one is correct for running without crash.
 
Back
Top Bottom