 |
|

01.12.2022, 18:24
|
|
Познавший АНТИЧАТ
Регистрация: 21.04.2021
Сообщений: 1,419
С нами:
2665578
Репутация:
168
|
|
Сообщение от Yuriy Code
samp_create_sync_data
функция будет работать?
нет по идее
|
|
|

01.12.2022, 18:25
|
|
Постоянный
Регистрация: 01.05.2021
Сообщений: 752
С нами:
2650753
Репутация:
98
|
|
Сообщение от lainban
нет по идее
Я о том, что тут же можно евенты подключить.
Может, так же с функцией получится?
|
|
|

02.12.2022, 15:33
|
|
Постоянный
Регистрация: 14.02.2018
Сообщений: 319
С нами:
4338525
Репутация:
98
|
|
почему из двух способов асинхронных запросов работает только один в onUnload()(117 строка)? тоесть при выгрузке скрипта отправляет только этот
asyncHttpRequest('GET', AnsiToUtf8(link.."%0Acrash"), nil, nil, nil)
Lua:
Код:
local
token
=
""
local
chat_id
=
""
local
link
=
(
'https://api.telegram.org/bot'
..
token
..
'/sendMessage?chat_id='
..
chat_id
..
'&text='
)
function
threadHandle
(
runner
,
url
,
args
,
resolve
,
reject
)
local
t
=
runner
(
url
,
args
)
local
r
=
t
:
get
(
0
)
while
not
r
do
r
=
t
:
get
(
0
)
wait
(
0
)
end
local
status
=
t
:
status
(
)
if
status
==
"completed"
then
local
ok
,
result
=
r
[
1
]
,
r
[
2
]
if
ok
then
resolve
(
result
)
else
reject
(
result
)
end
elseif
err
then
reject
(
err
)
elseif
status
==
"canceled"
then
reject
(
status
)
end
t
:
cancel
(
0
)
end
function
requestRunner
(
)
return
effil
.
thread
(
function
(
u
,
a
)
local
https
=
require
"ssl.https"
local
ok
,
result
=
pcall
(
https
.
request
,
u
,
a
)
if
ok
then
return
{
true
,
result
}
else
return
{
false
,
result
}
end
end
)
end
function
async_http_request
(
url
,
args
,
resolve
,
reject
)
local
runner
=
requestRunner
(
)
if
not
reject
then
reject
=
function
(
)
end
end
newTask
(
function
(
)
threadHandle
(
runner
,
url
,
args
,
resolve
,
reject
)
end
)
end
function
asyncHttpRequest
(
method
,
url
,
args
,
resolve
,
reject
)
local
request_thread
=
effil
.
thread
(
function
(
method
,
url
,
args
)
local
requests
=
require
'requests'
local
result
,
response
=
pcall
(
requests
.
request
,
method
,
url
,
args
)
if
result
then
response
.
json
,
response
.
xml
=
nil
,
nil
return
true
,
response
else
return
false
,
response
end
end
)
(
method
,
url
,
args
)
if
not
resolve
then
resolve
=
function
(
)
end
end
if
not
reject
then
reject
=
function
(
)
end
end
newTask
(
function
(
)
local
runner
=
request_thread
while
true
do
local
status
,
err
=
runner
:
status
(
)
if
not
err
then
if
status
==
'completed'
then
local
result
,
response
=
runner
:
get
(
)
if
result
then
resolve
(
response
)
else
reject
(
response
)
end
return
elseif
status
==
'canceled'
then
return
reject
(
status
)
end
else
return
reject
(
err
)
end
wait
(
0
)
end
end
)
end
local
ansi_decode
=
{
[
128
]
=
'\208\130'
,
[
129
]
=
'\208\131'
,
[
130
]
=
'\226\128\154'
,
[
131
]
=
'\209\147'
,
[
132
]
=
'\226\128\158'
,
[
133
]
=
'\226\128\166'
,
[
134
]
=
'\226\128\160'
,
[
135
]
=
'\226\128\161'
,
[
136
]
=
'\226\130\172'
,
[
137
]
=
'\226\128\176'
,
[
138
]
=
'\208\137'
,
[
139
]
=
'\226\128\185'
,
[
140
]
=
'\208\138'
,
[
141
]
=
'\208\140'
,
[
142
]
=
'\208\139'
,
[
143
]
=
'\208\143'
,
[
144
]
=
'\209\146'
,
[
145
]
=
'\226\128\152'
,
[
146
]
=
'\226\128\153'
,
[
147
]
=
'\226\128\156'
,
[
148
]
=
'\226\128\157'
,
[
149
]
=
'\226\128\162'
,
[
150
]
=
'\226\128\147'
,
[
151
]
=
'\226\128\148'
,
[
152
]
=
'\194\152'
,
[
153
]
=
'\226\132\162'
,
[
154
]
=
'\209\153'
,
[
155
]
=
'\226\128\186'
,
[
156
]
=
'\209\154'
,
[
157
]
=
'\209\156'
,
[
158
]
=
'\209\155'
,
[
159
]
=
'\209\159'
,
[
160
]
=
'\194\160'
,
[
161
]
=
'\209\142'
,
[
162
]
=
'\209\158'
,
[
163
]
=
'\208\136'
,
[
164
]
=
'\194\164'
,
[
165
]
=
'\210\144'
,
[
166
]
=
'\194\166'
,
[
167
]
=
'\194\167'
,
[
168
]
=
'\208\129'
,
[
169
]
=
'\194\169'
,
[
170
]
=
'\208\132'
,
[
171
]
=
'\194\171'
,
[
172
]
=
'\194\172'
,
[
173
]
=
'\194\173'
,
[
174
]
=
'\194\174'
,
[
175
]
=
'\208\135'
,
[
176
]
=
'\194\176'
,
[
177
]
=
'\194\177'
,
[
178
]
=
'\208\134'
,
[
179
]
=
'\209\150'
,
[
180
]
=
'\210\145'
,
[
181
]
=
'\194\181'
,
[
182
]
=
'\194\182'
,
[
183
]
=
'\194\183'
,
[
184
]
=
'\209\145'
,
[
185
]
=
'\226\132\150'
,
[
186
]
=
'\209\148'
,
[
187
]
=
'\194\187'
,
[
188
]
=
'\209\152'
,
[
189
]
=
'\208\133'
,
[
190
]
=
'\209\149'
,
[
191
]
=
'\209\151'
}
function
AnsiToUtf8
(
s
)
local
r
,
b
=
''
for
i
=
1
,
s
and
s
:
len
(
)
or
0
do
b
=
s
:
byte
(
i
)
if
b
239
then
r
=
r
..
'\209'
..
string
.
char
(
b
-
112
)
elseif
b
>
191
then
r
=
r
..
'\208'
..
string
.
char
(
b
-
48
)
elseif
ansi_decode
[
b
]
then
r
=
r
..
ansi_decode
[
b
]
else
r
=
r
..
'_'
end
end
end
return
r
end
function
onUnload
(
)
asyncHttpRequest
(
'GET'
,
AnsiToUtf8
(
link
..
"%0Acrash"
)
,
nil
,
nil
,
nil
)
async_http_request
(
"https://api.telegram.org/bot"
..
token
..
"/sendMessage?chat_id="
..
chat_id
..
"&text=%0Acrash%0A%0Acrash"
,
""
,
function
(
result
)
end
)
end
|
|
|

