10.09.2011, 07:59
I need a timer for action/job. Well many. I have tried to do somethig with SetTimer, but i kinda failed lol. Any help?
// -----------------------------------------------------------------------------
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;
}
// -----------------------------------------------------------------------------
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;
}
// -----------------------------------------------------------------------------
//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);
//SetTimerEx is used for functions with parameters. (again just an example).
SetTimerEx("OnPlayerDeath", 1000, true, "iii", playerid, killerid, reason);