random taunt sound when kill enemies and objects?

rafhot

Member
how can i make my characters play random sounds ( around 10 variations of taunts for each player character) when they kill enemies but without do it too often?

also i want to do some shouts for my characters when they break stuff on the screen but not everytime

any idea how to do it?
 
In that case, writing totally indepent and custom rangeEvent and didhit functions sounds like a better solution than using generic functions.

Thing's functions would, in addition to calling the generic functions, explicitly check for Hulk or Human Torch players/npc, among others.

Here's an example of what his custom rangeEvent function could be like (the code is not actually working) :

Code:
void cRangeEvent(int rX, int rZ, int rA, int checkBehind, char type, int count){
	void vSelf = getlocalvar("self");
	int seeingEntities = getentityvar(vSelf, "seeing_" + type);
	int didShout = 0;
	
	int lastShout = getentityvar(vSelf, "lastShout");
	int elapsed_time = openborvariant("elapsed_time");
	if(seeingEntities == NULL() && (lastShout == NULL() || lastShout != NULL() && elapsed_time > lastShout + 1000)){
		if(findTarget02(rX, rZ, rA, checkBehind, "player&npc", "hulk")){
			playSound("data/chars/thing/see_hulk.wav");
			didShout = 1;
		} else if findTarget02(rX, rZ, rA, checkBehind, "player&npc", "human_torch")){
			playSound("data/chars/thing/see_human_torch.wav");
			didShout = 1;
		}
		
		if(didShout){
			setentityvar(vSelf, "lastShout", elapsed_time);
			setentityvar(vSelf, "seeing_" + type, 1);
			
			return; // return so that we don't call generic rangeEvent
		}
		
	}
	
	// if not returned yet, call generic rangeEvent
	rangeEvent(rX, rZ, rA, checkBehind, type, count)
	
}
 
Well that will be up to you to tweak the code so that it does. If you want multiple sounds somewhere, you just have to call variableSound (with the right parameters) instead of playSound.
 
rafhot said:
if you need more sounds for your project
get those from marvel heroes mmo they have some gigas of sound files
http://www.chronocrash.com/forum/index.php?topic=1733.0

Excellent  :o I'll check if I can find interesting sounds in these.

rafhot said:
im reading the code, did you have the findTarget02 function?

Yes but it is not finished (it works but it does only check entity name, find_types is not used yet).

Code:
void findTarget02(int Rx, int Rz,int Ra, int searchBack, char find_types, char name){
	int iECnt = openborvariant("count_entities");
	int iEnt;
	void vEnt,ani;
	void self = getlocalvar("self");
	float x = getentityproperty(self, "x");
	float z = getentityproperty(self, "z");
	float a = getentityproperty(self, "a");
	int dir=getentityproperty(self,"direction");

	for(iEnt=0; iEnt<iECnt; iEnt++) {
		vEnt = getentity(iEnt);
		if(!getentityproperty(vEnt,"exists")) continue;
		if (
			getentityproperty(vEnt,"defaultmodel") == name &&
			!getentityproperty(vEnt,"dead") &&
			vEnt
		){
			if (isInRange(self,dir,vEnt,Rx,Rz,Ra,x,z,a, searchBack)){
				return vEnt;
			}
		}
	}
	return NULL();
}
 
can you check my functions to see if im in the right way?

i will use a custom rangevent for each playable character to check for other players and npcs
so it is a switch to check if is a player or npc like in the previous (obstacle/ enemy)
do you think this way should work?

