How to change speed running while running?

16-bit Fighter

Active member
I'd like a player to change his speed running while running if his MP is under a certain number. I unsuccessfully tried the code below in the running anim of a char whose running speed is 18 in his header:

Code:
@script
	void self = getlocalvar("self");
	void MP = getentityproperty(self,"mp");
     	       if (MP<10)
	{ 
		changeentityproperty(self, "running", 14);
     	}
	@end_script

Thanks in advance!
 
16-bit Fighter said:
Beside, I noticed that what is thrown by an enemy is considered as an enemy. But I don't know how to substract this kind of entity to the count. :/
I tested it and when a player is thrown by an enemy your type will not be changed. But if you need to subtract any entity to the count in the didhit, you can use this:

Code:
target = getlocalvar("damagetaker"); //THE ENTITY THAT GOT DAMAGE

if(target != openborconstant("TYPE_NAME")){ //TARGET TYPE IS DIFFERENT OF TYPE_NAME?? EXECUTE THE COMMAND
    command();
}
But if you are talking about projectiles that are thrown by enemies, you can define subtypes to these projectiles and avoid them in the script, like the example above.
 
Kratus said:
But if you are talking about projectiles that are thrown by enemies, you can define subtypes to these projectiles and avoid them in the script, like the example above.
Thanks and yes, sorry, I'm talking about projectiles. I'm not very familiar with all of this (target, didhitscript, subtype) yet, so I hope I don't write whatever but I feel like there's a misunderstood. I mean, it's not about player at all but "count_enemies". Here is a example: there is a single enemy to beat and he has a "load knife" in the header, then when he throws the thrown entity (knife), instead of just one enemy is counted, there are two counted until the knife is away. So I don't understand what "didhit" and "target" have to do with the problem since no one is hit.
 
16-bit Fighter said:
Kratus said:
But if you are talking about projectiles that are thrown by enemies, you can define subtypes to these projectiles and avoid them in the script, like the example above.
Thanks and yes, sorry, I'm talking about projectiles. I'm not very familiar with all of this (target, didhitscript, subtype) yet, so I hope I don't write whatever but I feel like there's a misunderstood. I mean, it's not about player at all but "count_enemies". Here is a example: there is a single enemy to beat and he has a "load knife" in the header, then when he throws the thrown entity (knife), instead of just one enemy is counted, there are two counted until the knife is away. So I don't understand what "didhit" and "target" have to do with the problem since no one is hit.

Yeah, now I understand your point. You mean the openborvariant "count_enemies", right? Really when an enemy throw a projectile using the native engine method, he will be the owner of this projectile and the engine will treat it like a enemy too.
projectile {relative} {name} {x} {z} {y} {direction} {ptype} {type} {map}

~ Despite the name, it can be used to spawn any type of entity. Useful for using more than one "spawnframe" or any other method as it offers much more control.
~ {relative} - Affects all other settings. See bellow
~ {name} - name of the spawned position, from models.txt
~ {x} - X spawn position, defaults to 0. Accept decimals. If relative is 0, the position will count from the edge of the screen, while if 1, it will use the parent x position as a it's x value
~ {z} - Z spawn position, defaults to 0. Accept decimals.
~ {y} - Y spawn position, defaults to 0. Accept decimals.
~ {direction} - direction of the spawn. According to the source, defaults to DIRECTION_RIGHT. If relative is 0, if will default to DIRECTION_RIGHT, but if relative is 1, it will uses it's parent direction.
~{ptype} - Defaults to 0. If it has any value other than 0, the projectile is given a default name of "shot" and a model index of -1 as opposed to the parent model's predefined knife or pshot index. Best left ignored.
~{type} - "0" - will use "knife' behaviour. "1" will use "bomb" behaviour (and ignores the ptype above). defaults to 0
~{map} - map of the spawned entity, defaults to 0

