AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   wait time (https://forums.alliedmods.net/showthread.php?t=318478)

KillerElite 09-02-2019 03:49

wait time
 
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

LearninG 09-02-2019 04:25

Re: wait time
 
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
........

KillerElite 09-02-2019 05:04

Re: wait time
 
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.

LearninG 09-02-2019 05:46

Re: wait time
 
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.

thEsp 09-02-2019 06:12

Re: wait time
 
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.


All times are GMT -4. The time now is 17:27.

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