Code:
void ThingRangeEvent(int rX, int rZ, int rA, int checkBehind, char type, int count)
{
	char find_type;
	switch(type)
	{
		case "player":
			find_type = openborconstant("TYPE_PLAYER");
			break;
		case "npc":
			find_type = openborconstant("TYPE_NPC");
			break;
		default:
			return;
	}

	void vSelf = getlocalvar("self");
	int seeingEntities = getentityvar(vSelf, "seeing_" + type);
	int didShout = 0;
	
	int lastShout = getentityvar(vSelf, "lastShout");
	int elapsed_time = openborvariant("elapsed_time");
	if(seeingEntities == NULL() && (lastShout == NULL() || lastShout != NULL() && elapsed_time > lastShout + 1000))
	{
		if(findTarget02(rX, rZ, rA, checkBehind, find_type, "hulk"))
		{
			//playSound("data/chars/thing/see_hulk.wav");
			variableSound("data/chars/" + name + "/hulk_" + type, 1, 50);
			didShout = 1;
		} else if findTarget02(rX, rZ, rA, checkBehind, find_type, "human_torch"))
		{
			//playSound("data/chars/thing/see_human_torch.wav");
			variableSound("data/chars/" + name + "/torch_" + type, 1, 50);
			didShout = 1;
		}
		else if findTarget02(rX, rZ, rA, checkBehind, find_type, "reed"))
		{
			
			variableSound("data/chars/" + name + "/reed_" + type, 1, 50);
			didShout = 1;
		}
		else if findTarget02(rX, rZ, rA, checkBehind, find_type, "sue"))
		{
			
			variableSound("data/chars/" + name + "/sue_" + type, 1, 50);
			didShout = 1;
		}
		
		if(didShout)
		{
			setentityvar(vSelf, "lastShout", elapsed_time);
			setentityvar(vSelf, "seeing_" + type, 1);
			
			return; // return so that we don't call generic rangeEvent
		}
		
	}
	
	// if not returned yet, call generic rangeEvent
	rangeEvent(rX, rZ, rA, checkBehind, type, count)



Code:
void findTarget02(int Rx, int Rz,int Ra, int searchBack, char find_type, char name){
	int iECnt = openborvariant("count_entities");
	int iEnt;
	void vEnt,ani;
	void self = getlocalvar("self");
	float x = getentityproperty(self, "x");
	float z = getentityproperty(self, "z");
	float a = getentityproperty(self, "a");
	int dir=getentityproperty(self,"direction");

	for(iEnt=0; iEnt<iECnt; iEnt++) {
		vEnt = getentity(iEnt);
		if(!getentityproperty(vEnt,"exists")) continue;
		if (
			getentityproperty(vEnt,"defaultmodel") == name &&
			!getentityproperty(vEnt,"dead") &&
			getentityproperty(vEnt,"type") == openborconstant(find_type) &&
			vEnt
		){
			if (isInRange(self,dir,vEnt,Rx,Rz,Ra,x,z,a, searchBack)){
				return vEnt;
			}
		}
	}
	return NULL();
}
 
Yes you're on the right way. To check multiple types (eg player and npc) you need to adapt the functions. Here's an example.

Code:
int checkType(void vEnt, char typeSeq){
	switch(typeSeq){
		case "pl":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER");
			break;
		case "npc":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC");
			break;
		case "pl|npc":
			return (getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER") || 
					getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC"));
			break;
		
		default:
			return 0;
	}
}

void findTarget02(int Rx, int Rz,int Ra, int searchBack, char find_type, char name){
	int iECnt = openborvariant("count_entities");
	int iEnt;
	void vEnt,ani;
	void self = getlocalvar("self");
	float x = getentityproperty(self, "x");
	float z = getentityproperty(self, "z");
	float a = getentityproperty(self, "a");
	int dir=getentityproperty(self,"direction");

	for(iEnt=0; iEnt<iECnt; iEnt++) {
		vEnt = getentity(iEnt);
		if(!getentityproperty(vEnt,"exists")) continue;
		if (
			getentityproperty(vEnt,"defaultmodel") == name &&
			checkType(vEnt, find_type) &&
			!getentityproperty(vEnt,"dead") &&
			vEnt
		){
			if (isInRange(self,dir,vEnt,Rx,Rz,Ra,x,z,a, searchBack)){
				return vEnt;
			}
		}
	}
	return NULL();
}

In your Thing function you would have this check for player or npc Hulk :

Code:
if(findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "hulk")){
	variableSound("data/chars/" + name + "/hulk", 1, 50);
}

Notice that I replaced
Code:
"data/chars/" + name + "/hulk_" + type
with
Code:
"data/chars/" + name + "/hulk"

That is because in this case the filename should not change whether Hulk is a player or a npc.
 
thanks, i updated the ThingRangeEvent as you said

i just dont get how to call the checktype function inside of it

