Water block not beeping

Posted By: Ruben

Water block not beeping - 06/30/15 06:49

I am trying to create swimming/buoyancy functionality in my game. I created a block in a castle moat that represents water. If the player jumps into the block, I want the player to start swimming. However, I am at the very beginning stages of trying to make this happen.

Right now, I am just trying to make my player "sense" the passable and transparent block, by sounding a beep() when the player makes contact with it. So far, the beep() is not sounding when the player jumps into and makes contact with the block.

The block is saved as a map entity in its own WED file.

Here is the code to try to make the beep() sound when the player makes contact with the block:

Code:
action moatSide1()
{
   moat_side_one = me;
}

...


player_code()
{

   ...


   while(my.x)
   {

      ...


      if(you == moat_side_one)
      {
         beep();
      }

      ...

      wait(1)
   }
}



The moat block is given the behaviour action of "moatSide1" in WED, and the player is given the behaviour action of "player_code". Yet when the player jumps in the block, and player passes through it since it is passable, no beep() is sounded off.

Does anyone know why?
Posted By: Reconnoiter

Re: Water block not beeping - 06/30/15 09:07

It looks like you forgot to copy the vital parts of the code here in your post. But anyway, what you wanna do is just trace below the player and check the texture (there are possible more alternatives but this works fine). First you need to go to your block and change the texture name of it in MED or whatever to e.g. water_tex or something else suiting, than use this code:

Code:
if (every_blabla_frame_this_reduces_fps) //optionally
{
  if (c_trace(my.x, vector(my.x, my.y, my.z - 1000), IGNORE_CONTENT | IGNORE_ME | SCAN_TEXTURE) > 0)
  {
    if (str_cmpi(hit.texname, "water_tex") == 1)
    {
      //do your thing
    }
  }
}

Posted By: Ruben

Re: Water block not beeping - 06/30/15 09:59

I tried placing your code in my player_code() function, and inside the while() loop, as follows:

Code:
if (c_trace(my.x, vector(my.x, my.y, my.z - 1000), IGNORE_CONTENT | IGNORE_ME | SCAN_TEXTURE) > 0)
      {
         //if (str_cmpi(hit.texname, "MoatSide1_wmb_734") == 1)
         //if (str_cmpi(hit.texname, "water2") == 1)
         if (str_cmpi(hit.texname, "MoatSide1") == 1)
         {
            beep();
         }
      }



The name of the block after being imported into a castle WED file as a map entity from its own WED file is "MoatSide1_wmb_734". The name of this same block sitting in its own WED file is "MoatSide1". The name of the texture on this same block is "*water2", taken straight from standard.wad. Yet none of these are producing the beep(). Am I doing something wrong to make this happen?
Posted By: Wjbender

Re: Water block not beeping - 06/30/15 12:45

what is while (my.x) ?

anyway , just use a region or the min max size to determine if the player has entered the area .

without the actual code which you use to detect whether the player is inside the water ,plus how you set up that events (I am assuming) no one will know WHY what's happening.

we don't even know if your windows system sounds has a sound assigned to the relevant beep (I dont know if GS has its own but usually its taken from system sounds) , I assume there's nothing wrong with the sound aspect as is normal but you really need to provide the relevant code , for people to help you .
Posted By: Reconnoiter

Re: Water block not beeping - 06/30/15 15:16

Small note: I also personally never use beep for debugging, I find error("hey_it_works!"); better for that.

@Ruben, try a beep/error() before the c_trace, and see if that works.
Posted By: rayp

Re: Water block not beeping - 06/30/15 19:16

Quote:
IGNORE_CONTENT
wont work with water ents btw.
Posted By: Ruben

Re: Water block not beeping - 07/01/15 05:28

Originally Posted By: Reconnoiter

@Ruben, try a beep/error() before the c_trace, and see if that works.

I put a beep before the c_trace, and I am definitely hearing a bunch of beeps over and over. However, the c_trace is not catching anything to initiate its own beep. Here is the code I tried:

Code:
...

action player_code()
{
   ...

   while(1)
   {

      ...

      //beep();  // DEFINITELY IS SOUNDING OFF WHEN UNCOMMENTED.

      if (c_trace(my.x, vector(my.x, my.y, my.z - 1000), IGNORE_ME | SCAN_TEXTURE) > 0)
      {
         if (str_cmpi(hit.texname, "*water2") == 1)
         {
            beep();
         }
      }

      ...

      wait(1);
   }
}



I am using the texture from standard.wad titled *water2 for the water block in question. Does anyone know why the beep() sounds before the c_trace(), but not in the c_trace()?
Posted By: Reconnoiter

Re: Water block not beeping - 07/01/15 09:59

Try a beep right after the c_trace (before the if).

