Raised This Month: $ Target: $400
 0% 

register_event conditions


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Aydeev
Junior Member
Join Date: Oct 2014
Old 10-28-2014 , 19:47   register_event conditions
Reply With Quote #1

Hi,

I'm trying to fetch the weapons from kills using register_event on DeathMsg.

Since I'm not interested in all weapons I thought I'd exclude those in the event condition.

I tried this:
PHP Code:
register_event("DeathMsg""weaponcheck""a""4!usp""4!elite"
That doesn't work, it registers all DeathMsg events (including usp and elite)


If i try it the other way round:
PHP Code:
register_event("DeathMsg""weaponcheck""a""4=usp""4=elite"
That works: It only registers usp and elite frags

It seems with multiple conditions that ! is AND while = is OR. If I only use one condition ! works fine too (register_event("DeathMsg", "weaponcheck", "a", "4!usp")

I could use the = comparison and list all weapons I'm trying to fetch (which is a lot) or filter the weapons in the called function, but that seems like a waste of resources

Anyone know how to solve that?

Thanks!

Last edited by Aydeev; 10-28-2014 at 19:48.
Aydeev is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 10-28-2014 , 20:50   Re: register_event conditions
Reply With Quote #2

Combining multiple not statements for the same parameter like that does not work. How this functions internally is that all conditions for a specific parameter are connected with or and all conditions for distinct parameters are connected with and.

In plugin pseudo-code it roughly works like this:
Code:
// Walk through all parameters of the current register_event forward for (new param = 0; param < paramc; ++param) {    new execute = 0;    new condc = get_condc(param);    /* Check each condition for the current parameter. If any one of them    applies, set the execute flag - effectively making this an *or* connection */    for (new cond = 0; cond < condc; ++cond) {       if (match_cond(param, cond))          execute = 1;    }    /* If the current parameter has any conditions, but none of them match    we exit out - so while the conditions for the current parameter are connected    with or, conditions across different parameters are connected with *and* */    if (condc > 0 && !execute)       return; } fire_forward();

Going even simpler, your first register_event basically causes this to happen internally:

Code:
if (!equal(param4, "usp") || !equal(param4, "elites")) {    // do stuff }

This will always be true, since parameter 4 will either not equal "usp" or not equal "elites" - it can't be both. The function will be executed for all weapons. The second version will result in logic equivalent to this:

Code:
if (equal(param4, "usp") || equal(param4, "elites")) {    // do stuff }

This will obviously trigger only if parameter 4 either equals "usp" or "elites" - exactly what you expect and what your tests show.

To achieve what you want you need to use two separate register_event calls. You can have them both call the same function without issues.

Great question btw
__________________
In Flames we trust!

Last edited by Nextra; 10-29-2014 at 08:12.
Nextra is offline
Aydeev
Junior Member
Join Date: Oct 2014
Old 10-29-2014 , 07:54   Re: register_event conditions
Reply With Quote #3

Thank you for your explanations!

I'm not sure about using two register_event calls with the same function though.

Code:
register_event("DeathMsg", "weaponcheck", "a", "4!usp")  
register_event("DeathMsg", "weaponcheck", "a","4!elite")  
A usp frag won't trigger event 1 but then it will trigger event 2, calling the function after all.
Aydeev is offline
Nextra
Veteran Member
Join Date: Apr 2008
Location: Germany
Old 10-29-2014 , 08:15   Re: register_event conditions
Reply With Quote #4

Quote:
Originally Posted by Aydeev View Post
Thank you for your explanations!

I'm not sure about using two register_event calls with the same function though.

A usp frag won't trigger event 1 but then it will trigger event 2, calling the function after all.
You're right. It was a little late when I wrote the post afterall.

With some extra logic you could make it work, though. Not sure if you'd want that.
__________________
In Flames we trust!
Nextra is offline
Aydeev
Junior Member
Join Date: Oct 2014
Old 10-29-2014 , 10:39   Re: register_event conditions
Reply With Quote #5

I ended up doing it like this:
PHP Code:
register_event("DeathMsg""weaponcheck""a""4!usp")

public 
weaponcheck()
{
if (!
equal(weaponName,"elite") && if (!equal(weaponName... 
Used usp in the conditin since it's the most used gun of those I want to exclude and did the rest in the function. Not very pretty but it works

Thanks again for your help

Last edited by Aydeev; 10-29-2014 at 10:39.
Aydeev is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 17:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode