Raised This Month: $32 Target: $400
 8% 

A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Jess98
Junior Member
Join Date: Apr 2018
Old 11-26-2018 , 08:58   A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
Reply With Quote #1

I'm in a logic error with those two ones..

I'll try to explain on my plugin..

This is my plugin, it spawns players when they write "/spawn" in say or say_team and if player has enough money for it.

Code:
#include <amxmodx>
#include <cstrike>

new gMoney

#define PLUGIN "Spawn Players With a Command"
#define VERSION "1.0"
#define AUTHOR "Jess"

#define SERVER_INFORMATION "Vengeance"

public plugin_init() {

       register_plugin(PLUGIN, VERSION, AUTHOR)

       register_clcmd("say /spawn", "Event_Spawn")
       register_clcmd("say_team /spawn", "Event_Spawn")

       gMoney = register_cvar("necessary_money", "10000")
}

public Event_Spawn(id) {

       if(is_user_alive(id))
       {
             client_print_color(id, id, "^04[%s]: ^3You Already Alive, You Can't Spawn Yourself", SERVER_INFORMATION)
             return PLUGIN_HANDLED
       }

       if(!is_user_alive(id))
       {
             if(cs_get_user_money(id) < get_pcvar_num(gMoney))
             { 
                   client_print_color(id, id, "^4[%s]: ^3You Don't Have Enough Money to Spawn Yourself", SERVER_INFORMATION)
                   return PLUGIN_HANDLED
             }
             else if(cs_get_user_money(id) >= get_pcvar_num(gMoney))
             {
                   cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(gMoney))
                   cs_user_spawn(id)
                   client_print_color(id, id, "^4[%s]: ^3You Have Spawned Yourself!", SERVER_INFORMATION)
             }
       }
       return PLUGIN_HANDLED
}
---

I put the code "return PLUGIN_HANDLED" under this line as you see:

Code:
 
if(is_user_alive(id))
{
      client_print_color(id, id, "^04[%s]: ^3You Already Alive, You Can't Spawn Yourself", SERVER_INFORMATION)
      return PLUGIN_HANDLED
}
What does it do in there? Does it stop the task of this line, just that? What there happens if I write "return PLUGIN_CONTINUE" instead of it?

Or.. I put the same return code at the end of "Event_Spawn" Public. What also does it do in there, it stops the plugin when all tasks done, is it right? Can't be sure.
Jess98 is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 11-26-2018 , 09:41   Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
Reply With Quote #2

Instead of using cs_user_spawn (id), I would use hamsandwich ExecuteHamB (Ham_CS_RoundRespawn, id), otherwise there are several and various topics related to "returns", use the search.
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
Jess98
Junior Member
Join Date: Apr 2018
Old 11-26-2018 , 10:12   Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
Reply With Quote #3

Quote:
Originally Posted by iceeedr View Post
Instead of using cs_user_spawn (id), I would use hamsandwich ExecuteHamB (Ham_CS_RoundRespawn, id), otherwise there are several and various topics related to "returns", use the search.
Sorry but what a classic answer is that, I already did it but didn't get as well 'cuz I'm not okay with Amx Mod X or software phrases.

It would be better if you ask me any question like "Do you know how to use hamsandwich?" before suggested the ExecuteHamB native. And yes, Hamsandwich seems more appropriate module as I heard but first I should finish the easier ones. Hope there'll be some real helpers.
Jess98 is offline
iceeedr
Veteran Member
Join Date: Apr 2017
Location: Brazil
Old 11-26-2018 , 10:23   Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
Reply With Quote #4

I did not understand the problem, "learn how to use ham sandwich" ??

I've given you the full function, you just have to add it to the top of the #include <hamsandwich> plugin, but do as you wish!
__________________


Quote:
Originally Posted by fysiks View Post
Please stop trying to help. You appear to just be posting random stuff. Wait until you actually understand more about AMX Mod X and how the game works.
https://iceeedr.com.br/
iceeedr is offline
Send a message via Skype™ to iceeedr
Jess98
Junior Member
Join Date: Apr 2018
Old 11-26-2018 , 10:36   Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
Reply With Quote #5

Quote:
Originally Posted by iceeedr View Post
I did not understand the problem, "learn how to use ham sandwich" ??

I've given you the full function, you just have to add it to the top of the #include <hamsandwich> plugin, but do as you wish!
It's too much easy, wouldn't it be good to do it after understand something about Hamsandwich and the ExecuteHamB native? I want to learn the logics of everything that I use in my plugins, there are a lot of details background of codes.

The only one problem that I have, I can't get all the Amx Mod X or software phrases. And, I have explained what I want to learn as full in this subject. I'm just in a logic error.
Jess98 is offline
Old 11-26-2018, 13:29
OciXCrom
This message has been deleted by OciXCrom.
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 11-26-2018 , 13:30   Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
Reply With Quote #6

PLUGIN_HANDLED in this case will block the /spawn command from showing in chat and will stop any other plugin from hooking it.
If it was PLUGIN_CONTINUE, the command would show in chat.
PLUGIN_HANDLED_MAIN will hide the command in chat, but won't stop any other plugins from hooking it.
It doesn't affect anything else in this case.
__________________

Last edited by OciXCrom; 11-26-2018 at 13:31.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
Jess98
Junior Member
Join Date: Apr 2018
Old 11-26-2018 , 17:25   Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
Reply With Quote #7

Quote:
Originally Posted by OciXCrom View Post
PLUGIN_HANDLED in this case will block the /spawn command from showing in chat and will stop any other plugin from hooking it.
If it was PLUGIN_CONTINUE, the command would show in chat.
PLUGIN_HANDLED_MAIN will hide the command in chat, but won't stop any other plugins from hooking it.
It doesn't affect anything else in this case.
The answer that I was waiting for, thank you. But what also there happens if I don't use PLUGIN_HANDLED and it hooks with other plugins?

And, does it block the other lines / cases in the plugin?

For an example, I'm meaning:

Code:
if(cs_get_user_money(id) < get_pcvar_num(gMoney))
{ 
       client_print_color(id, id, "^4[%s]: ^3You Don't Have Enough Money to Spawn Yourself", SERVER_INFORMATION)
       return PLUGIN_HANDLED
}
I finished the task on the top line / case and wrote PLUGIN_HANDLED ( ↑ ). Will it hooking with the second line / case in the bottom ( ↓ )?

Code:
else if(cs_get_user_money(id) >= get_pcvar_num(gMoney))
{
         cs_set_user_money(id, cs_get_user_money(id) - get_pcvar_num(gMoney))
         cs_user_spawn(id)
         client_print_color(id, id, "^4[%s]: ^3You Have Spawned Yourself!", SERVER_INFORMATION)
}

Last edited by Jess98; 11-26-2018 at 17:30. Reason: A little change for making question easy
Jess98 is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 11-26-2018 , 17:52   Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
Reply With Quote #8

1. The compiler will say you that a function must return a value (use return).
2. 'return' means 'immediate exit from function'.
__________________
My English is A0
E1_531G is offline
Reply


Thread Tools
Display Modes

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 20:49.


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