If that works/beeps, try your code with a model: e.g. some flat transparent model with your water texture and change the skin name it has in MED to "water2" without the quotes ofcoures. If that still won't work something is wrong with the code, if that will work than the WAD skin name isn't called water2 or isn't detected correctly by str_cmpi (I don't use WAD so much so I can't help you there).
Posted By: Wjbender

Re: Water block not beeping - 07/01/15 11:42

okay so i did a little test , i created a block ,set it passable , applied a texture "grey" to it
then i assigned the test action script to a object (dont have time to create a player) and used
the camera to trace from.

now here comes the catch with that c_trace approach , the trace hits the surface and when
the surface is hit , the tex name is retrieved , if you are inside of the block there will be NO HIT
and it wil not help .

like i suggested , use a region or min max sizes ,so that you can detect when the player ,like its
center point or something is INSIDE the area ,or whatever other event detection /code/flags stuff you think up .

here is the code i used to test it , now fly around and see for yourseld that , the trace will work
only when you are above the surface of the block because i you are tracing down against the surface here

Code:
#include <acknex.h>
#include <default.c>

action test()
{
	while(1)
	{
		if(c_trace(camera.x,vector(camera.x,camera.y,camera.z-1000),IGNORE_ME | SCAN_TEXTURE))
		{
			if(str_cmpi(hit.texname,"grey"))
			{
				DEBUG_VAR(1,100);
			}
			else DEBUG_VAR(0,100);
		}
		
		wait(1);
	}
}

function main()
{
	warn_level = 4;	
	def_move();
	level_load("1.wmb");
}



for example try a c_intersect approach
Posted By: Reconnoiter

Re: Water block not beeping - 07/01/15 15:14

Your right, the c_trace method is indeed not a good one for this example.
Posted By: Ruben

Re: Water block not beeping - 07/02/15 02:15

I tried a different method that I just recently learned, and it seems to partially work. I went into the WED file and applied the water block to a region titled "water". I then used the region_check() function in the player_code() function to see if the player made contact with the "water" region. Sure enough, the player did. The game is beeping like crazy when the player makes contact with the water block, but I keep getting this error pop-up message every time before the game loads as follows:

Code:
Error E1513
Script crash in terrain_get_z:
OK             Cancel



When I click the OK button, the player starts moving on its own without me moving it. Once I fiddle with the move buttons, then the player will stay put, and move according to my commands. However, the pop-up error above will not go away every time I restart the game, even when I erase the new code that I put in the program.

This is the new code I put:

Code:
...

action player_code()
{
   ...

   player = me;

   ...
	
   my.shadow = 1;
	
   vec_fill(move_vec, 0); // always reset a vector to zero when creating
	
   ...
	
   my.JUMP_FORCE = 13;
   var gravity_var = 0;
   var gravity_force = 2;
   var jumplck = 0;
   var space_lck = 0;
   my.FEET_HEIGHT = -my.min_z+1; // ORIGINAL
   
   my.eflags |= FAT | NARROW; // set both flags to prevent automatic recalculation on
	                            //      scale changes.
   my.emask |= ENABLE_SHOOT;

   ...
	 
   // set FLAG2 to make the guard detectable by c_scan, 
   // and store the guard pointer in its own CREATOR skill 
   // so that the detecting entity knows its enemy	
   set(my,FLAG2);  
   my.CREATOR = me;
	 
   set(my, POLYGON);
  
   camera.tilt = -5;

   ...
	
   wait(1);

   while (1)
   {
      VECTOR vMin,vMax; // NEW CODE
      vec_set(vMin,my.x); // NEW CODE
      vec_set(vMax,my.x); // NEW CODE
      vec_add(vMin,my.min_x); // NEW CODE
      vec_add(vMax,my.max_x); // NEW CODE
		
      if(region_check("water",vMin,vMax)) // NEW CODE
      {
         beep(); // NEW CODE
      }

      ...

      wait(1);
   }
}

...



Does anyone have an idea why I might be getting this error?
Posted By: Ruben

Re: Water block not beeping - 07/02/15 04:10

Okay, I believe I figured out what is causing the pop-up error, and it has nothing to do with my code in SED. When I delete the "region" I created in the WED file, and I restart the game, the error is gone. However, when I place the region back into the WED file, the error comes back when I restart the game. Specifically, the pop-up error is:

Code:
Error E1513
Script crash in terrain_get_z:
OK                Cancel



Has anyone else had this particular situation? If so, any ideas on how you solved it?
Posted By: FBL

Re: Water block not beeping - 07/02/15 06:38

I don't know about that error (sounds strange to me), but for checking things with passable and solid blocks you can use following keywords in your entity function:

in_passable (inside passable block)
on_passable (standing on passable block)

Those temporary variables are set after each c_move and c_trace automatically.
For more details check the manual pages of those commands.
Posted By: Ruben

Re: Water block not beeping - 07/02/15 06:55

Originally Posted By: Firoball
I don't know about that error (sounds strange to me), but for checking things with passable and solid blocks you can use following keywords in your entity function:

in_passable (inside passable block)
on_passable (standing on passable block)

Those temporary variables are set after each c_move and c_trace automatically.
For more details check the manual pages of those commands.

So, you do not recommend using regions?
Posted By: FBL

Re: Water block not beeping - 07/02/15 07:43

The last time I did "water code" was several years ago, regions were not existing back then. I just added inmformation to the c_trace approach.

It also depends on how you plan to build your level.
in_passable/on_passable is for level blocks (referred to as "water entities" in the manual), but as soon as you add models with polygon flag as level surfaces, it won't work anymore.

A water entity should be a level entity (which is a pre-built level block) with water texture.
Posted By: Reconnoiter

Re: Water block not beeping - 07/02/15 09:09

Originally Posted By: Ruben
Okay, I believe I figured out what is causing the pop-up error, and it has nothing to do with my code in SED. When I delete the "region" I created in the WED file, and I restart the game, the error is gone. However, when I place the region back into the WED file, the error comes back when I restart the game. Specifically, the pop-up error is:

Code:
Error E1513
Script crash in terrain_get_z:
OK                Cancel



Has anyone else had this particular situation? If so, any ideas on how you solved it?
, hmm strange error, maybe memory error? Removing/adding a region should not matter with this. What is in this terrain_get_z function? Just incase, better check if your not trying to access empty pointer somewhere cause memory errors are a pain the ass to solve once your project is bigger. It can become really random.
Posted By: Wjbender

Re: Water block not beeping - 07/02/15 09:11

I am not sure about this , but the terrain thingy sounds familiar to me , I had the issue once and figured out that the terrain min and max were empty directly after a terrain creation , it could be that the water surface (if it had waves) is when its created as a piece of terrain ?

then just after its created it needs the c_setminmax or something to update min and max or else they remain uninitialised .

will check it out of curiosity.
Posted By: Wjbender

Re: Water block not beeping - 07/02/15 10:07

http://wikisend.com/download/686600/test.zip

I couldn't find a issue , what are you doing different in yours?

terrain_get_z could only have a few possible empty pointers/whatever , a non existing entity or empty min max I believe ..

but I did what you said and didn't get the same issue , you must be using / doing something more than just that , are you using water planes and shaders or something ,something is missing from your explanation.
Posted By: FBL

Re: Water block not beeping - 07/02/15 10:21

Looking at the templates, it's possibly something with the water() action (water.c). Looks like shader stuff.
Posted By: Wjbender

Re: Water block not beeping - 07/02/15 17:43

Code:
action water()
{
	fx_mirrorWater();
	while(1) {
		if(key_hit("1")) terrain_raise(me,-0.5);
		if(key_hit("2")) terrain_raise(me,0.5);
// skills are defined as var, but shaders use float values 
// conversion is not automatic here, thus we need floatv/fixv
		if(key_hit("3")) my.skill43 = floatv(fixv(my.skill43)-5);
		if(key_hit("4")) my.skill43 = floatv(fixv(my.skill43)+5);
		if(key_hit("5")) my.skill44 = floatv(fixv(my.skill44)-5);
		if(key_hit("6")) my.skill44 = floatv(fixv(my.skill44)+5);
		if(key_hit("7")) mtl_hdr.skill2 = floatv(fixv(mtl_hdr.skill2)+1);
		if(key_hit("8")) mtl_hdr.skill2 = floatv(fixv(mtl_hdr.skill2)-1);
----------------->>>>>> water_height = terrain_get_z(my,1);<<<<<---------------------------------------
		water_ripple = fixv(my.skill43);
		water_scale = fixv(my.skill44);
		hdr_threshold = fixv(mtl_hdr.skill2);
		wait(1);
	}
}



yeah only one i can find too , have you assigned this action to a block or something ?
Posted By: Ruben

Re: Water block not beeping - 07/02/15 20:58

Originally Posted By: Wjbender
Code:
action water()
{
	fx_mirrorWater();
	while(1) {
		if(key_hit("1")) terrain_raise(me,-0.5);
		if(key_hit("2")) terrain_raise(me,0.5);
// skills are defined as var, but shaders use float values 
// conversion is not automatic here, thus we need floatv/fixv
		if(key_hit("3")) my.skill43 = floatv(fixv(my.skill43)-5);
		if(key_hit("4")) my.skill43 = floatv(fixv(my.skill43)+5);
		if(key_hit("5")) my.skill44 = floatv(fixv(my.skill44)-5);
		if(key_hit("6")) my.skill44 = floatv(fixv(my.skill44)+5);
		if(key_hit("7")) mtl_hdr.skill2 = floatv(fixv(mtl_hdr.skill2)+1);
		if(key_hit("8")) mtl_hdr.skill2 = floatv(fixv(mtl_hdr.skill2)-1);
----------------->>>>>> water_height = terrain_get_z(my,1);<<<<<---------------------------------------
		water_ripple = fixv(my.skill43);
		water_scale = fixv(my.skill44);
		hdr_threshold = fixv(mtl_hdr.skill2);
		wait(1);
	}
}



yeah only one i can find too , have you assigned this action to a block or something ?

Ah! Okay, I think you hit on something. I do have a texture in the WED with this same water() action assigned to it, with all the same code assigned to that action, such as fx_mirrorWater(), etc.

I am at work right now. When I get home, I will try deleting this texture from the WED, and see what happens. Thank you! :-)
Posted By: Ruben

Re: Water block not beeping - 07/03/15 06:04

Okay, so I deleted the file containing the water() action, and I deleted the terrain that used the water() action. I re-attached the main script file in Map Properties in WED to refresh it. I compiled the WED, but I am still getting the same error pop-up about terrain_get_z .

I tried going to a different WED file of mine that never had the water() terrain in it. I placed a region inside of it, and I am still getting the same error pop-up about terrain_get_z .

Does the error just persist even after I deleted the water() file containing terrain_get_z ?
Posted By: FBL

Re: Water block not beeping - 07/03/15 06:35

next option is terrain.c level.c
Posted By: Wjbender

Re: Water block not beeping - 07/03/15 09:45

Code:
/ get and set terrain height
function terrain_get_z(ENTITY* ent,number)

// returns the height of the next vertex at the given position
function terrain_height(ENTITY* ent,VECTOR* position)

// return a terrain position above ground
VECTOR* terrain_pos(ENTITY* terrain,x,y,z)

// raise all terrain vertices by the given value
function terrain_raise(ENTITY* terrain, var raise_z)

// raise one terrain vertex by the given value
function terrain_raisevertex(ENTITY* terrain,var x,var y,var raise_z)

function terrain_fence(ENTITY* terrain, var height)

// place an entity at a random position between two height values on terrain
// uses: terrain_buffer
function ent_terrain_place(ENTITY* ent,ENTITY* terrain,minheight,maxheight)

// create entities on terrain, guided from on color spots in a mask
var ent_seed(char* name,ENTITY* terrain,BMAP* mask,COLOR* color,var dist,var mode,EVENT act)

var ent_seed(char* name,ENTITY* terrain,BMAP* mask,COLOR* color,var dist,EVENT act)



are you using any of these functions, they are from "level.c"
see if you can find theire function names somewhere in your scripts..
Posted By: Wjbender

Re: Water block not beeping - 07/03/15 12:01

screw it , try this ..

assign this action to your water block

Code:
action water_block()
{
	while(!me)wait(1);
	
	//this will be the min/max of the water block
	VECTOR water_min;
	VECTOR water_max;
	
	//this should be your player's min/max you dont need this 
	//i did this for the camera as a demo
	VECTOR player_min;
	VECTOR player_max;
	
	while(me)
	{
		//water min/max values plus position
		vec_set(water_min,my.min_x);
		vec_set(water_max,my.max_x);
		
		vec_add(water_min,my.x);
		vec_add(water_max,my.x);
		
		//player min/max 
		//this should be your player sizes you wish to test intersection against
		vec_set(player_min,vector(camera.x-50,camera.y-50,camera.z-50));
		vec_set(player_max,vector(camera.x+50,camera.y+50,camera.z+50));
		
		//check if player min/max , intersects with , water min/max
		if(c_intersect(water_min,water_max,NULL,player_min,player_max,NULL)==-1)
		{
			DEBUG_VAR(1,100);
			draw_box3d(water_min,water_max,COLOR_GREEN,100);
		}
		else 
		{
			DEBUG_VAR(0,100);
			draw_box3d(water_min,water_max,COLOR_RED,100);
		}

		wait(1);

	}
}


or go with in_passable, I am done.
Posted By: Ruben

Re: Water block not beeping - 07/03/15 16:41

Thank you Wjbender.

However, I think I figured out why I kept getting the terrain_get_z error. I had this code in my main() function:

Code:
function main()
{
   ...

   level_terrain = level_ent; // CAUSING terrain_get_z ERROR WHEN REGION IS  PRESENT.
   terrain_tile(level_terrain); // CAUSING terrain_get_z ERROR WHEN REGION IS PRESENT.

   ...
}



When I commented out this code, I no longer get the terrain_get_z error, even if I have a region in my WED file.

I will try to make the region method work. If it does not, I will try your water_block() action method. Thank you.
Posted By: Wjbender

Re: Water block not beeping - 07/03/15 16:47

okay
© 2024 lite-C Forums