Add cooldown dynamically on npcs

Hyroshima

New member
Messages
51
Points
0
Age
16
Emulator
I made this function for a friend and it can be useful in general. 

basically allows you to add wait time for something in npc, you can put different times in the same npc using the reference names.

a utility to put in Global_Functions

Code:
//== Function F_SetNpcCD ================================
// Add cooldown to access specific functions of a pc but not limited
//==
// callfunc "F_SetNpcCD","reference_name",time_in_seconds{,cooldown type};
// Examples:
//    callfunc("F_SetNpcCD","name_example0",45)		// Adds 45 second cooldown at player level
//    callfunc("F_SetNpcCD","name_example1",85,1)	// Adds 1 minute 25 second cooldown at player level
//    callfunc("F_SetNpcCD","name_example2",120,2)	// Adds 2-minute cooldown at account level
function	script	F_SetNpcCD	{
	set .@var$,(countstr(getarg(0)," ")?replacestr(getarg(0)," ","_"):getarg(0));
	set .@time,getarg(1);
	set .@type,getarg(2,0);
	setd(""+(.@type==2?"#":"")+""+.@var$+"_time",gettimetick(2)+.@time);
return;
}

//== Function F_GetNpcCD ================================
// Check npc access cooldown
//==
// callfunc "F_GetNpcCD","name_example"{,cooldown type};
// Examples:
//    callfunc("F_GetNpcCD","name_example0")	// returns "NPC Cooldown: 00H:00M:45s (player)"
//    callfunc("F_GetNpcCD","name_example1",1)	// returns "NPC Cooldown: 00H:01M:25s (player)"
//    callfunc("F_GetNpcCD","name_example2",2)	// returns "NPC Cooldown: 00H:02M:00s (account)"
function	script	F_GetNpcCD	{
	set .@var$,(countstr(getarg(0)," ")?replacestr(getarg(0)," ","_"):getarg(0));
	set .@type,getarg(1,0);
	
	if(gettimetick(2) < getd(""+(.@type==2?"#":"")+""+.@var$+"_time"))
	{
		set .@ts,getd(""+(.@type==2?"#":"")+""+.@var$+"_time")-gettimetick(2);
		set .@h,.@ts/3600;
		set .@m,(.@ts%3600)/60;
		set .@s,.@ts%60;
		dispbottom "NPC Cooldown: "+(.@h<10?"0"+.@h:.@h)+"H:"+(.@m<10?"0"+.@m:.@m)+"M:"+(.@s<10?"0"+.@s:.@s)+"s ("+(.@type==2?"account":"player")+")";
		end;
	}
return;
}
 
I made this function for a friend and it can be useful in general. 

basically allows you to add wait time for something in npc, you can put different times in the same npc using the reference names.

a utility to put in Global_Functions

//== Function F_SetNpcCD ================================
// Add cooldown to access specific functions of a pc but not limited
//==
// callfunc "F_SetNpcCD","reference_name",time_in_seconds{,cooldown type};
// Examples:
// callfunc("F_SetNpcCD","name_example0",45) // Adds 45 second cooldown at player level
// callfunc("F_SetNpcCD","name_example1",85,1) // Adds 1 minute 25 second cooldown at player level
// callfunc("F_SetNpcCD","name_example2",120,2) // Adds 2-minute cooldown at account level
function script F_SetNpcCD {
set .@var$,(countstr(getarg(0)," ")?replacestr(getarg(0)," ","_"):getarg(0));
set .@time,getarg(1);
set .@type,getarg(2,0);
setd(""+(.@type==2?"#":"")+""+.@var$+"_time",gettimetick(2)+.@time);
return;
}

//== Function F_GetNpcCD ================================
// Check npc access cooldown
//==
// callfunc "F_GetNpcCD","name_example"{,cooldown type};
// Examples:
// callfunc("F_GetNpcCD","name_example0") // returns "NPC Cooldown: 00H:00M:45s (player)"
// callfunc("F_GetNpcCD","name_example1",1) // returns "NPC Cooldown: 00H:01M:25s (player)"
// callfunc("F_GetNpcCD","name_example2",2) // returns "NPC Cooldown: 00H:02M:00s (account)"
function script F_GetNpcCD {
set .@var$,(countstr(getarg(0)," ")?replacestr(getarg(0)," ","_"):getarg(0));
set .@type,getarg(1,0);

if(gettimetick(2) < getd(""+(.@type==2?"#":"")+""+.@var$+"_time"))
{
set .@ts,getd(""+(.@type==2?"#":"")+""+.@var$+"_time")-gettimetick(2);
set .@h,.@ts/3600;
set .@m,(.@ts%3600)/60;
set .@s,.@ts%60;
dispbottom "NPC Cooldown: "+(.@h<10?"0"+.@h:.@h)+"H:"+(.@m<10?"0"+.@m:.@m)+"M:"+(.@s<10?"0"+.@s:.@s)+"s ("+(.@type==2?"account":"player")+")";
end;
}
return;
}


congrats Hyro, this will help a lot of people.
Nice func! Thanks for sharing ❤️

 
Last edited by a moderator:
Back
Top