However, this is necessary to connect the actions of the projectile with your owner. For example, if a player throw a knife using the native projectile method, this will be used to add hit combo count, fill your mp, show last opponent, etc... In other words, the projectile will be treated like a extension of the spawner and not an individual entity.
But if you don't want this connection, you can use the global engine spawn system, and the projectile will be treated like an individual entity.
Code:
void spawn01(void vName, float fX, float fY, float fZ)
{	//spawn01 (Generic spawner)
	//Damon Vaughn Caskey
	//07/06/2007
	//
	//Spawns entity next to caller.
	//
	//vName: Model name of entity to be spawned in.
	//fX: X location adjustment.
	//fZ: Y location adjustment.
	//fY: Z location adjustment.

	void self 	= getlocalvar("self"); //Get calling entity.
	void vSpawn; //Spawn object.
	int  direction = getentityproperty(self, "direction");

	clearspawnentry(); //Clear current spawn entry.
	setspawnentry("name", vName); //Acquire spawn entity by name.

	if(direction == 0){ //Is entity facing left?                  
		fX = -fX; //Reverse X direction to match facing.
	}
	
	fX = fX + getentityproperty(self, "x"); //Get X location and add adjustment.
	fY = fY + getentityproperty(self, "y"); //Get Y location and add adjustment.
	fZ = fZ + getentityproperty(self, "z"); //Get Z location and add adjustment.
	
	vSpawn = spawn(); //Spawn in entity.

	changeentityproperty(vSpawn, "position", fX, fZ, fY); //Set spawn location.
	changeentityproperty(vSpawn, "direction", direction); //Set direction.
	
	return vSpawn; //Return spawn.
}

Based on what I know about the engine, I think this is the correct explanation. Here is an example of how "count_enemies" works using the default projectile method. You can see the enemy count in my debug mode:
https://youtu.be/5rGJv7ZTcLs
 
You know what? You're right again, thank you Kratos!

I copied a big part of the text of an entity from another mod which uses the toss command. It's still complicated to me to understand this command ATM but it works. ^^
 
ANy clue as to why this script gives me null values for self ? i cant acquire it, says vg empty uninitialised, what am i missing ?
I have it in updatescript or in ondrawscript, i hate having dumb issues like this, how come self can be empty when updatescript is working , so there should be acquired self , ofherwise this very updatescript would not ran... oh man. Im sure i miss one stupid thing somewhere...
Code:
void main()
{//Change running speed and edelay properties according to MP
	void self 	= getlocalvar("self");
	void ani	= getentityproperty(self, "animationID"); //GET CURRENT ANIMATION
	int maxMp	= getentityproperty(self, "maxmp"); //GET MAXIMUM MP
	int mp		= getentityproperty(self, "mp"); //GET CURRENT MP
	int cost 	= 1; //DEFAULT COST VALUE
	float speed = getentityproperty(self, "running", "speed"); //GET CURRENT RUNNING SPEED
	float rate	= 20; //DEFAULT RATE INTERVAL
	float time	= openborvariant("elapsed_time"); //GET CURRENT TIME
	
	if(getlocalvar("defaultSpeed"+self) == NULL()){ //VARIABLE "DEFAULT SPEED" IS NULL?? FIRST CHARACTER SPAWN IN THE GAME??
		setlocalvar("defaultSpeed"+self, speed); //CREATE A VARIABLE AND SAVE DEFAULT SPEED
	}
	
	if(ani == openborconstant("ANI_RUN")){ //IS IN RUNNING ANIMATION??
		if(mp > 0){ //CHECK IF MP IS ZERO TO PAUSE SCRIPT EXECUTION WITH NO MP
			if(time%rate == 0){ //ADJUST COST RATE BY CHANGING RATE INTERVAL BETWEEN EACH SUBTRACTION. BIG RATE = BIG INTERVAL
				changeentityproperty(self, "mp", mp-cost); //CHANGE MP ACCORDING TO COST VALUE
			}
		}
		
		if(mp >= maxMp/1.5){ //MORE OR EQUAL THAN 2/3 MP?? IF YOUR MAX MP IS 30, THIS WILL BE EQUAL TO 20 MP
			changeentityproperty(self, "running", getlocalvar("defaultSpeed"+self)); //DEFAULT RUNNING SPEED
			changeentityproperty(self, "edelay", 1, 1, 1, 999, 1, 999); //DEFAULT DELAY
		}else if(mp < maxMp/1.5 && mp >= maxMp/3){ //LESS THAN 2/3 MP AND MORE OR EQUAL THAN 1/3 MP?? BETWEEN 10 AND 19 MP
			changeentityproperty(self, "running", getlocalvar("defaultSpeed"+self)/2); //AVERAGE RUNNING SPEED
			changeentityproperty(self, "edelay", 1, 1.5, 1, 999, 1, 999); //AVERAGE DELAY
		}else{//LESS THAN 1/3 MP?? IF YOUR MAX MP IS 30, THIS WILL BE EQUAL TO 9 MP OR BELOW
			changeentityproperty(self, "running", getlocalvar("defaultSpeed"+self)/4); //SLOW RUNNING SPEED
			changeentityproperty(self, "edelay", 1, 2, 1, 999, 1, 999); //SLOW DELAY
		}
	}else{ //IS NOT IN RUNNING ANIMATION??
		changeentityproperty(self, "running", getlocalvar("defaultSpeed"+self)); //DEFAULT RUNNING SPEED
		changeentityproperty(self, "edelay", 1, 1, 1, 999, 1, 999); //DEFAULT DELAY
	}
	
	//DRAW VALUES IN THE SCREEN TO CHECK IF THE SCRIPT IS WORKING. ERASE THIS 3 LINES AFTER THE TESTS ARE DONE!!!
	drawstring(100, 100, 0, speed); //SHOW CURRENT RUNNING SPEED APPLIED IN THE CHARACTER IN REAL TIME
	drawstring(100, 110, 0, getlocalvar("defaultSpeed"+self)); //SHOW DEFAULT SPEED SAVED INTO A VARIABLE TO CHECK IF IS ALL RIGHT
	drawstring(100, 120, 0, mp); //DRAW CURRENT MP TO CHECK IF THE SCRIPT IS ACTIVATING IN THE DEFINED MP VALUES
}

Even simple crap like this gives me empty uninitialised\
Code:
void main(){
	
if(openborvariant("in_level"))
	{	
	void self = getlocalvar("self");
settextobj(2, 250 , 420 , 1, 1, getentityproperty(self, "xdir"), openborvariant("elapsed_time")+2000);
	drawstring(100, 120, 0, getentityproperty(self, "xdir")); //DRAW CURRENT MP TO CHECK IF THE SCRIPT IS ACTIVATING IN THE DEFINED MP VALUES
}
}
 
I dont see it, also entities in stage dont clear anyvars, i just used different way do acquire it, anyway im trying to do something similar about controlling speed when walking but i dont think ill be able to on my own
Im trying to make characters slide on snow, like on ice , so when i hold right then velocity is increasing till it hits 50, when i dont hold it, then its decreasing till it hits 0. I kinda did it but its shutting engine down... so i know its not the right way to do it
Did you experimented with this maybe ? I want velocity increase/decrease to affect me only when on ground so i still need to check base i suppose, it acts strangely now when i get hit.
I want him to still slide and slowdown when hes in idle anim, but im using velocity and it looks choppy sometimes, using speed looked better but it only works when im in actual walk animation, so im using speed 0 in header, and just add velocity to move my char when pressing right.
Ideally id like it to be independent of direction, so even when you tap left/right/left while slowing down then you will still slide in that one main direction you were walking towards.So i wouldnt want it to be attached to direction at all.
HEres the code . im having it as keyscript, maybe updatescript would be better ?
Code:
void main(){
    void self = getplayerproperty(0, "entity");
		int pindex 	= getentityproperty(self,"playerindex");
		void speed = getentityproperty(self, "speed");
			void moveright 	=  playerkeys(pindex, 0, "moveright");
	void moveleft 	=  playerkeys(pindex, 0, "moveleft");
	int aid = getentityproperty(self, "animationid");	
	
if(openborvariant("in_level"))
	{	
	drawstring(100, 120, 0,  getentityvar(self,"num")+ "dziallla"); //DRAW CURRENT MP TO CHECK IF THE SCRIPT IS ACTIVATING IN THE DEFINED MP VALUES
if( getentityvar(self, "num") == NULL()){
	setentityvar(self, "num", 0);
}
if(  moveright && getentityvar(self, "num") < 50  ){	
		changeentityproperty(self,"velocity", getentityvar(self,"num") );
		setentityvar(self, "num",  getentityvar(self, "num")+1);
}
if(  !moveright && getentityvar(self, "num") > 0   ){	
		changeentityproperty(self, "velocity", getentityvar(self,"num") );
		setentityvar(self, "num",  getentityvar(self, "num")-1);
}
if( getentityvar(self, "num") == 0 ){	

		changeentityproperty(self, "velocity", getentityvar(self,"num") );

}
	}

}
 
bWWd

The snow effect is a very interesting idea. Is something like this?

https://www.youtube.com/watch?v=bMfdekNpxXI

I made a quick test using the script below, it's experimental and probably there's a lot of things to improve.
But I think that it's a good start and it's possible to simulate a snow effect correctly. Tested in the updateentity event, I didn't test on keyscript events yet.

Code:
void snow()
{//Simulates a "Snow" effect
	void self	= getlocalvar("self");
	void anim	= getentityproperty(self, "animationID");
	int pIndex	= getentityproperty(self, "playerindex");
	float speed	= getentityproperty(self, "speed");
	float xDir	= getentityproperty(self, "xdir");
	float zDir	= getentityproperty(self, "zdir");
	float xRate	= 0.005;
	float zRate	= 0.005;
	float walk	= 1.6;

	//DEBUG INFO ONLY, ERASE WHEN ALL TESTS ARE DONE
	drawstring(50, 40, 1, speed);
	drawstring(50, 50, 0, xDir);
	drawstring(50, 60, 0, getlocalvar("xVel"+self));
	drawstring(50, 70, 0, zDir);
	drawstring(50, 80, 0, getlocalvar("zVel"+self));

	//SAVE CURRENT VELOCITY WHILE NOT IN IDLE ANIMATION
	if(anim != openborconstant("ANI_IDLE")){
		
		//PRESSING RIGHT??
		if(playerkeys(pIndex, 0, "moveright")){
			setlocalvar("xVel"+self, xDir);

			//INCREASE SPEED WHILE MOVING
			if(speed < walk){changeentityproperty(self, "speed", speed+xRate);}
		}

		//PRESSING LEFT??
		if(playerkeys(pIndex, 0, "moveleft")){
			setlocalvar("xVel"+self, xDir);

			//INCREASE SPEED WHILE MOVING
			if(speed < walk){changeentityproperty(self, "speed", speed+xRate);}

		}

		//PRESSING DOWN??
		if(playerkeys(pIndex, 0, "movedown")){
			setlocalvar("zVel"+self, zDir);

			//INCREASE SPEED WHILE MOVING
			if(speed < walk){changeentityproperty(self, "speed", speed+xRate);}

		}

		//PRESSING UP??
		if(playerkeys(pIndex, 0, "moveup")){
			setlocalvar("zVel"+self, zDir);

			//INCREASE SPEED WHILE MOVING
			if(speed < walk){changeentityproperty(self, "speed", speed+xRate);}
		}
	}
	else
	{
		//APPLY THE PREVIOUS SAVED VELOCITY AND DECREASE GRADUALLY WHILE IN IDLE ANIMATION

		//MOVING RIGHT IN X AXIS??
		if(getlocalvar("xVel"+self) > 0){
			changeentityproperty(self, "speed", -xDir/2);
			changeentityproperty(self, "velocity", getlocalvar("xVel"+self));
			setlocalvar("xVel"+self, getlocalvar("xVel"+self)-xRate);
		}
		else
		//MOVING LEFT IN X AXIS??
		if(getlocalvar("xVel"+self) < 0){
			changeentityproperty(self, "speed", xDir/2);
			changeentityproperty(self, "velocity", getlocalvar("xVel"+self));
			setlocalvar("xVel"+self, getlocalvar("xVel"+self)+xRate);
		}
		
		//MOVING DOWN IN Z AXIS??
		if(getlocalvar("zVel"+self) > 0){
			changeentityproperty(self, "speed", -zDir/2);
			changeentityproperty(self, "velocity", NULL(), getlocalvar("zVel"+self));
			setlocalvar("zVel"+self, getlocalvar("zVel"+self)-zRate);
		}
		else
		//MOVING UP IN Z AXIS??
		if(getlocalvar("zVel"+self) < 0){
			changeentityproperty(self, "speed", zDir/2);
			changeentityproperty(self, "velocity", NULL(), getlocalvar("zVel"+self));
			setlocalvar("zVel"+self, getlocalvar("zVel"+self)+zRate);
		}
	}
}
 
wow that looks very good , ill try that asap, just woke up  ;D
im going to use it in platformers too and try to adapt it for jumping so when you hold button longer you jump higher.
--
Kratus    I checked it and i have VT empty uninitialised in most of my mods , even in neo edit pack which is impossible to have clearvariable commands.
I have no idea whats causing this.
I uploaded my mod but i know its not fun to dig into someone elses code and find mistakes when you dont know where to start, Mauybe you have some extra commands in script.txt

Code:
#maxscriptvars {int}
#define a variable list in each script that can be accessed by index
#use getscriptvar(index) and setscriptvar(index, value) to use those variables
maxscriptvars   5

#maxentityvars {int}
#define a variable list in each entity that can be accessed by index
#use getentityvar(entity, index) and setentityvar(entity, index, value) to use those variables
maxentityvars   250

#maxindexedvars {int}
#define a global variable list that can be accessed by index
#use getindexedvar(index) and setindexedvar(index, value) to use those variables
maxindexedvars  1000

#maxglobalvars {int}
#define a global variable list that can be accessed by name
#see getglobalvar setglobalvar getlocalvar setlocalvar for details
#the default value is 2048
#If there's no script in the game, just set it to 0, or don't change it unless you know how big it should be
maxglobalvars  2048



alwaysupdate  1

