SA-MP Forums Archive
SetTimerEx pushing wrong values? - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: SetTimerEx pushing wrong values? (/showthread.php?tid=324064)



SetTimerEx pushing wrong values? - Kar - 07.03.2012

pawn Код:
public OnPlayerRequestClass(playerid, classid)
{
    if(IsPlayerNPC(playerid)) return 1;
    PlayerInfo[playerid][pSelection] = 0;
    SetTimerEx("SpawnPlayerEx", 75, false, "i", playerid);
    new Preloading[3];//preload objects
    Preloading[0] = CreatePlayerObject(playerid, Machine_Gun,               TM_SELECTION_X, TM_SELECTION_Y + 5, TM_SELECTION_Z, 0.0, 0.0, 0.0, 300.0);
    Preloading[1] = CreatePlayerObject(playerid, Missile_Default_Object,    TM_SELECTION_X, TM_SELECTION_Y + 5, TM_SELECTION_Z, 0.0, 0.0, 0.0, 300.0);
    Preloading[2] = CreatePlayerObject(playerid, Missile_Napalm_Object,     TM_SELECTION_X, TM_SELECTION_Y + 5, TM_SELECTION_Z, 0.0, 0.0, 0.0, 300.0);
    SendClientMessageFormatted(playerid, -1, "0: %d - 1: %d - 2: %d", Preloading[0], Preloading[1], Preloading[2]);
    SetTimerEx("FinishPreloading", 2000, false, "iiii", playerid, Preloading[0], Preloading[1], Preloading[2]);
    return 1;
}

forward FinishPreloading(playerid, ...);
public FinishPreloading(playerid, ...)
{
    new iArgs = numargs();
    while(--iArgs)
    {
        SendClientMessageFormatted(playerid, -1, "player objectid: %d - arg: %d", getarg(iArgs), iArgs);
        DestroyPlayerObject(playerid, getarg(iArgs));
    }
    return 1;
}
Self Explanatory

Код:
[19:11:34] 0: 19 - 1: 20 - 2: 21

[19:11:39] player objectid: 1090519040 - arg: 3

[19:11:39] player objectid: 67 - arg: 2

[19:11:39] player objectid: 17152 - arg: 1
See the problem ^? it was 19, 20 and 21 before settimerex, but now when the function is called it's like those numbers?


Re: SetTimerEx pushing wrong values? - Mike_Peterson - 07.03.2012

replace ur settimerex line with this
Код:
SetTimerEx("FinishPreloading", 2000, false, "iiii", playerid, Preloading[2], Preloading[1], Preloading[0]);



Re: SetTimerEx pushing wrong values? - Kar - 07.03.2012

that didn't fix anything?> it only switched the order to
pawn Код:
[19:11:39] player objectid: 17152 - arg: 3

[19:11:39] player objectid: 67 - arg: 2

[19:11:39] player objectid: 1090519040 - arg: 1



Re: SetTimerEx pushing wrong values? - Mike_Peterson - 07.03.2012

haha, i didnt even notice that big number, i thought that the order was the problem rofl.. its late, i might mix up things hehe..
So, what are the values that should be 'pushed out'? 19, 20 and 21?


Re: SetTimerEx pushing wrong values? - Kar - 07.03.2012

okay, settimerex should call the function like this FinishPreloading(playerid, 19, 20, 21);

the values are printed here.. SendClientMessageFormatted(playerid, -1, "0: %d - 1: %d - 2: %d", Preloading[0], Preloading[1], Preloading[2]);

but yet it returns these [19:11:39] player objectid: 1090519040 - arg: 3

[19:11:39] player objectid: 67 - arg: 2

[19:11:39] player objectid: 17152 - arg: 1

1090519040, 67 and 17152

get it?


Re: SetTimerEx pushing wrong values? - Mauzen - 07.03.2012

Hm, I guess timers are bugged for dynamic parameters, just like they are with strings.


Re: SetTimerEx pushing wrong values? - Mike_Peterson - 07.03.2012

I've read everything about numargs, getarg now, and to my eyes the code looks fine, but i just wonder atm what that while(--iArgs) does, it's a loop.. but, what exactly are you trying to achieve on that line?

edit: Perhaps what Mauzen says, everything I saw with numargs and getarg were stock functions..


Re: SetTimerEx pushing wrong values? - Kar - 07.03.2012

Quote:
Originally Posted by Mauzen
Посмотреть сообщение
Hm, I guess timers are bugged for dynamic parameters, just like they are with strings.
I'm not sure about that. I have something here

pawn Код:
forward UpdateMissile(playerid, id, objectid, missileid, slot, vehicleid);
it doesn't bug, but it seems to bug after certain things in the server happen

I think it has a buffer overflow (somewhere in the script)


Re: SetTimerEx pushing wrong values? - Mike_Peterson - 07.03.2012

I don't think you can compare UpdateMissile's parameters to FinishPreloading function's parameters that easily..


Respuesta: SetTimerEx pushing wrong values? - Jovanny - 07.03.2012

pawn Код:
#include <a_samp>



public OnPlayerRequestClass(playerid, classid)
{
    if(IsPlayerNPC(playerid)) return 1;
    PlayerInfo[playerid][pSelection] = 0;
    SetTimerEx("SpawnPlayerEx", 75, false, "i", playerid);
    new Preloading[3];//preload objects
    Preloading[0] = CreatePlayerObject(playerid, Machine_Gun,               TM_SELECTION_X, TM_SELECTION_Y + 5, TM_SELECTION_Z, 0.0, 0.0, 0.0, 300.0);
    Preloading[1] = CreatePlayerObject(playerid, Missile_Default_Object,    TM_SELECTION_X, TM_SELECTION_Y + 5, TM_SELECTION_Z, 0.0, 0.0, 0.0, 300.0);
    Preloading[2] = CreatePlayerObject(playerid, Missile_Napalm_Object,     TM_SELECTION_X, TM_SELECTION_Y + 5, TM_SELECTION_Z, 0.0, 0.0, 0.0, 300.0);
    SendClientMessageFormatted(playerid, -1, "0: %d - 1: %d - 2: %d", Preloading[0], Preloading[1], Preloading[2]);
    SetTimerEx("FinishPreloading", 2000, false, "iiii", playerid, Preloading);
    return 1;
}


forward FinishPreloading(playerid,received[3]);
public FinishPreloading(playerid,received[3])
{
    for(new i,d=numargs();i != d;i++)
    {
        SendClientMessageFormatted(playerid, -1, "player objectid: %d - arg: received[%d]",received[i], i);
            DestroyPlayerObject(playerid,received[i]);
    }

}
I tested a similar code and it worked

pawn Код:
#include <a_samp>

public OnFilterScriptInit()
{
new integers[3] = {0,1,2};
SetTimerEx("test",2000,false,"iiii",9,integers);

}

forward test(playerid,received[3]);
public test(playerid,received[3])
{
    for(new i,d=numargs();i != d;i++)
    {
        printf("%d",received[i]);
    }

}
Console:
Код:
0
1
2