View Full Version : Scripting Help FAQ
29/06/2012, 02:21 PM
We all know the sorts of questions that come up time and time and time and time again! Yet there is no FAQ with a collection of neat answers following the latest techniques and best practices. It's time to put one together! Consider this a way to answer all those questions once and for all. Basically post any questions you've seen multiple times and if you can the best possible answers to them. Don't forget things like global naming conventions, libraries and plugins, pitfalls, options etc. Also, some of the answers will just be links to existing tutorials bringing the good ones together in to one handy reference.
Some questions to get this started:
Gates - HAS to be top of the list! Automatic, locked, button activated, command activated, rotating, sliding, lifting etc.
File saving - INI files, LOG files (very different formats and uses), write caches...
Commands - (strcmp, dcmd, zcmd, y_commands, other), how to upgrade from one.
SQL queries (MySQL and SQLite).
I'll say now, I'm working on something BIG to address part of this problem (might need help with some parts if anyone is interested).
29/06/2012, 02:32 PM
Q: Where can I learn how to script?
A: There is already a beginner's introduction posted here (http://forum.sa-mp.com/showthread.php?t=92). IMO, if you are new to the programming and have never seen nor written a piece of code, read this http://compuphase.com/pawn/Pawn_Getting_Started.pdf.
Q: Help, warnings and errors!
Q: What is the best command processor?
A: To clarify, a good command processor is one which offers speed and functionality. YCMD (http://forum.sa-mp.com/showthread.php?t=169029), ZCMD (http://forum.sa-mp.com/showthread.php?t=91354) and rCMD (http://forum.sa-mp.com/showthread.php?t=323777) are examples of up-to-date command processors.
Q: Run time error 19: File or function not found!
A: This is a server error. It occurs upon server execution (hence a run time error) and when the server can't retrieve information from a plugin. A simple fix would be to make sure your plugins are in the correct directory (/plugins) and to also make sure it is added to server.cfg.
Q: Problem with sscanf!
A: There is extensive documentation written about sscanf. If you have any issues, post in the topic section here (http://forum.sa-mp.com/showthread.php?t=120356).
Q: MySQL vs SQLite
A: There has been countless threads on this; 1 (http://forum.sa-mp.com/showthread.php?t=305158), 2 (http://forum.sa-mp.com/showthread.php?t=268639), 3 (http://forum.sa-mp.com/showthread.php?t=169462). Also, please take your time to read through the threads, as one's person's opinion isn't necessarily fact.
Topic: No original topic needed.
Q: Difference between Stock and Public functions.
A: To clarify:
"stock" defines that a function may not be used, and if it isn't don't give a warning at compile time. This is used for library functions, you don't need it for writing normal modes.
"public" saves the name of the function in the amx (normally functions are just called be address, the human-readable name is not important). Saving the name means that the function can be found by name later on. When you specify a function in "SetTimer", "SetTimerEx", "CallLocalFunction" or "CallRemoteFunction" you specify it by name so these can only call public functions. Callbacks such as "OnPlayerConnect" are also public for the same reason.
Q: Isn't foreach the same as a for loop!? (for loop vs foreach)
A: Foreach uses a method known as Linked Lists. Instead of each index validating a check of whether the player is connected or not, it stores the id of the next connected player. A separate variable stores the id of the first connected player, therefore, you may use the current index, to retrieve the next index and ONLY loop through connected players until it has been fulfilled (index of -1).
Q: How to make a Register/Login script.
A: There are dozens of threads on the matter; 1 (http://forum.sa-mp.com/showthread.php?t=273088), 2 (http://forum.sa-mp.com/showthread.php?t=160971), 3 (http://forum.sa-mp.com/showthread.php?t=281736), 4 (http://forum.sa-mp.com/showthread.php?t=278188), 5 (http://forum.sa-mp.com/showthread.php?t=308390).
Q: Need help with a command!
A: If you need help with a command, post it here (http://forum.sa-mp.com/showthread.php?t=187229).
29/06/2012, 04:17 PM
Scripting FAQ is definitely needed. The spam produced by asking/answering same questions over and over and over again in new topics is overwhelming.
Is this the thread where we can link new scripters to or is it just for gathering info for something else?
I'll add some here:
Q: Command not working / dialog not responding
A: You have a return 1 in OnPlayerCommandText / OnDialogResponse (in some other script) that blocks it. The last return in these callbacks should always be 0 in filterscripts.
Q: Where can I find interiors?
Q: Where can I find custom SA-MP objects?
A: There should be SAMP.ide file in your GTA San Andreas folder (..\GTA San Andreas\SAMP\SAMP.ide). Open it with a text editor (Notepad)
Q: How can I get coordinates for a gang zone?
Q: How can I make gang zones capturable?
Q: Compiling gives "error 017: undefined symbol" when using a SA-MP native function
A: Download latest server package from http://www.sa-mp.com/download.php
Q: How can I get a random player?
29/06/2012, 06:49 PM
I think this should be a sticked topic.
Q: How do I make movable gates/objects?
A: Checkout these tutorials:
Q: How many (vehicles/virtual worlds/map icons/menus..etc) can I have in my server?
Q: I have too many objects/checkpoints and I want to add them all into my server, can I?
A: Yes you can. All you have to do is using a Streamer (Most used: Incognito's Streamer (http://forum.sa-mp.com/showthread.php?t=102865)).
Q: Pawno crashes (and/or gives a 0kb .amx file) when compiling, how can I fix that?
A: You are probably missing something in your code (Usually a bracket) so try to find what's missing and fix it. If you couldn't solve the problem yourself, then you might post in the Scripting Help (http://forum.sa-mp.com/forumdisplay.php?f=12) forum as long as you'll be following the RULES (http://forum.sa-mp.com/showthread.php?t=355296) of it.
Q: How do I get the min and max X, Y, and/or Z co-ordinates for my gang zone, area ... etc?
A: Use this (http://forum.sa-mp.com/showthread.php?t=360200) filterscript to get them easily.
Q: How to go to an interior using SA-MP Map Editor (http://forum.sa-mp.com/showthread.php?t=282801)?
#1 Open your SA-MP Map Editor (http://forum.sa-mp.com/showthread.php?t=282801).
#2 Click the Views tab http://i46.tinypic.com/2hey89s.jpg
#3 Get the co-ordinates of the interior you want to go to (All interiors co-ordinates can be found here (http://weedarr.wikidot.com/interior/) or here (http://wiki.sa-mp.com/wiki/InteriorIDs)).
#4 Put them under Camera View http://i49.tinypic.com/23vesxz.jpg.
#5 Click "Point camera at these Coords".
29/06/2012, 11:55 PM
Q: When I compile I get the "cannot read from file" error?
A: There are two things that could cause this. You have multiple installations of Pawno.
Go into your server directory.
Double-click the folder 'pawno'.
Open up pawno.exe
Click the open icon.
Access the script you are trying to compile.
The include is not in your pawno/includes folder.
Pay attention to what the compiler says it cannot read from.
Go into your server directory and access the pawno/includes folder.
Make sure the file that is giving you the error is located in that folder.
If it is, check the file extension. ( ie: ".txt" )
Make sure the file extenstion is " .inc "
If you don't have the file search for it on the internet and donwload it.
30/06/2012, 11:44 AM
Q: Help! Why do I get "Undefined symbol: mysql_query"?
A: BlueG's MySQL plugin R7 replaced mysql_query and mysql_query_callback from R6 and earlier with a new function: myqsl_function_query. Unthreaded queries are no longer supported. See AndreT's tutorial (http://forum.sa-mp.com/showthread.php?t=337810) on how to use the new functions and the cache.
vBulletin® v3.8.6, Copyright ©2000-2013, Jelsoft Enterprises Ltd.