I tried to change acquiring self to  int self = getplayerproperty(0, "entity");  just to force it to work
When it works then player slides in weird directions and wont actually stop, im sure i have something very off in my mod.

Heres the link to data folder
https://drive.google.com/file/d/1lwuvrNc9AUUjYlrcZ5_7sE6aySSRYyiE/view?usp=sharing
 
I pasted it to your SORX mod and it works great, i have to find out what im missing
--
OK i got it working ! I defined it wrong, now its as script scripts/snow.c
Somehow zvel variable isnt knocked down when i dont hold up/down buttons and wont move up/down , this one : drawstring(50, 544, 0, "zvar___"+ getlocalvar("zVel"+self));  Any clues how to solve that ?
It also doesnt work as nice for enemies, they sometimes get stuck in idle, its getting very close tho.
You know, maybe its a wrong approach, maybe its better to have one big attackbox that would make entities slide once they stop from walk,run or jump, cause i see at the moment it works on top of enemy walking AI, and its interfering.
Heres link to the game :
https://drive.google.com/file/d/1SGuKHI7ELg69qp9QqnbQf-gTe4AM3VUz/view?usp=sharing
bor---0061.png

Code:
void main()
{
	snow();
}

void snow()
{//Simulates a "Snow" effect
	void self	= getlocalvar("self");
	void anim	= getentityproperty(self, "animationID");
	int pIndex	= getentityproperty(self, "playerindex");
	float speed	= getentityproperty(self, "speed");
	float rspeed = getentityproperty(self, "running", "speed"); //GET CURRENT RUNNING SPEED
	float xDir	= getentityproperty(self, "xdir");
	float zDir	= getentityproperty(self, "zdir");
	int a = getentityproperty(self,"a"); //Get bomb's altitude
	float xRate	= 0.03;
	float zRate	= 0.03;
	float walk	= 3;
	float run	= 6.5;
	float accel = 0.06;
		float raccel = 0.1;

	//DEBUG INFO ONLY, ERASE WHEN ALL TESTS ARE DONE
	//drawstring(50, 144, 1, "speed___"+ speed);
	//drawstring(50, 244, 0, "xdir___"+ xDir);
	//drawstring(50, 344, 0, "zdir___"+ zDir);
	//drawstring(50, 444, 0, "xvar___"+ getlocalvar("xVel"+self));
//	drawstring(50, 544, 0, "zvar___"+ getlocalvar("zVel"+self));
	//	drawstring(50, 644, 0, "att___"+ getentityproperty(self,"a"));
	//	drawstring(50, 684, 0, "run___"+ getentityproperty(self, "running", "speed") );

	//SAVE CURRENT VELOCITY WHILE NOT IN IDLE ANIMATION
	if( !anim == openborconstant("ANI_IDLE")){


		//PRESSING RIGHT??
		if(  playerkeys(pIndex, 0, "moveright") ){
			setlocalvar("xVel"+self, xDir);
			setlocalvar("rxVel"+self, xDir);

			//INCREASE SPEED WHILE MOVING
			if(speed < walk){changeentityproperty(self, "speed", speed+accel);
	
		}
	if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);
}	 
		}
		//PRESSING LEFT??
			if(  playerkeys(pIndex, 0, "moveleft")  ){
			setlocalvar("xVel"+self, xDir);
			setlocalvar("rxVel"+self, xDir);

			//INCREASE SPEED WHILE MOVING
			if(speed < walk){changeentityproperty(self, "speed", speed+accel);}
	if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);
}	
		}

		//PRESSING DOWN??
			if(  playerkeys(pIndex, 0, "movedown")  ){
			setlocalvar("zVel"+self, zDir);
			setlocalvar("rzVel"+self, zDir);

			//INCREASE SPEED WHILE MOVING
			if(speed < walk){changeentityproperty(self, "speed", speed+accel);}
	if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);
}	
		}

		//PRESSING UP??
	if(  playerkeys(pIndex, 0, "moveup") ){
			setlocalvar("zVel"+self, zDir);
			setlocalvar("rzVel"+self, zDir);

			//INCREASE SPEED WHILE MOVING
			if(speed < walk){changeentityproperty(self, "speed", speed+accel);}
		}
	if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);
}	
	}
	else
	{
		//APPLY THE PREVIOUS SAVED VELOCITY AND DECREASE GRADUALLY WHILE IN IDLE ANIMATION

		//MOVING RIGHT IN X AXIS??
		if(getlocalvar("xVel"+self) > 0  ){
		
			changeentityproperty(self, "velocity", getlocalvar("xVel"+self));
			setlocalvar("xVel"+self, getlocalvar("xVel"+self)-xRate);
			setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)-xRate);
			changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
         	changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);
		}

		//MOVING LEFT IN X AXIS??
		if(getlocalvar("xVel"+self) < 0){
			
			changeentityproperty(self, "velocity", getlocalvar("xVel"+self));
			setlocalvar("xVel"+self, getlocalvar("xVel"+self)+xRate);
			setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)-xRate);
			changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
         	changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);
			

		}
	
		//MOVING DOWN IN Z AXIS??
		if(getlocalvar("zVel"+self) > 0){
		
			changeentityproperty(self, "velocity", NULL(), getlocalvar("zVel"+self));
			setlocalvar("zVel"+self, getlocalvar("zVel"+self)-zRate);
			setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)-xRate);
			changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
         	changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);

		}
	
		//MOVING UP IN Z AXIS??
		if(getlocalvar("zVel"+self) < 0 ){
		
			changeentityproperty(self, "velocity", NULL(), getlocalvar("zVel"+self));
			setlocalvar("zVel"+self, getlocalvar("zVel"+self)+zRate);
			setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)-xRate);
			changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
         	changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);
	
		}
	}
}
 
OK i have it like this, its almost perfect and not dependant on keypresses , i also tried to make it compact , works fine with enemies but, i have one final polish:
- when i slide right and press left, then i continue sliding left and stop, i should still slide right and stop.
How can i modify the script so no matter where i turn  i will slide towards original slide direction until i stop So sliding is kinda independent of which side youre facing ?

Code:
void main()
{
	if(openborvariant("in_level"))
	
	snow();
}

void snow()
{//Simulates a "Snow" effect
	void self	= getlocalvar("self");
	void anim	= getentityproperty(self, "animationID");
	void Direction	= getentityproperty(self, "direction");
	int pIndex	= getentityproperty(self, "playerindex");
	float speed	= getentityproperty(self, "speed");
	float rspeed = getentityproperty(self, "running", "speed"); //GET CURRENT RUNNING SPEED
	float xDir	= getentityproperty(self, "xdir");
	float zDir	= getentityproperty(self, "zdir");
	int a = getentityproperty(self,"a"); //Get bomb's altitude
	float accel = 0.04;
	float raccel = 0.08;
	int walks = 3;
	int runs = 6.5;
	//DEBUG INFO ONLY, ERASE WHEN ALL TESTS ARE DONE
	//drawstring(50, 144, 1, "walk___"+ speed);
	//drawstring(50, 244, 0, "xdir___"+ xDir);
	//drawstring(50, 344, 0, "zdir___"+ zDir);
	//drawstring(50, 444, 0, "xvar___"+ getlocalvar("xVel"+self));
//drawstring(50, 484, 0, "slix___"+ getlocalvar("slix"+self));
	//drawstring(50, 544, 0, "zvar___"+ getlocalvar("zVel"+self));
		//drawstring(50, 644, 0, "att___"+ getentityproperty(self,"a"));
		//drawstring(50, 684, 0, "run___"+ getentityproperty(self, "running", "speed") );
	//SAVE CURRENT VELOCITY WHILE NOT IN IDLE ANIMATION
	if( !anim == openborconstant("ANI_WALK") || !anim == openborconstant("ANI_RUN") ){
		changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
     changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);
  	setlocalvar("xVel"+self, getlocalvar("xVel"+self)/1.015);
	setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)/1.015);
	setlocalvar("zVel"+self, getlocalvar("zVel"+self)/1.015);
	setlocalvar("rzVel"+self, getlocalvar("rzVel"+self)/1.015);
	}
	if( anim == openborconstant("ANI_WALK") || anim == openborconstant("ANI_RUN") || anim == openborconstant("ANI_ATTACK1")){
		setlocalvar("xVel"+self, xDir);
		setlocalvar("zVel"+self, zDir);
	        setlocalvar("rxVel"+self, xDir);
			  setlocalvar("rzVel"+self, zDir);
			//INCREASE SPEED WHILE MOVING
			if(speed < walks ){changeentityproperty(self, "speed", speed+accel);
			}
		if(rspeed < runs ){changeentityproperty(self, "running", rspeed+raccel);
		}
   
	}
	else
	{
		//MOVING RIGHT IN X AXIS??
		if(   !getentityproperty(self, "aiflag", "jumping") && !anim == openborconstant("ANI_WALK")){
			changeentityproperty(self, "velocity", getlocalvar("xVel"+self));
				changeentityproperty(self, "velocity", getlocalvar("rxVel"+self));
 			changeentityproperty(self, "speed", speed/1.015 );
         	changeentityproperty(self, "running", speed/1.015);
		}

		//MOVING UP IN Z AXIS??
		if(  !getentityproperty(self, "aiflag", "jumping")  && !anim == openborconstant("ANI_WALK")){
			changeentityproperty(self, "velocity", NULL(), getlocalvar("zVel"+self));
			changeentityproperty(self, "velocity", NULL(), getlocalvar("rzVel"+self));
         	changeentityproperty(self, "speed", speed/1.015 );
         	changeentityproperty(self, "running", speed/1.015);
			}	
		}
}
 
