Results 1 to 10 of 34

Thread: Weapon functions (+ setMoveSpeedScale)

Threaded View

Previous Post Previous Post   Next Post Next Post
  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; 6th March 2015 at 23:48.

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

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

Posting Permissions

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