-
-
Notifications
You must be signed in to change notification settings - Fork 206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a flags update forward and a override param in set_user_flags #475
base: master
Are you sure you want to change the base?
Conversation
amxmodx/amxmodx.cpp
Outdated
|
||
pPlayer->flags[id] |= flag; | ||
|
||
if(params[4]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to check for parameter availability here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I'm fairly new to this. How do I exactly add that check?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here's an example
Line 1443 in 7b3646a
if (params[0] / sizeof(cell) >= 12) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it actually necessary? The 4th parameter has a default value of "false" if it's not used. Just curious why it's needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OciXCrom you will need to recompile all plugins that using get_players
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OciXCrom Plugins that don't get compiled against the new *.inc will pass you 3 parameters, and core needs to handle that situation gracefully.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Nextra @Amaroq7 @WPMGPRoSToTeMa - Thanks, I added the necessary check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added some notes of mine and also as it has been said by @Nextra there's missing check.
plugins/include/amxmodx.inc
Outdated
@@ -1826,6 +1836,7 @@ native set_user_flags(index, flags = -1, id = 0); | |||
* | |||
* @param index Client index, 0 to set flags of server | |||
* @param id Flag set id, ranging from 0 to 31 | |||
* @param override If set to true, all other flags will be removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Misplaced param's description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops, I always get confused when viewing .inc files because of the way the description is placed above the native. Fixed.
plugins/include/amxmodx.inc
Outdated
* | ||
* @noreturn | ||
*/ | ||
forward client_flags_updated(id, flags); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd also pass id of set here, so we'll know which set of flags has been updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never knew different sets of flag existed until I saw the actual .cpp file. Are different sets ever used? Because if not, it would be rather unnecessary to have to write the set argument every time we use the forward if we'll never have to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't have to write all params in forward, they can be skipped, so if someone doesn't depend on sets, they can safely omit last param.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I knew they existed but I never knew their purpose. The doc says:
AMXX stores multiple sets of flags internally, but only flag set
0 is actively used. You should not change the value of the third
parameter from the default.
I almost feel that we should just ignore flag sets and use a single one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if AMXX doesn't use other values than 0, it still may be used by 3rd plugins for their some specific permission system, so they don't mess up with the AMXX's one. I think including that param wouldn't do much harm, but it's just my opinion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Amaroq7 we can add it later if someone really uses sets.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually if they can really be skipped when using the forwards (haven't actually checked this), then there's really no problem if that param can be passed too. I'll check this tomorrow and add it if that's the case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Amaroq7 @rsKliPPy @WPMGPRoSToTeMa - I added the flag set as the last parameter in the forward, so people can skip it if not needed. I also passed the old flags so people can see which flags were changed.
I added a check whether the new flags are different from the old ones, since there's not really a point in executing the forward if they are the same. |
I think something like In the first place why does not |
It should have added them in the first place, but it's too late now. I don't think there's really a point in deprecating it just because of the name. |
Or |
Hmm, I'm starting to like that idea. Maybe we can deprecate both |
This PR makes two independent changes, and you're talking about adding even more - each change should be a separate PR. I suggest retargeting this to be only the forward, and make a separate PR if you want to change how |
Well, the PR is mainly about the forward, and the other change is just a small improvement to a function that's calling it. If I made them separate, one would become incompatible if the other one got merged, so I found it to be better this way. I won't be adding any more stuff until this gets approved (if it does). If it's really a problem I'll remove the |
@Arkshine will it be merged? |
* | ||
* @noreturn | ||
*/ | ||
forward client_flags_updated(id, oldflags, newflags, set); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe use same terminology that is used in set_user_flags
?
Client ID is index
Set ID is just id
@Arkshine bump. Should it be splitted into 2 PRs? |
@Arkshine if you wouldn't mind. |
Added a forward called "client_flags_updated" which will be called when the client's flags are modified using "set_user_flags" or "remove_user_flags". I also added another param in the "set_user_flags" function called "override", which if set to true will remove any other flags from the user - I found this necessary because the name of the function is "SET_user_flags", but it actually adds them to the current ones. This way coders can actually SET the flags instead of add them to the current ones.