SA-MP Forums Archive
[Plugin] Lua in SA-MP v0.1 (Alpha) - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Plugin Development (https://sampforum.blast.hk/forumdisplay.php?fid=18)
+--- Thread: [Plugin] Lua in SA-MP v0.1 (Alpha) (/showthread.php?tid=580092)

Pages: 1 2 3 4


Re: Lua in SA-MP v0.1 (Alpha) - Logofero - 26.08.2015

I like that it is offered as an alternative Pawn, but there is already a plugin allows you to work with Lua in the sа-mp.

Good job.

PS: Need a wiki will be even more popular

Add example:
I agree it is nice (LUA):
PHP код:
-- Declaration new function
function 
sendMsgToPlayer(playeridcolorform, ...)
    
sendClientMessage(playeridcolorstring.format(form, ...))
end
-- Test formatted messages
sendMsgToPlayer
(playerid, -1"integer %d text '%s' float %.1f"1"text and smile :)"100.0
what is so (PAWNO):
PHP код:
// Sending a formatted message..
new msg[256];
format(msgsizeof(msg), "integer %d text '%s' float %.1f"1"text and smile :)"100.0);
SendClientMessage(playerid, -1msg); 
And the result is the same in chat:
Код:
integer 1 text 'text and smile :)' float 100.0



Re: Lua in SA-MP v0.1 (Alpha) - SkittlesAreFalling - 28.08.2015

3 Things please:
You need to add:
BitAnd
bitNot
bitOr
BitXor
bitLshift
bitRshift
bitARshift
(look them up at MTA wiki/utility functions)
bitTest (optional: just uses bitAnd ~= 0)

Because Lua does not support the bitmask/bitwise operators: | & ^ ~ >> << >>>

(We will not be able to easily detect player key presses until you add those.)
https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange

-- ------------------------------------------------------------------------------------------------------------------------------------
Код:
LUA_FUNCTION lua_HTTP(lua_State *L)
{
	int index;
	int type;
	std::string url;
	std::string data;
	//std::string callback;

	ArgReader argReader(L);
	argReader.ReadNumber(index);
	argReader.ReadNumber(type);
	argReader.ReadString(url);
	argReader.ReadString(data);
	//argReader.ReadString(callback);

	bool success = HTTP(index, type, url.c_str(), data.c_str());
	lua_pushboolean(L, success);

	return 1;
}
Can you make the "callback" a function for me that pushes the arguments returned, so I can do:
Код:
lua_HTTP(0, "www.example.com", HTTP_POST, "request=Hello world!", 
	function(index, responseCode, data) 
		if responseCode == 404 then
			print("HTTP response: 404 Page not found!");
		elseif responseCode == 400 then
			print("HTTP response: " .. data);
		end
	end
);
https://sampwiki.blast.hk/wiki/HTTP

It would be very helpful to me

-- -----------------------------------------------------------------------------------------------------------------------------------------

That socket module I PM'ed you the other day.

-- -----------------------------------------------------------------------------------------------------------------------------------------

My only wishes for this, I would add them if I knew exactly how to (maybe make a tutorial for me on how to add/remove functions (I know C++)) xD
I'm thankful if you do. Good work.


Re: Lua in SA-MP v0.1 (Alpha) - Logofero - 28.08.2015

Interesting

@Drake1994
Will it be possible SAMP + Lua state pressing all the keys (A-Z,.0-9) in the MTA?


Re: Lua in SA-MP v0.1 (Alpha) - SkittlesAreFalling - 28.08.2015

Quote:
Originally Posted by Logofero
Посмотреть сообщение
Interesting

@Drake1994
Will it be possible SAMP + Lua state pressing all the keys (A-Z,.0-9) in the MTA?
No, the keys detected are defined by the user's client, SA-MP has no intention on changing them or adding more. Kye has made that perfectly clear.


Re: Lua in SA-MP v0.1 (Alpha) - Rancho - 29.08.2015

Quote:
Originally Posted by Logofero
Посмотреть сообщение
I like that it is offered as an alternative Pawn, but there is already a plugin allows you to work with Lua in the sа-mp.

Good job.

PS: Need a wiki will be even more popular

Add example:
I agree it is nice (LUA):
PHP код:
-- Declaration new function
function 
sendMsgToPlayer(playeridcolorform, ...)
    
sendClientMessage(playeridcolorstring.format(form, ...))
end
-- Test formatted messages
sendMsgToPlayer
(playerid, -1"integer %d text '%s' float %.1f"1"text and smile :)"100.0
what is so (PAWNO):
PHP код:
// Sending a formatted message..
new msg[256];
format(msgsizeof(msg), "integer %d text '%s' float %.1f"1"text and smile :)"100.0);
SendClientMessage(playerid, -1msg); 
And the result is the same in chat:
Код:
integer 1 text 'text and smile :)' float 100.0
Actually you dont need to format the string. LUA has support for string-concatenation.

Код:
print("Hello " .. "World")  --> Hello World
print(0 .. 1)               --> 01
Код:
a = "Hello"
print(a .. " World")   --> Hello World
print(a)               --> Hello



Re: Lua in SA-MP v0.1 (Alpha) - Logofero - 29.08.2015

Quote:
Originally Posted by Rancho
Посмотреть сообщение
Actually you dont need to format the string. LUA has support for string-concatenation.

Код:
print("Hello " .. "World")  --> Hello World
print(0 .. 1)               --> 01
Код:
a = "Hello"
print(a .. " World")   --> Hello World
print(a)               --> Hello
Yes, but in some cases where it is necessary to glue the line, but where you want to format and display a sequence of variables as the message. My example clearly - Because it is more convenient to use the scheme to which most are used to: sendToPlayer(playerid, color, "arg %d arg %f", var1, var2) and not sendToPlayer(playerid, color, "arg " .. var1 .. "arg " .. var2)

PS: I was always comfortable working with a formatted string. So I can store/transmit "format" apart from the arguments.


Re: Lua in SA-MP v0.1 (Alpha) - Drake1994 - 29.08.2015

Quote:
Originally Posted by SkittlesAreFalling
Посмотреть сообщение
3 Things please:
You need to add:
BitAnd
bitNot
bitOr
BitXor
bitLshift
bitRshift
bitARshift
(look them up at MTA wiki/utility functions)
bitTest (optional: just uses bitAnd ~= 0)

Because Lua does not support the bitmask/bitwise operators: | & ^ ~ >> << >>>

(We will not be able to easily detect player key presses until you add those.)
https://sampwiki.blast.hk/wiki/OnPlayerKeyStateChange

-- ------------------------------------------------------------------------------------------------------------------------------------
Код:
LUA_FUNCTION lua_HTTP(lua_State *L)
{
	int index;
	int type;
	std::string url;
	std::string data;
	//std::string callback;

	ArgReader argReader(L);
	argReader.ReadNumber(index);
	argReader.ReadNumber(type);
	argReader.ReadString(url);
	argReader.ReadString(data);
	//argReader.ReadString(callback);

	bool success = HTTP(index, type, url.c_str(), data.c_str());
	lua_pushboolean(L, success);

	return 1;
}
Can you make the "callback" a function for me that pushes the arguments returned, so I can do:
Код:
lua_HTTP(0, "www.example.com", HTTP_POST, "request=Hello world!", 
	function(index, responseCode, data) 
		if responseCode == 404 then
			print("HTTP response: 404 Page not found!");
		elseif responseCode == 400 then
			print("HTTP response: " .. data);
		end
	end
);
https://sampwiki.blast.hk/wiki/HTTP

It would be very helpful to me

-- -----------------------------------------------------------------------------------------------------------------------------------------

That socket module I PM'ed you the other day.

-- -----------------------------------------------------------------------------------------------------------------------------------------

My only wishes for this, I would add them if I knew exactly how to (maybe make a tutorial for me on how to add/remove functions (I know C++)) xD
I'm thankful if you do. Good work.
For some reason in the sampgdk the callback paramter is deprecated, so HTTP will call OnHTTPResponse everytime (but unfortunately I forgot to add to calling that event, but later I will fixed it).

As I said if I have some free time I'll trying to make a wiki for it (or if somebody have time for that then feel free to make it ) , plus add some feature (bit manipulation, mysql/sqlite functions, start/stop resources, etc).


Re: Lua in SA-MP v0.1 (Alpha) - YuKki1 - 30.08.2015

That's good


Re: Lua in SA-MP v0.1 (Alpha) - MD15 - 30.08.2015

I support this project and will use it actively as Lua is a more efficient and flexible language for rapidly deploying scripts and modes.

I have to point out a bug though which I am not sure if it is a problem with the plugin, samp-gdk, or SA-MP's AMX plugin architecture.

When you stop a resource and start a new one, it will not wipe any skins added from AddPlayerClass and will just add on to the list. Slightly same behavior if you do the 'gmx' command.

The way around this I have found is to stop the resource first, and then issue 'gmx'. I believe it is possible to automate this using a pawn script to issue these commands via rcon.

Also, is it possible MTA's Lua XML wrapper will be implemented? It is very useful.

Thanks.


Re: Lua in SA-MP v0.1 (Alpha) - Inn0cent - 31.08.2015

Wow.. That kinda am, nice.


Re: Lua in SA-MP v0.1 (Alpha) - IllidanS4 - 18.11.2015

May you please explain these "security reasons" for disabling dofile etc.?


Re: Lua in SA-MP v0.1 (Alpha) - Leka74 - 04.12.2015

Any idea why I'm getting "----------------------------------" from the inputtext variable when trying to grab the password via the onDialogResponse event? It returns that no matter what I type in the input. (https://sampwiki.blast.hk/wiki/OnDialogResponse)

EDIT: Having the same problem with the onPlayerText event. text is always returned as the dashed line as mentioned above. Any idea why?

Here's the code:
PHP код:
addEventHandler("onPlayerText", function(playeridtext)
    
sendPlayerMessageToAll(playeridgetPlayerName(playerid).." says: "..text);
end



Re: Lua in SA-MP v0.1 (Alpha) - SkittlesAreFalling - 05.12.2015

Quote:
Originally Posted by Leka74
Посмотреть сообщение
Any idea why I'm getting "----------------------------------" from the inputtext variable when trying to grab the password via the onDialogResponse event? It returns that no matter what I type in the input. (https://sampwiki.blast.hk/wiki/OnDialogResponse)

EDIT: Having the same problem with the onPlayerText event. text is always returned as the dashed line as mentioned above. Any idea why?

Here's the code:
PHP код:
addEventHandler("onPlayerText", function(playeridtext)
    
sendPlayerMessageToAll(playeridgetPlayerName(playerid).." says: "..text);
end
I do not get that problem, it must be something you are doing. PM me for help if you want it.


Re: Lua in SA-MP v0.1 (Alpha) - Leka74 - 05.12.2015

In case anyone has the same issue as the one above, make sure you create a new gamemode with the following code:
Код:
#include <a_samp>

main() {}
I was using the 'bare' gamemode and that's where the issue was coming from.

Thanks to SkittlesAreFalling for helping me out.


Re: Lua in SA-MP v0.1 (Alpha) - SkittlesAreFalling - 17.12.2015

Best way to learn Lua: https://www.youtube.com/watch?v=iMacxZQMPXs


Re: Lua in SA-MP v0.1 (Alpha) - Leka74 - 17.12.2015

I've written couple of scripts using this plugin to test it around and gotta say it's pretty great so far. Lua is pretty easy and light so it is very useful for people who find Pawn difficult or complicated.

Here are two of the scripts if anyone is interested in looking around:

Realistic bug/mole script for roleplay servers: http://pastebin.com/jSA71wAS

Quote:

Commands
/joinfrequency [frequency] [password] - joins a frequency
/leavefrequency [frequency] - leaves a frequency
/listfrequencies - shows the frequencies that you are in (only 3 slots available)

/placebug [frequency] [reference] - places a bug
/removebug [frequency] [bug id] - removes bug
/checkbug - checks in the vicinity if there is any bug, if there is it only displays its ID
/listbugs [frequency] - lists the bugs in the frequency, their bug IDs and references.






Realistic time interpolation for roleplay servers: http://pastebin.com/zPHDDCR4


Re: Lua in SA-MP v0.1 (Alpha) - PaulDinam - 18.12.2015

For some reason, math. functions don't seem to work properly. Or specifically, math.random.

EDIT: nevermind, figured out you need to call a seed before using it.


Re: Lua in SA-MP v0.1 (Alpha) - PaulDinam - 19.12.2015

Textdraws have a problem as well, would be nice if you could fix it; I converted my pawn gamemode to Lua completely but the textdraws are the only issue.


pawn Код:
addEventHandler("onScriptInit", function()

    for i=1,MAX_COMMANDS do
        Commands[i] = {}
        Commands[i].Command = "invalid"
    end

    dbHandle = mysql_connect("localhost", "root", "", "cop")
    if ( not dbHandle ) then
      print("\n\nUnable to connect to the MySQL server\n")
    else
      print("\n\nMySQL connection has been made\n")
    end
   
    LoadServerInfo()
   
    disableInteriorEnterExits()
    allowInteriorWeapons(false)
    enableStuntBonusForAll(false)
    showPlayerMarkers(false)
    setNameTagDrawDistance(25.0)
   
    playerTD = textDrawCreate(133.233703, 328.633453, "");
    textDrawLetterSize(playerTD, 0.315666, 0.952889);
    textDrawAlignment(playerTD, 1);
    textDrawColor(playerTD, -1);
    textDrawSetShadow(playerTD, 1);
    textDrawSetOutline(playerTD, 0);
    textDrawBackgroundColor(playerTD, 255);
    textDrawFont(playerTD, 1);
    textDrawSetProportional(playerTD, 1);
    textDrawSetShadow(playerTD, 1);
    textDrawSetString(playerTD, "");
   
    ---------------------- [Timers] --------------------------
    secondTimer = setTimer(1000, true, function()
        SecondUpdate()
    end);
end)

addEventHandler("onScriptExit", function()
    killTimer(secondTimer);
end);

function SecondUpdate()
    local playerList

    for i=0, getPlayerPoolSize() do
        if (isPlayerConnected(i)) then

            if (getPlayerPoolSize() == 0) then
                playerList = string.format("~b~%s [%d]~n~", Player[i].NameEx, i)
                textDrawSetString(playerTD, playerList)
            else
                playerList = string.format("%s~b~%s [%d]~n~", playerList, Player[i].NameEx, i)
                textDrawSetString(playerTD, playerList)
            end

            if (Player[i].showSide ~= nil) then
                if (Player[i].showSide > 0) then
                    Player[i].showSide = Player[i].showSide - 1;
                    if (Player[i].showSide == 0) then
                        playerTextDrawHide(i, Player[i].sideText);
                    end
                end
            end
        end
    end
end

function showText(playerid, text, seconds)
    Player[playerid].showSide = seconds
    playerTextDrawSetString(playerid, Player[playerid].sideText, text)
    playerTextDrawShow(playerid, Player[playerid].sideText)
end

addEventHandler("onPlayerConnect", function(playerid)
    showPlayerDialog(playerid, -1, 0, " ", " ", " ", " ");
    Player[playerid] = {}
    setPlayerColor(playerid, tocolor(COLOR_WHITE))
    Player[playerid].NameEx = string.gsub(getPlayerName(playerid), "_", " ", 1)
   
    Player[playerid].sideText = createPlayerTextDraw(playerid, 30.000041, 276.563079, "");
    playerTextDrawLetterSize(playerid, Player[playerid].sideText, 0.299666, 1.147850);
    playerTextDrawAlignment(playerid, Player[playerid].sideText, 1);
    playerTextDrawColor(playerid, Player[playerid].sideText, -1);
    playerTextDrawSetShadow(playerid, Player[playerid].sideText, 1);
    playerTextDrawSetOutline(playerid, Player[playerid].sideText, 0);
    playerTextDrawBackgroundColor(playerid, Player[playerid].sideText, 255);
    playerTextDrawFont(playerid, Player[playerid].sideText, 1);
    playerTextDrawSetProportional(playerid, Player[playerid].sideText, 1);
    playerTextDrawSetShadow(playerid, Player[playerid].sideText, 1);
    playerTextDrawSetString(playerid, Player[playerid].sideText, "");
end)



Re: Lua in SA-MP v0.1 (Alpha) - Drake1994 - 19.12.2015

Well, to tell the truth I no longer updating the plugin (because I thought nobody use it) and I already give this project away to SkittlesAreFalling. He will updating the project but his plugin is not released yet.


Re: Lua in SA-MP v0.1 (Alpha) - PaulDinam - 19.12.2015

Quote:
Originally Posted by Drake1994
Посмотреть сообщение
Well, to tell the truth I no longer updating the plugin (because I thought nobody use it) and I already give this project away to SkittlesAreFalling. He will updating the project but his plugin is not released yet.
This plugin is great, I hope he'll release it soon.