Lua scripts for samp r4 servers

Warklot

Известный
Автор темы
112
3
Версия MoonLoader
Другое
Hello , is there some tutorials or something to learn to write scripts without sampfuncs? for samp r4 servers
 

horacy

Известный
110
96
Hello , is there some tutorials or something to learn to write scripts without sampfuncs? for samp r4 servers
Without sampfuncs, you can write with a memory module, you can write in both lua and cleo but I think lua is better because of its mobility and ease of understanding the code.
For example, I can tell you how I wrote a function for 0.3dl that gets the nickname from the player id. The function is not mine, I just rewritten it from cleo to lua. (you will have to learn this because a lot of code snippets are in cleo)

:GetPlayerNameByID
{
0.3.DL
0AC8: 0@ = allocate_memory_size 1024
0AB1: @GetPlayerNameByID 1 ID 995 _Returned: Name 0@
}
if 0AA2: 10@ = loadLib "samp.dll" //samp base offset
then
10@ += 0x2ACA24
0A8D: 10@ = readmem 10@ sz 4 vp 0 //stInfo
10@ += 0x3DE
0A8D: 10@ = readmem 10@ sz 4 vp 0 //stPools
10@ += 0x8
0A8D: 10@ = readmem 10@ sz 4 vp 0 //stPlayerPools
10@ += 0x26
0@ *= 0x4
005A: 10@ += 0@
0A8D: 10@ readMem 10@ sz 4 vp 0
if 10@ > 0
then
10@ += 0x14
0A8D: 11@ readMem 10@ sz 4 vp 0
11@ += 0x0
0A8D: 26@ = readmem 0x8580DC sz 4 vp 0 // 0x8580DC - KERNEL32.lstrlenA
0AA7: strlen_addr 26@ num_params 1 pop 0 string 11@ _returned_length 25@
if 25@ > 0
then 0AB2: ret 1 11@
else 0AB2: ret 1 10@
end
end
end
0AB2: ret 0

local memory = require 'memory'

function test()
--name(id)
name(995)
end

function name(samp0)
samp10 = getModuleHandle('samp.dll')
samp10 = samp10 + 0x2ACA24
samp10 = readMemory(samp10, 4, false)
samp10 = samp10 + 0x3DE
samp10 = readMemory(samp10, 4, false)
samp10 = samp10 + 0x8
samp10 = readMemory(samp10, 4, false)
samp10 = samp10 + 0x26
samp0 = samp0 * 0x4
samp10 = samp10 + samp0
samp10 = readMemory(samp10, 4, false)
if samp10 > 0 then
samp10 = samp10 + 0x14
samp11 = readMemory(samp10, 4, false)
samp11 = samp10 + 0x0

samp26 = readMemory(0x8580DC, 4, false)
samp25 = callFunction(samp26, 1, 0, samp11)
if samp25 > 0 then
str = memory.tostring(samp11, samp25, false)
nick = str
--dl.AddMessageToChat(4, "lenght: "..samp25, "", 0xFFFFFF, 0xFFFFFF) This samp api(only 0.3dl/0.3.7) module but you can addmessage in memory
--dl.AddMessageToChat(4, "address: "..samp11, "", 0xFFFFFF, 0xFFFFFF)
else
--dl.AddMessageToChat(4, "error: "..samp10, "", 0xFFFFFF, 0xFFFFFF)
end
end
end

Of course it is not easy at first, before I rewritten this function correctly there were many attempts due to my poor knowledge of cleo. So you need to know the basics of cleo syntax and know lua well to rewrite functions. Once you have it, go to https://wiki.blast.hk/ru/moonloader/opcodes then click ctrl + f and enter the cleo opcode you are looking for and then you will find what code corresponds to this opcode in lua.
eg opcode 0001 in lua is 'wait'. And so you convert every cleo opcode to lua code.
Here you will find functions for samp 0.3.7-r4 and much more https://ugbase.eu/threads/some-snippets.20983/
 
  • Нравится
Реакции: Warklot