How to change string into int?
Hey I am to get better in sourcepawn (as you may see) but i feel like I am doing terrible job. The source api not really helping because i need to know how to actually use these functions so I have no other chooise then to ask you.
I wanted to create a plugin that will spam "spam" in the chat. and added a color choose to the client. for exaple he will write /spam r 5, this will print 5 times in red spam. (I am really trying to get better so i guess i need to practice in these nonesence plugins, If someone challange me to write a plugin for begginers ofc, i started learning only 3 days ago.. i will be more then happy to try) anyway, How bad is it? Code:
public void OnPluginStart() |
Re: How to change string into int?
Don't put yourself down over it, gotta start somewhere.
The thing that stands out is that you really should indent your code. Take a look at other (released) plugins as examples and see that they indent the line after every opening brace ({) and unindent before the closing one (}). It'll easily catch the missing bracket at the end that would cause this to not compile, assuming it didn't get lost when making this post. StringToInt is used correctly, so you're fine there, and so are the other function calls from what I can tell. if (args > 2) doesn't catch the case if you only pass in zero or one argument (something like /spam r may throw an error at GetCmdArg(2, ...)). if (iamount = 0) is also incorrect. The compiler or your development environment will give you a warning about a possibly unintended assignment because of the single equals; equality checks use ==. You'll want to use if (iamount <= 0) to ensure the player doesn't put in a negative value. You may also want to add one last else to tell the player that they didn't pick a valid color, but I'm sure you'd catch that in a more serious plugin. You should also use return to leave the function early (after you use ReplyToCommand, you don't want to process the rest of the function). For console / chat commands, return Plugin_Handled is generally the way to go about it. |
Re: How to change string into int?
Quote:
how can i fix the arg thing? i mean i thought it should catch it because if(args >2) means also 0 and 1 but i dont know, How should I fix it? yeah i totally forgot about the return plugin handled thing.. i guess its very important. forgot too about the case the client will input negetive values, thanks for that. i feel really bored, i dont know if these stuff really help me progress (have you done these kind of plugins just for practice?). |
Re: How to change string into int?
Quote:
Quote:
Quote:
Quote:
|
Re: How to change string into int?
You might wanna have a space on PrintToChatAll(""); in the beginning, because for some reason, color codes as first character isn't readable.
|
Re: How to change string into int?
Space in the beginning required only for CS:GO. For normal games like CS:S or TF2, all color works without space.
|
Re: How to change string into int?
Quote:
Code:
#include <sourcemod> |
All times are GMT -4. The time now is 11:59. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.