Author Topic: Weapon Ammo Discussion  (Read 378 times)

TurboGrafx

  • Full Member
  • ***
  • Posts: 229
  • Karma: +32/-33
    • View Profile
Weapon Ammo Discussion
« on: November 27, 2016, 12:00:06 am »
Hey everyone. Since we have not heard from the developers in sometime after the update I would Like to create this topic about ways to manually update player.WeaponAmmo

There has only been one successful method I have found and that would be:
Code: [Select]
function onScriptLoad()
{
  NewTimer("Loop", 1000, 0);
  return true;
}

function Loop()
{
  for (local i=0;i<GetMaxPlayers();i++)
  {
    local player = FindPlayer(i);
   
    if (player)
    {
      if (player.Weapon)
      {
         MessagePlayer( "Your current weapon ammo is - " + player.WeaponAmmo, player );
      }
    }
  }
}

szAmmo <- 1;
function onPlayerCommand( player, cmd, text )
{
   if ( cmd == "weapon" )
   {
    player.ClearWeapons()
    player.SetWeapon(4, szAmmo.tofloat())

    szAmmo++
     return true;
  }
}

Now you might be saying, Why would you clear the weapons, Why would we store the ammo in a pointer/class/array, Why that nasty loop.

This is a true test. With this method you will be capable of manually updating the players ammo

Now for decreasing the ammo, I have not found a measure to detect the fire-key while pressing other keys at once.

Code: [Select]
function onPlayerKeyStateChange ( pPlayer, key, down )
{
local model = 0;
switch( pPlayer.Weapon )
{
case 1:
model = 1;
break;

case 2:
model = 2;
break;

case 3:
model = 3;
break;

case 4:
model = 4;
break;

case 5:
model = 5;
break;

case 6:
model = 6;
break;

case 7:
model = 7;
break;

case 8:
model = 8;
break;

case 9:
model = 9;
break;

case 10:
model = 10;
break;

case 11:
model = 11;
break;
}


if( model != 0 )
{
  if (( key == KEY_ONFOOT_FIRE ) )
         {

pPlayer.ClearWeapons()
szAmmo --;
pPlayer.SetWeapon(model, szAmmo.tofloat())
Message("Shots FIRED " + szAmmo.tofloat())


          }
         }
}

Remember these were not intended to be pretty, After many testing I began to get lazy. Maybe someone could expand this.

Lets keep this topic on topic, Feel free to have a rant but at the same time make sure to say something about improving this method.

SetWeapon( id, Ammo)
ClearWeapons()


Is the only way to manually make calls to update.
« Last Edit: November 27, 2016, 12:09:09 am by Mötley »

 

© Liberty Unleashed Team.