AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE" (https://forums.alliedmods.net/showthread.php?t=312315)

Jess98 11-26-2018 08:58

A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
 
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.

iceeedr 11-26-2018 09:41

Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
 
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.

Jess98 11-26-2018 10:12

Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
 
Quote:

Originally Posted by iceeedr (Post 2625756)
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.

iceeedr 11-26-2018 10:23

Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
 
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!

Jess98 11-26-2018 10:36

Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
 
Quote:

Originally Posted by iceeedr (Post 2625764)
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.

OciXCrom 11-26-2018 13:30

Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
 
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.

Jess98 11-26-2018 17:25

Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
 
Quote:

Originally Posted by OciXCrom (Post 2625781)
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)
}


E1_531G 11-26-2018 17:52

Re: A Question About "return PLUGIN_HANDLED" & "return PLUGIN_CONTINUE"
 
1. The compiler will say you that a function must return a value (use return).
2. 'return' means 'immediate exit from function'.


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

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