PDA

View Full Version : Cog request...



CaptBevvil
11-16-2005, 01:47 PM
TriggerZone.cog

Parameters:

The cog must allow the user to enter 6 x,y,z coordinates.
The cog should call for the players current position at a "flex" rate.
The cog will check to determine if the player is within these 6 coordinates
IF No, then it will ignore the rest of the cog. IF Yes, then it will continue.
The cog must allow the user to modify or enable the following varibles:
Modify (change) Sector Tint Locally.
Modify the gravity value (0-4) Locally.
Enable Water effect for Sector Locally.
Execute Cogs Locally (allow the user to specify 4 or more cogs to be executed while the player is within the 6 specified coordinates).

Obviously, this cog needs to be local as to work in MP.

Thanks in advance!

Centrist
11-16-2005, 08:23 PM
The cog must allow the user to enter 6 x,y,z coordinates.

Are these coords part of a surface or sector?



Modify (change) Sector Tint Locally.
Modify the gravity value (0-4) Locally.
Enable Water effect for Sector Locally.


I would need a little more information than that. What sectors are going to be affected?



Execute Cogs Locally (allow the user to specify 4 or more cogs to be executed while the player is within the 6 specified coordinates).

I'm assuming you want this cog to send the user0 message to the other cogs. :confused:

CaptBevvil
11-17-2005, 11:41 AM
Are these coords part of a surface or sector?

No, they are level x,y,z coordinates. Completely independant. Basically, what you're doing is getting the players position getCurrentPlayersPos() (or whatever it's called) and then checking the returned values against the user entered values to see if the player exist within those coordinates.




I would need a little more information than that. What sectors are going to be affected?

User determined. Theoretically, if everything goes right, only Sector 0 will need to be used.


I'm assuming you want this cog to send the user0 message to the other cogs. :confused:

I want this cog to check to see if the player is within an invisible x,y,z boxed shape area that acts as a "trigger zone" vs using "touched" or "colide" as an indicator of rather or not to initiate a cog.

So, when the cog runs it's check:
If NO, then nothing happens.
If YES, then the sector changes take effect and any cogs that need to run will be executed.

CaptBevvil
11-17-2005, 12:02 PM
I know this isn't correct, buy maybe it'll help



using
getCurrentPlayerPos() //or whatever that function is called
getSectorTint()
getSectorFlag()
getLevelGrav()

float playerPos = 0.0; //to store and check the players position
float cord1 = 0.0; //if it'll be easier, this can be xCordHi
float cord2 = 0.0; //if it'll be easier, this can be xCordLo
float cord3 = 0.0; //if it'll be easier, this can be yCordHi
float cord4 = 0.0; //if it'll be easier, this can be yCordLo
float cord5 = 0.0; //if it'll be easier, this can be zCordHi
float cord6 = 0.0; //if it'll be easier, this can be zCordLo
float secTint = 0.0; //to change the sector tint
int waterEffect = 0; //0 = no, 1 = yes
int gravity = 0; //to change gravity 0-4 as per the level header
string cog1 = " ";
string cog2 = " ";
string cog3 = " ";
string cog4 = " ";

Code:

getCurrentPlayerPos();

IF
getCurrentPlayerPos (x < cord1 && x > cord2 && y < cord3 && y > cord4 && z < cord 5 && z > cord6);
setSectorTINT = secTint
setSectorFlag = waterEffect
setLevelGrav = gravity
Start cog1
Start cog2
Start cog3
Start cog4

Else
Nothing

End

CaptBevvil
11-18-2005, 09:10 AM
Woops, and everything has to go back to the way it was before when they leave out of that area.

Centrist
11-18-2005, 11:42 PM
Haven't forgotten - I'll see what I can do tomorrow. ;)

Centrist
11-19-2005, 06:56 PM
Here it is:



# triggerzone.cog
#
# A cog that will create effects in a sector when a player enters a set of coordinates.
# All effects will be client-side only with no synchronization.
#
# [CT]
#================================================= =============#
flags=0x240
symbols

message startup
message pulse

thing player local
int i local
vector pos local
flex enabled=0 local

flex pulseInterval=1

flex xmin=0
flex xmax=1
flex ymin=0
flex ymax=1
flex zmin=0
flex zmax=1

int numEffectSectors=1
sector effectSector0=-1
sector effectSector1=-1
sector effectSector2=-1
sector effectSector3=-1

int numMessageCogs=1
cog messageCog0=-1
cog messageCog1=-1
cog messageCog2=-1
cog messageCog3=-1

flex newGravity=8
flex curGravity=4

vector newTint=(0/0.5/0)
vector curTint=(0/0/0)

end
#================================================= =============#
code
#------------------------------------------------------
startup:
player=GetLocalPlayerThing();
SetPulse(pulseInterval);

return;
#------------------------------------------------------
pulse:
pos=GetThingPos(player);
if(VectorX(pos) > xmin && VectorX(pos) < xmax &&
VectorY(pos) > ymin && VectorY(pos) < ymax &&
VectorZ(pos) > zmin && VectorZ(pos) < zmax) call enable_effect;
else call disable_effect;

return;
#------------------------------------------------------
enable_effect:
if(enabled) return;
enabled=1;
for(i=0; i < numEffectSectors && effectSector0[i] != -1; i=i+1) SetSectorTint(effectSector0[i], newTint);
for(i=0; i < numMessageCogs && messageCog0[i] != -1; i=i+1) SendMessage(messageCog0[i], user0);
SetGravity(newGravity);

return;
#------------------------------------------------------
disable_effect:
if(!enabled) return;
enabled=0;
for(i=0; i < numEffectSectors && effectSector0[i] != -1; i=i+1) SetSectorTint(effectSector0[i], curTint);
for(i=0; i < numMessageCogs && messageCog0[i] != -1; i=i+1) SendMessage(messageCog0[i], user1);
SetGravity(curGravity);

return;
#------------------------------------------------------
end


I have this cog sending user0 and user1 to the other cogs that you want to "start," but any message can be sent instead.

So try it out. ;)

CaptBevvil
11-28-2005, 11:22 AM
Sorry it took so long to respond.

The cog seems to be working "OK" but was missing a couple imporatant things.

First, the pulse was set to 1 sec by default, so I had to reduce it to 0.1 to make the cog viable.

Secondly, the Tint change never worked. I tried a bunch of different combinations to make sure (including 'extreme' values).

Third, the cog lacked the option to change the sectors +FLAGS (for such things as the "water" effect, etc.)

Other then that, the cog seems to recognize the "boundries" pretty well.

Thanks again for you help on this. This cog will make a great impact on the community once it's full potential is realized...

ZeqMacaw
11-29-2005, 02:12 AM
I considered making this cog, but I thought of at least two problems with the general idea.

Consider:

(1) The sector effects will be for the entire sector, not just inside the "zone". This means, for example, that when the zone is supposed to be water, the player will see not just the zone as water, but the entire sector, in which the zone is located, as water. Also, this doesn't just affect visuals; projectiles shot out of the zone would also have to run through other zone coding to handle the various physics effects properly in those other zones.

(2) The way the zone vertices are given and used in the current cog means having only box-shaped zones. This is very limiting, as normal sectors can be almost any shape. A more general way would be to give a set of vertices, and the code would determine if the player is inside those vertices. This, of course, is what the engine currently does with sectors, so it is unlikely coding it in cog would provide any benefit over engine code.

:)

CaptBevvil
11-29-2005, 08:39 AM
I considered making this cog, but I thought of at least two problems with the general idea.

Consider:

(1) The sector effects will be for the entire sector, not just inside the "zone". This means, for example, that when the zone is supposed to be water, the player will see not just the zone as water, but the entire sector, in which the zone is located, as water. Also, this doesn't just affect visuals; projectiles shot out of the zone would also have to run through other zone coding to handle the various physics effects properly in those other zones.

First, if you're in water, the whole sector is going to look like water to you anyhow. You can write another cog to handle the other issues. In general, the cog would supliment "trigger" messages associated with either crossing adjoins, touching surfaces, or even touching objects.


(2) The way the zone vertices are given and used in the current cog means having only box-shaped zones. This is very limiting, as normal sectors can be almost any shape. A more general way would be to give a set of vertices, and the code would determine if the player is inside those vertices. This, of course, is what the engine currently does with sectors, so it is unlikely coding it in cog would provide any benefit over engine code.

Yes, having a minimium of 8 verticies would be far more flexible. I'd like to see that for future versions of this cog. However, for right now, I wanted to keep it simple. As far as 'that's what sectors do anyway' the point of this cog is to not use multiple sectors. This cog should allow an editor to just have one sector and then build the level out of 3do's. This cog is suppose to alliviate the problem with "flickering" associated with 3do's used in conjunction with multiple sectors.

I hope now you are able to begin to see the benifits of such a cog...

ZeqMacaw
11-29-2005, 04:29 PM
Indeed, I was incorrect about the water visuals problem. :S (I just now retested by swimming around in Canyon Oasis.) :D

I understand what you are trying to do, and I still suspect it will be more problematic than dealing with the 3do "flickering" issues.

I will help with the cog when I can, even with my doubts. ;)

:)