Code:
void ThingRangeEvent(int rX, int rZ, int rA, int checkBehind, char type, int count)
{
	char find_type;
	switch(type)
	{
		case "player":
			find_type = openborconstant("TYPE_PLAYER");
			break;
		case "npc":
			find_type = openborconstant("TYPE_NPC");
			break;
		default:
			return;
	}

	void vSelf = getlocalvar("self");
	int seeingEntities = getentityvar(vSelf, "seeing_" + type);
	int didShout = 0;
	
	int lastShout = getentityvar(vSelf, "lastShout");
	int elapsed_time = openborvariant("elapsed_time");
	if(seeingEntities == NULL() && (lastShout == NULL() || lastShout != NULL() && elapsed_time > lastShout + 1000))
	{
		if(findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "hulk"))
		{
			//playSound("data/chars/thing/see_hulk.wav");
			variableSound("data/chars/" + name + "/hulk", 1, 50);
			didShout = 1;
		} else if findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "human_torch"))
		{
			//playSound("data/chars/thing/see_human_torch.wav");
			variableSound("data/chars/" + name + "/torch", 1, 50);
			didShout = 1;
		}
		else if findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "reed"))
		{
			
			variableSound("data/chars/" + name + "/reed", 1, 50);
			didShout = 1;
		}
		else if findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "sue"))
		{
			
			variableSound("data/chars/" + name + "/sue", 1, 50);
			didShout = 1;
		}
		
		if(didShout)
		{
			setentityvar(vSelf, "lastShout", elapsed_time);
			setentityvar(vSelf, "seeing_" + type, 1);
			
			return; // return so that we don't call generic rangeEvent
		}
		
	}
	
	// if not returned yet, call generic rangeEvent
	rangeEvent(rX, rZ, rA, checkBehind, type, count)

}

in times like this i can notice how rusted i become with my code skills. last time i really code was in 2007 i feel so dumb ehehe
 
The script looks ok, except that name is used but not declared. You should add :

Code:
char name = getentityproperty(vSelf, "defaultmodel");

around the start of the function, or directly write the entity name (here "thing") because it's a character specific function.
 
not compile yet, i changed
else if
to if  put the ( at the begin of each else if
tried everything but the log point to things that are not wrong

i checked for a }  without his pair{  but there is not this error


Script error: data/scripts/lib001.c, line 68: Invalid function call or expression '}' (in production 'postfix_expr2')

}
^



In file included from data/scripts/dumm001.c, line 1:
Script error: data/scripts/lib001.c, line 72: Invalid declaration(expected comma, semicolon or initializer?) ')' (in production 'decl')

int checkType(void vEnt, char typeSeq)
                                    ^
 
Code:
void ThingRangeEvent(int rX, int rZ, int rA, int checkBehind, char type, int count)
{
	char find_type;
	switch(type)
	{
		case "player":
			find_type = openborconstant("TYPE_PLAYER");
			break;
		case "npc":
			find_type = openborconstant("TYPE_NPC");
			break;
		default:
			return;
	}

	char name = getentityproperty(vSelf, "thing"); //"defaultmodel"
	void vSelf = getlocalvar("self");
	int seeingEntities = getentityvar(vSelf, "seeing_" + type);
	int didShout = 0;
	
	int lastShout = getentityvar(vSelf, "lastShout");
	int elapsed_time = openborvariant("elapsed_time");
	if(seeingEntities == NULL() && (lastShout == NULL() || lastShout != NULL() && elapsed_time > lastShout + 1000))
	{
		if(findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "hulk"))
		{
			//playSound("data/chars/thing/see_hulk.wav");
			variableSound("data/chars/" + name + "/hulk", 1, 50);
			didShout = 1;
		}
		else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "human_torch"))
		{
			//playSound("data/chars/thing/see_human_torch.wav");
			variableSound("data/chars/" + name + "/torch", 1, 50);
			didShout = 1;
		}
		else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "reed"))
		{
			
			variableSound("data/chars/" + name + "/reed", 1, 50);
			didShout = 1;
		}
		else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "sue"))
		{
			
			variableSound("data/chars/" + name + "/sue", 1, 50);
			didShout = 1;
		}
		
		if(didShout)
		{
			setentityvar(vSelf, "lastShout", elapsed_time);
			setentityvar(vSelf, "seeing_" + type, 1);
			
			return; // return so that we don't call generic rangeEvent
		}
		
	}
	
	// if not returned yet, call generic rangeEvent
	rangeEvent(rX, rZ, rA, checkBehind, type, count)

}



