Raised This Month: $32 Target: $400
 8% 

wait time


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
KillerElite
Junior Member
Join Date: Aug 2019
Old 09-02-2019 , 03:49   wait time
Reply With Quote #1

hi, i want a plugin which paste a text after 10 seconds.
Example: /test -> client_print(id, print_chat, "Example")
after 10 seconds -> client_print(id, print_chat, "Example2")

Thxxxx
KillerElite is offline
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 09-02-2019 , 04:25   Re: wait time
Reply With Quote #2

hi
1 - declare a variable so we can increase/decrease it's value when needed.
2 - register your command.
3 - before printing message, increase variable value by 1 (++) (decrease = (--) , then get variable value on client_print. after that set a task and put function in it.
1 -
Code:
new g_timer

2 -
Code:
register_clcmd("say /test" , "test")
3 -
Code:
public test(id) {      g_timer ++      client_print(id , print_chat , "Example %d", g_timer)      set_task(10.0,"test") }

results :
Quote:
/test
Example1
After 10 sec...
Example2
After 10 sec...
Example3
After 10 sec...
Example4
........

Last edited by LearninG; 09-02-2019 at 04:46.
LearninG is offline
KillerElite
Junior Member
Join Date: Aug 2019
Old 09-02-2019 , 05:04   Re: wait time
Reply With Quote #3

And if i want to add different messages, like. "The score is X for Red", "The score is X for Blue" etc..(just a plain text not a score system).
Meaning just 3 times, or 4 times. Not infinite.

Last edited by KillerElite; 09-02-2019 at 05:07.
KillerElite is offline
LearninG
Senior Member
Join Date: Apr 2019
Location: Iran
Old 09-02-2019 , 05:46   Re: wait time
Reply With Quote #4

Then you will need to store messages in an array.

1- define array_size before creating array , so compiler will now which value is for which array.
2- declare a variable so we can increase/decrease it's value again.
3- store all messages that you want to print out in an array.
4- register your command
5- on "pre_test" function set g_test_variable value to ARRAY_SIZE and call "test" function once , then we will set our task.
6- on "test" function decrease variable value by 1 (--) then get variable value in client_print.
1-
Code:
#define ARRAY_SIZE  5
2-
Code:
new g_test_variable
3-
Code:
new g_test_array[ARRAY_SIZE][] = {     "name",     "name2",     "name3",     "name4",     "name5" }
4-
Code:
register_clcmd("say /test" , "pre_test")
5-
Code:
public pre_test(id) {     g_test_variable = ARRAY_SIZE     test(id)     set_task(10.0, "test",_,_,_, "a",ARRAY_SIZE - 1) }
6-
Code:
public test(id) {     g_test_variable--     client_print(id , print_chat , "[AMXX] The score is X for %s" , g_test_array[g_test_variable]) }

result :
Quote:
/test
call "pre_test"
print_message : [AMXX] The score is X for name5
set_task
After 10 sec...
print_message : [AMXX] The score is X for name4
After 10 sec...
print_message : [AMXX] The score is X for name3
After 10 sec...
print_message : [AMXX] The score is X for name2
After 10 sec...
print_message : [AMXX] The score is X for name
Plugin is Done here.
Note : i did ARRAY_SIZE - 1 because we called our function once before.
Code:
test(id) set_task(10.0, "test",_,_,_, "a",ARRAY_SIZE - 1)

if you didn't understand any part , feel free to ask.

Last edited by LearninG; 09-02-2019 at 06:58.
LearninG is offline
thEsp
BANNED
Join Date: Aug 2017
Old 09-02-2019 , 06:12   Re: wait time
Reply With Quote #5

Working with tasks is the good and only way. Since HLDS runs at a single core, Pawn does not have threads, and functions will execute in order. If Pawn had threads, looping until (gametime - delay) equals 0 would simulate a simple delay.
thEsp is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 03:40.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode