-
Posts
1,143 -
Joined
-
Last visited
-
Days Won
43
Everything posted by Patrick
-
--Table playersT = {} --Code function isNicknameAlreadyAdded(nickname) for k, v in ipairs(playersT) do if v == nickname then return true -- found it, stop and return true end end return false -- nickname not found in playersT, return false end addEventHandler("onPlayerConnect", root, function(nickname) local alreadyAdded = isNicknameAlreadyAdded(nickname) if not alreadyAdded then -- some code end end)
-
In this case, it works well if it do nothing. Because you can't loop the nothing.
-
What is inside playersT?
-
Try to sync table, something like this: -- SHARED local thisIsClientSide = isElement(localPlayer) -- it returns true if script running on client side and localPlayer defined local t = {} function f(i, v) print((thisIsClientSide and "Client:" or "Server:").." f => i:"..i..", v:"..v) -- debug t[i] = v -- send sync to different side if not source then -- if source is exists, don't need to send back to different side, because we got it from there (otherwise we would make a loop) if thisIsClientSide then triggerServerEvent("f:sync", resourceRoot, i, v) else triggerClientEvent("f:sync", resourceRoot, i, v) end end end addEvent("f:sync", true) addEventHandler("f:sync", root, f)
-
Something like this local location_ls = {"Vinewood", "Marina", "Mulholland"} function isPlayerInSpecifiedZone(player) local x, y, z = getElementPosition(player) local zoneName = getZoneName(x, y, z) for _, v in ipairs(location_ls) do if v == zoneName then return true end end return false end
-
No, it's just a pattern. You need to be able to do it based on that.
-
https://wiki.multitheftauto.com/wiki/GetZoneName local x, y, z = getElementPosition(player) local zoneName = getZoneName(x, y, z, true) -- only the city's name if zoneName == "Los Santos" then ... end
-
send the full code dude, its not enough info
-
http://www.Lua.org/manual/5.1/manual.html#pdf-string.match Do you want to check is v not equals player's name? If yes, you need to do something like this: for k, v in ipairs(accounts) do if v ~= getPlayerName(player) then -- if v not equals player's name --some code end end
-
Only english posts in this forum section. And please try to search before you post.
- 3 replies
-
- portuguese
- Lua
-
(and 1 more)
Tagged with:
-
Welcome
-
Its cant be always 1 if you use auto increment in correct way.
-
Why need textID? Use Auto Increment, it's the easiest and best way. Helps https://www.youtube.com/watch?v=pzGMAkqRtAI https://stackoverflow.com/questions/5665571/auto-increment-in-phpmyadmin
-
https://wiki.multitheftauto.com/wiki/DbExec You need to use dbQuery with callback. -- Something like this local function createtext(player,cmd,textID,...) if GetElementData(player,"AdminLvl", 5) then local text = table.concat( { ... }, " " ) local x, y, z = getElementPosition( player ) dbQuery(function(qh) -- callback function local result, inserted_rows, lastinsertedid = dbPoll(qh, 0) if lastinsertedid then loadText( lastinsertedid, text, x, y, z, getElementInterior( player ), getElementDimension( player ) ) outputChatBox( "Text created. (ID " .. lastinsertedid .. ")", player, 0, 255, 0 ) else outputDebugString( e ) outputChatBox( "Error MYSQL.", player, 255, 0, 0 ) end end, handler, "INSERT INTO `3dtext`(`text`, `x`, `y`, `z`, `interior`, `dimension`) VALUES (?,?,?,?,?,?)", text, x, y, z, getElementInterior( player ),getElementDimension( player ) ) else outputChatBox( "Command: /" .. cmd .. " [text]", player, 255, 255, 255 ) end end addCommandHandler("createtext",createtext)
-
Do you want to disable camera distance adjustment? What do you set with the V button?
-
https://wiki.multitheftauto.com/wiki/SetCameraViewMode https://wiki.multitheftauto.com/wiki/GetCameraViewMode -- CLIENT bindKey("change_camera", "up", function() setCameraViewMode(2) -- change back to normal end)
-
The first 4 args are same as dxDrawImage, its absolute x, y, width and height. The position on your screen, where you want to render the image section. The 5-8th args are the coordinates of the image section. If you have a 500x500px image and you want to render the left top corner of the image (50x50px section) on center of your screen: local sx, sy = guiGetScreenSize() dxDrawImageSection( sx/2-75/2, sy/2-75/2, 75, 75, -- the position on the screen 0, 0, 50, 50, -- coordinates of the section. "image.png" ) Hungarian: Első négy argument az a dxDrawImage-hez hasonlóan a kép pozíciója a képernyődön Viszont a 5-8. argumentet már magán a képen belül kell nézned, a képrészlet amit ki szeretnél vágni. Ha van egy 500x500 pixeles képed aminek a bal felső sarkát szeretnéd kivágni (egy 50x50 pixeles négyzetet), akkor fenti kódrészletben látod mit kell tenned. Természetesen ha egy 50x50 pixeles képed vágsz ki attól renderelheted nagyobb méretben, csak romlani fog a minősége, ahogy fent is csináltam.
-
It speeds up everything, but maybe helps: https://wiki.multitheftauto.com/wiki/SetGameSpeed
-
https://wiki.multitheftauto.com/wiki/OnResourceStop Its log when the resource stops, make a new resource only for this code. local filePath = "shutdown.log" -- log file path addEventHandler("onResourceStop", resourceRoot, function() -- call this function at resource stop -- logfile not found, create it first. if not fileExists(filePath) then fileCreate(filePath) end -- get the current datetime and make the new line what we want to insert end of the file local DateTime = getRealTime() DateTime.year = DateTime.year + 1900 DateTime.month = DateTime.month + 1 local timeString = ("%d-%02d-%02d %02d:%02d:%02d"):format(DateTime.year, DateTime.month, DateTime.monthday, DateTime.hour, DateTime.minute, DateTime.second) local newLine = "["..timeString.."] Server shutdown!" -- open file local file = fileOpen(filePath) local fileSize = fileGetSize(file) -- length of text in file fileSetPos(file, fileSize) -- move cursor the end of the file (because we want to write to the end of the file) fileWrite(file, newLine.."\n") -- add the new line with linebreak on the end fileClose(file) -- close the file (save) end)
-
Because you leave from function with return before break. function findPlayerKey(player) for k, v in pairs(joinedPlayers) do if v[1] == player then return k -- return key if player found end end return false -- return false at and of the function if player not found end
-
PHP Mail sending: https://www.php.net/manual/en/function.mail.php PHP GET requests: https://www.php.net/manual/en/reserved.variables.get.php MTA fetchRemote: https://wiki.multitheftauto.com/wiki/FetchRemote PHP CODE <?php if ($_SERVER["REQUEST_METHOD"] != "GET") die("Wrong request method."); // allow only GET requests. // READ VALUES FROM URL (the GET request's values) if (!isset($_GET["api_key"])) die("Value 'api_key' missing."); $api_key = $_GET["api_key"]; if (!isset($_GET["email"])) die("Value 'email' missing."); $email = $_GET["email"]; if (!isset($_GET["subject"])) die("Value 'subject' missing."); $subject = $_GET["subject"]; if (!isset($_GET["message"])) die("Value 'message' missing."); $message = $_GET["message"]; // CHECK IS API KEY ALLOWED? $allowed_api_keys = array("a5BNx7hspRZ5dWJ30", "q9bXRAawamr5K5ab"); // ... list of allow keys if (!in_array($api_key, $allowed_api_keys)) die("Wrong api key! (".$api_key.")"); // SEND THE EMAIL $headers = array( 'From' => '[email protected]', // replace 'Reply-To' => '[email protected]', // replace 'X-Mailer' => 'PHP/' . phpversion() ); if (mail($email, $subject, $message, $headers)) { die("Email sent to '".$email."'"); } else { die("Failed to send email '".$email."'"); } ?> And now, you only need to call this php file with values. Example: http://YOURDOMAIN.COM/email_api.php?api_key=a5BNx7hspRZ5dWJ30&[email protected]&subject=subject_text&message=message_text And you can call from MTA with fetchRemote: fetchRemote( "http://YOURDOMAIN.COM/email_api.php?api_key=a5BNx7hspRZ5dWJ30&[email protected]&subject=subject_text&message=message_text", function (response, errno) if (errno == 0) then print("fetchRemote success"); else print("fetchRemote failed. (error: "..errno..")"); end end );
-
You need to create a 'email api' on a webserver. And you need to call this api from MTA with fetchRemote.
-
addCommandHandler("give", function(player, cmd, ...) local args = {...} -- example: bot 7777 robot 8888 unknown 9999 -- we know: every 2th arg is the amount local args_count = #args if args_count < 2 or args_count % 2 ~= 0 then return outputChatBox("USE: /"..cmd.." [name amount ... name amount]", player) end -- minimum need 2 argument -- loop datas for i = 0, args_count/2-1 do local name = args[i*2+1] local amount = tonumber(args[i*2+2]) if amount and amount > 0 then local target_player = getPlayerFromPartialName(name) if isElement(target_player) then outputChatBox(amount .. " gived to " .. getPlayerName(target_player), player) else outputChatBox("Player " .. name .. " not found.", player) end else outputChatBox("Invalid amount '"..(args[i*2+2]).."' for "..name, player) end end end) -- https://wiki.multitheftauto.com/wiki/GetPlayerFromPartialName function getPlayerFromPartialName(name) local name = name and name:gsub("#%x%x%x%x%x%x", ""):lower() or nil if name then for _, player in ipairs(getElementsByType("player")) do local name_ = getPlayerName(player):gsub("#%x%x%x%x%x%x", ""):lower() if name_:find(name, 1, true) then return player end end end end
