Vice City: Multiplayer

VC:MP Discussion => General Discussion => Topic started by: NicusorN5 on Apr 03, 2016, 08:59 AM

Title: /wep (arma) command is not working
Post by: NicusorN5 on Apr 03, 2016, 08:59 AM
/arma command gives the player a weapon and decreases its money.
My command
    if(!text) MessagePlayer( "[#ffffff] Foloseste - /arma <nume> <ID>", player );
    else
    {
    local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
    if(!plr) MessagePlayer( "[#ffffff]Eroare - Jucator Invalid", player );
    else if(!wep || GetWeaponName(wep.tointeger()) == "Unknown") MessagePlayer( "[#ffffff]Error - invalid wep ID", player );
else
 {
                if(wep == 1)
                {
                  if(plr.Cash >100)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -100 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
       
                  }
                if(wep == 2)
                {
                  if(plr.Cash >150)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -150 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 3)
                {
                  if(plr.Cash >200)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -200 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 4)
                {         
                  if(plr.Cash >500)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 5)
                {         
                  if(player.Cash >350)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -350 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 6)
                {         
                  if(player.Cash >300)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -300 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 7)
                {         
                  if(player.Cash >250)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -250 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 8)
                {         
                  if(player.Cash >350)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -350 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 9)
                {         
                  if(player.Cash >500)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 10)
                {         
                  if(player.Cash >600)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -600 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 11)
                {         
                  if(player.Cash >1000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -1000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 12)
                {         
                  if(player.Cash >750)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -750 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 13)
                {         
                  if(player.Cash >850)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -850 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 14)
                {         
                  if(player.Cash >700)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -700 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 15)
                {         
                  if(player.Cash >1000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -1000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 16)
                {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];         
                  MessagePlayer("Arma invalida!",player);
                  local hp = player.Health;
                  player.Health = 0.0;
                  Message(player+"a luat o arma invalida!");
                 }
                if(wep == 17)
                {         
                  if(player.Cash >1500)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -1500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 18)
                {         
                  if(player.Cash >5000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -5000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 19)
                {         
                  if(player.Cash >3500)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -3500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 20)
                {         
                  if(player.Cash >16750)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -16750 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 21)
                {         
                  if(player.Cash >5000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -5000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 22)
                {         
                  if(player.Cash >500)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 23)
                {         
                  if(player.Cash >1250)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -1250 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 24)
                {         
                  if(player.Cash >2000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  player.Cash += -2000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 25)
                {         
                  if(plr.Cash >2500)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -2500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 26)
                {         
                  if(plr.Cash >7500)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -7500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 27)
                {         
                  if(plr.Cash >6500)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -6500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }   
                if(wep == 28)
                {         
                  if(plr.Cash >7550)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -7550 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 29)
                {         
                  if(plr.Cash >8000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -8000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }     
                if(wep == 30)
                {         
                  if(plr.Cash >20000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -20000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 31)
                {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];         
                  if(plr.Cash >12500)
                  {
                  plr.Cash += -12500 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 32)
                {         
                  if(plr.Cash >25000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -25000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
                if(wep == 33)
                {         
                  if(plr.Cash > 100000)
                  {
                  local params = split( text, " " ), plr = FindPlayer( params[0] ), wep = params[1];
                  plr.Cash += -100000 ;
                  plr.GiveWeapon(wep.tointeteger(),500);
                  MessagePlayer( GetWeaponName(wep.tointeger())+"a fost data la"+plr.name,player);
                  }
                 }
            }
        }
    }
    }
Title: Re: /wep (arma) command is not working
Post by: Thijn on Apr 03, 2016, 09:23 AM
Jesus christ what a horrible piece of code.

What's not working?
Title: Re: /wep (arma) command is not working
Post by: . on Apr 03, 2016, 09:43 AM
Probably because you've misspelled several things, such as "plr.name" which is supposed to be "plr.Name". And next time consider telling us what the actual error says. Otherwise you're going to get ignored. If you don't know which is the error then at least take a screenshot of your server console window (make sure it's large enough to include the whole error output). But to be honest you are complicating your self a lot. That whole thing can be simplified for quick future adjustments.

g_WepAttrib <- {  };

g_WepAttrib[WEP_FIST]           <- { Cost = 501, Ammo = 10 };
g_WepAttrib[WEP_BRASSKNUCKLES]  <- { Cost = 2278, Ammo = 34 };
g_WepAttrib[WEP_SCREWDRIVER]    <- { Cost = 1290, Ammo = 63 };
g_WepAttrib[WEP_GOLFCLUB]       <- { Cost = 1508, Ammo = 47 };
g_WepAttrib[WEP_NIGHTSTICK]     <- { Cost = 1366, Ammo = 1 };
g_WepAttrib[WEP_KNIFE]          <- { Cost = 2133, Ammo = 41 };
g_WepAttrib[WEP_BASEBALLBAT]    <- { Cost = 1959, Ammo = 8 };
g_WepAttrib[WEP_HAMMER]         <- { Cost = 2439, Ammo = 75 };
g_WepAttrib[WEP_MEATCLEAVER]    <- { Cost = 1494, Ammo = 11 };
g_WepAttrib[WEP_MACHETE]        <- { Cost = 2331, Ammo = 13 };
g_WepAttrib[WEP_KATANA]         <- { Cost = 704, Ammo = 22 };
g_WepAttrib[WEP_CHAINSAW]       <- { Cost = 1133, Ammo = 36 };
g_WepAttrib[WEP_GRENADE]        <- { Cost = 625, Ammo = 47 };
g_WepAttrib[WEP_REMOTE]         <- { Cost = 2500, Ammo = 17 };
g_WepAttrib[WEP_TEARGAS]        <- { Cost = 1754, Ammo = 10 };
g_WepAttrib[WEP_MOLOTOV]        <- { Cost = 2215, Ammo = 38 };
g_WepAttrib[WEP_ROCKET]         <- { Cost = 2008, Ammo = 77 };
g_WepAttrib[WEP_COLT45]         <- { Cost = 1888, Ammo = 71 };
g_WepAttrib[WEP_PYTHON]         <- { Cost = 1252, Ammo = 33 };
g_WepAttrib[WEP_SHOTGUN]        <- { Cost = 1966, Ammo = 100 };
g_WepAttrib[WEP_SPAS12]         <- { Cost = 2154, Ammo = 74 };
g_WepAttrib[WEP_STUBBY]         <- { Cost = 1866, Ammo = 13 };
g_WepAttrib[WEP_TEC9]           <- { Cost = 1717, Ammo = 95 };
g_WepAttrib[WEP_UZI]            <- { Cost = 2137, Ammo = 63 };
g_WepAttrib[WEP_INGRAM]         <- { Cost = 2439, Ammo = 96 };
g_WepAttrib[WEP_MP5]            <- { Cost = 766, Ammo = 71 };
g_WepAttrib[WEP_M4]             <- { Cost = 1315, Ammo = 35 };
g_WepAttrib[WEP_RUGER]          <- { Cost = 981, Ammo = 29 };
g_WepAttrib[WEP_SNIPER]         <- { Cost = 2342, Ammo = 2 };
g_WepAttrib[WEP_LASERSCOPE]     <- { Cost = 1635, Ammo = 18 };
g_WepAttrib[WEP_ROCKETLAUNCHER] <- { Cost = 527, Ammo = 26 };
g_WepAttrib[WEP_FLAMETHROWER]   <- { Cost = 1953, Ammo = 72 };
g_WepAttrib[WEP_M60]            <- { Cost = 2012, Ammo = 21 };
g_WepAttrib[WEP_MINIGUN]        <- { Cost = 1982, Ammo = 84 };
g_WepAttrib[WEP_BOMB]           <- { Cost = 1831, Ammo = 26 };
g_WepAttrib[WEP_HELICANNON]     <- { Cost = 1898, Ammo = 75 };
g_WepAttrib[WEP_CAMERA]         <- { Cost = 538, Ammo = 20 };
g_WepAttrib[WEP_VEHICLE]        <- { Cost = 901, Ammo = 90 };
g_WepAttrib[WEP_DRIVEBY]        <- { Cost = 827, Ammo = 13 };
g_WepAttrib[WEP_DROWNED]        <- { Cost = 955, Ammo = 4 };
g_WepAttrib[WEP_FALL]           <- { Cost = 1236, Ammo = 17 };
g_WepAttrib[WEP_EXPLOSION]      <- { Cost = 1079, Ammo = 56 };
g_WepAttrib[WEP_SUICIDE]        <- { Cost = 642, Ammo = 18 };

// ^^^ that doesn't go inside the command function!!!

if (!text)
{
    MessagePlayer("[#ffffff] Foloseste - /arma <nick> <tag/id>", player);
}
else
{
    local args = split(text, " ");

    if (args.len() < 2)
    {
        MessagePlayer("[#ffffff] Foloseste - /arma <nick> <tag/id>", player);
        return;
    }

    local target = FindPlayer(args[0]);

    if (!target)
    {
        MessagePlayer("[#ffffff] Eroare - Jucator Invalid", player);
        return;
    }

    local wepid = -1;

    if (IsNum(args[1]))
    {
        wepid = args[1].tointeger(10);
    }
    else
    {
        wepid = GetWeaponID(args[1]);
    }

    local wepname = GetWeaponName(wepid);

    if (wepname == "Unknown" || !g_WepAttrib.rawin(wepid))
    {
        MessagePlayer("[#ffffff]Error - invalid wep ID", player);
        return;
    }
    else if (target.Cash < g_WepAttrib[wepid].Cost)
    {
        MessagePlayer("[#ffffff]Error - insufficient cash", player);
        return;
    }

    target.Cash -= g_WepAttrib[wepid].Cost ;
    target.GiveWeapon(wepid, g_WepAttrib[wepid].Ammo);

    MessagePlayer(wepname + " a fost data la " + target.Name, player);
}

NOTE: Untested code. By untested I mean I haven't started a server to see if it pops any errors or something.
Title: Re: /wep (arma) command is not working
Post by: NicusorN5 on Apr 03, 2016, 10:32 AM
I have no error in the console :P
Title: Re: /wep (arma) command is not working
Post by: NicusorN5 on Apr 03, 2016, 04:06 PM
Fixed it myself...
     else if(text =="1" && player.Cash >100)
     {
      player.Cash += -100;
      player.GiveWeapon(1,500);
      Message(player + " a cumparat arma cu id "+text);
     }