Skip to content

Commit aed02c4

Browse files
committed
example
Код который поможет новичкам понять как использовать данный API.
1 parent 27e67f4 commit aed02c4

6 files changed

Lines changed: 136 additions & 0 deletions

File tree

example/ClearChat/ClearChat.lua

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
script_name("ClearChat")
2+
script_version("v1.0")
3+
script_authors("Tim4ukys")
4+
script_dependencies("SA-MP v0.3.7 R1", "SA-MP v0.3.7 R3-1", "SA-MP v0.3.DL R1")
5+
6+
local dl = require( 'SA-MP API.init' )
7+
local ffi = require( 'ffi' )
8+
9+
function ClearEntry(kolvo)
10+
local m_pChat = dl.Get().pChat
11+
for i = 99, 100 - kolvo, -1 do
12+
local this = m_pChat.chatEntry[i]
13+
this.SystemTime = 0
14+
this.szPrefix = ffi.new("char[28]", "\0")
15+
this.szText = ffi.new("char[144]", "\0")
16+
this.iType = 0
17+
this.clTextColor = 0
18+
this.clPrefixColor = 0
19+
20+
end
21+
m_pChat.m_iRedraw = ffi.cast("int", 1)
22+
end
23+
24+
function cmdChatClear(param)
25+
local kolvoEntry = tonumber(ffi.string(param))
26+
if kolvoEntry ~= nil and kolvoEntry >= 1 and kolvoEntry <= 100 then
27+
ClearEntry(kolvoEntry)
28+
else
29+
ClearEntry(100)
30+
end
31+
end
32+
33+
function main()
34+
while not dl.GetIsAvailable() do
35+
wait(0)
36+
end
37+
38+
dl.RegisterClientCommand("cclear", cmdChatClear, true)
39+
40+
wait(-1)
41+
end

example/ClearChat/README.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Clear Chat
2+
Это LUA скрипт, который очищает чат по команде '/cclear'
3+
4+
<p align="center"><img src="https://i.imgur.com/UMxCZBW.png" height="275px" /> <img src="https://i.imgur.com/EqOBNCb.png" height="275px"/></p>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
script_name("GetTextdrawText")
2+
script_version("v1.0")
3+
script_authors("Tim4ukys")
4+
script_dependencies("SA-MP v0.3.7 R1", "SA-MP v0.3.7 R3-1", "SA-MP v0.3.DL R1")
5+
6+
local dl = require "SA-MP API.init"
7+
local ffi = require( 'ffi' )
8+
9+
function main()
10+
while not dl.GetIsAvailable() do
11+
wait(0)
12+
end
13+
14+
for i=0, 2048 do
15+
local textdrawText = ffi.string(dl.TextdrawGetString(i))
16+
17+
if textdrawText ~= '' then
18+
print('ID: ' .. i .. ' | ' .. textdrawText)
19+
end
20+
end
21+
end

example/GetTextdrawText/README.MD

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Get Textdraw Text
2+
Это LUA скрипт, который выводит в log Moonloader текст всех текстдравов которые есть.
3+
4+
<p align="center"><img src="https://i.imgur.com/sLUVyji.png" height="275px" /> <img src="https://i.imgur.com/1JWuGkq.png" height="275px"/></p>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## Set Time and Weather
2+
Это LUA скрипт, который даёт возможность менять время и погоду в SA-MP.
3+
4+
<p align="center"><img src="https://i.imgur.com/gd9ay9r.png" height="275px" /> <img src="https://i.imgur.com/t1tVdvP.png" height="275px"/></p>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
script_name("SetTimeAndWeather")
2+
script_description("/set_weather(/sw) - change weather, /set_time(/st) - change time")
3+
script_version("v1.0")
4+
script_authors("Tim4ukys")
5+
script_dependencies("SA-MP v0.3.7 R1", "SA-MP v0.3.7 R3-1", "SA-MP v0.3.DL R1")
6+
7+
local dl = require "SA-MP API.init"
8+
local ffi = require( 'ffi' )
9+
10+
local encoding = require 'encoding'
11+
encoding.default = 'UTF-8'
12+
cp1251 = encoding.CP1251
13+
14+
function cmdSetTime(param)
15+
local hour = tonumber(ffi.string(param))
16+
if hour ~= nil and hour >= 0 and hour <= 23 then
17+
18+
local this = dl.Get().pBase.pSettings
19+
20+
this.byteWorldTime_Hour = ffi.cast("unsigned char", hour)
21+
22+
local textbuff = string.format(cp1251"[{FF9900}SetTime{990000}] {FF9900}Новое время {990000}- {FF9900}%02d:00{990000}!", hour)
23+
-- print(textbuff)
24+
dl.AddMessageToChat(8, ffi.new("char[" .. string.len( textbuff ) .. "]", textbuff), nullptr, 0x990000, 0)
25+
else
26+
dl.AddMessageToChat(8, cp1251"[{FF9900}SetTime{990000}] {FF9900}/set_time {606060}[0 - 23]", nullptr, 0x990000, 0)
27+
end
28+
end
29+
30+
function cmdSetWeather(param)
31+
local weather = tonumber(ffi.string(param))
32+
if weather ~= nil and weather >= 0 and weather <= 45 then
33+
34+
local this = dl.Get().pBase.pSettings
35+
36+
this.byteWeather = ffi.cast("unsigned char", weather)
37+
forceWeatherNow(weather)
38+
39+
local textbuff = string.format(cp1251"[{FF9900}SetWeather{990000}] {FF9900}Новая погода {990000}- {FF9900}%d{990000}!", weather)
40+
-- print(textbuff)
41+
dl.AddMessageToChat(8, ffi.new("char[" .. string.len( textbuff ) .. "]", textbuff), nullptr, 0x990000, 0)
42+
else
43+
dl.AddMessageToChat(8, cp1251"[{FF9900}SetWeather{990000}] {FF9900}/set_weather {606060}[0 - 45]", nullptr, 0x990000, 0)
44+
end
45+
end
46+
47+
function main()
48+
while not dl.GetIsAvailable() do
49+
wait(0)
50+
end
51+
dl.AddMessageToChat(8, cp1251"[{FF9900}SetTime&Weather{990000}] {FF9900}Lua скрипт инициализирован{990000}!", nullptr, 0x990000, 0)
52+
dl.AddMessageToChat(8, cp1251"Команды: {FF9900}/set_time{606060}(/st) {606060}| {FF9900}/set_weather{606060}(/sw)", nullptr, 0x990000, 0)
53+
dl.AddMessageToChat(8, cp1251"Автор: {FF9900}Tim4ukys {606060}| {990000}Ссылка: {FF9900}vk.com/petrov_team", nullptr, 0x990000, 0)
54+
55+
56+
dl.RegisterClientCommand("st", cmdSetTime, true)
57+
dl.RegisterClientCommand("set_time", cmdSetTime, true)
58+
dl.RegisterClientCommand("sw", cmdSetWeather, true)
59+
dl.RegisterClientCommand("set_weather", cmdSetWeather, true)
60+
61+
wait(-1)
62+
end

0 commit comments

Comments
 (0)