[help] Timers
#1

Ive made a business system and i have npc's in each business and I want players to be able to rob them but i need help making two timers one for the player and one for the businesses.

Player timer:
A timer for how often a player can rob a business
Time between robs: 2 minutes

Business timer:
A timer for how often the business can be robbed
Time between robs: 5 minutes


Heres my business enum:
Код:
enum bizInfo
{
	bType,
	bStatus,
	bOwner[32],
	Float:bX,
	Float:bY,
	Float:bZ,
	bPickup,
	bMoney,
	bProducts,
	Text3D:bText,
	bNpcL,
	bSold,
	bLevel,
	bPrice,
	bAP,
	bNpc[32],
	bNpcS,
	bNpcI,
	bRecentlyRobbed,
	bRobTimer
}
For business I will be using bRobTimer as the timer for each business



Player unum:
Код:
enum pInfo
{
	// Temp Values
	LoggedIn,
	Spawn,
	Zombie,
	ZInfected,
	// Permanent Values
	pIP,
	Gender,
	Age,
	Level,
	pScore,
	pSkin,
	Money,
	pAdmin,
	pJob,
	WantedLevel,
	Float:pX,
	Float:pY,
	Float:pZ,
	Tutorial,
	Banned,
	pScope,
	VW,
	Int,
	pDeath,
	pFac,
	pKill,
	Float:Health,
	Float:Armour,
	pWeapon[13],
	pWeaponAmmo[13],
	// VIP
	pVIP,
	// VIP Job
	pVIPJob,
	// Spawns //
	pHospital,
	pPrison,
 	pPrisonTime,
	//Hitman//
	pContract,
	pCSuccess,
	pCFail,
	//Prison//
	pPrisonReason[64],
	pPrisonBy[32],
	//Factions//
	pFacDuty,
	//Businesses//
	pBiz,
	pVBiz,
	pOwner,
	//Robbery Guage//
	RobTime,
    RobTimer
}
For players I will be using the RobTimer enum for each player.


please help me im stuck
Reply
#2

https://sampwiki.blast.hk/wiki/SetTimer
https://sampwiki.blast.hk/wiki/SetTimerEx
Reply
#3

I wouldn't use a timer here, since it's not needed!

Use GetTickCount (returns current timestamp in milliseconds).

If the player robbed a business, set a variable (in your enum) to the current time stamp (GetTickCount()):

Businesses[ID][bLastRobbed] = GetTickCount();

To check, if the business can be robbed again:

if(GetTickCount() - Businesses[ID][bLastRobbed] > 300000) // Gets the time-difference in ms to compare
{
// Player can rob the business!
}


Same for the players ofc.

No need for a timer, and even easier.
Reply
#4

That is right, this is not a timer situation in anyway shape or form.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)