Raised This Month: $ Target: $400
 0% 

Checking Syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
SentryIII
Junior Member
Join Date: Oct 2004
Old 09-03-2005 , 02:39   Checking Syntax
Reply With Quote #1

Could someone show me a more efiicient way to write the following conditional statement?

Code:
if (!equali(check, "somevalue")||!equali(check, "somevalue")||!equali(check, "somevalue")||!equali(check, "somevalue")||!equali(check, "somevalue")||!equali(check, "somevalue")||!equali(check, "somevalue"))   return PLUGIN_HANDLED
SentryIII is offline
SentryIII
Junior Member
Join Date: Oct 2004
Old 09-03-2005 , 23:07  
Reply With Quote #2

Reason I ask is because Im trying to block certain commands through amx_rcon and it seems to be blocking everything even if its not one of the items here.
SentryIII is offline
pdoubleopdawg
Senior Member
Join Date: Aug 2005
Old 09-03-2005 , 23:13  
Reply With Quote #3

if(!equali(a,b)) means if it's not this command.
Remove the !

There's not much you can do to make it shorter. Maybe make a stock for it, but I don't think it's worth simplifying a few characters shorter.
pdoubleopdawg is offline
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 09-03-2005 , 23:18  
Reply With Quote #4

well you could do something like:
Code:
new const g_szCommands[4][] = {     "Command1",     "Command2",     "Command3",     "Command4" }; for(new iCmd = 0; iCmd < 4; iCmd++)     if(equali(check, g_szCommands[iCmd]))         return PLUGIN_HANDLED;
Or something like that to make the code look cleaner/nicer.
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
colby
Senior Member
Join Date: Jun 2005
Location: NC
Old 09-03-2005 , 23:25  
Reply With Quote #5

While we're on the subject, those || between the statements mean 'or' right?
colby is offline
Send a message via AIM to colby
knekter
Senior Member
Join Date: Mar 2004
Location: PA
Old 09-03-2005 , 23:27  
Reply With Quote #6

Quote:
Originally Posted by colby
While we're on the subject, those || between the statements mean 'or' right?
yes
__________________
More updates for Matrix Mod!
knekter is offline
Send a message via AIM to knekter Send a message via MSN to knekter
SentryIII
Junior Member
Join Date: Oct 2004
Old 09-03-2005 , 23:34  
Reply With Quote #7

Quote:
Originally Posted by knekter
well you could do something like:
Code:
new const g_szCommands[4][] = {     "Command1",     "Command2",     "Command3",     "Command4" }; for(new iCmd = 0; iCmd < 4; iCmd++)     if(equali(check, g_szCommands[iCmd]))         return PLUGIN_HANDLED;
Or something like that to make the code look cleaner/nicer.
Perfect, thankyou!
Just for the record, Im listing the commands Im allowing, not trying to block. I decided that trying to block every possible rcon command would take much more time/space than just listing a few commands.
SentryIII is offline
SentryIII
Junior Member
Join Date: Oct 2004
Old 09-04-2005 , 00:57  
Reply With Quote #8

Ok, this is what Im using and it does not see to be working. It seems to be blocking every command.
Code:
  new const cmd[5][] =   {       "changelevel",       "exec",       "kick",       "sv_password",       "sv_restart"   }   for(new i = 0; i < 5; i++)     if(!equali(check,cmd[i]))       return PLUGIN_HANDLED

I have just realised there is no OR (||) conditions using this. So basically if the argument isnt changelevel it stops there. This is not what I want.

I may have a solution to this by counting the total number of commands here and checking to see if any of them matched by checking totals, kinda like a tally system. For example since I have 5 possible commands here I can do a check at the end of the "for" loop to see if it counted 5 mismatches and if so, then to stop there.

Heres my question:
To do what I mentioned above I was wondering if there was a way to count how many items are in my array and replacing the 5 with that variable.
SentryIII is offline
jsauce
Senior Member
Join Date: Aug 2004
Location: Fitchburg, MA USA
Old 09-04-2005 , 06:00  
Reply With Quote #9

What about something like this.
Code:
new const cmd[5][] =     {         "changelevel",         "exec",         "kick",         "sv_password",         "sv_restart"     }     for(new i = 0; i < 5; i++)     {         if(!equali(check,cmd[i])) continue                 if (equal(check,cmd[i]))         {             server_cmd("%s",cmd[i])             break         }     }     return PLUGIN_HANDLED
__________________
"Those people who think they know everything are a great annoyance to those of us who do." -- Isaac Asimov

The Saucy Blog
jsauce is offline
Send a message via ICQ to jsauce Send a message via AIM to jsauce Send a message via MSN to jsauce
Xanimos
Veteran Member
Join Date: Apr 2005
Location: Florida
Old 09-04-2005 , 10:58  
Reply With Quote #10

your supposed to use it like so:
Code:
#include <amxmodx> new const cmd[5][] =     {         "changelevel",         "exec",         "kick",         "sv_password",         "sv_restart"     } public plugin_init() { //.... } public YourFunction() {     for(new i = 0; i < 5; i++)     {         if(!equal(check,cmd[i])) continue                 if (equal(check,cmd[i]))         {             server_cmd("%s",cmd[i])             break         }     } }
Xanimos is offline
Send a message via AIM to Xanimos Send a message via MSN to Xanimos
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 14:27.


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