Announcement
Collapse
No announcement yet.
Accessing items
Collapse
X
-
You can't check bits with logical operators (&&, ||, etc). You need to use bitwise operators (&, etc)
-
Just like you suggested, works like a charm (just realized it's pretty much the same structure as in that weapons.qc function).if (person.items & IT_ROCKET_LAUNCHER)
Thanks again for your input.
Best,
wizardmachine
Leave a comment:
-
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:
I want to check, for example, whether player owns the shotgun or not:if (player.items) {}
Would the above be correct?if (player.items && IT_SHOTGUN) {}
Also, I found in weapons.qc the following piece of code inside function W_ChangeWeapon:
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.if (!(self.items & fl))
{// don't have the weapon or the ammosprint (self, "no weapon.\n");
return;}
Thanks!
Leave a comment:
-
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 thingLast edited by nahuel; 05-13-2017, 06:32 PM.
Leave a comment:
-
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:
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.if (items.Contains(itemIndex))
{// do something!}
Best,
wizardmachine
Leave a comment: