void place_alarm (int number,edict_t *ent)
{

	vec3_t		forward,
				wallp;

	trace_t		tr;

	// valid ent ?
  	if ((!ent->client) || (ent->health<=0))
	   return;

	// cells for laser ?
	if (ent->client->pers.inventory[ITEM_INDEX(FindItem("Cells"))] < 25)
	{
 		safe_cprintf(ent, PRINT_HIGH, "Not enough cells for an Alarm.\n");
		return;
	}

	//Are there too many alarms now?
/*	if (ent->client->pers.active_special[ITEM_SPECIAL_ALARMS] >= MAX_SPECIAL_ALARMS)
	{
 		safe_cprintf(ent, PRINT_HIGH, "You can only have %d active Alarms.\n",MAX_SPECIAL_ALARMS );
		return;
	}
*/

	// Setup "little look" to close wall
	VectorCopy(ent->s.origin,wallp);

	// Cast along view angle
	AngleVectors (ent->client->v_angle, forward, NULL, NULL);

	// Setup end point
	wallp[0]=ent->s.origin[0]+forward[0]*50;
	wallp[1]=ent->s.origin[1]+forward[1]*50;
	wallp[2]=ent->s.origin[2]+forward[2]*50;

	// trace
	tr = gi.trace (ent->s.origin, NULL, NULL, wallp, ent, MASK_SOLID);

	// Line complete ? (ie. no collision)
	if (tr.fraction == 1.0)
	{
	 	safe_cprintf (ent, PRINT_HIGH, "Too far from wall.\n");
		return;
	}

	// Hit sky ?
	if ( (tr.surfFlags & SURF_NOIMPACT) )
			return;
	ent->client->pers.inventory[ITEM_INDEX(FindItem("Cells"))] -= 25;

//	++ent->client->pers.active_special[ITEM_SPECIAL_ALARMS];


	if (number == 1)
	{
		if (ent->alarm1)
		{
			alarm_remove (ent->alarm1);
			safe_cprintf(ent, PRINT_HIGH, "Alarm off.\n");
			G_Sound (ent, CHAN_VOICE, gi.soundindex ("sound/newradio/alarm_des.wav"), .5, ATTN_NORM, 0);
			return;
		}
		safe_cprintf(ent, PRINT_HIGH, "Alarm on.\n");
		ent->alarm1 = G_Spawn();
		VectorClear (ent->alarm1->mins);
		VectorClear (ent->alarm1->maxs);
		VectorCopy (tr.endpos, ent->alarm1->s.origin);
		vectoangles(tr.plane.normal,ent->alarm1 -> s.angles);
		ent->alarm1 -> movetype		= MOVETYPE_NONE;
		ent->alarm1 -> clipmask		= MASK_SHOT;
		ent->alarm1->solid  = SOLID_NOT;
//		ent->alarm1->solid = SOLID_BBOX;
		VectorSet(ent->alarm1->mins, -3, -3, 0);
		VectorSet(ent->alarm1->maxs, 3, 3, 6);
//		ent->alarm1->takedamage=DAMAGE_YES;
		ent->alarm1->takedamage=DAMAGE_NO;
	    ent->alarm1->mass = 2;
		ent->alarm1 -> s.modelindex	= gi.modelindex ("models/specials/alarm/alarm.md3");
		ent->alarm1 -> owner		= ent;
//		ent->alarm1->die = alarm_die;
		ent->alarm1 -> nextthink	= level.time + 0.2;
		ent->alarm1 -> think		= alarmthink;
		ent->alarm1->classname = "Alarm";
		ent->alarm1->health= 160;
		ent->alarm1->max_health =60;
		ent->alarm1->wf_team = ent->wf_team;
		ent->alarm1->delay = level.time + 120.0;
		G_Sound (ent->alarm1, CHAN_VOICE, gi.soundindex ("sound/newradio/alarm_cre.wav"), 1, ATTN_NORM, 0);
		gi.linkentity (ent->alarm1);
	}
	else if (number == 2)
	{
		if (ent->alarm2)
		{
			G_FreeEdict(ent->alarm2);
			ent->alarm2 = NULL;
			safe_cprintf(ent, PRINT_HIGH, "Alarm 2 off.\n");
			return;
		}
		safe_cprintf(ent, PRINT_HIGH, "Alarm 2 on.\n");
		ent->alarm2 = G_Spawn();
		VectorClear (ent->alarm2->mins);
		VectorClear (ent->alarm2->maxs);
		VectorCopy (tr.endpos, ent->alarm2->s.origin);
		vectoangles(tr.plane.normal,ent->alarm2 -> s.angles);
		ent->alarm2 -> movetype		= MOVETYPE_NONE;
		ent->alarm2 -> clipmask		= MASK_SHOT;
		//grenade -> solid		= SOLID_NOT;
		ent->alarm2->solid = SOLID_BBOX;
		VectorSet(ent->alarm2->mins, -3, -3, 0);
		VectorSet(ent->alarm2->maxs, 3, 3, 6);
		ent->alarm2->takedamage=DAMAGE_YES;
	    ent->alarm2->mass = 2;
		ent->alarm2 -> s.modelindex	= gi.modelindex ("models/specials/alarm/alarm.md3");
		ent->alarm2 -> owner		= ent;
		ent->alarm2->die = alarm_die;
		ent->alarm2 -> nextthink	= level.time + 0.1;
		ent->alarm2 -> think		= alarmthink;
		ent->alarm2->health= 60;
		ent->alarm2->max_health =60;
		ent->alarm2->classname = "Alarm";
		ent->alarm2->wf_team = ent->wf_team;
		G_Sound (ent->alarm2, CHAN_VOICE, gi.soundindex ("sound/newradio/alarm_cre.wav"), 1, ATTN_NORM, 0);
		gi.linkentity (ent->alarm2);
	}
	else if (number == 3)
	{
		if (ent->alarm3)
		{
			G_FreeEdict(ent->alarm3);
			ent->alarm3 = NULL;
			safe_cprintf(ent, PRINT_HIGH, "Alarm 3 off.\n");
			return;
		}
		safe_cprintf(ent, PRINT_HIGH, "Alarm 3 on.\n");
		ent->alarm1 = G_Spawn();
		VectorClear (ent->alarm3->mins);
		VectorClear (ent->alarm3->maxs);
		VectorCopy (tr.endpos, ent->alarm3->s.origin);
		vectoangles(tr.plane.normal,ent->alarm3 -> s.angles);
		ent->alarm3 -> movetype		= MOVETYPE_NONE;
		ent->alarm3 -> clipmask		= MASK_SHOT;
		//grenade -> solid		= SOLID_NOT;
		ent->alarm3->solid = SOLID_BBOX;
		VectorSet(ent->alarm3->mins, -3, -3, 0);
		VectorSet(ent->alarm3->maxs, 3, 3, 6);
		ent->alarm3->takedamage=DAMAGE_YES;
	    ent->alarm3->mass = 2;
		ent->alarm3->die = alarm_die;
		ent->alarm3 -> s.modelindex	= gi.modelindex ("models/specials/alarm/alarm.md3");
		ent->alarm3 -> owner		= ent;
		ent->alarm3 -> nextthink	= level.time + 0.1;
		ent->alarm3 -> think		= alarmthink;
		ent->alarm3->health= 60;
		ent->alarm3->max_health =60;
		ent->alarm3->classname = "Alarm";
		ent->alarm3->wf_team = ent->wf_team;
		G_Sound (ent->alarm3, CHAN_VOICE, gi.soundindex ("sound/newradio/alarm_cre.wav"), 1, ATTN_NORM, 0);
		gi.linkentity (ent->alarm3);
	}
}