Показать сообщение отдельно

  #5513  
Старый 08.10.2021, 22:28
kin4stat
Флудер
Регистрация: 06.11.2017
Сообщений: 2,759
С нами: 4483143

Репутация: 183


По умолчанию

самый красивый вариант

Информация - Полезные функции

uint8_t getPlayerWeaponModelID(int iPlayerID) { if (g_Players == NULL || iPlayerID SAMP_MAX_PLAYERS) return NULL; if (iPlayerID == g_Players->sLocalPlayerID) { if (g_Players->pLocalPlayer->pSAMP_Actor == NULL) return NULL...

www.blast.hk


or

самый уебанский вариант

Задержка

Пишу СФ плагин и вопрос, отправляю сообщение в чат но проблема, как сделать задержку между ними? Если использовать функции популярные то игру тупо фризит до тех пор пока все сообщения не отправятся

www.blast.hk


or

что-то между:

C++:





Код:
#include "SAMPFUNCS_API.h"
#include "game_api\game_api.h"
#include 
#include 
#include 
class
Timer
{
struct
TimerInfo
{
std
::
chrono
::
steady_clock
::
time_point start
;
std
::
chrono
::
milliseconds duration
;
std
::
function

callback
;
TimerInfo
(
std
::
chrono
::
steady_clock
::
time_point s
,
std
::
chrono
::
milliseconds dur
,
std
::
function

cb
)
:
start
(
s
)
,
duration
(
dur
)
,
callback
(
cb
)
{
}
}
;
public
:
static
Timer
&
Instance
(
)
{
static
Timer inst
;
return
inst
;
}
void
Update
(
)
{
using
namespace
std
::
chrono
;
for
(
auto
it
=
timers
.
begin
(
)
;
it
!=
timers
.
end
(
)
;
)
{
auto
&
timer
=
*
it
;
if
(
steady_clock
::
now
(
)
-
timer
.
start
>
timer
.
duration
)
{
timer
.
callback
(
)
;
timers
.
erase
(
it
++
)
;
}
else
{
++
it
;
}
}
}
void
AddTimer
(
std
::
function

callback
,
std
::
chrono
::
milliseconds duration
)
{
timers
.
emplace_back
(
std
::
chrono
::
steady_clock
::
now
(
)
,
duration
,
callback
)
;
}
std
::
list

timers
;
}
;
SAMPFUNCS
*
SF
=
new
SAMPFUNCS
(
)
;
void
CALLBACK
k1d
(
std
::
string params
)
{
using
namespace
std
::
chrono_literals
;
SF
->
getSAMP
(
)
->
getChat
(
)
->
AddChatMessage
(
0xFF00FF00
,
"text"
)
;
Timer
::
Instance
(
)
.
AddTimer
(
[
]
{
SF
->
getSAMP
(
)
->
getChat
(
)
->
AddChatMessage
(
0xFFFF0000
,
"text2"
)
;
}
,
3
s
)
;
}
void
CALLBACK
mainloop
(
)
{
Timer
::
Instance
(
)
.
Update
(
)
;
static
bool
init
=
false
;
if
(
!
init
)
{
if
(
GAME
==
nullptr
&&
GAME
->
GetSystemState
(
)
!=
eSystemState
::
GS_PLAYING_GAME
&&
!
SF
->
getSAMP
(
)
->
IsInitialized
(
)
)
return
;
SF
->
getSAMP
(
)
->
registerChatCommand
(
"kr"
,
k1d
)
;
init
=
true
;
}
}
BOOL APIENTRY
DllMain
(
HMODULE hModule
,
DWORD dwReasonForCall
,
LPVOID
)
{
if
(
dwReasonForCall
==
DLL_PROCESS_ATTACH
)
{
SF
->
initPlugin
(
mainloop
,
hModule
)
;
}
return
TRUE
;
}


P.S. код таймера был написан за 5 минут как proof of concept, кто хочет - оптимизируйте
 
Ответить с цитированием