Forum

trigger_usekey center print blues

Discuss programming in the QuakeC language.

Moderator: InsideQC Admins

trigger_usekey center print blues

Postby dumptruck_ds » Mon Sep 10, 2018 5:48 am

Tearing my hair out! Most of what follows is ripped directly from hipnotic's hiptrigs.qc I have only made explicit spawnflags as part of my trial and error process as I am not a coder. Very simply, I am trying to get the "trigger_usekey" entity to work. Where I am at currently is that the functionality is there but the message always prints "You Need the Gold Key" whether I have spawnflags set to sivler or gold. Again IT WORKS but the centerprint is wrong no matter what I try.

I have seemingly tried everything but there has to be something small I am missing. Going nuts. Please help.

Code: Select all
float USE_SILV_KEY = 8;
float USE_GOLD_KEY = 16;

void() keytrigger_use =
{
   if (activator.classname != "player")
      return;
   if (self.attack_finished > time)
      return;

   self.attack_finished = time + 2;

// FIXME: blink key on player's status bar
   if ( (self.items & activator.items) != self.items )

   {
      if (self.message != "")
         centerprint (activator, self.message);
      else
      {
         if (self.owner.items == IT_KEY1)
         {
            if (world.worldtype == 2)
               centerprint (activator, "You need the silver keycard");
            else if (world.worldtype == 1)
               centerprint (activator, "You need the silver runekey");
            else if (world.worldtype == 0)
               centerprint (activator, "You need the silver key");
         }
         else
         {
            if (world.worldtype == 2)
               centerprint (activator, "You need the gold keycard");
            else if (world.worldtype == 1)
               centerprint (activator, "You need the gold runekey");
            else if (world.worldtype == 0)
               centerprint (activator, "You need the gold key");
         }
      }
      sound (self, CHAN_VOICE, self.noise3, 1, ATTN_NORM);
      return;
   }

   activator.items = activator.items - self.items;

   // we can't just remove (self) here, because this is a touch function
   // called while C code is looping through area links...
   self.touch = SUB_Null;
   self.use = SUB_Null;
   self.nextthink = time + 0.1;
   self.think = SUB_Remove;
   self.message = "";

   sound (self, CHAN_VOICE, self.noise4, 1, ATTN_NORM);

   SUB_UseTargets();
};

void() keytrigger_touch =
{
   activator = other;
   keytrigger_use();
};

/*QUAKED trigger_usekey (0 .5 0) ? USE_GOLD_KEY
Variable sized single use trigger that requires a key to trigger targets.  Must be targeted at one or more entities.

"message" is printed when the trigger is touched without having the right key.
*/

void() trigger_usekey =
{
   if (world.worldtype == 0)
   {
      precache_sound ("doors/medtry.wav");
      precache_sound ("doors/meduse.wav");
      self.noise3 = "doors/medtry.wav";
      self.noise4 = "doors/meduse.wav";
   }
   else if (world.worldtype == 1)
   {
      precache_sound ("doors/runetry.wav");
      precache_sound ("doors/runeuse.wav");
      self.noise3 = "doors/runetry.wav";
      self.noise4 = "doors/runeuse.wav";
   }
   else if (world.worldtype == 2)
   {
      precache_sound ("doors/basetry.wav");
      precache_sound ("doors/baseuse.wav");
      self.noise3 = "doors/basetry.wav";
      self.noise4 = "doors/baseuse.wav";
   }
   else
      dprint ("no worldtype set!\n");

   if (self.spawnflags & USE_SILV_KEY) //dumptruck_ds
      self.items = IT_KEY1;
      if (self.spawnflags & USE_GOLD_KEY) //dumptruck_ds
      self.items = IT_KEY2;

   self.use = keytrigger_use;
   self.touch = keytrigger_touch;

   InitTrigger ();
};
dumptruck_ds
 
Posts: 2
Joined: Thu Jan 04, 2018 7:19 pm

Re: trigger_usekey center print blues

Postby dumptruck_ds » Mon Sep 10, 2018 6:42 am

Spike and Khreathor helped me solve this.

Code: Select all
if (self.owner.items == IT_KEY1)


should instead be

Code: Select all
if (self.items == IT_KEY1)


hurray!
dumptruck_ds
 
Posts: 2
Joined: Thu Jan 04, 2018 7:19 pm


Return to QuakeC Programming

Who is online

Users browsing this forum: No registered users and 1 guest