AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Hook for task ID (https://forums.alliedmods.net/showthread.php?t=313169)

Youcallmedaddy 12-30-2018 08:29

Hook for task ID
 
Hello everyone.

I would like to make this task for ID (just remove this hook task) because there is remove_task(id) which removes all the id tasks I have.

Code:

code censored
Thanks a lot, guys.

Bugsy 12-30-2018 11:28

Re: Hook for task ID
 
Please indent your code, and use php tags.

Youcallmedaddy 12-30-2018 11:51

Re: Hook for task ID
 
PHP Code:

code censored 

That is a hook plugin inserted to a mod plugin where I have another tasks, but remove_task(id) removes all of them. I was searching and I found something about adding ID to specific task.
(https://forums.alliedmods.net/showthread.php?t=125638)
I hope it's more clear now.

Bugsy 12-30-2018 15:07

Re: Hook for task ID
 
Quote:

Originally Posted by Bugsy (Post 2631829)
Please indent your code, and use php tags.


Youcallmedaddy 12-30-2018 15:30

Re: Hook for task ID
 
PHP Code:

code censored 


fysiks 12-30-2018 17:46

Re: Hook for task ID
 
You can make unique tasks by doing what is in the thread to which you linked (see post #8).

eat1k 12-31-2018 12:31

Re: Hook for task ID
 
Here you are an example of how your code should look like:

Code:
public hook_on(id) {     if(!(get_user_flags(id) & ADMIN_BAN) && !g_CanBuild)         return PLUGIN_HANDLED;     if(get_user_team(id) != 2)         return PLUGIN_HANDLED;     if(g_CanBuild || get_user_flags(id) & ADMIN_BAN && !g_CanBuild)     {         get_user_origin(id, gHookOrigins[ id ], 3);         g_bHook[ id ] = true;         set_task(0.1, "hook_task", id, "", 0, "ab");         hook_task(id);     }     return PLUGIN_HANDLED; }

You need to do this to make all your code more readable.

eat1k 01-01-2019 10:34

Re: Hook for task ID
 
1. Don't use stocks as ColorChat, etc... we have client_print_color().
2. Use constants:
Code:
new bool:g_bHook[ 33 ]; new gHookOrigins[ 33 ][ 3 ];
->
Code:
new bool:g_bHook[MAX_PLAYERS+1]; new g_iHookOrigins[MAX_PLAYERS+1][3];
3.
Code:
set_task( 0.1, "hook_task", id, "", 0, "ab" );
Why do you put "a" flag if you don't specify how many times it'll be repeated? Also, consider to use set_task_ex()
So:
Code:
set_task_ex(0.1, "hook_task", id, .flags = SetTask_Repeat);
4.
Code:
if( task_exists(id) )
You don't need to check if the task exists, just remove it.
5. Consider to use get_players_ex() instead of get_players().
6. If you're using that code in other plugin (jb mod for example) so you can remove it just like that:
Code:
remove_task(id+TASK_ID_HOOK);
Otherwise, just: remove_task(id);
Moreover, you need to add:
Code:
enum (+= 100) {     TASK_ID_HOOK };
So when you create task:
Code:
set_task_ex(0.1, "hook_task", id+TASK_ID_HOOK, .flags = SetTask_Repeat);
7. Btw finally, I recommend you to use ReAPI, for what using old modules?

HamletEagle 01-01-2019 10:48

Re: Hook for task ID
 
Quote:

7. Btw finally, I recommend you to use ReAPI, for what using old modules?
1.Not everyone is using regamedll/rehlds and not everyone wants to switch therefore not everyone can use reapi.
2.The "old" modules are perfectly fine. You don't gain anything by replacing them with reapi. It's fakemeta syndrome all over again. Try to understand how things actually work and then you will see that your claim is silly.
3.You don't gain anything, but you actually lose generality by creating unneeded dependencies. If you code only for yourself, yeah, do whatever you want.
If you plan to release plugins here, then you should use default amxx modules where it's possible, so the code works in both default hlds and RE* stuff.
I can understand using reapi and releasing here if you need to hook non virtual functions for example. But if you are replacing set_pev with whatever reapi's equivalent is or ham hooks with reapi hooks, then that's just dumb beyond belief.

eat1k 01-01-2019 10:53

Re: Hook for task ID
 
Quote:

Originally Posted by HamletEagle (Post 2632195)
1.Not everyone is using regamedll/rehlds and not everyone wants to switch therefore not everyone can use reapi.
2.The "old" modules are perfectly fine. You don't gain anything by replacing them with reapi. It's fakemeta syndrome all over again. Try to understand how things actually work and then you will see that your claim is silly.
3.You don't gain anything, but you actually loose generality by creating unneeded dependencies. If you code only for yourself, yeah, do whatever you want.
If you plan to release plugins here, then you should use default amxx modules where it's possible, so the code works in both default hlds and RE* stuff.
I can understand using reapi and releasing here if you need to hook non virtual functions for example. But if you are replacing set_pev with whatever reapi's equivalent is or ham hooks with reapi hooks, then that's just dumb beyond belief.

They're old. ReAPI is newer and better for using. I don't understand people who still use HLDS, it's already 2019, lol. But yes, there are people who still use old and official not supported AMXX 1.8.2, so, in my opinion, it's better to write plugins using ReAPI if it's possible. So, if someone wants to use that plugin, he/she will must switch to ReHLDS/ReGameDLL. It's like here you want to use only old things. We don't have to use fakemeta, ham or engine if it can be easily be done with ReAPI.
However, there are few things that cannot be done with ReAPI so in some cases that modules are useful, but in other cases, you can do almost everything with ReAPI. IMHO. That's only my recommendation.


All times are GMT -4. The time now is 07:38.

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