Solved (ReAPI) AntiFlashLightSpam + ResetScore

Coding Help/Re-API Supported
User avatar
Night Fury
Mod Developer
Mod Developer
Posts: 677
Joined: 7 years ago
Contact:

#11

Post by Night Fury » 6 years ago

Here you go.
Sound has been added: client_cmd(id, "spk \"cleanup(t20) progress(t20)\"")
Dictionary file has been removed.
You can add more commands like in: new const resetScoreCommands[][]
Replace yoursound with Your own sound.

Code: Select all

#include <amxmodx>
#include <reapi>

#define MIN_FRAGS 5 // Player who has more than minimum frags will be able to reset his score but not lower
#define MIN_DEATHS 5 // Player who has more than minimum deaths will be able to reset his score but not lower

new const resetScoreCommands[][] =
{
	"/rs", "/resetscore", "/rscore", "/resets"
}

new sayCmd[64], sayTeamCmd[64], x

public plugin_init()
{
	register_plugin("Reset Score", "1.1", "Raheem")
	
	// Commands
	for (x = 0; x <= charsmax(resetScoreCommands); x++)
	{
		formatex(sayCmd, charsmax(sayCmd), "say %s", resetScoreCommands[x])
		formatex(sayTeamCmd, charsmax(sayTeamCmd), "say_team %s", resetScoreCommands[x])
		register_clcmd(sayCmd, "CmdSay")
		register_clcmd(sayTeamCmd, "CmdSay")
	}
}

public CmdSay(id)
{
	if (get_entvar(id, var_frags) > MIN_FRAGS || get_member(id, m_iDeaths) > MIN_DEATHS)
	{
		set_entvar(id, var_frags, 0.0)
		set_member(id, m_iDeaths, 0)
		
		message_begin(MSG_BROADCAST, get_user_msgid("ScoreInfo"))
		write_byte(id) // id
		write_short(0) // Frags
		write_short(0) // Deaths
		write_short(0) // Class
		write_short(get_member(id, m_iTeam)) // Team
		message_end()
		
		client_print_color(id, print_team_default, "^3Your score has been reset successfully^1.")
		client_cmd(id, "spk yoursound")
		return PLUGIN_HANDLED
	}
	
	return PLUGIN_CONTINUE
}
Want your own mod edition? PM me.
Accepting private projects.
Discord: Fury#7469
Image

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#12

Post by ArminC » 6 years ago

Thank you, the "spk" isn't affected by the sheild/filterstuff.. right?

But it don't have the tag (like tag have color x and the chat have color y) -- client_print_color(id, print_team_default, "^4[RS]^3Your score has been reset successfully^1.")

Right?

(edit) can you set an else chat print if no required connditon achived = a message if deaths/frags lower than #definde

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#13

Post by Raheem » 6 years ago

ArminC wrote: 6 years ago Thank you, the "spk" isn't affected by the sheild/filterstuff.. right?
Yes not filtered by CS. Not blocked by VALVE so it still working.
ArminC wrote: 6 years ago But it don't have the tag (like tag have color x and the chat have color y) -- client_print_color(id, print_team_default, "^4[RS]^3Your score has been reset successfully^1.")

Right?
Right like: client_print_color(id, print_team_default, "^4[RS] ^3Your score has been reset successfully^1.")
ArminC wrote: 6 years ago (edit) can you set an else chat print if no required connditon achived = a message if deaths/frags lower than #definde
Simply add it:
  • Code: Select all

    	if (get_entvar(id, var_frags) > MIN_FRAGS || get_member(id, m_iDeaths) > MIN_DEATHS)
    	{
    		set_entvar(id, var_frags, 0.0)
    		set_member(id, m_iDeaths, 0)
    		
    		message_begin(MSG_BROADCAST, get_user_msgid("ScoreInfo"))
    		write_byte(id) // id
    		write_short(0) // Frags
    		write_short(0) // Deaths
    		write_short(0) // Class
    		write_short(get_member(id, m_iTeam)) // Team
    		message_end()
    		
    		client_print_color(id, print_team_default, "^3Your score has been reset successfully^1.")
    		client_cmd(id, "spk yoursound")
    		return PLUGIN_HANDLED
    	}
    	else
    	{
    		client_print_color(id, print_team_default, "ANY THING")
    	}
He who fails to plan is planning to fail

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#14

Post by ArminC » 6 years ago

Oh I found another one.. (why I can't think at all in first reply.. ideeas appear on the run :))

Code: Select all

client_print_color(id, print_team_default, "1[^4RS^1] ^3You don't have %s frags and %s to ^4reset ^3the score^1.")
If you didn't get it already.. how I can connect the already checked/known (from this)

Code: Select all

if (get_entvar(id, var_frags) > MIN_FRAGS || get_member(id, m_iDeaths) > MIN_DEATHS)
deaths/frags to my message (replace the %s with #define value) ?
Oh and here I can include some acces declined sounds.. (I like verrry much Half-life lol)

(edit) Can you fix this for me, just an ideea :) + add the above features? Thanks for nr.100 request :lol: (I tried more ideeas from more pawn/amxx wiki but nothing..)

Code: Select all

#include <amxmodx>
#include <reapi>

#define MIN_FRAGS 2 // Player who has more than minimum frags will be able to reset his score but not lower.
#define MIN_DEATHS 2 // Player who has more than minimum deaths will be able to reset his score but not lower.

new const resetScoreCommands[][] =
{
	"/rs", "/resetscore", "/reset", "/rscore", "/resets"
}

new sayCmd[64], sayTeamCmd[64], x

public plugin_init()
{
	register_plugin("Reset Score", "1.1", "Raheem")
	
	// Commands
	for (x = 0; x <= charsmax(resetScoreCommands); x++)
	{
		formatex(sayCmd, charsmax(sayCmd), "say %s", resetScoreCommands[x])
		formatex(sayTeamCmd, charsmax(sayTeamCmd), "say_team %s", resetScoreCommands[x])
		register_clcmd(sayCmd, "CmdSay")
		register_clcmd(sayTeamCmd, "CmdSay")
	}
}

public CmdSay(id)
{
	static iFloodTime[33], systime;
	if (iFloodTime[id] > (systime = get_systime()))
	{
		client_print_color(id, print_team_default, "^1[^4RS^1] ^3To ^4reset ^3the score, wait %d seconds.^1.", iFloodTime[id] - systime);
	} 
	else if (get_entvar(id, var_frags) > MIN_FRAGS || get_member(id, m_iDeaths) > MIN_DEATHS)
	{
		set_entvar(id, var_frags, 0.0)
		set_member(id, m_iDeaths, 0)
		
		message_begin(MSG_BROADCAST, get_user_msgid("ScoreInfo"))
		write_byte(id) // id
		write_short(0) // Frags
		write_short(0) // Deaths
		write_short(0) // Class
		write_short(get_member(id, m_iTeam)) // Team
		message_end()
		
		client_print_color(id, print_team_default, "^1[^4RS^1] ^3Your score has been ^4reset^1.")
		client_cmd(id, "spk ^"cleanup(t20) terminated(t20)^"")
		
		iFloodTime[id] = systime + 20;
		
		return PLUGIN_HANDLED

	else
	{
		client_print_color(id, print_team_default, "1[^4RS^1] ^3You don't have %s frags and %s in order to ^4reset ^3the score^1.")
		client_cmd(id, "spk ^"cleanup(t20) denied(t20)^"")
	}

	return PLUGIN_CONTINUE
}

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#15

Post by Raheem » 6 years ago

Yes, You can include any sounds in Valve/sound folder without any problem and not needed to precache them.

Second thing: You should know that %i is used for integer and %s used for string arrays. You may read more about it, It's explained well here: https://www.codingunit.com/printf-forma ... ted-output and note that these specifiers used when you need to send a Chat, Text HUD Message ... etc.
So in your code this:
    1. client_print_color(id, print_team_default, "1[^4RS^1] ^3You don't have %s frags and %s deaths in order to ^4reset ^3the score^1.")
Should be:
    1. client_print_color(id, print_team_default, "1[^4RS^1] ^3You don't have %i frags and %i deaths in order to ^4reset ^3the score^1.", MIN_FRAGS, MIN_DEATHS)
He who fails to plan is planning to fail

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#16

Post by ArminC » 6 years ago

Ah, ok I understand.. I wasn't sure what letter to put after %..

I put the string but as I said eariler.. I can't code it correctly.. any help? -- until now I did have if + else now I have 3 scenarios and I don't know how to make it to work..

Code: Select all

#include <amxmodx>
#include <reapi>

#define MIN_FRAGS 2 // Player who has more than minimum frags will be able to reset his score but not lower.
#define MIN_DEATHS 2 // Player who has more than minimum deaths will be able to reset his score but not lower.
#define FLOODTIME 20

new const resetScoreCommands[][] =
{
	"/rs", "/resetscore", "/reset", "/rscore", "/resets"
}

new sayCmd[64], sayTeamCmd[64], x

public plugin_init()
{
	register_plugin("Reset Score", "1.1", "Raheem")
	
	// Commands
	for (x = 0; x <= charsmax(resetScoreCommands); x++)
	{
		formatex(sayCmd, charsmax(sayCmd), "say %s", resetScoreCommands[x])
		formatex(sayTeamCmd, charsmax(sayTeamCmd), "say_team %s", resetScoreCommands[x])
		register_clcmd(sayCmd, "CmdSay")
		register_clcmd(sayTeamCmd, "CmdSay")
	}
}

public CmdSay(id)
{
	static iFloodTime[33], systime;
	if (iFloodTime[id] > (systime = get_systime()))
	{
		client_print_color(id, print_team_default, "^1[^4RS^1] ^3To ^4reset ^3the score, wait %d seconds.^1.", iFloodTime[id] - systime);
	} 
	else if (get_entvar(id, var_frags) > MIN_FRAGS || get_member(id, m_iDeaths) > MIN_DEATHS)
	{
		set_entvar(id, var_frags, 0.0)
		set_member(id, m_iDeaths, 0)
		
		message_begin(MSG_BROADCAST, get_user_msgid("ScoreInfo"))
		write_byte(id) // id
		write_short(0) // Frags
		write_short(0) // Deaths
		write_short(0) // Class
		write_short(get_member(id, m_iTeam)) // Team
		message_end()
		
		client_print_color(id, print_team_default, "^1[^4RS^1] ^3Your score has been ^4reset^1.")
		client_cmd(id, "spk ^"cleanup(t20) terminated(t20)^"")
		
		iFloodTime[id] = systime + FLOODTIME; 
		
		return PLUGIN_HANDLED

	else
	{
		client_print_color(id, print_team_default, "1[^4RS^1] ^3You don't have minimum %i frags and %i deaths to ^4reset ^3the score^1.", MIN_FRAGS, MIN_DEATHS)
		client_cmd(id, "spk ^"cleanup(t20) denied(t20)^"")
	}

	return PLUGIN_CONTINUE
}}
// C:\Users\armin\Desktop\Compiler\reset_score.sma(56) : warning 225: unreachable code
// C:\Users\armin\Desktop\Compiler\reset_score.sma(56) : warning 217: loose indentation
// C:\Users\armin\Desktop\Compiler\reset_score.sma(56) : error 029: invalid expression, assumed zero
// C:\Users\armin\Desktop\Compiler\reset_score.sma(63) : warning 209: function "CmdSay" should return a value
(because that 2nd else?)
Last edited by ArminC 6 years ago, edited 1 time in total.

User avatar
Night Fury
Mod Developer
Mod Developer
Posts: 677
Joined: 7 years ago
Contact:

#17

Post by Night Fury » 6 years ago

Missing } before last 2nd else.
Want your own mod edition? PM me.
Accepting private projects.
Discord: Fury#7469
Image

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#18

Post by ArminC » 6 years ago

wtf? That's all a misstype.. omfg.. I didn't see it lool (and I searched over 10 topics :\ )

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#19

Post by Raheem » 6 years ago

Hmm, Not need to search next time you read the error not warning. Error which will not allow compiler to compile but warning not important to fix. So if you read reset_score.sma(56) : error 029: invalid expression, assumed zero this mean in line 56 there is an invalid expression which jack tells you about it it's the missing closing bracket.

If compiler with smart enough to detect these things like missing bracket '}' or parentheses ')' and fix it .. but it's not smart so you should review your code and concentrate.
He who fails to plan is planning to fail

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#20

Post by ArminC » 6 years ago

Code: Select all

#include <amxmodx>
#include <reapi>

#define CHAT			// Message in chat when the score is reseted.
#define SOUND 			// Audio speak when the score is rested.
#define FLOODTIME 20	// Block reusing resetscore for defined seconds.
#define MIN_FRAGS 2 	// Player who has more than minimum frags will be able to reset his score but not lower.
#define MIN_DEATHS 2 	// Player who has more than minimum deaths will be able to reset his score but not lower.

new const resetScoreCommands[][] =
{
	"/rs", "/resetscore", "/reset", "/rscore", "/resets"
}

new sayCmd[64], sayTeamCmd[64], x

public plugin_init()
{
	register_plugin("Reset Score", "1.1", "Raheem")
	
	// Commands
	for (x = 0; x <= charsmax(resetScoreCommands); x++)
	{
		formatex(sayCmd, charsmax(sayCmd), "say %s", resetScoreCommands[x])
		formatex(sayTeamCmd, charsmax(sayTeamCmd), "say_team %s", resetScoreCommands[x])
		register_clcmd(sayCmd, "CmdSay")
		register_clcmd(sayTeamCmd, "CmdSay")
	}
}

public CmdSay(id)
{
	#if defined FLOODTIME
	static iFloodTime[33], systime;
	if (iFloodTime[id] > (systime = get_systime()))
	{
		#if defined CHAT
		client_print_color(id, print_team_default, "^1[^4RS^1] ^3To ^4reset ^3the score, wait %d seconds.^1.", iFloodTime[id] - systime);
		#endif
	} 
	#endif
	else if (get_entvar(id, var_frags) > MIN_FRAGS || get_member(id, m_iDeaths) > MIN_DEATHS)
	{
		set_entvar(id, var_frags, 0.0)
		set_member(id, m_iDeaths, 0)
		
		message_begin(MSG_BROADCAST, get_user_msgid("ScoreInfo"))
		write_byte(id) // id
		write_short(0) // Frags
		write_short(0) // Deaths
		write_short(0) // Class
		write_short(get_member(id, m_iTeam)) // Team
		message_end()
		
		#if defined CHAT
		client_print_color(id, print_team_default, "^1[^4RS^1] ^3Your score has been ^4reset^1.")
		#endif
		#if defined SOUND
		client_cmd(id, "spk ^"cleanup(t20) terminated(t20)^"")
		#endif
		
		#if defined FLOODTIME
		iFloodTime[id] = systime + FLOODTIME; 
		#endif
		
		return PLUGIN_HANDLED
	}
	else
	{
		#if defined CHAT
		client_print_color(id, print_team_default, "1[^4RS^1] ^3You don't have minimum %i frags and %i deaths to ^4reset ^3the score^1.", MIN_FRAGS, MIN_DEATHS)
		#endif
		#if defined SOUND
		client_cmd(id, "spk ^"cleanup(t20) denied(t20)^"")
		#endif
	}

	return PLUGIN_CONTINUE
}
That's my final code :o It's final or could be re-sized to be smaller (more efficient?)

Anyway what return PLUGIN_CONTINUE+HANDLED do?

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#21

Post by Raheem » 6 years ago

These returns tell the function what to do now. For example take damage function (This function will be called when any player take damage):
    1. #include <amxmodx>
    2. #include <reapi>
    3.  
    4. public plugin_init()
    5. {
    6.     // Register our plugin first
    7.     register_plugin("Return Explaning", "1.0", "Raheem")
    8.    
    9.     // HookChains (This will be called when any player take damage)
    10.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Post", 1)
    11.    
    12.     // HookChains (This will be called just before damage take place)
    13.     RegisterHookChain(RG_CBasePlayer_TakeDamage, "Fw_TakeDamage_Pre", 0)
    14. }
    15.  
    16. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    17. {
    18.     // This return exit your function you used in this plugin so the print message won't be printed
    19.     return HC_CONTINUE;
    20.    
    21.     client_print(id, print_chat, "This message will not be printed in game!!!")
    22. }
    23.  
    24. public Fw_TakeDamage_Post(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    25. {
    26.     client_print(id, print_chat, "This message will be printed in game!!!")
    27.    
    28.     // After the message printed, This return will exit this function which used in this plugin
    29.     return HC_CONTINUE;
    30. }
    31.  
    32. public Fw_TakeDamage_Pre(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    33. {
    34.     // This will exit the main function so player will not take damage at all (Exit real function which is taking damage)
    35.     return HC_SUPERCEDE;
    36. }
    37.  
    38. public Fw_TakeDamage_Pre(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    39. {
    40.     client_print(id, print_chat, "This message will appear in the game! + No damage at all")
    41.    
    42.     // The message will appear and then the real function won't be executed so no damage will take place
    43.     return HC_SUPERCEDE;
    44. }
    45.  
    46. public Fw_TakeDamage_Pre(iVictim, iInflictor, iAttacker, Float:fDamage, bitsDamageType)
    47. {
    48.     // No damage will take place, Real function exit + The down client print won't be executed as this function in this plugin will exit too
    49.     return HC_SUPERCEDE;
    50.    
    51.     client_print(id, print_chat, "This message will not appear in the game! + No damage at all")
    52. }
Hope you get anything. In brief return is used to decide if you need now to stop this function and exit from it or continue? Or stop(exit) the real function that run by default by CS? Tell me what you don't get and i explain again 8-)
He who fails to plan is planning to fail

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#22

Post by ArminC » 6 years ago

Ok :) somehow I get it (like I don't know to code but I want to understand it atleast :D ) + if there isn't nothing to re-size that plugin from above.. I think that's the final for this topic. Amen!

Off-topic: hmm.. for this friday I had to make a ancient Egypt (powerpoint), best of the class lol :lol:

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#23

Post by Raheem » 6 years ago

ArminC wrote: 6 years ago Ok :) somehow I get it (like I don't know to code but I want to understand it atleast :D ) + if there isn't nothing to re-size that plugin from above.. I think that's the final for this topic. Amen!
Yes it's nice to know what these returns done so you understand if you need just to edit simple things. This topic will be marked as solved.
ArminC wrote: 6 years ago Off-topic: hmm.. for this friday I had to make a ancient Egypt (powerpoint), best of the class lol :lol:
Hehe, Need any help? :lol: :lol:
He who fails to plan is planning to fail

User avatar
ArminC
Senior Member
Senior Member
Romania
Posts: 137
Joined: 6 years ago
Location: Bucharest
Contact:

#24

Post by ArminC » 6 years ago

NoNoNo, everything was already finished and reviewed by teacher ^_^ 33 slides of Egypt, about 10hours of work :X *effort was good enough for the best callificative in the classroom #rekt)

User avatar
Raheem
Mod Developer
Mod Developer
Posts: 2214
Joined: 7 years ago
Contact:

#25

Post by Raheem » 6 years ago

Nice, Good luck and hope you best in your studies : )
He who fails to plan is planning to fail

Post Reply

Create an account or sign in to join the discussion

You need to be a member in order to post a reply

Create an account

Not a member? register to join our community
Members can start their own topics & subscribe to topics
It’s free and only takes a minute

Register

Sign in

Who is online

Users browsing this forum: No registered users and 1 guest