[SetTimerEx] Carrying IP's Across Timers
#1

I need a little help, can someone give a basic example of how to carry someone's IP address over a timer? I know how to get the timer, I know the timer works, I know it can carry data, I know the IP data is set properly, but I cannot get it to go properly. I'm not new to scripting, but this is bugging me. Help is much appreciated.
Reply
#2

SetTimerEx("public",time,loop,"s",IPstring);
Reply
#3

Quote:
Originally Posted by gamer_Z
SetTimerEx("public",time,loop,"s",IPstring);
Already formatted properly, and fowarded accordingly, but the string comes out flawed.
Reply
#4

may u let see the code?

and what does it come out like? if the ip is 127.0.0.1 for example.. ?
Reply
#5

Strings in timers always mess up, I got the same issue.
Reply
#6

Quote:
Originally Posted by //exora
Strings in timers always mess up, I got the same issue.
well next one, i'm gonna check it.
w8 until i give here an edit of this post, i have some ideas in my head..

__
edit:

pawn Код:
#include <a_samp>

public OnFilterScriptInit(){
    new string[256],packed[256];
    format(string,256,"abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789");
    strpack(packed,string);
    SetTimerEx("TheTestPublic",2000,0,"s",packed);
    return 1;
}

forward TheTestPublic(source);// edit: lol forgot to add []... i'm gonna test this
public TheTestPublic(source){
    new dSource[256];
    format(dSource,256,"%s",source);
    new unpacked[256];
    strunpack(unpacked,dSource);
    printf(dSource);
    printf(unpacked);
    return 1;
}
fail ;/

prints:
Код:
P
P
but i don't give up!
i try again with new an idea.

_
GOT IT!!!
just using arrays.. maybe u can do it in a other way but here is a simple solution:
pawn Код:
#include <a_samp>

#define MAX_SLOTS (10)

new
    GlobalStringToSend[MAX_SLOTS][256],
    IsSlotUsed[MAX_SLOTS] = {0,...};

public OnFilterScriptInit(){
    new string[256];
    format(string,256,"abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789");
    for(new slot;slot < MAX_SLOTS; slot++){
      if(!IsSlotUsed[slot]){
        GlobalStringToSend[slot] = string;
        IsSlotUsed[slot] = 1;
        SetTimerEx("TheTestPublic",2000,0,"i",slot);
        return 1;
      }
    }
    return 1;
}

forward TheTestPublic(slot);
public TheTestPublic(slot){
    printf("%s",GlobalStringToSend[slot]);
    IsSlotUsed[slot] = 0;
    return 1;
}
study the code and let me know what you think about it.

so when the string arrives u can manipulate it as you want, so you can even "sent" strings up to 2048 characters without any problems.
but yea for 500 players just the ip has 16 chars so 500*16 = 8000, so we're making a "new string[8000];", lol.

so just to give u an idea
#define MAX_SLOTS MAX_PLAYERS .. ;]
and change [256] to [16]

__
next solution
:
(this works)
pawn Код:
public OnFilterScriptInit(){
    new string[256],packed[256];
    format(string,256,"abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789");
    strpack(packed,string);
    printf(packed);
    SetTimerEx("TheTestPublic",2000,0,"s",packed);
    return 1;
}

forward TheTestPublic(source[]);
public TheTestPublic(source[]){
    new dSource[256];
    format(dSource,256,"%s",source);
    new unpacked[256];
    strunpack(unpacked,dSource);
    printf(dSource);
    printf(unpacked);
    return 1;
}
now gonna test it without packing.
__
pawn Код:
public OnFilterScriptInit(){
    new string[256];
    format(string,256,"abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ 0123456789");
    SetTimerEx("TheTestPublic",2000,0,"s",string);
    return 1;
}

forward TheTestPublic(source[]);
public TheTestPublic(source[]){
    new dSource[256];
    format(dSource,256,"%s",source);
    printf(dSource);
    printf("%s",source);
    return 1;
}

forward TheTestPublic2(const source[]);
public TheTestPublic2(const source[]){
    new dSource[256];
    format(dSource,256,"%s",source);
    printf(dSource);
    printf("%s",source);
    return 1;
}
also works.. so i don't see any problems here lolz
Reply
#7

That doesn't help all that much, as it still does not carry an IP properly.
Reply
#8

Quote:
Originally Posted by spartan1178
That doesn't help all that much, as it still does not carry an IP properly.
let me see your code, I'm sure it's a human-side mistake , not PAWN..
Reply
#9

Show us your code, cuz if you want to carry ip with timer just to return it after a couple of seconds so uhm, well it's better to use global array.
Reply
#10

Timers have always had problems with strings, and as far as I'm aware - they haven't been resolved. I counter-acted against this by using global variables, or using properties, though that may not be needed UNLESS you're calling a function from another AMX.

~Cueball~
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)