Yak's FAQs on Scripting
:bacon!: IMPORTANT UPDATE :bacon!: Yak's FAQ's has moved to the wiki! http://wiki.alliedmods.net/Scripting_FAQ_(SourceMod) The thread will be kept for archival purposes, but all future additions and edits will be made to the wiki article. Please contribute to the wiki page for the benefit of all! Thanks, guys :) Most of the time, we volunteer support specialists are in gs#sourcemod to answer all your questions. Unfortunately, some of us have lives (except for sawce) and we can't be on every waking moment. Fortunately, there is a solution. It is... Yak's FAQs on Scripting! A guide to common and not-so-common tasks in SourcePawn If you have a question and/or answer to add, reply to the thread and I will tack it onto the list. Suggestions (and corrections) are welcome! Table of Contents 1. How do I learn SourcePawn? 2. Where can I find all the SourcePawn functions and other information? 3. How do I find the classname of an entity? (e.g., "weapon_knife" or "prop_physics") 4. How do I block regular commands, such as kill and say? 5. How do I hook +commands, such as +zoom and +attack? 6. How do I get rid of loose indentation warnings? 7. How do I get rid of tag mismatch warnings? 8. How do I add color to my messages? 9. Why do I get an "unknown symbol" error when using an SDKTools native? 10. Why is Source telling me my command is an "Unknown command"? 1. How do I learn SourcePawn? Look at the AlliedModders wiki: http://wiki.alliedmods.net/Introduction_to_SourcePawn 2. Where can I find all the SourcePawn functions and other information? When you #include <sourcemod>, the compiler retrieves the file sourcemod.inc from the sourcemod/scripting/include/ folder. Every function, variable, and definition can be found in the .inc files inside scripting/include. Searching through all those files can be quite tedious. Thankfully, the honorable Nican created an API reference on the web, complete with searching and commenting: http://docs.sourcemod.net/api/ If you are in gs#sourcemod, you can use the !api command to search Nican's API reference: Code:
<theY4Kman> !api Netclass The classname of an entity (not to be confused with a netclass) is a unique identifier. It's the most well known of entity names. To find it, use the function GetEdictClassname(edict, String:clsname[], maxlength): Code:
4. How do I block regular commands, such as kill and say? Use RegConsoleCmd(const String:cmd[], ConCmd:callback, const String:description[]="", flags=0) (API reference) to hook the command you wish to block. Then, in the callback for the command, return Plugin_Handled: Code:
Code:
5. How do I hook +commands, such as +zoom and +attack? Unlike regular commands, the +commands are handled on the client, then sent to the server by other means. That means you cannot use RegConsoleCmd to hook +commands. It also means that unless you're using SourceMod 1.3, you can only hook +commands, you CANNOT block them. You must use loop through all the clients OnGameFrame() and call GetClientButtons(client) with the proper IN_ definition (see entity_prop_stocks.inc) to check if a client is using a +command: Code:
A better method for hooking +commands was added in SourceMod 1.3, rev 2711: the forward OnPlayerRunCmd(client, &buttons, &impulse, Float:vel[3], Float:angles[3], &weapon). This forward is fired every time a player uses a movement button. The great thing about this forward is that changes to the buttons are saved. Thus, we can actually block +commands: Code:
6. How do I get rid of loose indentation warnings? Code:
myplugin.sp(#) : warning 217: loose indentation 7. How do I get rid of tag mismatch warnings? Though every variable in SourcePawn is one cell (4 bytes), with the exception of strings, there are many different ways to interpret what's contained in the cell. To signify what is in a cell, tags are used. The most common are _ (the default tag: a vanilla cell. This tag is implied when no other tag is specified.), Float, bool, and String. See http://wiki.alliedmods.net/Introduct...Pawn#Variables for more information. Functions wear these tags on their parameters so you can tell what needs to be passed to the function: Code:
To call this function, then, you must pass values with the specified tags. For example: Code:
Code:
8. How do I add color to my messages? Thanks to antihacker for the question/answer and psychonic for some corrections. Though the actual colors will vary depending on the mod, you can add color to any chat message using the characters 0x01 to 0x08. For example: Code:
http://y4kstudios.com/sourcemod/yaks_faqs/sm_colors.png With a little experimenting, you can learn the colors for a mod. However, the meaning behind the colors is generally as follows: 0x01 = Normal color 0x02 = Use team color to the end of a player's name. When used, it can be the only color used, and it must be at the start of the message. 0x03 = Team color 0x04 = Location color This data comes from Counter-Strike: Source. Unfortunately, to use players' team colors, you must use UserMessages, because there is no way for the current SourceMod functions to know what team color to use. Here's an example: Code:
Code:
<player_from team color> My message EDIT: exvel has released an excellent library of functions that will do all this work for you. Instead of using color codes, you merely write "{green}" or "{blue}". 9. Why do I get an "unknown symbol" error when using an SDKTools native? Thanks to Tsunami None of SourceMod's or SDKTools's functions are built into SourcePawn. Therefore, every time you use one of their functions, SourcePawn needs to know how to call the function. Normally, this is done using includes. Just like you would #include <sourcemod> to use SourceMod's functions, you need to: Code:
10. Why is Source telling me my command is an "Unknown command"? This is because you're not returning Plugin_Handled in your callback. If you don't, SourceMod believes you didn't want the Source Engine to know the command was registered, and it handles it so. |
Re: Yak's FAQs on Scripting
Thank you
|
Re: Yak's FAQs on Scripting
8. How to color your messages?
Use \x01, \x02 ... \x08 to color your message, example: PHP Code:
http://i43.tinypic.com/2dvj1c5.png You must find out wich color you get, because this is different for nearly every mod. \x01 normal color \x03 is the team depend color. Also see this. I hope you dont mind for posting here. |
Re: Yak's FAQs on Scripting
9. Why do I get "unknown symbol" when using an SDKTools native?
Code:
|
Re: Yak's FAQs on Scripting
An addition to
6. How do I get rid of loose indentation warnings? If using notepad++, Rightclick Select All PHP Code:
|
Re: Yak's FAQs on Scripting
in left 4 dead
how can i spawn a don't fire tank? |
Re: Yak's FAQs on Scripting
This is a more general FAQ about how to do general things in SourcePawn. If you're looking for something mod-specific, I suggest searching around the Scripting forum. If you can't find anything after searching your heart out, create a thread.
I'm trying to keep this thread as mod-neutral as possible. |
Re: Yak's FAQs on Scripting
Quote:
|
Re: Yak's FAQs on Scripting
Quote:
|
Re: Yak's FAQs on Scripting
#4 needs to be updated to use AddCommandListener ;)
|
All times are GMT -4. The time now is 11:33. |
Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.