12.08.2010, 23:15
(
Last edited by Toribio; 05/09/2010 at 06:03 PM.
)
squirsamp
Squirrel in SA:MP
This plugin, as the name suggests, makes possible the use of Squirrel in SA:MP Servers, an object oriented programming language, which is known by its easy syntax and the various possibilities to do incredible things on it.
This is an experimental project, SA:MP Team may update the server and Squirsamp not, so all your work with Squirrel scripting will be lost until we decide to update the plugin to your SA:MP server version.
Kalcor and I do not recommend the use of this plugin for public servers, this is just an experiment.
And remember that when changing the scripting language, you won't be able to use any other plugin that modifies the language, such as MySQL plugin, YSF, etc. If you have any knowledge in plugin scripting, you may want to modify the source and add your own functions.
Requirements
- Microsoft Windows 9x/NT 5.0+, we do not support Linux YET
- SA:MP Server 0.3a R6 to 0.3b
Unfortunately, as every SA:MP native function passed to C++ and parsed with AMX functions, to transform items in cells, the functions called by C++ are 1.5x slower than called by Pawn, and when called by Squirrel, with all the stack functions, it gets 2x slower then Pawn. See the speed test we made to get these results.
In Alpha versions, the plugin used to loop every function in the function table to find the requested one and then call it. It was very slow. But in actual versions it prepares the table with each function with indexes, so it passes to be vastly faster, comparing to the old method.
Changes from Pawn
- We currently don't include the SA:MP constants, like MAX_PLAYERS, etc.
- We have added two callbacks: OnScriptInit and OnScriptExit.
- The SetTimerEx function was removed and in its place we've added only SetTimer with optional parameters at the end:
- SetTimer(function, interval, repeat, ...)
- Remember that the "function" parameter isn't a string
- You don't have to use the parameters string list anymore
- Added IsTimerActive(timerid)
- All the GetPVar* functions don't have referenced parameters anymore
- Functions with referenced string parameters in Pawn have been changed to return a string, they are:
- GetPlayerName
- GetWeaponName
- GetPlayerIp
- All the SQLite functions that return strings
- Functions with referenced float parameters in Pawn have been changed in Squirrel, they are:
- GetVehicleRotationQuat: returns a table with .w, .x, .y and .z
- All these functions return a float value:
- GetPlayerFacingAngle
- GetVehicleZAngle
- GetVehicleHealth
- GetPlayerHealth
- GetPlayerArmour
- All these functions return a table with the float values .x, .y and .z:
- GetPlayerPos
- GetVehiclePos
- GetObjectPos
- GetObjectRot
- GetPlayerObjectPos
- GetPlayerObjectRot
- GetPlayerVelocity
- GetVehicleVelocity
- GetPlayerCameraPos
- GetPlayerCameraFrontVector
- GetPlayerCameraUpVector
- Functions with referenced integer parameters in Pawn have been changed in Squirrel, they are:
- GetPlayerTime: returns a table with .hour and .minute
- GetPlayerKeys: returns a table with .keys, .updown and .leftright
- GetVehicleDamageStatus: returns a table with .panels, .doors, .lights and .tires
- GetPlayerWeaponData: returns a table with .weapon and .ammo
- Added the RCON/console commands: loadss, unloadss and reloadss (just to clarify: ss = Squirrel Script)
- Place the file squirsamp.dll into your plugins folder
- Add the line "plugins squirsamp.dll" into your server.cfg file
- Add the line "scripts" into server.cfg, e.g. "scripts myscript.nut other.nut"
- Create the folder "scripts" into your root folder to place your Squirrel scripts
- You can't use this plugin with other plugins like YSF
- Run your server
Remember that this code is protected by the Mozilla Public License (MPL 1.1) and you must follow this contract when doing any kind of modification and/or distribution of the source code.
Other
There are several code tests on the source.
If you know how to call the filterscripts callbacks on Linux (see the inline-assembly for Windows in callbacks.cpp), post here. Because that's one more thing left we should do to release this plugin for Linux.
This is an Alpha version and may have some bugs, reporting them will help us making this plugin better.
Download
squirsamp.dll
SHA1 Checksum: a19be886684caf71c90f4b2fcb16e009ca4b1afa
Please, no mirrors.
Source
This code is hosted on ****** Code and can be found here.
You can also checkout the code with SVN.
Source summary
Code:
======================================================================== DYNAMIC LINK LIBRARY : Squirrel in SA:MP Project Overview ======================================================================== This file contains a summary of what you will find in each of the files that make up this application. squirsamp.sln The Visual Studio Solution file, it contains the project file "squirrel.vcxproj". All these VC++ files are for the 2010 version of Visual Studio. squirrel.vcxproj This is the main project file for VC++ projects. It contains information about the version of Visual C++ that generated the file, and information about the platforms, configurations, and project features. squirrel.vcxproj.filters This is the filters file for VC++ projects. It contains information about the association between the files in your project and the filters. This association is used in the IDE to show grouping of files with similar extensions under a specific node (for e.g. ".cpp" files are associated with the "Source" filter). main.cpp This is the main DLL source file. It initializes all the other functions and verifies all the needed information to the application run correctly. global.h This file contains the general configuration for the project and the needed includes. squirsamp.cpp Contains the main class definition where all the other classes are defined and initialized. squirsamp.h Contains the main class declaration and lines importing all the external references. This file has to be included in any other file in the project to be linked correctly. callback.cpp This file is responsible to do the check between the versions of SA:MP Server to then initialize all the hooks used along the files. This file also contains the functions Call and Unlock that are property from ****** (Alex "******" Cole), extracted from the YSF plugin made by him release on the SA:MP Official Forums. The initial purpose of this file was to do the callbacks hook, but now it does every hook on the project. callback.h This is the header file for callback.cpp that contains the CCallback class declaration and the callbacks struct to store the initial callback addresses from filterscripts. callbacks.cpp This file contains all the callbacks that are passed to the Squirel scripts along the server execution routine. For more information, see the comments inside it. callbacks.h This file is the header for callbacks.cpp that contains the callbacks declarations inside it, so other files can use the callbacks name. function.cpp Contains the CFunctions class definition that stores and initializes all the function addresses and names. It also contains the function that parse C++ parameters to Pawn's virtual machine parameters so the target function can be called corretly. function.h This is the header file for function.cpp. It contains the functions struct and the enumaration indexes for the SA:MP native functions. functions.cpp This file contains all the SA:MP native functions that are passed to the Squirrel scripts. It also contains customized functions like SetTimer and CallRemoteFunction. It's responsible to register all the functions on the Squirrel actual virtual machine. functions.h This is the header file for functions.cpp. It only contains the declaration of sq_register_pawn for use in scripts.cpp. scripts.cpp This file contains the CScripts class that are responsible for (un)loading Squirrel files into the SA:MP Server. scripts.h This is the header file for scripts.cpp and contains the class declaration for it. It also contains the struct responsible for storing the Squirrel scripts in. squser.cpp This file contains all the functions that are in the "Squirrel syntax". Such as the functions to handle the virtual machine's stack, etc. squser.h The header file for squser.cpp, only with functions' declarations. timer.cpp This file contains all the functions to handle the timers for Squirrel Scripts. The functions are stored in the class CTimers, and the timers are stored in the "Timer timers[MAX_TIMERS]" struct array. timer.h This is the header file for timer.cpp that contains the class declaration for it and the "Timer" struct declaration. SDK/ Filter All the files inside this filter are licensed to their own authors which are distributed "as-is" with their own purposes. The squirrel/ folder contains all the Squirrel source files. The amx/ folder contains the AMX architeture and definitions for SA:MP plugins. All the other files are extracted from the "Hello World" SA:MP Plugin SDK released on the official SA:MP site (http://www.sa-mp.com/)nl67475a152bbb31.2...06160Other notes: MAX_FILTERSCRIPTS It doesn't need to match the actual max filtescripts supported by the executed SA:MP Server version. It needs to be the maximum ammount of filterscripts ever supported by all SA:MP Server versions. MAX_SCRIPTS This is a user-configurable option which I prefer to use the same ammount as MAX_FILTERSCRIPTS to mantain a standard amount of scripts. MAX_TIMERS It can be any value you like. MIN_TIMER_INTERVAL This option was made to avoid execution problems while parsing the timers, because it may be slow if the user choices a low interval ammount for his timers. See copyright notice in the file "COPYRIGHT". /////////////////////////////////////////////////////////////////////////////
Flбvio Toribio and Jones Nathan.