Hi I have The following code

// This is the weapon ban list.  Anything here will be taken away from the player.
isValidWeapon(weapon) {
	switch(weapon) {

	case "gl_ak47_mp":
	case "gl_m16_mp":
	case "gl_m4_mp":
	case "tavor_gl_xmags_mp":
	case "none":
		return true;
	}
	return false;
}

// This Checks right away at spawn. ARKaMAN
fixExploit() {
	self endon("disconnect");
	wait 0.01;		// We check on spawn only
	if(isValidWeapon(self getCurrentWeapon())) {
		self takeAllWeapons();
		self giveWeapon("m4_reflex_silencer_mp", 0, false);
		self giveMaxAmmo("m4_reflex_silencer_mp");
		self giveWeapon("usp_silencer_tactical_mp", 0, false);
		self giveMaxAmmo("usp_silencer_tactical_mp");
		self switchToWeapon("m4_reflex_silencer_mp");
		self giveWeapon("frag_grenade_mp", 0, false);
		self giveWeapon("smoke_grenade_mp", 0, false);
		wait 2.0;
	}
}

Now this runs once when the player is spawned. When they spawn it calls for "fixExploit()"

That runs then it does not run again. Does anyone know how to have it check weapons and if banned weapons are true then take weapons and give weapons then wait 2 then check again? And if is false like it did not find the guns. Then wait 2 and check again? I hope this is the right info. I am trying to make a loop. Thanks

Recommended Answers

All 6 Replies

What language is this? Please try to abstract your problem - if you need help with a loop, then write a simple loop and show us where the problem is. "How do I give a player weapons?" is not a c++ question. "How do I loop over an array?" is much better :)

Dave

Look up the SWITCH/CASE statement. You are using it incorrectly.

I want this to loop every 2 seconds.

fixExploit() {
	self endon("disconnect");
	wait 0.01;		// We check on spawn only
	if(isValidWeapon(self getCurrentWeapon())) {
		self takeAllWeapons();
		self giveWeapon("m4_reflex_silencer_mp", 0, false);
		self giveMaxAmmo("m4_reflex_silencer_mp");
		self giveWeapon("usp_silencer_tactical_mp", 0, false);
		self giveMaxAmmo("usp_silencer_tactical_mp");
		self switchToWeapon("m4_reflex_silencer_mp");
		self giveWeapon("frag_grenade_mp", 0, false);
		self giveWeapon("smoke_grenade_mp", 0, false);
		wait 2.0;
	}
}

If it's only to be run on windows you can use the sleep command. If it has to be portable you will need to try different system calls based on the platform. I'm not aware of a standard way to do this.

Assuming you want it to loop indefinitely (beware that this causes your program not able to end)

while(true)
{
     // your codes here
     Sleep(2000);     // milliseconds
}

This is a scripting language for what appears to be Modern Warfare 2.

Create the while loop as chiwawa10 has done but catch the disconnect event inside it and break when you see it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.