bWWd

First I have to say, your game has an awesome graphic design, probably one of the most beautiful OpenBOR games I have ever seen. You did a good job :)

About the script, I will test your new code now. I like the idea of a code that is not dependant on keypresses and more compact.
About the previous script, I don't know why but after I changed the operator "!" for the "!=" the script works better and is more accurate.

Previous:
Code:
if(  !anim == openborconstant("ANI_IDLE")){

Changed:
Code:
if(  anim != openborconstant("ANI_IDLE")){

Another change is about the enemy type. I separated the "non-idle" animations in two parts:
1) Increase speed by detecting keys pressed, if the entity is a player
2) Increase speedby detecting animations (walk, backwalk, run), if the entity is a enemy

For the IDLE animation, the script is the same for both types. In fact I think that the correct way to increase the enemy's velocity is if we could detect the enemy's "intention" of making a movevent, but unfortunately I don't know if it's possible.

The attack box could be an option for enemies, but I don't know if the enemy behaviour will be the same as the player. As you said and I totally agree, the A.I. will interfere all the time, but at least the snow behaviour while the enemy stops and goes to the IDLE animation, the effect works correctly.

Here's the changed script:
Code:
void main()
{
	snow();
}

void snow()
{//Simulates a "Snow" effect
	void self	= getlocalvar("self");
	void anim	= getentityproperty(self, "animationID");
	void type	= getentityproperty(self, "type");
	int pIndex	= getentityproperty(self, "playerindex");
	float speed	= getentityproperty(self, "speed");
	float rspeed = getentityproperty(self, "running", "speed"); //GET CURRENT RUNNING SPEED
	float xDir	= getentityproperty(self, "xdir");
	float zDir	= getentityproperty(self, "zdir");
	int a = getentityproperty(self,"a"); //Get bomb's altitude
	float xRate	= 0.03;
	float zRate	= 0.03;
	float walk	= 3;
	float run	= 6.5;
	float accel = 0.06;
	float raccel = 0.1;

	//DEBUG INFO ONLY, ERASE WHEN ALL TESTS ARE DONE
	//drawstring(50, 144, 1, "speed___"+ speed);
	//drawstring(50, 244, 0, "xdir___"+ xDir);
	//drawstring(50, 344, 0, "zdir___"+ zDir);
	//drawstring(50, 444, 0, "xvar___"+ getlocalvar("xVel"+self));
	//	drawstring(50, 544, 0, "zvar___"+ getlocalvar("zVel"+self));
	//	drawstring(50, 644, 0, "att___"+ getentityproperty(self,"a"));
	//	drawstring(50, 684, 0, "run___"+ getentityproperty(self, "running", "speed") );

	//SAVE CURRENT VELOCITY WHILE NOT IN IDLE ANIMATION
	if(  anim != openborconstant("ANI_IDLE")){

		//USED ONLY FOR PLAYERS, DETECT KEYS PRESSED
		if(type == openborconstant("TYPE_PLAYER")){

			//PRESSING RIGHT??
			if(  playerkeys(pIndex, 0, "moveright")  ){
				setlocalvar("xVel"+self, xDir);
				setlocalvar("rxVel"+self, xDir);

				//INCREASE SPEED WHILE MOVING
				if(speed < walk){changeentityproperty(self, "speed", speed+accel);}
				if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);} 
			}

			//PRESSING LEFT??
			if(  playerkeys(pIndex, 0, "moveleft")  ){
				setlocalvar("xVel"+self, xDir);
				setlocalvar("rxVel"+self, xDir);

				//INCREASE SPEED WHILE MOVING
				if(speed < walk){changeentityproperty(self, "speed", speed+accel);}
				if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);} 
			}

			//PRESSING DOWN??
			if(  playerkeys(pIndex, 0, "movedown")  ){
				setlocalvar("zVel"+self, zDir);

				//INCREASE SPEED WHILE MOVING
				if(speed < walk){changeentityproperty(self, "speed", speed+accel);}
				if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);} 
			}

			//PRESSING UP??
			if(  playerkeys(pIndex, 0, "moveup")  ){
				setlocalvar("zVel"+self, zDir);

				//INCREASE SPEED WHILE MOVING
				if(speed < walk){changeentityproperty(self, "speed", speed+accel);}
				if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);} 
			}
		}

		//USED ONLY FOR ENEMIES, DETECT ANIMATIONS
		if(type == openborconstant("TYPE_ENEMY")){

			//TRYING TO MOVE??
			if(  anim == openborconstant("ANI_WALK")  ||  anim == openborconstant("ANI_BACKWALK")  || anim == openborconstant("ANI_RUN")  ){
				setlocalvar("xVel"+self, xDir);
				setlocalvar("rxVel"+self, xDir);
				setlocalvar("zVel"+self, zDir);

				//INCREASE SPEED WHILE MOVING
				if(speed < walk){changeentityproperty(self, "speed", speed+accel);}
				if(rspeed < run ){changeentityproperty(self, "running", rspeed+raccel);} 
			}
		}
	}
	else
	{
		//APPLY THE PREVIOUS SAVED VELOCITY AND DECREASE GRADUALLY WHILE IN IDLE ANIMATION

		//MOVING RIGHT IN X AXIS??
		if(getlocalvar("xVel"+self) > 0  ){
		
			changeentityproperty(self, "velocity", getlocalvar("xVel"+self));
			setlocalvar("xVel"+self, getlocalvar("xVel"+self)-xRate);
			setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)-xRate);
			changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
			changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);
		}

		//MOVING LEFT IN X AXIS??
		if(getlocalvar("xVel"+self) < 0){
			
			changeentityproperty(self, "velocity", getlocalvar("xVel"+self));
			setlocalvar("xVel"+self, getlocalvar("xVel"+self)+xRate);
			setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)-xRate);
			changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
			changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);
			

		}
	
		//MOVING DOWN IN Z AXIS??
		if(getlocalvar("zVel"+self) > 0){
		
			changeentityproperty(self, "velocity", NULL(), getlocalvar("zVel"+self));
			setlocalvar("zVel"+self, getlocalvar("zVel"+self)-zRate);
			setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)-xRate);
			changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
			changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);

		}
	
		//MOVING UP IN Z AXIS??
		if(getlocalvar("zVel"+self) < 0 ){
		
			changeentityproperty(self, "velocity", NULL(), getlocalvar("zVel"+self));
			setlocalvar("zVel"+self, getlocalvar("zVel"+self)+zRate);
			setlocalvar("rxVel"+self, getlocalvar("rxVel"+self)-xRate);
			changeentityproperty(self, "speed", getentityproperty(self, "speed")/1.015);
			changeentityproperty(self, "running", getentityproperty(self, "running","speed")/8);
	
		}
	}
}