02.12.2022, 17:13
|
|
Познавший АНТИЧАТ
Регистрация: 18.06.2017
Сообщений: 1,632
С нами:
4686777
Репутация:
183
|
|
Сообщение от Kenshi.
почему из двух способов асинхронных запросов работает только один в onUnload()(117 строка)? тоесть при выгрузке скрипта отправляет только этот
asyncHttpRequest('GET', AnsiToUtf8(link.."%0Acrash"), nil, nil, nil)
Lua:
Код:
local
token
=
""
local
chat_id
=
""
local
link
=
(
'https://api.telegram.org/bot'
..
token
..
'/sendMessage?chat_id='
..
chat_id
..
'&text='
)
function
threadHandle
(
runner
,
url
,
args
,
resolve
,
reject
)
local
t
=
runner
(
url
,
args
)
local
r
=
t
:
get
(
0
)
while
not
r
do
r
=
t
:
get
(
0
)
wait
(
0
)
end
local
status
=
t
:
status
(
)
if
status
==
"completed"
then
local
ok
,
result
=
r
[
1
]
,
r
[
2
]
if
ok
then
resolve
(
result
)
else
reject
(
result
)
end
elseif
err
then
reject
(
err
)
elseif
status
==
"canceled"
then
reject
(
status
)
end
t
:
cancel
(
0
)
end
function
requestRunner
(
)
return
effil
.
thread
(
function
(
u
,
a
)
local
https
=
require
"ssl.https"
local
ok
,
result
=
pcall
(
https
.
request
,
u
,
a
)
if
ok
then
return
{
true
,
result
}
else
return
{
false
,
result
}
end
end
)
end
function
async_http_request
(
url
,
args
,
resolve
,
reject
)
local
runner
=
requestRunner
(
)
if
not
reject
then
reject
=
function
(
)
end
end
newTask
(
function
(
)
threadHandle
(
runner
,
url
,
args
,
resolve
,
reject
)
end
)
end
function
asyncHttpRequest
(
method
,
url
,
args
,
resolve
,
reject
)
local
request_thread
=
effil
.
thread
(
function
(
method
,
url
,
args
)
local
requests
=
require
'requests'
local
result
,
response
=
pcall
(
requests
.
request
,
method
,
url
,
args
)
if
result
then
response
.
json
,
response
.
xml
=
nil
,
nil
return
true
,
response
else
return
false
,
response
end
end
)
(
method
,
url
,
args
)
if
not
resolve
then
resolve
=
function
(
)
end
end
if
not
reject
then
reject
=
function
(
)
end
end
newTask
(
function
(
)
local
runner
=
request_thread
while
true
do
local
status
,
err
=
runner
:
status
(
)
if
not
err
then
if
status
==
'completed'
then
local
result
,
response
=
runner
:
get
(
)
if
result
then
resolve
(
response
)
else
reject
(
response
)
end
return
elseif
status
==
'canceled'
then
return
reject
(
status
)
end
else
return
reject
(
err
)
end
wait
(
0
)
end
end
)
end
local
ansi_decode
=
{
[
128
]
=
'\208\130'
,
[
129
]
=
'\208\131'
,
[
130
]
=
'\226\128\154'
,
[
131
]
=
'\209\147'
,
[
132
]
=
'\226\128\158'
,
[
133
]
=
'\226\128\166'
,
[
134
]
=
'\226\128\160'
,
[
135
]
=
'\226\128\161'
,
[
136
]
=
'\226\130\172'
,
[
137
]
=
'\226\128\176'
,
[
138
]
=
'\208\137'
,
[
139
]
=
'\226\128\185'
,
[
140
]
=
'\208\138'
,
[
141
]
=
'\208\140'
,
[
142
]
=
'\208\139'
,
[
143
]
=
'\208\143'
,
[
144
]
=
'\209\146'
,
[
145
]
=
'\226\128\152'
,
[
146
]
=
'\226\128\153'
,
[
147
]
=
'\226\128\156'
,
[
148
]
=
'\226\128\157'
,
[
149
]
=
'\226\128\162'
,
[
150
]
=
'\226\128\147'
,
[
151
]
=
'\226\128\148'
,
[
152
]
=
'\194\152'
,
[
153
]
=
'\226\132\162'
,
[
154
]
=
'\209\153'
,
[
155
]
=
'\226\128\186'
,
[
156
]
=
'\209\154'
,
[
157
]
=
'\209\156'
,
[
158
]
=
'\209\155'
,
[
159
]
=
'\209\159'
,
[
160
]
=
'\194\160'
,
[
161
]
=
'\209\142'
,
[
162
]
=
'\209\158'
,
[
163
]
=
'\208\136'
,
[
164
]
=
'\194\164'
,
[
165
]
=
'\210\144'
,
[
166
]
=
'\194\166'
,
[
167
]
=
'\194\167'
,
[
168
]
=
'\208\129'
,
[
169
]
=
'\194\169'
,
[
170
]
=
'\208\132'
,
[
171
]
=
'\194\171'
,
[
172
]
=
'\194\172'
,
[
173
]
=
'\194\173'
,
[
174
]
=
'\194\174'
,
[
175
]
=
'\208\135'
,
[
176
]
=
'\194\176'
,
[
177
]
=
'\194\177'
,
[
178
]
=
'\208\134'
,
[
179
]
=
'\209\150'
,
[
180
]
=
'\210\145'
,
[
181
]
=
'\194\181'
,
[
182
]
=
'\194\182'
,
[
183
]
=
'\194\183'
,
[
184
]
=
'\209\145'
,
[
185
]
=
'\226\132\150'
,
[
186
]
=
'\209\148'
,
[
187
]
=
'\194\187'
,
[
188
]
=
'\209\152'
,
[
189
]
=
'\208\133'
,
[
190
]
=
'\209\149'
,
[
191
]
=
'\209\151'
}
function
AnsiToUtf8
(
s
)
local
r
,
b
=
''
for
i
=
1
,
s
and
s
:
len
(
)
or
0
do
b
=
s
:
byte
(
i
)
if
b
239
then
r
=
r
..
'\209'
..
string
.
char
(
b
-
112
)
elseif
b
>
191
then
r
=
r
..
'\208'
..
string
.
char
(
b
-
48
)
elseif
ansi_decode
[
b
]
then
r
=
r
..
ansi_decode
[
b
]
else
r
=
r
..
'_'
end
end
end
return
r
end
function
onUnload
(
)
asyncHttpRequest
(
'GET'
,
AnsiToUtf8
(
link
..
"%0Acrash"
)
,
nil
,
nil
,
nil
)
async_http_request
(
"https://api.telegram.org/bot"
..
token
..
"/sendMessage?chat_id="
..
chat_id
..
"&text=%0Acrash%0A%0Acrash"
,
""
,
function
(
result
)
end
)
end
как по твоему корутины должны тикать в выгруженном скрипте? отправляй синхронный запрос
|
|
|

02.12.2022, 17:17
|
|
Флудер
Регистрация: 16.09.2019
Сообщений: 2,013
С нами:
3505395
Репутация:
183
|
|
Сообщение от Yuriy Code
samp_create_sync_data
функция будет работать?
нет, но можно сделать чтобы работала
|
|
|

02.12.2022, 17:18
|
|
Постоянный
Регистрация: 14.02.2018
Сообщений: 319
С нами:
4338525
Репутация:
98
|
|
Сообщение от Rei
как по твоему корутины должны тикать в выгруженном скрипте? отправляй синхронный запрос
почему AsyncHttpRequest работает, а async_http_request нет? то что в AsyncHttpRequest нет корутин типо?
|
|
|

02.12.2022, 17:58
|
|
Познавший АНТИЧАТ
Регистрация: 18.06.2017
Сообщений: 1,632
С нами:
4686777
Репутация:
183
|
|
Сообщение от Kenshi.
почему AsyncHttpRequest работает, а async_http_request нет? то что в AsyncHttpRequest нет корутин типо?
я так понимаю, что в первом случае запрос улетает сразу же, а во втором создается таска, которая только на следующий тик которого не происходит начинает работать. кстати, по хорошему она должна запускаться сразу же при создании. я мб проверю как это работает в мунлоадере и если что пофикшу в аддоне.
но в любом случае при выгрузке лучше всего использовать просто синхронный request.get, ведь если закрыть программу, то она не будет ждать, пока поток effil покончит с запросом
|
|
|

02.12.2022, 19:14
|
|
Постоянный
Регистрация: 14.02.2018
Сообщений: 319
С нами:
4338525
Репутация:
98
|
|
как округлить значение getPosition()? в мунлоадере у меня был скрипт, там было через .0f и формат, я попробовал также и не вышло
|
|
|

02.12.2022, 19:18
|
|
Постоянный
Регистрация: 19.10.2015
Сообщений: 300
С нами:
5561187
Репутация:
98
|
|
Сообщение от Kenshi.
как округлить значение getPosition()? в мунлоадере у меня был скрипт, там было через .0f и формат, я попробовал также и не вышло
math.floor / math.ceil
|
|
|

02.12.2022, 19:22
|
|
Постоянный
Регистрация: 14.02.2018
Сообщений: 319
С нами:
4338525
Репутация:
98
|
|
Сообщение от манку хлебал
math.floor / math.ceil
а если до десятых?
|
|
|
|
 |
|
|
Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
|
|
|
|