AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Need some help with a function (https://forums.alliedmods.net/showthread.php?t=164523)

asdff 08-12-2011 15:11

Need some help with a function
 
I'm trying to make a screenshot plugin. I did all I wanted the plugin to do but I have a problem: I don't know how to make the plugin to wait for a function to be completed and the go on. Below is the code, and I wrote the function that i'm having problems with like this:
*************
function
*************

Thanks

Code:
#include <amxmodx> #include <amxmisc> #include <cstrike> #include <fun> new ip[32], authid2[32]; new bool:a_poze = false; new help, screens, increment; new timestamp[32], timestampmsg[128], name[32], adminname[32]; public plugin_init() {     register_plugin("Ultimate SS", "1.0", "SS");     register_concmd("amx_ss", "concmd_screen", ADMIN_LEVEL_A, "<authid, nick or #userid> <screens>");     register_clcmd("say /ip", "show_ip"); } public concmd_screen(id, level, cid) {     if(!cmd_access(id, level, cid, 3))         return PLUGIN_HANDLED;     new arg1[24], arg2[2], ip2[32]     new authid[32], player;     read_argv(1, arg1, 23);     read_argv(2, arg2, 1);     screens = str_to_num(arg2);     if(screens > 5)     {         console_print(id, "Prea multe poze! Maxim 5!");         return PLUGIN_HANDLED;     }         if(a_poze)     {         console_print(id, "Nu poti face poze cat timp comanda este executata pe alt player.");         return PLUGIN_HANDLED;     }         player = cmd_target(id, arg1, 4);     if (!player)         return PLUGIN_HANDLED;     a_poze = true;     set_user_godmode(player,1);         get_user_name(player, name, 31);     get_user_name(id, adminname, 31);     get_user_ip(player, ip, 31);     get_user_ip(id, ip2, 31);     get_user_authid(player, authid2, 31);     get_user_authid(id, authid, 31);     client_cmd(id, "amx_chat Ii fac %d poze lui ^"%s^"", screens, name);     console_print(id, "IP-ul lui %s este %s!", name, ip);         increment = 0;     help = 5;     ****************************************************************************************************     SS_propriuzis(player); -- this is where I want the plugin to hang till it makes the screenshots and then continue below ****************************************************************************************************         client_print(player, print_chat, "Posteaza Pozele pe: <a href="http://www.***.***" target="_blank" rel="nofollow noopener">www.***.***</a> pentru unban!");     client_print(player, print_chat, "Posteaza Pozele pe: <a href="http://www.***.***" target="_blank" rel="nofollow noopener">www.***.***</a> pentru unban!");         log_amx("Screenshot: Admin ^"%s<%d><%s><%s>^" took %d+1 ss on ^"%s<%d><%s><%s>^"", adminname, get_user_userid(id), authid, ip2, screens, name, get_user_userid(player), authid2, ip);     set_user_godmode(player);     a_poze = false;         return PLUGIN_HANDLED; } public SS_propriuzis(player) {     increment++;     get_time("%m/%d/%Y - %H:%M:%S", timestamp, 31);     set_hudmessage(player, 255, 0, -1.0, 0.3, 0, 0.25, 1.0, 0.0, 0.0, 4);     format(timestampmsg, 127, "** PLAYER %s ORA: - %s **",name,timestamp);     show_hudmessage(player, timestampmsg);     client_print(0, print_chat, "** Screenshot taken on player ^"%s^" by admin ^"%s^" (%s) **", name, adminname, timestamp);     client_print(player, print_chat, "IP-ul tau: %s | %s | Screenshot %d", ip, authid2, pula);     client_cmd(player, "wait;snapshot");     if(increment < screens) set_task(2.0, "SS_propriuzis");     else SS_second(player); } public SS_second(player) {     if(help == 4)         do something;             if(help == 3)     {         do something;     }     if(help == 2)         do something;     help--;     if(help == 0)     {         do something;     }     else set_task(0.25, "SS_second"); } public show_ip(id) {     console_print(id, "Last Stored IP: %s!",ip); }

Hunter-Digital 08-12-2011 15:16

Re: Need some help with a function
 
set_task(), see amxmodx.org -> functions for syntax.

EDIT: you edited your code adding a function that already has set_task() in it, you just need to move the code that you want to "hang" into the final loop of set_task().

asdff 08-13-2011 03:54

Re: Need some help with a function
 
Ok thanks. Now I figured out that the function only hangs till it executes the code inside it and the goes on, does not wait for any other set_task or function calls inside that code.

I rewrote it using set_task and now it works fine :)

Code:
public concmd_screen(id, level, cid) {     ..............     a_poze = true;     a_poze1[player] = true;     ..............     increment = 0;     help = 4;     set_task(2.0, "SS_propriuzis", player, _, _, "a", screens)     log_amx("Screenshot: Admin ^"%s<%d><%s><%s>^" took %d+1 ss on ^"%s<%d><%s><%s>^"", adminname, get_user_userid(id), authid, ip2, screens, name, get_user_userid(player), authid2, ip);     return PLUGIN_HANDLED; } public SS_propriuzis(player) {     increment++;     get_time("%m/%d/%Y - %H:%M:%S", timestamp, 31);     set_hudmessage(player, 255, 0, -1.0, 0.3, 0, 0.25, 1.0, 0.0, 0.0, 4);     format(timestampmsg, 127, "** PLAYER %s ORA: - %s **",name,timestamp);     show_hudmessage(player, timestampmsg);     client_print(0, print_chat, "** Screenshot taken on player ^"%s^" by admin ^"%s^" (%s) **", name, adminname, timestamp);     client_print(player, print_chat, "IP-ul tau: %s | %s | Screenshot %d", ip, authid2, pula);     client_cmd(player, "wait;snapshot");     if(increment > screens-1) set_task(0.20, "SS_sigil", player, _, _, "a",4) } public SS_sigil(player) {     if(help == 4)         do something;             if(help == 3)     {         do something;     }     if(help == 2)         do something;     help--;     if(help == 0)     {         do something;         set_task(0.30, "SS_finish", player);     } } public SS_finish(player) {     client_print(player, print_chat, "Posteaza Pozele pe: <a href="http://www.***.***" target="_blank" rel="nofollow noopener">www.***.***</a> pentru unban!");     client_print(player, print_chat, "Posteaza Pozele pe: <a href="http://www.***.***" target="_blank" rel="nofollow noopener">www.***.***</a> pentru unban!");     a_poze = false;     a_poze1[player] = false; } public client_disconnect(id) {     if(a_poze1[id])     {         a_poze = false;         a_poze1[id] = false;         set_user_godmode(id);         remove_task(id);         PrintActivity(name, "^x04[Screenshot]^x01: ^x03$name disconnected!");     } } public show_ip(id) {     console_print(id, "Last Stored IP: %s!",ip); } PrintActivity(const admin_name[], const message_fmt[], any:...) {     if( !get_playersnum() ) return;     static message[192], temp[192];     vformat(message, sizeof(message) - 1, message_fmt, 3);     for( new client = 1; client <= get_maxplayers(); client++ )     {         if( !is_user_connected(client) ) continue;         copy(temp, sizeof(temp) - 1, message);         replace(temp, sizeof(temp) - 1, "$name", admin_name);         message_begin(MSG_ONE_UNRELIABLE, get_user_msgid("SayText"), _, client);         write_byte(client);         write_string(temp);         message_end();     }     log_amx("Screenshot: ^"%s^" disconnected after screenshot %d!", name, increment); }


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

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