Raised This Month: $51 Target: $400
 12% 

I get warning that says a function should return a value. How do i fix this warning?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-23-2022 , 11:24   I get warning that says a function should return a value. How do i fix this warning?
Reply With Quote #1

Hello. There is a plugin that gives a bazooka automatically to all players. I want to make the plugin to not give bazooka to bots, bot only to real players.

At the top of the following code:

Code:
/*================================================================================
 [Zombie Plague Forwards]
=================================================================================*/

public zp_user_infected_post(id, infector)
{

	// User is Nemesis
	if(zp_get_user_nemesis(id))
	{
		// Plugin enabled
		if(g_bCvar_Enabled) 
		{
			// Check cvar
			if(g_bCvar_GiveFree) // Free
			{
				// Give gun
				set_user_nrlauncher(id, 1)
			}
			// User must buy
			else 
			{
				// Reset Vars
				set_user_nrlauncher(id, 0)
				
				// Messages
				set_task(1.5, "nrl_hudmessage", id)
				client_printcolor(id, "/g[Hell Hole]/y %L", id, "NRL_PRINT_BUY")
				client_printcolor(id, "/g[Hell Hole]/y %L", id, "NRL_PRINT_HELP")
			}
		}
	}
	// is Zombie
	else
	{
		// Reset Vars
		set_user_nrlauncher(id, 0)
	}
}

public zp_user_humanized_post(id)
{
	// Reset Vars
	set_user_nrlauncher(id, 0)
}

public zp_round_ended(team)
{
	// Remove all the rockets in the map
	// remove_rockets_in_map()
	set_task(0.1, "remove_rockets_in_map")
	
	// Update var
	g_bRoundEnding = true
}
I add the following code:

Code:
	// Preventing bot users from receiving the bazooka
	if(is_user_bot(id))
	return PLUGIN_HANDLED
So, the code can be like this:

Code:
/*================================================================================
 [Zombie Plague Forwards]
=================================================================================*/

public zp_user_infected_post(id, infector)
{

	// Preventing bot users from receiving the bazooka
	if(is_user_bot(id))
	return PLUGIN_HANDLED

	// User is Nemesis
	if(zp_get_user_nemesis(id))
	{
		// Plugin enabled
		if(g_bCvar_Enabled) 
		{
			// Check cvar
			if(g_bCvar_GiveFree) // Free
			{
				// Give gun
				set_user_nrlauncher(id, 1)
			}
			// User must buy
			else 
			{
				// Reset Vars
				set_user_nrlauncher(id, 0)
				
				// Messages
				set_task(1.5, "nrl_hudmessage", id)
				client_printcolor(id, "/g[Hell Hole]/y %L", id, "NRL_PRINT_BUY")
				client_printcolor(id, "/g[Hell Hole]/y %L", id, "NRL_PRINT_HELP")
			}
		}
	}
	// is Zombie
	else
	{
		// Reset Vars
		set_user_nrlauncher(id, 0)
	}
}

public zp_user_humanized_post(id)
{
	// Reset Vars
	set_user_nrlauncher(id, 0)
}

public zp_round_ended(team)
{
	// Remove all the rockets in the map
	// remove_rockets_in_map()
	set_task(0.1, "remove_rockets_in_map")
	
	// Update var
	g_bRoundEnding = true
}
When i try to compile the plugin, i get the following warning:

warning 209: function "zp_user_infected_post" should return a value

Can someone tell me how to fix this warning?

Last edited by GlobalPlague; 03-23-2022 at 11:26.
GlobalPlague is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-23-2022 , 11:31   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #2

Remove PLUGIN_HANDLED, keep the return only.

Code:
if(is_user_bot(id))
	return
__________________








CrazY. is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 03-23-2022 , 12:14   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #3

The warning literally tells you to return a value.
Either use "return" with no value, or return a value in the end of the function.
__________________

Last edited by OciXCrom; 03-23-2022 at 12:14.
OciXCrom is offline
Send a message via Skype™ to OciXCrom
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-23-2022 , 15:43   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #4

Quote:
Originally Posted by CrazY. View Post
Remove PLUGIN_HANDLED, keep the return only.

Code:
if(is_user_bot(id))
	return
Now, it works.

Thanks.
GlobalPlague is offline
GlobalPlague
Senior Member
Join Date: Feb 2016
Location: Pluto
Old 03-23-2022 , 15:47   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #5

Quote:
Originally Posted by OciXCrom View Post
The warning literally tells you to return a value.
Either use "return" with no value, or return a value in the end of the function.
The warning said i have to return a value, but now it works only with "return", without any value attached to "return".

The warning said there should be a value, and this value was "PLUGIN_HANDLED". However, the warning came exactly from the "PLUGIN_HANDLED" value, but the warning disappeared when i removed the "PLUGIN_HANDLED" value, meaning no value was actually needed.

See? It shows it needs a value, then shows a warning when a value is added, and then works fine when the value is removed...

Last edited by GlobalPlague; 03-23-2022 at 15:48.
GlobalPlague is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-23-2022 , 16:07   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #6

Your function has multiple execution paths but only one of them returns a value. You either return a value from all or none. See?
__________________

Last edited by HamletEagle; 03-23-2022 at 16:07.
HamletEagle is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-24-2022 , 12:17   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #7

You could also put "return PLUGIN_CONTINUE" at the end of your function if you wanted to use "return PLUGIN_HANDLED"
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951

Last edited by kww; 03-24-2022 at 12:20.
kww is offline
CrazY.
Veteran Member
Join Date: May 2015
Location: SP, Brazil
Old 03-24-2022 , 12:56   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #8

Return value is ignored on zp_user_infected_post.
__________________








CrazY. is offline
kww
Senior Member
Join Date: Feb 2021
Location: Russia
Old 03-25-2022 , 01:12   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #9

Quote:
Originally Posted by CrazY. View Post
Return value is ignored on zp_user_infected_post.
does it matter if he will use PLUGIN_CONTINUE or not?
__________________
Now working on: Side Weapons (Very lazy, tbh)
Avatar source: https://bit.ly/3BAk19g
Discord: kww#9951
kww is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 03-25-2022 , 04:12   Re: I get warning that says a function should return a value. How do i fix this warni
Reply With Quote #10

Quote:
Originally Posted by kww View Post
does it matter if he will use PLUGIN_CONTINUE or not?
It does not matter what you return, the value is ignored by the forward.
__________________
HamletEagle 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 04:58.


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