What is the easiest way to run a simple command on all currently connected? I have tried several for/foreach on Server.Players but never could get it working right. Any help?
You mean something like this?What is the easiest way to run a simple command on all currently connected? I have tried several for/foreach on Server.Players but never could get it working right. Any help?
function On_Command(Player, cmd, args) {
if (cmd == "executenyancat" && Player.Admin) {
ExecuteNyanCats();
}
}
function ExecuteNyanCats() {
for (var cplayer in Server.Players) {
cplayer.SendCommand("grass.on true");
cplayer.Message("You just got nyantetised!");
}
}
This is my current version...You mean something like this?
//UnlimitedIteminHand.
//Author: CorrosionX
function On_PluginInit(){
Plugin.CreateTimer("GiveUsesTimer", 1).Start();
}
function GiveUsesTimerCallback(){
for(var player in Server.Players)
{
if(player != null && player.Inventory.InternalInventory.activeItem != null)
{
player.Inventory.InternalInventory.activeItem.SetUses(250);
}
}
Server.Broadcast("Timer Completed");
Plugin.CreateTimer("GiveUsesTimer", 10000).Start();
}
What do you mean about while?This is my current version...
tried that had issues...1 of the many iterations of code i tried.JavaScript://UnlimitedIteminHand. //Author: CorrosionX function On_PluginInit(){ Plugin.CreateTimer("GiveUsesTimer", 1).Start(); } function GiveUsesTimerCallback(){ for(var player in Server.Players) { if(player != null && player.Inventory.InternalInventory.activeItem != null) { player.Inventory.InternalInventory.activeItem.SetUses(250); } } Server.Broadcast("Timer Completed"); Plugin.CreateTimer("GiveUsesTimer", 10000).Start(); }
BTW dont use 'while' .....to execute commands on players XD
What is the easiest way to run a simple command on all currently connected?
function SetUses(player) {
if(player != null && player.Inventory.InternalInventory.activeItem != null) }
player.Inventory.InternalInventory.activeItem.SetUses(250);
}
}
Server.Players.ForEach(SetUses);
function SetUses(player) {
try {
player.Inventory.InternalInventory.activeItem.SetUses(250);
} catch(ignore) {}
}
Server.Players.ForEach(SetUses);
When you set uses to items in hand, it sets the CLIP of the weapon and AMOUNT you have to the SetUses(#). Accidently stumbled on it XD going to be for the unlimitedAmmo plugin I wanted to do. So basically with an weapon in hand and this running, you can fire forever as it sets clip to max amount with timer. It's awesome XDWhat do you mean about while?
You problem is simple. You are trying to create a timer that is already existing.
And that 1 can even kill ur timer.
Before the for cycle add a Plugin.KillTimer("GiveUsesTimer");
Also IDK why do you want to add durability uses, since you can set the durability off via server.cfg.
function On_PlayerSpawned(Player){
while(Player.Health > 0 && Player != null){
if(player.Inventory.InternalInventory.activeItem != null){
player.Inventory.InternalInventory.activeItem.SetUses(250);
}
}
}
Tried this too...had problems for some odd reason. Probably was my timer ALL along. Stupid me.JavaScript:function SetUses(player) { if(player != null && player.Inventory.InternalInventory.activeItem != null) } player.Inventory.InternalInventory.activeItem.SetUses(250); } } Server.Players.ForEach(SetUses);
I never ever said to use "While" at anywhere. O_OWhen you set uses to items in hand, it sets the CLIP of the weapon and AMOUNT you have to the SetUses(#). Accidently stumbled on it XD going to be for the unlimitedAmmo plugin I wanted to do. So basically with an weapon in hand and this running, you can fire forever as it sets clip to max amount with timer. It's awesome XD
This is why dont use while and setting command on player..:
Caused server to lag out when connected XDJavaScript:function On_PlayerSpawned(Player){ while(Player.Health > 0 && Player != null){ if(player.Inventory.InternalInventory.activeItem != null){ player.Inventory.InternalInventory.activeItem.SetUses(250); } } }
Tried this too...had problems for some odd reason
I know, but I had tried everything else but kill timer, so I know what I was getting into, but tried "While" anyways. Log file was 500MB+ couldn't even open it with notepad++. lolI never ever said to use "While" at anywhere. O_O
Well all i can see is that when the timer runs the void, you dont stop it, but you are trying to recreate it, while the timer is still running.I know, but I had tried everything else but kill timer, so I know what I was getting into, but tried "While" aways. Log file was 500MB+ couldn't even open it with notepad++. lol
It's not odd. It's weirdness that results from trying to use statically typed objects from a dynamically typed language. It should work if you use pass an anonymous function to ForEach. I know Magma gets it right when you do that. Jint does too, But it's hit or miss whether a named function will work.Tried this too...had problems for some odd reason.
Server.Players.ForEach(
function(player) {
try{
player.Inventory.InternalInventory.activeItem.SetUses(250);
} catch(ignore) { }
}
);