I don't know what OpenBOR build you are using at the moment, but all my tests were made with the latest source-code version, same as I'm using in SOR2X.

Here's the changed data folder:
https://drive.google.com/file/d/18V0stSX5oZ2q0IUAQ6BTDErCyB436vT0/view?usp=sharing
 
Great. Now my only gripe is with turning while sliding on snow, id like to make it so im still sliding right even when i turnleft-right-left during sliding.
Sliding direction and velocity independent of entity facing.Kinda like real ice, when you turn your back opposite of sliding direction you will still slide the same direction anyway.Does it require some variables ?
 
bWWd said:
Great. Now my only gripe is with turning while sliding on snow, id like to make it so im still sliding right even when i turnleft-right-left during sliding.
Sliding direction and velocity independent of entity facing.Kinda like real ice, when you turn your back opposite of sliding direction you will still slide the same direction anyway.Does it require some variables ?
Maybe you can make it by detecting the "TURN" animation. I will did some tests using your new code.
 
Id prefere not to use it if i dont have to, and figure out something independent of turning, so no matter which way you will turn - you will always slide the same main direction that you started with. i think that needs local variable to be set when starting, and gradually decreasing it to 0 and second variable for negative values maybe.

Originally there should be speed, acceleration and friction, thats how they do it in other engines.


As for the game and look of it, its my 3yr old daughter fav cartoon at the moment so i wanted to make somethin for her and i wish fglayer code wouldnt be so unoptimised, i can only use 3 fglayers no matter what machine im on - it starts to lag when i use more.The ones with alpha effects.Maybe alpha code is not optimised.
Cause when i disable alpha and have 10 fglayers with same settings(movable like that snow) then speed does not drop.IMO theres something off in alpha transparency code..
 
Back
Top Bottom