Last active
October 10, 2023 04:37
-
-
Save AmyrAhmady/898bcafca0034bf293e63f73774b2035 to your computer and use it in GitHub Desktop.
a simple js qr code for samp-node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qrcode from "qrcode-generator"; | |
async function generateQRCodeForSamp(context) { | |
let typeNumber = 4; | |
let errorCorrectionLevel = 'L'; | |
let qr = qrcode(typeNumber, errorCorrectionLevel); | |
qr.addData(context); | |
qr.make(); | |
let newQRCode = ""; | |
let QRLines = qr.createASCII().split("\n"); | |
await QRLines.map((line, index) => { | |
let string1 = ""; | |
let string2 = "\n"; | |
for (let i = 0; i < line.length; i++) { | |
if (line.charAt(i) == "█") { | |
string1 += 'g'; | |
string2 += 'g'; | |
} else if (line.charAt(i) == "▄") { | |
string1 += 'c'; | |
string2 += 'g'; | |
} | |
else if (line.charAt(i) == "▀") { | |
string1 += 'g'; | |
if (QRLines.length - 1 != index) | |
string2 += 'c'; | |
} | |
else if (line.charAt(i) == " ") { | |
string1 += 'c'; | |
string2 += 'c'; | |
} | |
} | |
newQRCode += "\n" + string1 + string2; | |
}) | |
return newQRCode; | |
} | |
samp.on(EVENT_PLAYER_COMMAND, async (playerid, cmdtext) => { | |
if (cmdtext == "/qrobj") { | |
const qrcode = await generateQRCodeForSamp("lmaoooo"); | |
const out = samp.callNative("GetPlayerPos", "iFFF", playerid); | |
const pos = { | |
x: out[0], | |
y: out[1], | |
z: out[2] | |
}; | |
const objectid = samp.callNative("CreateObject", "ifffffff", 19371, pos.x + 1, pos.y + 1, pos.z + 1, 0, 0, 0, 300); | |
samp.callNative("SetObjectMaterialText", "isiisiiiii", objectid, qrcode, 0, 100, "Webdings", 6, 1, 0xFFFFFFFF, 0xFF000000, 1); | |
} | |
}) |
Author
AmyrAhmady
commented
Apr 2, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment