Results 1 to 10 of 34

Thread: Weapon functions (+ setMoveSpeedScale)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #10
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    Quote Originally Posted by Mitch View Post
    I think setting the damage per client won't be easy. But it is doable to set the delay time until the next bash.
    Basically blocking the melee for a short time. (It might cause side effects e.g. unable to fire either)
    Hmm, being unable to shoot while sprinting won't be a problem. If you managed to do this it would be great.

    Also, here is the sprint code i'v done. Credits to Iznogod for the base, Tally for the HUD and mitch for setg_speed.
    Code:
    init()
    {
    	if(getCvarInt("serv_disable_sprint") != 1)
    	{
    		precacheShader("gfx/hud/hud@health_back.tga");
    		precacheShader("gfx/hud/hud@health_bar.tga");
    		
    		level thread onPlayerConnect();
    	}
    }
    
    onPlayerConnect()
    {
    	level endon("intermission");
    	
    	for(;;)
    	{
    		level waittill("connecting", player);
    		
    		player thread waitforspawn();
    	}
    }
    
    waitForSpawn()
    {
    	self endon("disconnect");
    	
    	for(;;)
    	{
    		self waittill("spawned_player");
    		
    		self thread onPlayerSpawn();
    	}
    }
    
    onPlayerSpawn()
    {
    	level endon("intermission");
    	self endon("disconnect");
    	self endon("killed_player");
    	
    	sprinting = false;
    	speed = getCvarInt("g_speed");
    	self setg_speed(speed);
    	maxStamina = 83;
    	minStamina = 15;
    	stamina = maxStamina;
    	sprintScale = 1.6;
    	
    	current = "";
    	clip = 0;
    	clipb = 0;
    	ammo = 0;
    	ammob = 0;
    	weapon1 = "";
    	weapon2 = "";
    	currentSlot = "";
    	
    	if(!isDefined(self.sprint_hud_back)) {
    		self.sprint_hud_back = newClientHudElem( self );
    		self.sprint_hud_back setShader("gfx/hud/hud@health_back.tga", stamina + 2, 5);
    		self.sprint_hud_back.horzAlign = "right";
    		self.sprint_hud_back.vertAlign = "bottom";
    		self.sprint_hud_back.x = -93;
    		self.sprint_hud_back.y = -49;
    	}
    	if(!isDefined(self.sprint_hud)) {
    		self.sprint_hud = newClientHudElem( self );
    		self.sprint_hud setShader("gfx/hud/hud@health_bar.tga", stamina, 3);
    		self.sprint_hud.color = ( 0, 0, 1);
    		self.sprint_hud.horzAlign = "right";
    		self.sprint_hud.vertAlign = "bottom";
    		self.sprint_hud.x = -92;
    		self.sprint_hud.y = -48;
    	}
    	
    	while(isAlive(self))
    	{
    		if(self useButtonPressed() && !sprinting && (self forwardbuttonpressed() - self backbuttonpressed() + self leftbuttonpressed() - self rightbuttonpressed() != 0) && self GetStance() == "stand" && !self isAiming())
    		{
    			if(stamina > minStamina)
    			{
    				sprinting = true;
    				
    				current = self getCurrentWeapon();
    				weapon1 = self getWeaponSlotWeapon("primary");
    				weapon2 = self getWeaponSlotWeapon("primaryb");
    
    				if(current == weapon1)	currentSlot = "primary";
    				else					currentSlot = "primaryb";
    
    				if(currentSlot == "none") continue;
    				
    				clip = self getWeaponSlotClipAmmo("primary");
    				ammo = self getWeaponSlotAmmo("primary");
    				clipb = self getWeaponSlotClipAmmo("primaryb");
    				ammob = self getWeaponSlotAmmo("primaryb");
    				
    				if(currentSlot == "primary")
    					self takeWeapon(weapon2);
    				else	self takeWeapon(weapon1);
    				
    				self setWeaponSlotClipAmmo(currentSlot, 0);
    				self setWeaponSlotAmmo(currentSlot, 0);
    				self setg_speed(int(speed * sprintScale));
    			}
    			else if(stamina < maxStamina)
    			{
    				stamina++;
    				self.sprint_hud setShader("gfx/hud/hud@health_bar.tga", stamina, 3);
    			}
    		}
    		else if(self useButtonPressed() && (self forwardbuttonpressed() - self backbuttonpressed() + self leftbuttonpressed() - self rightbuttonpressed() != 0) && self GetStance() == "stand" && !self isAiming())
    		{
    			//continue sprinting
    			stamina--;
    			self.sprint_hud setShader("gfx/hud/hud@health_bar.tga", stamina, 3);
    			if(stamina <= 0)
    			{
    				sprinting = false;
    				stamina = 0;
    				
    				if(currentSlot == "primary")
    					self setWeaponSlotWeapon("primaryb", weapon2);
    				else	self setWeaponSlotWeapon("primary", weapon1);
    				
    				self setWeaponSlotClipAmmo("primary", clip);
    				self setWeaponSlotAmmo("primary", ammo);
    				self setWeaponSlotClipAmmo("primaryb", clipb);
    				self setWeaponSlotAmmo("primaryb", ammob);
    				self setg_speed(speed);
    			}
    		}
    		else if(sprinting)
    		{
    			sprinting = false;
    			
    			if(stamina < 0)
    				stamina = 0;
    			
    			if(currentSlot == "primary")
    				self setWeaponSlotWeapon("primaryb", weapon2);
    			else	self setWeaponSlotWeapon("primary", weapon1);
    			
    			self setWeaponSlotClipAmmo("primary", clip);
    			self setWeaponSlotAmmo("primary", ammo);
    			self setWeaponSlotClipAmmo("primaryb", clipb);
    			self setWeaponSlotAmmo("primaryb", ammob);
    			self setg_speed(speed);
    		}
    		else
    		{
    			if(stamina < maxStamina)
    			{
    				stamina++;
    				self.sprint_hud setShader("gfx/hud/hud@health_bar.tga", stamina, 3);
    			}
    		}
    		wait 0.05;
    	}
    }
    
    isAiming()
    {
    	if(self playerads() > 0)
    		return true;
    	else
    		return false;
    }
    Just call init(); on gametype startup.
    Last edited by filthy_freak_; 20th May 2015 at 08:35.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •