keyscript question

msmalik681

OpenBOR Developer
Staff member
if i set a keyscript to entity can I refer to keyscripts in external entity's or do all codes have to be within the keyscript file.

Also how can I disable a button for a set time after pressed and can I use start for other operations or will start always pause the game.
 
msmalik681 said:
if i set a keyscript to entity can I refer to keyscripts in external entity's or do all codes have to be within the keyscript file.

No keyscript is actually just an event. What you can access in a keyscript event is basically the same as what you can access in other scripts events.

[quote author=msmalik681]
Also how can I disable a button for a set time after pressed[/quote]

I think you have to use update.c for that, and remove the disabled keys from the newskeys property of player during the interval you want. I can provide an example if necessary.

[quote author=msmalik681]can I use start for other operations or will start always pause the game.
[/quote]

Yes you can use it for other operations by using it in scripts and removing it froms player keys before the pause code is executed.
 
Here's a partial example to get you started. It does disable all attack presses by removing the corresponding inputs at the start of each cycle.

This code should be in update.c

Code:
void removeDisabledKeys(){
	int playerIndex;
	
	for(playerIndex=0; playerIndex<4;playerIndex++){
		
		
		if(playerkeys(playerIndex, 1, "attack")){
			changeplayerproperty(playerIndex, "newkeys", 0);
			changeplayerproperty(playerIndex, "playkeys", 0);
		}
		
		
	}
	
}

void main(){
	removeDisabledKeys();
}
 
There is no timeout in this code.

If you want a timeout, you need an event to trigger it. Assuming the event is the button press itself, the code would look like this :

Code:
void removeDisabledKeys(){
	int playerIndex;
	
	for(playerIndex=0; playerIndex<4;playerIndex++){		
		
		if(playerkeys(playerIndex, 1, "attack")){
			int elapsedTime = openborvariant("elapsed_time");
			int lastAttackPressTime = getindexedvar("lastAttackPressTime_" + playerIndex);

			if(lastAttackPressTime == NULL() || elapsedTime > lastAttackPressTime + 100){
				setindexedvar("lastAttackPressTime_" + playerIndex, elapsedTime);
			} else {
				changeplayerproperty(playerIndex, "newkeys", 0);
				changeplayerproperty(playerIndex, "playkeys", 0);
			}
		}
		
		
	}
	
}
 
I have some other questions how do I make a input string like D F A for a keyscript and can inputs be based on holding a key or how long a key was held for and finally can a keyscript activate on button release rather then the initial press ?

any examples would be much appreciated.
 
Back
Top Bottom