[Plugin] Lua in SAMP (alpha)
#1


Lua in SAMP
Introduction

This plugin, as the name suggests, makes possible the use of Lua in SA:MP Servers, which is known by its easy syntax and the various possibilities to do incredible things on it.

So, how can i create plugin for lua? It's easy to do.Download "l_base" Plugin Development Kit.And write your own plugin:
Pre-coming plugins: ml_mysql 5.0 <transported from MTA-MYSQL> (Not pre-comes on Linux)


Kalcor and I do not recommend the use of this plugin for public servers, this is just an experiment.

Requirements
  • Microsoft Windows 9x/NT 5.0+, Linux
  • SA:MP Server 0.3e
Speed

In strings 5x faster, In booleans 22x faster than pawn.

Changes from Pawn
  • We currently include SA-MP Constants.
  • We have added two event: onLoad, onUnload
  • The SetTimerEx function was removed and in its place we've added only SetTimer with optional parameters at the end:
      • Timer.set(function, interval, repeat, ...)
        • Remember that the "function" parameter isn't a string
        • You don't have to use the parameters string list anymore
        • Auto start
      • Timer.create(function, interval, repeat, ...)
        • Remember that the "function" parameter isn't a string
        • You don't have to use the parameters string list anymore
        • Create but pause
      • Timer : start()
        • Start the timer (Timer.set auto call this)
      • Timer : stop()
        • Stop timer, stop thread reset repeated count
      • Timer : pause()
        • Pause thread, pause timer, store repeat count
      • Timer : isPaused()
        • Is paused
      • Timer : isStopped()
        • Is stopped
    • Functions with referenced string parameters in Pawn have been changed to return a string, they are:
    • GetPlayerName
    • GetWeaponName
    • GetPlayerIp
    • etc...
    • Functions with referenced float parameters in Pawn have been changed in Lua, they are:
      • GetVehicleRotationQuat: returns w,x,y,z ( Lua allows multiple return )
      • All these functions return a float value:
        • GetPlayerFacingAngle
        • GetVehicleZAngle
        • GetVehicleHealth
        • GetPlayerHealth
        • GetPlayerArmour
      • All these functions return a x,y,z
        • GetPlayerPos
        • GetVehiclePos
        • GetObjectPos
        • GetObjectRot
        • GetPlayerObjectPos
        • GetPlayerObjectRot
        • GetPlayerVelocity
        • GetVehicleVelocity
        • GetPlayerCameraPos
        • GetPlayerCameraFrontVector
        • GetPlayerCameraUpVector
  • Added the RCON/console commands: start, stop and restart,
    loadplugin, unloadplugin, reloadplugin
Setting up
In README.txt (Open with Notepad++)

This project is now private for some reasons.I can put it when it come fully.(may be)


I will add LUA lessons to Tutorials category.
Reply
#2

Yay When I was a little bit younger, i scripted for "roblox" :P Lua is my favorite, ty!
Reply
#3

Good working man !!

Downloading ..
Reply
#4

Great Job, looking forward to this.
Reply
#5

Good job!
Reply
#6

Are you serious? I was nearly finishing my LUA plugin... damn Though mine is able to work perfectly together with pawn and could really be used as a second language so i still gonna finish it.
Reply
#7

Nice plugin, are there any advantages using this?

I guess it's a good way to script if you don't know PAWN, and you know LUA.
Reply
#8

As far as im able to see is this one a bit slow so currently i won't use it to much. Though it's a good job and we'll we gonna be concurrents i guess since im one of these days releasing my version. :3
Reply
#9

Quote:
Originally Posted by irinel1996
Посмотреть сообщение
Nice plugin, are there any advantages using this?

I guess it's a good way to script if you don't know PAWN, and you know LUA.
Yes, Pawn has static allocated arrays & strings.Lua has dynamic allocated arrays&strings

You can add commands with event handlers or addCommandHandler like;

Код:
function myCmd(playerid, cmdName, number1, number2, ...)
print('Number 1 ',number1);
print('Number 2:' .. number2);
print(...);
end
addCommandHandler('cmd',myCmd);
You can add multiple event handlers, you can make custom events, addEvent and call it with triggerEvent..

Has Thread's.
Has auto-include system. etc...

For example
Код:
local VehicleNames = {
    "Landstalker","Bravura","Buffalo","Linerunner","Pereniel","Sentinel","Dumper","Firetruck","Trashmaster","Stretch","Manana","Infernus",
    "Voodoo","Pony","Mule","Cheetah","Ambulance","Leviathan","Moonbeam","Esperanto","Taxi","Washington","Bobcat","Mr Whoopee","BF Injection",
    "Hunter","Premier","Enforcer","Securicar","Banshee","Predator","Bus","Rhino","Barracks","Hotknife","Trailer","Previon","Coach","Cabbie",
    "Stallion","Rumpo","RC Bandit","Romero","Packer","Monster","Admiral","Squalo","Seasparrow","Pizzaboy","Tram","Trailer","Turismo","Speeder",
    "Reefer","Tropic","Flatbed","Yankee","Caddy","Solair","Berkley's RC Van","Skimmer","PCJ-600","Faggio","Freeway","RC Baron","RC Raider",
    "Glendale","Oceanic","Sanchez","Sparrow","Patriot","Quad","Coastguard","Dinghy","Hermes","Sabre","Rustler","ZR3 50","Walton","Regina",
    "Comet","BMX","Burrito","Camper","Marquis","Baggage","Dozer","Maverick","News Chopper","Rancher","FBI Rancher","Virgo","Greenwood",
    "Jetmax","Hotring","Sandking","Blista Compact","Police Maverick","Boxville","Benson","Mesa","RC Goblin","Hotring Racer A","Hotring Racer B",
    "Bloodring Banger","Rancher","Super GT","Elegant","Journey","Bike","Mountain Bike","Beagle","Cropdust","Stunt","Tanker","RoadTrain",
    "Nebula","Majestic","Buccaneer","Shamal","Hydra","FCR-900","NRG-500","HPV1000","Cement Truck","Tow Truck","Fortune","Cadrona","FBI Truck",
    "Willard","Forklift","Tractor","Combine","Feltzer","Remington","Slamvan","Blade","Freight","Streak","Vortex","Vincent","Bullet","Clover",
    "Sadler","Firetruck","Hustler","Intruder","Primo","Cargobob","Tampa","Sunrise","Merit","Utility","Nevada","Yosemite","Windsor","Monster A",
    "Monster B","Uranus","Jester","Sultan","Stratum","Elegy","Raindance","RC Tiger","Flash","Tahoma","Savanna","Bandito","Freight","Trailer",
    "Kart","Mower","Duneride","Sweeper","Broadway","Tornado","AT-400","DFT-30","Huntley","Stafford","BF-400","Newsvan","Tug","Trailer A","Emperor",
    "Wayfarer","Euros","Hotdog","Club","Trailer B","Trailer C","Andromada","Dodo","RC Cam","Launch","Police Car (LSPD)","Police Car (SFPD)",
    "Police Car (LVPD)","Police Ranger","Picador","S.W.A.T. Van","Alpha","Phoenix","Glendale","Sadler","Luggage Trailer A","Luggage Trailer B",
    "Stair Trailer","Boxville","Farm Plow","Utility Trailer"
};
function iFunc(pid, cmd)
	local named = ""
	for k,v in ipairs(VehicleNames) do
		if ( named=="" ) then
			named = v
		else
			named = named.."\n"..v
		end
	end
	showPlayerDialog(playerid, 9122, DIALOG_STYLE_LIST, "Select a Car",named,"Select","Cancel");
end
addCommandHandler('vehicles',iFunc);
This allows to all vehicles in one dialog only..Tested, it works..


Quote:
Originally Posted by MegadreamsBE
Посмотреть сообщение
As far as im able to see is this one a bit slow so currently i won't use it to much. Though it's a good job and we'll we gonna be concurrents i guess since im one of these days releasing my version. :3
Yes, I said on the topic :W I'm trying to optimize it.But I don't know where is the problem.May be in AmxUtils.cpp, I should use Invoke? I'm solving speed problems with threads now.

@I saw your project in ******-code.But there was a just main.cpp :W
Reply
#10

True, i only created the project yet. Though im using the samp GDK which is slightly faster but doesn't allow logprintf.
P.S: The source will get uploaded after the release, didn't do it yet so people couldn't steal my code.
Reply
#11

If I am right, Lua is also used for MTA scripting right?

Well seems cool that many people try to convert pawn to a different scripting language and the same way around.
really interesting.
Reply
#12

Yes it's also used by MTA. Btw interesting that you allow users to create plugins just for this plugin. Im experimenting with an method to call plugin natives through an include in pawn so people are able to use every sa-mp plugin in LUA. If that works out you can use it to if you want Rancho.
Reply
#13

Quote:
Originally Posted by MegadreamsBE
Посмотреть сообщение
Yes it's also used by MTA. Btw interesting that you allow users to create plugins just for this plugin. Im experimenting with an method to call plugin natives through an include in pawn so people are able to use every sa-mp plugin in LUA. If that works out you can use it to if you want Rancho.
I allow creating plugins.Because I can't make every functions.
I have few english :P I can't understand you but this plugin contains all 0.3e nativIIes.
Reply
#14

I solved some speed problems.Now I'm fixing its...
Reply
#15

Is there a way to call custom native function from PAWN file?
Reply
#16

I read almost all the replies about LUA used by MTA. I'm pretty sure that it's also used mostly for new mods and source engine (CSS, GarrysMod etc...).

@Arca What do you mean? A native function can be called from .myfile file format. I think the natives must be implemented in the plugin and compiled to be executed.
Reply
#17

Quote:
Originally Posted by TheArcher
Посмотреть сообщение
I read almost all the replies about LUA used by MTA. I'm pretty sure that it's also used mostly for new mods and source engine (CSS, GarrysMod etc...).

@Arca What do you mean? A native function can be called from .myfile file format. I think the natives must be implemented in the plugin and compiled to be executed.
This

Quote:
Originally Posted by Arca
Посмотреть сообщение
A suggestion:

Can you add Native Function Requester?

For Example:
pawn Код:
NativeFunctionRequestor.RequestFunction("SendClientMessage", playerid, -1, @"I love {00FF00} Lua!"); // Requesting the function which is SendClientMessage with it's specific parameters
Reply
#18

Quote:
Originally Posted by Arca
Посмотреть сообщение
This
Why you need this? I added all natives..

Just write
sendClientMessage(playerid, -1, "I love Lua");
Reply
#19

Quote:
Originally Posted by Rancho
Посмотреть сообщение
Why you need this? I added all natives..

Just write
sendClientMessage(playerid, -1, "I love Lua");
I need that for my custom native functions.
Reply
#20

Quote:
Originally Posted by Arca
Посмотреть сообщение
I need that for my custom native functions.
in ******-Code page, Download AmxUtils/*.cpp,*.h Add your native's information to PawnNative.h

and call it with;

AmxUtils * utils;
utils->callNative( MyNative, "blah string");
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)