Forum

a small question

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

a small question

Postby ajay » Tue Aug 23, 2005 2:06 pm

A trigger's self.touch calls this:

void() wsy_counter_on =
{
wsy_check = 1;
other.nextthink = time + 10;
other.think = tellme;
};


tellme being:

void() tellme =
{
sound (other, CHAN_VOICE, "boss1/pain.wav", 1, ATTN_NONE);
};


Which does what I want it to; plays that sound 10 seconds after the player passes through the trigger. However, the weapon animation is all messed up, worse still if I set it to self.nextthink, self.think etc., rather than other...

Why does this happen, is it because the next.think is affecting the player, whether I set it to self, or other?
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby RenegadeC » Tue Aug 23, 2005 5:23 pm

because you're messing with the players self.think by using "other".

You could simply spawn another entity once those 10 seconds are up to play the sound OR spawn the entity immediately, have it count to 10, then have it play the sound, then remove itself once the sound is finished playing.

Pros:
Simple, gets the job done
Cons:
Extra temporary entity in the game world, can be deadly for older quake engines if you're near the MAX entity limit.

Or,

define 2 variables.. "sound_on", and "sound_count".
If the player touches the trigger, sound_on becomes TRUE on the player, which then activates self.sound_count, which will count upwards. If sound_count > #, then play the sound, reset sound_count to 0, and self.sound_on to 0 also as to stop it from repeating.

Pros:
No messing with think times, no spawning additional entities (if you're really worried about that).
Cons:
You're increasing the # of variables on every entity.
User avatar
RenegadeC
 
Posts: 391
Joined: Fri Oct 15, 2004 10:19 pm
Location: The freezing hell; Canada

Postby ajay » Tue Aug 23, 2005 7:09 pm

// ===================================================
// WSY . QC
// ===================================================


// =====================================
// wsy define stuff
// =====================================

float wsy_check = 0; //checks whether or not the counter is on or off
entity wsy_ent; //for timer


// =====================================
// temp stuff; for testing and the like
// =====================================

void() tellme =
{
sound (other, CHAN_VOICE, "boss1/pain.wav", 1, ATTN_NONE);
};


// ======================================================================
// wsy_counter_on and _off
// these turn the wsy counter on and off sent by trigger_wsy
// ======================================================================
void(vector org) wsy_counter_on =
{
wsy_check = 1;
wsy_ent = spawn ();
wsy_ent.origin = org;
wsy_ent.nextthink = time + 10;
wsy_ent.think = tellme;
};

void() wsy_counter_off =
{
wsy_check = 0;
};


// ======================================================================
// trigger_wsy
// ======================================================================

void() touch_wsy =
{
if (other.classname != "player")
return;
if (wsy_check == 0)
wsy_counter_on();
else if (wsy_check == 1)
wsy_counter_off();
};

void() trigger_wsy =
{
InitTrigger();
self.movetype = MOVETYPE_NONE;
self.solid = SOLID_TRIGGER;
self.touch = touch_wsy;
};


Thanks Ren, I tried the above, but still the same. I'm missing something obvious aren't I? ;)
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby FrikaC » Tue Aug 23, 2005 7:12 pm

Or you could simply use the trigger's own think (make sure it's self.think and self.nextthink, If either of those are other, it will affect the entity touching the trigger).

There's also something Renegade forgot to mention, you're using "other" as the entity emitting the sound in the tellme function. In a think function, other is undefined (it could be anything, most probably world). That should probably be self.
FrikaC
Site Admin
 
Posts: 1026
Joined: Fri Oct 08, 2004 11:19 pm

Postby Sajt » Tue Aug 23, 2005 7:47 pm

In wsy_counter_on, add 'wsy_ent.enemy = other;'

Then in tellme, change other to self.enemy

I'm not really sure why you want the sound the play from the player, but oh well :)
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby RenegadeC » Wed Aug 24, 2005 6:17 pm

FrikaC wrote:Or you could simply use the trigger's own think (make sure it's self.think and self.nextthink, If either of those are other, it will affect the entity touching the trigger).

There's also something Renegade forgot to mention, you're using "other" as the entity emitting the sound in the tellme function. In a think function, other is undefined (it could be anything, most probably world). That should probably be self.


