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

Solved how to creatertimer in foreach maxplayers


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Alexunder
Member
Join Date: Jun 2018
Old 09-25-2019 , 13:37   how to creatertimer in foreach maxplayers
Reply With Quote #1

hi guys , i write this script :
Code:
public OnPluginStart()
{
    RegAdminCmd("sm_test", test, ADMFLAG_CONVARS);
}

public Action:test(client, args)
{
	for(int i = 1; i <= MaxClients; i++) {
		if(IsClientInGame(i) || (!IsFakeClient(i))) {
			new String:ClientIP[32];
			new String:TargetName[32];
		
			GetClientName(i, TargetName, sizeof(TargetName));
			GetClientIP(i, ClientIP, sizeof(ClientIP));
				
			char urlapi[128];
			Format(urlapi,128,"http://google.com/test?IP=%s&name=%s", ClientIP, TargetName);
			System2_GetPage(OnComplete, urlapi, "", "", client);
		}
	}
}

public OnComplete(const String:output[], const size, CMDReturn:status, any:client)
{
			if(strlen(output) > 2) {
				PrintToChat(client, "\x01 \x04[test]\x01 %s", output);
			}
}
when i use "!test" , after 3-4 displaying some data , i got the "400 bad request" , i think if i use createtimer (2s ..) my problem is fix ! but i don't know how to use

sorry my english is poor

Last edited by Alexunder; 10-12-2019 at 16:36.
Alexunder is offline
Alexunder
Member
Join Date: Jun 2018
Old 10-06-2019 , 19:50   Re: how to creatertimer in foreach maxplayers
Reply With Quote #2

some one can help me ?

i just wanna make delay on "for" , its can fix error (400 bad request) .
Alexunder is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 10-06-2019 , 22:06   Re: how to creatertimer in foreach maxplayers
Reply With Quote #3

https://wiki.alliedmods.net/Timers_(SourceMod_Scripting)
__________________
8guawong is offline
Alexunder
Member
Join Date: Jun 2018
Old 10-08-2019 , 07:25   Re: how to creatertimer in foreach maxplayers
Reply With Quote #4

Quote:
Originally Posted by 8guawong View Post
idk how to add "client id" to timer , can you fix my plugin ?
Alexunder is offline
8guawong
AlliedModders Donor
Join Date: Dec 2013
Location: BlackMarke7
Old 10-08-2019 , 08:11   Re: how to creatertimer in foreach maxplayers
Reply With Quote #5

Quote:
Originally Posted by Alexunder View Post
idk how to add "client id" to timer , can you fix my plugin ?
https://wiki.alliedmods.net/Timers_(...)#Passing_Data
__________________
8guawong is offline
OhHai
Junior Member
Join Date: Aug 2019
Old 10-08-2019 , 08:14   Re: how to creatertimer in foreach maxplayers
Reply With Quote #6

Quote:
Originally Posted by 8guawong View Post
He doesn't want advice on how to fix the issue, he wants you to do all the work for him.
OhHai is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-08-2019 , 12:39   Re: how to creatertimer in foreach maxplayers
Reply With Quote #7

You can try something like this, I didn't tested but the logic may work.

PHP Code:
static int clientIndex 1;

public 
OnPluginStart()
{
    
RegAdminCmd("sm_test"testADMFLAG_CONVARS);
}


public 
Action:test(clientargs)
{
    
clientIndex 1;
    
CreateTimer(2.0TimerAction_TIMER_REPEAT);
}
 
public 
Action TimerAction(Handle timer)
{
    if (
clientIndex <= MaxClients)
    {
        if(
IsClientInGame(clientIndex) || (!IsFakeClient(clientIndex))) {
            new 
String:ClientIP[32];
            new 
String:TargetName[32];
        
            
GetClientName(clientIndexTargetNamesizeof(TargetName));
            
GetClientIP(clientIndexClientIPsizeof(ClientIP));
                
            
char urlapi[128];
            
Format(urlapi,128,"http://google.com/test?IP=%s&name=%s"ClientIPTargetName);
            
System2_GetPage(OnCompleteurlapi""""client);
        }
        
        
clientIndex++;
        
        return 
Plugin_Continue;
    }
    
    return 
Plugin_Stop;

__________________

Last edited by Marttt; 10-08-2019 at 12:41.
Marttt is offline
Alexunder
Member
Join Date: Jun 2018
Old 10-09-2019 , 14:22   Re: how to creatertimer in foreach maxplayers
Reply With Quote #8

Quote:
Originally Posted by Marttt View Post
You can try something like this, I didn't tested but the logic may work.

PHP Code:
static int clientIndex 1;

public 
OnPluginStart()
{
    
RegAdminCmd("sm_test"testADMFLAG_CONVARS);
}


public 
Action:test(clientargs)
{
    
clientIndex 1;
    
CreateTimer(2.0TimerAction_TIMER_REPEAT);
}
 
public 
Action TimerAction(Handle timer)
{
    if (
clientIndex <= MaxClients)
    {
        if(
IsClientInGame(clientIndex) || (!IsFakeClient(clientIndex))) {
            new 
String:ClientIP[32];
            new 
String:TargetName[32];
        
            
GetClientName(clientIndexTargetNamesizeof(TargetName));
            
GetClientIP(clientIndexClientIPsizeof(ClientIP));
                
            
char urlapi[128];
            
Format(urlapi,128,"http://google.com/test?IP=%s&name=%s"ClientIPTargetName);
            
System2_GetPage(OnCompleteurlapi""""client);
        }
        
        
clientIndex++;
        
        return 
Plugin_Continue;
    }
    
    return 
Plugin_Stop;

thx man , but client in TimerAction is not ok , i add any:client to TimerAction and add client to CreateTimer, now for is print for me and there !

i just wanna see print to me (bicause i say !test) , do you know what i want ?
Alexunder is offline
Marttt
Veteran Member
Join Date: Jan 2019
Location: Brazil
Old 10-09-2019 , 16:48   Re: how to creatertimer in foreach maxplayers
Reply With Quote #9

Well you can try to do something like this (is ugly but may work, not the best solution)
If you are the only admin in the server, should work.

PHP Code:
static int clientIndex 1;
static 
int testCmdClient 0;

public 
OnPluginStart()
{
    
RegAdminCmd("sm_test"testADMFLAG_CONVARS);
}


public 
Action:test(clientargs)
{
    
clientIndex 1;
    
testCmdClient client;
    
CreateTimer(2.0TimerActionclientTIMER_REPEAT);
}

public 
OnComplete(const String:output[], const sizeCMDReturn:statusany:client)
{
            if(
strlen(output) > 2) {
                
PrintToChat(testCmdClient"\x01 \x04[test]\x01 %s"output);
            }

__________________

Last edited by Marttt; 10-09-2019 at 16:49.
Marttt 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 17:52.


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