Page 1 of 4 123 ... LastLast
Results 1 to 10 of 34

Thread: Weapon functions (+ setMoveSpeedScale)

  1. #1
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts

    Weapon functions (+ setMoveSpeedScale)

    I have been adding weapon related functions to my libcod git the last few weeks.

    Also I found out how the weapons use their move speed scale. So i added this cod4 function to cod2 .
    PHP Code:
    player SetMoveSpeedScale(2.5
    Note: you need to reset the value manual. It doesn't automatically revert back to 1 when the player disconnects or the map restarts.

    PHP Code:
    init()
    {
        
    setdefaultweapon("mp44_mp"); // changes defaultweapon_mp to mp44_mp

        
    level.otherweapons = []; // for weapons that aren't stored in level.weapons
        
    level.otherweapons["glock_mp"] = spawnstruct();

        
    loadedweapons getloadedweapons();
        
    developer getCvarInt("developer_script");
        for(
    i=0;i<loadedweapons.size;i++)
        {
            
    weaponname loadedweapons[i]; // i = weapon index
            
    if(isDefined(level.weapons[weaponname]))
                
    loadWeaponInfo(ilevel.weapons[weaponname]);
            else if(
    isDefined(level.otherweapons[weaponname]))
                
    loadWeaponInfo(ilevel.otherweapons[weaponname]);
            
            if(
    developer == || >= 64)
                
    printfline("[%]: %"iweaponname);
        }

        
    setWepDamage("glock_mp"65true);
        
    setWepMeleeDamage("raygun_m2_mp"400true);

    I made these wrappers to make the function easier and less messy.
    PHP Code:
    loadWeaponInfo(i, array)
    {
        array.
    id i;
        array.
    dmg getweapondamage(i); // store baseline
        
    array.meleedmg getweaponmeleedamage(i); // in case you want to restore old value
        
        
    if(>= 64// no viewmodels after 64th weapon
            
    array.bugged 1;
    }

    getWeaponArray(weapon)
    {
        if(
    isDefined(level.weapons[weapon]) && isDefined(level.weapons[weapon].id))
            return 
    level.weapons[weapon];
        else if(
    isDefined(level.otherweapons[weapon]) && isDefined(level.otherweapons[weapon].id))
            return 
    level.otherweapons[weapon];
        else
            return 
    undefined;
    }

    updateWepDamage(weapondmg)
    {
        array = 
    getWeaponArray(weapon);
        if(
    isDefined(array))
            array.
    dmg dmg;
    }

    updateWepMeleeDamage(weapondmg)
    {
        array = 
    getWeaponArray(weapon);
        if(
    isDefined(array))
            array.
    meleedmg dmg;
    }

    getWeaponId(weapon)
    {
        if(
    isDefined(level.weapons[weapon]) && isDefined(level.weapons[weapon].id))
            return 
    level.weapons[weapon].id;
        else if(
    isDefined(level.otherweapons[weapon]) && isDefined(level.otherweapons[weapon].id))
            return 
    level.otherweapons[weapon].id;
        else
            return -
    1;
    }

    WeaponMaxAmmo(weapon)
    {
        
    id getWeaponId(weapon);
        if(
    id == -1)
            return 
    0;
        
        return 
    getweaponmaxammo(id);
    }

    WeaponDamage(weapon)
    {
        
    id getWeaponId(weapon);
        if(
    id == -1)
            return 
    0;
        
        return 
    getweapondamage(id);
    }

    WeaponMeleeDamage(weapon)
    {
        
    id getWeaponId(weapon);
        if(
    id == -1)
            return 
    0;
        
        return 
    getweaponmeleedamage(id);
    }

    setWepDamage(weapondmgisdefault)
    {
        
    id getWeaponId(weapon);
        if(
    id == -1)
            return 
    0;
        
        if(
    isDefined(isdefault) && isdefault)
            
    updateWepDamage(weapondmg);
        
        return 
    setweapondamage(iddmg);
    }

    setWepMeleeDamage(weapondmgisdefault)
    {
        
    id getWeaponId(weapon);
        if(
    id == -1)
            return 
    0;
        
        if(
    isDefined(isdefault) && isdefault)
            
    updateWepMeleeDamage(weapondmg);
        
        return 
    setweaponmeleedamage(iddmg);

    I haven't found where cod stored the hit location multiplier yet. You can check the bottom of gsc_utils.cpp to see what i mapped so far.
    Is there any function related to weapon that you would like?

    Edit: forgot one example (i copied the cod4 name)
    PHP Code:
    maxammo WeaponMaxAmmo("mp44_mp"); 
    Last edited by Mitch; 7th March 2015 at 00:48.

  2. The Following 5 Users Say Thank You to Mitch For This Useful Post:

    brague (10th March 2021),filthy_freak_ (20th May 2015),kung foo man (6th March 2015),Ni3ls (6th March 2015),Paho (17th January 2016)

  3. #2
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Reloadtime, firetime and melee time maybe?

  4. The Following User Says Thank You to Ni3ls For This Useful Post:

    Mitch (7th March 2015)

  5. #3
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by Ni3ls View Post
    Reloadtime, firetime and melee time maybe?
    I tried firetime, but i don't get the exact values as in the weapon files back and when i change the value it bugs your weapon. Also it has no affect on your fire speed.

    Edit: read value: 7.00649e-44, actual firetime: 0.05.
    Edit 2: It looks like firetime is not a float, but a integer.
    Edit 3: it works now. CoD2 saves firetime multiplied by 1000. So 0.05 is 50.

    http://classic.xfire.com/video/6335c5/

    PHP Code:
    sayOrUpdateFireTime(args)
    {
        if(
    args.size >= 3// say !firetime time
        
    {
            
    firetime Int(args[2]);
            
    maps\mp\gametypes\_weapons::setWepFireTime(self getCurrentWeapon(), firetime);
        }
        else
        {
            
    firetime maps\mp\gametypes\_weapons::WeaponFireTime(self getCurrentWeapon());
            
    maps\mp\gametypes\_util::tellMessage("FireTime: " firetime);
        }

    PHP Code:
    WeaponFireTime(weapon)
    {
        
    id getWeaponId(weapon);
        if(
    id == -1)
            return 
    0;
        
        return 
    getweaponfiretime(id);
    }

    setWepFireTime(weapontime)
    {
        
    id getWeaponId(weapon);
        if(
    id == -1)
            return 
    0;
        
        return 
    setweaponfiretime(idtime);

    Last edited by Mitch; 7th March 2015 at 12:13.

  6. The Following 3 Users Say Thank You to Mitch For This Useful Post:

    filthy_freak_ (20th May 2015),kung foo man (8th March 2015),Ni3ls (7th March 2015)

  7. #4
    Brigadier General
    Join Date
    Dec 2012
    Posts
    1,012
    Thanks
    440
    Thanked 171 Times in 132 Posts
    Nice work! And what about the others? Im very curious right now :0

  8. The Following User Says Thank You to Ni3ls For This Useful Post:

    Mitch (7th March 2015)

  9. #5
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by Ni3ls View Post
    Nice work! And what about the others? Im very curious right now :0
    Thank you. But i'm gonna try those a other time.
    Finding the right offset is very easy. It works exactly as how you find the 'closer' function. But instead of getting a function you have a hex value as offset. (press D a few times until you see ...h then google 0x... to decimal)

    Changing the firetime doesn't always change how fast you can fire. For some weapons it doesn't work.

    I committed my changes. https://github.com/M-itch/libcod/com...0f04c343e27dff

  10. The Following User Says Thank You to Mitch For This Useful Post:

    Paho (17th January 2016)

  11. #6
    Assadministrator IzNoGoD's Avatar
    Join Date
    Aug 2012
    Posts
    1,718
    Thanks
    17
    Thanked 1,068 Times in 674 Posts
    The big problem with movespeedscale is that it does not influence the acceleration in air.
    I finally finished a patch that allows that (player set_g_speed(210))

    Mitch, ring me up on xfire for the code
    "Does not work" is an error report for a bug between keyboard and chair.

    All hail Artie Effem

  12. #7
    Private First Class
    Join Date
    Oct 2013
    Posts
    219
    Thanks
    56
    Thanked 105 Times in 66 Posts
    Is it possible to set melee damage per client? I'm working on a sprinting code that does not change your weapon or use modified weapon files. Only roadblock is disabling melee while sprinting.

  13. #8
    Brigadier General
    Join Date
    Oct 2012
    Posts
    994
    Thanks
    20
    Thanked 588 Times in 388 Posts
    Quote Originally Posted by filthy_freak_ View Post
    Is it possible to set melee damage per client? I'm working on a sprinting code that does not change your weapon or use modified weapon files. Only roadblock is disabling melee while sprinting.
    Nope. Very few weapon attributes can be set with script. Melee is not one of them. I have no idea if Libcod can set it.

  14. #9
    Global Mossaderator Mitch's Avatar
    Join Date
    Nov 2012
    Posts
    654
    Thanks
    204
    Thanked 450 Times in 305 Posts
    Quote Originally Posted by Tally View Post
    Nope. Very few weapon attributes can be set with script. Melee is not one of them. I have no idea if Libcod can set it.
    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)

  15. #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 09: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
  •