Raised This Month: $51 Target: $400
 12% 

Send multiple data thru timer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lugui
Senior Member
Join Date: Feb 2016
Location: GetClientAbsOrigin();
Old 06-12-2017 , 18:23   Send multiple data thru timer
Reply With Quote #1

Hi. I need to send multiple int values (client and info about the client) thru a timer.
How can I do that?
lugui is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-12-2017 , 18:24   Re: Send multiple data thru timer
Reply With Quote #2

https://wiki.alliedmods.net/DataPacks
__________________
xines is offline
Drixevel
AlliedModders Donor
Join Date: Sep 2009
Location: Somewhere headbangin'
Old 06-12-2017 , 18:29   Re: Send multiple data thru timer
Reply With Quote #3

Code:
DatPack pack;
CreateDataTimer(1.0, timer_callback, pack);
WritePackCell(pack, int_variable);
WritePackString(pack, "sup fam");

public Action timer_callback(Handle timer, any data)
{
     ResetPack(data);
     int int_variable = ReadPackCell(data);

     char buffer[32];
     ReadPackString(data, buffer, sizeof(buffer));

     //do stuff
}
crude but whatever
Drixevel is offline
lugui
Senior Member
Join Date: Feb 2016
Location: GetClientAbsOrigin();
Old 06-12-2017 , 18:36   Re: Send multiple data thru timer
Reply With Quote #4

Is there a way to pass 2 int values? Or The only way is sending one string?
lugui is offline
xines
Veteran Member
Join Date: Aug 2013
Location: Denmark
Old 06-12-2017 , 18:48   Re: Send multiple data thru timer
Reply With Quote #5

Quote:
Originally Posted by lugui View Post
Is there a way to pass 2 int values? Or The only way is sending one string?
PHP Code:
//variables to fire
int MyIntValue 1;
int AnotherIntValue 2;

//Write DataPack
DataPack pack;
CreateDataTimer(1.0DoStuffpack);
pack.WriteCell(MyIntValue); //1
pack.WriteCell(AnotherIntValue); //2

//DataPack Timer
public Action DoStuff(Handle timerDataPack pack)
{
    
//Receive data
    
pack.Reset();
    
int MyIntValue pack.ReadCell(); //1
    
int AnotherIntValue pack.ReadCell(); //2
    
    //Do something with the values like...
    
PrintToChatAll("MyIntValue = %i, AnotherIntValue = %i"MyIntValueAnotherIntValue);

    return 
Plugin_Stop;

__________________
xines is offline
lugui
Senior Member
Join Date: Feb 2016
Location: GetClientAbsOrigin();
Old 06-12-2017 , 19:54   Re: Send multiple data thru timer
Reply With Quote #6

thx
lugui 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 23:09.


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