D'oh, I so should of thought of that. *slaps forehead*

Also ajay, always define entity = spawn(); FIRST before changing any variables on it. You cannot change floats/strings on an entity before it exists.
User avatar
RenegadeC
 
Posts: 391
Joined: Fri Oct 15, 2004 10:19 pm
Location: The freezing hell; Canada

Postby ajay » Wed Aug 24, 2005 9:12 pm

Thanks for the tips, but I'm struggling, so I'm dragging myself back to the beginning.

So I want to have this trigger:
void() trigger_wsy =
{
InitTrigger();
self.movetype = MOVETYPE_NONE;
self.solid = SOLID_TRIGGER;
self.touch = touch_wsy;
};

Which when triggered, does this:
void() touch_wsy =
{
if (other.classname != "player")
return;
if (wsy_check == 0)
wsy_counter_on();
else if (wsy_check == 1)
wsy_counter_off();
};

Checks that it's the player doing the triggering, then checks if it's been triggered already, the wsy_check variable. If it == 0, it goes to the turning it on function:
void(vector org) wsy_counter_on =
{
wsy_check = 1;
wsy_ent = spawn ();
wsy_ent.origin = org;
wsy_ent.nextthink = time + 10;
wsy_ent.think = tellme;
};

void() wsy_counter_off =
{
wsy_check = 0;
};

This sets the variable to 1, so that next time the player goes throught the trigger, it's set to "on", and will therefore go to the "off" function
void() wsy_counter_off =
{
wsy_check = 0;
};

It (the wsy_counter_on function) then does the waiting for 10 seconds, before setting off the sound bit. Now when I finally get all this business working, it will play a sound, but it'll also do some other stuff, at the moment the sound is just a test for me that it's working. But I'm ahed of myself, the problem that I mentioned is that the weapon animation gets all screwy, either as soon as the trigger is activated (my first attempt at the top of the thread), or when the timer bit reaches 10 seconds (the last example).

I've since tried setting the self.nextthink etc in the trigger's touch function:
void() touch_wsy =
{
if (other.classname != "player")
return;
self.nextthink = time + wsy_wait; // defined as 10 btw
self.think = wsy_counter;
};


wsy_counter being the function thats does an on/off check:
void() wsy_counter =
{
if (wsy_check == 0)
{
wsy_counter_on();//play the sound
}
else if (wsy_check == 1)
{
wsy_counter_off();//turn it off type stuff
}
};


But, although after 10 seconds the sound is triggered, and will be prevented if the player goes back through the trigger, the same animation problem exists.

Now the reason I write all this out again, is to just get myself organised and clear in what I'm trying to do, 'cos I'm confused, and realise I'm not getting exactly what I'm meant to be doing. I also think the solution is, like what I'm actually trying to acheive, pretty simple. I have hoped I'd just luck out getting it working, but I guess doing it because I understand it properly is probably better in the long run ;)
Sorry for all this, but it's kinda fundemental to my whole mod type thing, and I do appreciate all the help.

ajay
User avatar
ajay
 
Posts: 559
Joined: Fri Oct 29, 2004 6:44 am
Location: Swindon, UK

Postby Sajt » Fri Aug 26, 2005 7:06 am

Well, first of all. If the player were to simply stand inside the trigger, would it alternate wsy_check between 0 and 1 rapidly? It doesn't look like there's anything stopping it from waiting a little while between triggers.

It would help greatly if you told us what this entity was doing, because I see things that may be wrong, or may be completely right, depending on what you are actually trying to do.
F. A. Špork, an enlightened nobleman and a great patron of art, had a stately Baroque spa complex built on the banks of the River Labe.
Sajt
 
Posts: 1215
Joined: Sat Oct 16, 2004 3:39 am

Postby RenegadeC » Fri Aug 26, 2005 11:06 pm

What Sajt said is correct, best way to correct that error is to either do one of the following:

A) Remove the trigger entity, remove(self);, SUB_Remove();

B) Set a boolean to 1 if it's touched then can no longer be touched if the boolean is 1

C) use a "time", like if (self.attack_finished > time) return;

good luck.
User avatar
RenegadeC
 
Posts: 391
Joined: Fri Oct 15, 2004 10:19 pm
Location: The freezing hell; Canada


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest