[Help] Timer for jobs and actions.
#1

I need a timer for action/job. Well many. I have tried to do somethig with SetTimer, but i kinda failed lol. Any help?
Reply
#2

Show us your failed code? And more information?
Reply
#3

I should like post every job, action and else where i want a timer? O.o It's like 5k lines all together..

I'm just asking should i use SetTimer, or SetTimerEx? And where actually put it? Up on the job/action's script or in the bottom of it? I can give you an example.

Example: I have a dropgun FS, and i want to add a timer there which allows you to pick up a gun 45 seconds after it's dropped from a player. (OnPlayerDeath, not /dropgun)
pawn Код:
// -----------------------------------------------------------------------------
public OnPlayerDeath(playerid, killerid, reason)
{
    new Float:pPosX, Float:pPosY, Float:pPosZ;
    GetPlayerPos(playerid, pPosX, pPosY, pPosZ);
    for(new i_slot = 0, gun, ammo; i_slot != 12; i_slot++)
    { // Сохраняем оружие в руках
        GetPlayerWeaponData(playerid, i_slot, gun, ammo);
        if(gun != 0 && ammo != 0) CreateDroppedGun(gun, ammo, pPosX+random(2)-random(2), pPosY+random(2)-random(2), pPosZ);
    }
    return 1;
}
stock CreateDroppedGun(GunID, GunAmmo, Float:gPosX, Float:gPosY, Float:gPosZ)
{
    new f = MAX_OBJ+1;
    for(new a = 0; a < MAX_OBJ; a++)
    {
        if(dGunData[a][ObjPos][0] == 0.0)
        {
            f = a;
            break;
        }
    }
    if(f > MAX_OBJ) return;
    dGunData[f][ObjData][0] = GunID;
    dGunData[f][ObjData][1] = GunAmmo;
    dGunData[f][ObjPos][0] = gPosX;
    dGunData[f][ObjPos][1] = gPosY;
    dGunData[f][ObjPos][2] = gPosZ;
    dGunData[f][ObjID] = CreateObject(GunObjects[GunID], dGunData[f][ObjPos][0], dGunData[f][ObjPos][1], dGunData[f][ObjPos][2]-1, 93.7, 120.0, 120.0);
    return;
}
// -----------------------------------------------------------------------------
And
pawn Код:
if(strcmp(cmdtext, "/pickupgun", true) == 0
    || strcmp(cmdtext, "/pickitem", true) == 0)
    {
        if(GetPlayerState(playerid) != PLAYER_STATE_ONFOOT) return 1;
        new f = MAX_OBJ+1;
        for(new a = 0; a < MAX_OBJ; a++)
        {
            if(IsPlayerInRangeOfPoint(playerid, 5.0, dGunData[a][ObjPos][0], dGunData[a][ObjPos][1], dGunData[a][ObjPos][2]))
            {
                f = a;
                break;
            }
        }
        if(f > MAX_OBJ) return SendClientMessage(playerid, 0x33AA3300, "You are not near the weapon which you can pick up!");
        DestroyObject(dGunData[f][ObjID]);
        GivePlayerWeapon(playerid, dGunData[f][ObjData][0], dGunData[f][ObjData][1]);
        dGunData[f][ObjPos][0] = 0.0;
        dGunData[f][ObjPos][1] = 0.0;
        dGunData[f][ObjPos][2] = 0.0;
        dGunData[f][ObjID] = -1;
        //dGunData[f][ObjData][0] = 0;
        dGunData[f][ObjData][1] = 0;
        new buffer[50];
        format(buffer, sizeof(buffer), "You picked up %s", GunNames[dGunData[f][ObjData][0]]);
        SendClientMessage(playerid, 0x33AA3300, buffer);
        return 1;
    }
    return 0;
}
// -----------------------------------------------------------------------------
If i can get a nice help for that, i think i can figure out all other things where i want the times aswell.
Reply
#4

Here is an example of what you need to use.

pawn Код:
//SetTimer is used to call public functions that do not have any parameters like OnGameModeInit
//You wouldn't call OnGameModeInit on a timer this is just an example.
SetTimer("OnGameModeInit", 1000, false);
pawn Код:
//SetTimerEx is used for functions with parameters. (again just an example).
SetTimerEx("OnPlayerDeath", 1000, true, "iii", playerid, killerid, reason);
I guess you can work out which one to use from that. You can make a public function that takes the pickupid as a parameter, then set a 45 second timer with "SetTimerEx" passing the pickupid as a parameter. Then destroy the pickup in the function.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)