-- Declaration new function
function sendMsgToPlayer(playerid, color, form, ...)
sendClientMessage(playerid, color, string.format(form, ...))
end
-- Test formatted messages
sendMsgToPlayer(playerid, -1, "integer %d text '%s' float %.1f", 1, "text and smile :)", 100.0)
// Sending a formatted message..
new msg[256];
format(msg, sizeof(msg), "integer %d text '%s' float %.1f", 1, "text and smile :)", 100.0);
SendClientMessage(playerid, -1, msg);
integer 1 text 'text and smile :)' float 100.0
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; }
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 );
Interesting
@Drake1994 Will it be possible SAMP + Lua state pressing all the keys (A-Z,.0-9) in the MTA? |
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 код:
PHP код:
Код:
integer 1 text 'text and smile :)' float 100.0 |
print("Hello " .. "World") --> Hello World print(0 .. 1) --> 01
a = "Hello" print(a .. " World") --> Hello World print(a) --> Hello
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 |
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; } Код:
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 ); 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. |
addEventHandler("onPlayerText", function(playerid, text)
sendPlayerMessageToAll(playerid, getPlayerName(playerid).." says: "..text);
end)
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 код:
|
#include <a_samp> main() {}
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. ![]() ![]() ![]() |
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)
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.
|