Announcement

Collapse
No announcement yet.

Accessing items

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Accessing items

    Hi again!

    I'm trying to do a boolean function to return true/false depending on self's owning an item or not:

    if (items.Contains(itemIndex))
    {
    // do something!
    }
    However, I'm failing to see how 'items' actually work. What would be the usual way to check if a weapon is already in the items list? It does kind of look like a list or an array but not really so I'm slightly confused (I'm looping through all .qc files trying to see if I can find some line that performs a similar check but no luck so far). Also my background is C#, JS and Python, so no C or C++ xpPoints at all.


    Best,
    wizardmachine

  • #2
    why do you weant to return a boolean??

    Code:
    float() = ... etc...
    ....

    quake uses touch. function to check
    Code:
    void () somecrazytouch  =
    {
    if (other.classname != "player") //
    return;
    if (other.items & self.items) // self.items or "items" that item is , sorry for my english
    return;
    
    etc...

    so the correct way to check is very simple

    if (player.items & somentity.items) // or (player.items & IT_SOMEITEM...
    //do something
    else
    //do another thing
    Last edited by nahuel; 05-13-2017, 06:32 PM.
    the invasion has begun! hide your children, grab the guns, and pack sandwiches.

    syluxman2803

    Comment


    • #3
      I simply wanted to create some custom function to help keep my coding clean, that's why I wanted to write some boolean returning function. Just a thought, could be an int returning function or whatever.

      I'm not really sure I get what you mean. What kind of check does the below do:

      if (player.items) {}
      I want to check, for example, whether player owns the shotgun or not:

      if (player.items && IT_SHOTGUN) {}
      Would the above be correct?

      Also, I found in weapons.qc the following piece of code inside function W_ChangeWeapon:

      if (!(self.items & fl))
      {
      // don't have the weapon or the ammo
      sprint (self, "no weapon.\n");
      return;
      }
      but I'm not sure I fully understand it. Variable 'fl' is assigned to one of the weapons, and then it checks !self.items & fl which looks quite similar to the check you suggested. I'll go for it and report back.

      Thanks!

      Comment


      • #4
        if (person.items & IT_ROCKET_LAUNCHER)
        Just like you suggested, works like a charm (just realized it's pretty much the same structure as in that weapons.qc function).

        Thanks again for your input.

        Best,
        wizardmachine

        Comment


        • #5
          You can't check bits with logical operators (&&, ||, etc). You need to use bitwise operators (&, etc)
          http://www.nextgenquake.com

          Comment

          Working...
          X