[HELP] Switch between const size numbers
Hey all! Now, I want to ask if it is possible to switch between the size numbers of a constant. I tried with a loop, switching and cases, doeasn't work. I want to know, because I register a clcmds with a constant. They are doing pretty simillar stuff and that's why I want to add all of the functions for these cmds in one. I will give an example - the cmds are 10. Five of them give you HP, the other five give you Armor. But we will get simplier - there are two cmds. The one is giving HP, the other is giving Armor. And I'm registering the with loop like this:
PHP Code:
PHP Code:
|
Re: [HELP] Switch between const size numbers
When the user type /hp or /armor, the will get those 10 cases in one time.
Why don't you try with this? PHP Code:
|
Re: [HELP] Switch between const size numbers
Because these 'say' commands are just an example. The command are many and different, but they are using thow natives- set_user_healt and sat_user_armor. And that's why I want to know how to mak that switch - that's what I am interested of. :)
|
Re: [HELP] Switch between const size numbers
I understand, but why do you still need case for constant variable? You can do it without swtich - case.
This is the example: PHP Code:
|
Re: [HELP] Switch between const size numbers
F*ck right :D Got it now, thanks. And you can agree, that I'm still searching an more optional way, if there is! For now, that's enough. :)
|
Re: [HELP] Switch between const size numbers
Code:
The SayText message on the other hand contains 4 arguments, and the text is within the 4th argument if it's a say command that triggered the message. sizeof is not suitable for strings alone. use sizeof X -1 or charsmax(). Code:
iNum will cause index out of bounds unless limited. You're far better of hardcoding it. This only increases the CPU usage and decreases readability, unless I'm misunderstanding something. |
Re: [HELP] Switch between const size numbers
Okay, any suggestions to detect in one function which command is exactly used?
|
Re: [HELP] Switch between const size numbers
Quote:
Quote:
|
Re: [HELP] Switch between const size numbers
And may you explain how exactly iNum gets 1 or 2 depending on str_to_num(szCmd) and why it gives me only HP whatever I type :D
|
Re: [HELP] Switch between const size numbers
Simply, I have made the filters. The filters are for the command hp or ap itself. For HP, I've filtered the iNum limit e.g: the const variable has 3 members, so I limit the iNum only three (0, 1, 2 and 3).
If you debug, e.g: Player types "/hp 2" The szCmd result will be "/hp 2" (String). The szCmd is converted to iNum using str_to_num(szCmd) and result will be "0" (String). (I don't know the value, just random example) It will get the wrong result, so I replace the "/hp " to "" and the result will be "2" then I convert it using str_to_num(szCmd) and the result is going to be a correct integer. |
| All times are GMT -4. The time now is 09:43. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.