int checkType(void vEnt, char typeSeq)
{
 
	switch(typeSeq)
	{
		case "pl":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER");
			break;
		case "npc":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC");
			break;
		case "pl|npc":
			return (getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER") || 
					getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC"));
			break;
		
		default:
			return 0;
	}
}

void findTarget02(int Rx, int Rz, int Ra, int searchBack, char find_type, char name){
	int iECnt = openborvariant("count_entities");
	int iEnt;
	void vEnt,ani;
	void self = getlocalvar("self");
	float x = getentityproperty(self, "x");
	float z = getentityproperty(self, "z");
	float a = getentityproperty(self, "a");
	int dir=getentityproperty(self,"direction");

	for(iEnt=0; iEnt<iECnt; iEnt++) {
		vEnt = getentity(iEnt);
		if(!getentityproperty(vEnt,"exists")) continue;
		if (
			getentityproperty(vEnt,"defaultmodel") == name &&
			checkType(vEnt, find_type) &&
			!getentityproperty(vEnt,"dead") &&
			vEnt
		){
			if (isInRange(self,dir,vEnt,Rx,Rz,Ra,x,z,a, searchBack)){
				return vEnt;
			}
		}
	}
	return NULL();
}
 
Here it goes

Code:
void ThingRangeEvent(int rX, int rZ, int rA, int checkBehind, char type, int count)
{
	char find_type;
	switch(type)
	{
		case "player":
			find_type = openborconstant("TYPE_PLAYER");
			break;
		case "npc":
			find_type = openborconstant("TYPE_NPC");
			break;
		default:
			return;
	}


	void vSelf = getlocalvar("self");
 	//char name = getentityproperty(vSelf, "defaultmodel");
	char name = "thing";
	int seeingEntities = getentityvar(vSelf, "seeing_" + type);
	int didShout = 0;
	
	int lastShout = getentityvar(vSelf, "lastShout");
	int elapsed_time = openborvariant("elapsed_time");
	if(seeingEntities == NULL() && (lastShout == NULL() || lastShout != NULL() && elapsed_time > lastShout + 1000))
	{
		if(findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "hulk"))
		{
			//playSound("data/chars/thing/see_hulk.wav");
			variableSound("data/chars/" + name + "/hulk", 1, 50);
			didShout = 1;
		}
		else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "human_torch"))
		{
			//playSound("data/chars/thing/see_human_torch.wav");
			variableSound("data/chars/" + name + "/torch", 1, 50);
			didShout = 1;
		}
		else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "reed"))
		{
			
			variableSound("data/chars/" + name + "/reed", 1, 50);
			didShout = 1;
		}
		else if (findTarget02(rX, rZ, rA, checkBehind, "pl|npc", "sue"))
		{
			
			variableSound("data/chars/" + name + "/sue", 1, 50);
			didShout = 1;
		}
		
		if(didShout)
		{
			setentityvar(vSelf, "lastShout", elapsed_time);
			setentityvar(vSelf, "seeing_" + type, 1);
			
			return; // return so that we don't call generic rangeEvent
		}
		
	}
	
	// if not returned yet, call generic rangeEvent
	rangeEvent(rX, rZ, rA, checkBehind, type, count);

}

The name line was wrong and there was a semicolon missing at the end of ThingRangeEvent.
 
i have expanded a little more the system

Code:
int checkType(void vEnt, char typeSeq)
{
 
	switch(typeSeq)
	{
	
		case "en":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_ENEMY");
			break;
		case "pl":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER");
			break;
		case "npc":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC");
			break;
		case "pl|npc":
			return (getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER") || 
					getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC") ||
					getentityproperty(vEnt, "type") == openborconstant("TYPE_ENEMY"));
			break;
		
		default:
			return 0;
	}
}

now player are able to bully also specific bosses when they spawn and the effect is awesome

one thing that at this point everybody maybe noticed that is the game size will exponentialy increase using this system

for example thing folder had around 5mb, but now it have around 60mb and the increase was all soundfiles
is there a way to make this system support .ogg instead of .wav files?
did the playsound function supports .ogg too or another function should be created?

if not i think this mod will be the first one to reach the house of gigabytes :P, but i really worried about that

 
You should change the string key to something like "pl|npc|en" if it accepts player, npc and enemy. You can add as many combination as you want in the switch block.

Code:
int checkType(void vEnt, char typeSeq)
{
 
	switch(typeSeq)
	{
	
		case "en":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_ENEMY");
			break;
		case "pl":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER");
			break;
		case "npc":
			return getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC");
			break;
		case "pl|npc":
			return (getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER") || 
					getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC"));
			break;
		case "pl|npc|en":
			return (getentityproperty(vEnt, "type") == openborconstant("TYPE_PLAYER") || 
				getentityproperty(vEnt, "type") == openborconstant("TYPE_NPC") ||
				getentityproperty(vEnt, "type") == openborconstant("TYPE_ENEMY"));
			break;
		default:
			return 0;
	}
}
 
Back
Top Bottom