load custom weps

Started by umar4911, Oct 23, 2017, 10:18 AM

Previous topic - Next topic

umar4911

While receiving custom weps through /wep cmd, the name changes to Unknown. example I added a ak47 in server. If I type /wep ak, it shows weapon Unknown. If I use id, it works and shows the name.
  else if( cmd == "wep" || cmd == "we" )
{
if( !text ) return MessagePlayer( "[#FFDD33]Command Error:[#FFFFFF] /"+cmd+" <wep 1> <wep 2> <...>", player );
else
{
local params = split( text, " " );
local weapons;
for( local i = 0; i <= params.len() - 1; i++ )
{
if( !IsNum( params[i] ) && GetWeaponID( params[i] ) && GetWeaponID( params[i] ) > 0 && GetWeaponID( params[i] ) <= 32 )
{
player.SetWeapon( GetWeaponID( params[i] ), 99999 );
weapons = GetWeaponName( GetWeaponID( params[i] ) );
MessagePlayer("[#FFDD33]Information:[#FFFFFF] You received the following weapon: "+GetWeaponName(GetWeaponID( params[i])) +".", player);

}
else if( !IsNum( params[i] ) && GetWeaponID( params[i] ) && GetWeaponID( params[i] ) > 101 && GetWeaponID( params[i] ) < 104 )
{
player.SetWeapon( GetWeaponID( params[i] ), 99999 );
if(params[i] == GetWeaponID(102)) weapons = "AK47";
else if(params[i] == GetWeaponID(103)) weapons = "IV Rocket Launcher";the ID and add it.
MessagePlayer("[#FFDD33]Information:[#FFFFFF] You received the following weapon: "+GetWeaponName(GetWeaponID( params[i])) +".", player);

}
else if( IsNum( params[i] ) && params[i].tointeger() < 33 && params[i].tointeger() > 0 )
{
player.SetWeapon( params[i].tointeger(), 99999 );
weapons = GetWeaponName( params[i].tointeger() );
MessagePlayer("[#FFDD33]Information:[#FFFFFF] You received the following weapon: "+weapons+".", player);

}
else if( IsNum( params[i] ) && params[i].tointeger() < 104 && params[i].tointeger() > 101 )
{
player.SetWeapon( params[i].tointeger(), 99999 );
if(params[i].tointeger() == 102) weapons = "AK47";
else if(params[i].tointeger() == 103) weapons = "IV Rocket Launcher";and add it.
MessagePlayer("[#FFDD33]Information:[#FFFFFF] You received the following weapon: "+weapons+".", player);
}
else MessagePlayer( "[#FFDD33]Information:[#FFFFFF] Invalid Weapon Name/ID", player );
}
}
}
RT Member | Asian City Scripter | VKs Contributor | European City Contributor | EAD Scripter

Xmair

#1
That's because the default GetWeaponName function only returns IDs of the weapons which exist originally in the game. You'd need to make a function like this:
function getWeaponName( intID )
{
switch( intID )
{
case 102:
{
return "AK-47";
}
break;
case 103:
{
return "IV Rocket Launcher";
}
break;
default:
{
return GetWeaponName( intID );
}
break;
};
};
This should just do the job. Usage:
getWeaponName( integer weaponID )

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

DizzasTeR


Xmair

Quote from: Doom_Kill3R on Oct 23, 2017, 11:19 AM
Quote from: Xmair on Oct 23, 2017, 10:41 AM...

You mean getWeaponName( weaponID )
Yeah, thanks for pointing out the mistake, edited the post.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

umar4911

You didnot understand. It doesnot compare the Get the ID. If I type /wep ak, it says Invalid wep
RT Member | Asian City Scripter | VKs Contributor | European City Contributor | EAD Scripter

Xmair

I gave you a fully copy pasta function, if you're still unable to do it, stop scripting.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

umar4911

Quote from: Xmair on Oct 23, 2017, 04:09 PMI gave you a fully copy pasta function, if you're still unable to do it, stop scripting.
I copy and pasted the function but I think there should a function of getWeaponID not name. It doesnot get the id from the weapon
RT Member | Asian City Scripter | VKs Contributor | European City Contributor | EAD Scripter

Xmair

Quote from: umar4911 on Oct 24, 2017, 07:33 AM
Quote from: Xmair on Oct 23, 2017, 04:09 PMI gave you a fully copy pasta function, if you're still unable to do it, stop scripting.
I copy and pasted the function but I think there should a function of getWeaponID not name. It doesnot get the id from the weapon
Stop scripting.

Credits to Boystang!

VU Full Member | VCDC 6 Coordinator & Scripter | EG A/D Contributor | Developer of VCCNR | Developer of KTB | Ex-Scripter of EAD

umar4911

Quote from: Xmair on Oct 24, 2017, 08:49 AM
Quote from: umar4911 on Oct 24, 2017, 07:33 AM
Quote from: Xmair on Oct 23, 2017, 04:09 PMI gave you a fully copy pasta function, if you're still unable to do it, stop scripting.
I copy and pasted the function but I think there should a function of getWeaponID not name. It doesnot get the id from the weapon
Stop scripting.
xD any solution pls
RT Member | Asian City Scripter | VKs Contributor | European City Contributor | EAD Scripter

umar4911

Bump

Let me clarify that while loading using /wep, if id(eg 102) is arguments, then ut identifies the id in integer and shows the text in place of it but if I directly use the string(eg ak), it doesnot identify and say invalid wep
RT Member | Asian City Scripter | VKs Contributor | European City Contributor | EAD Scripter

D4rkR420R

Make sure it's the same text as used in the ak47.xml.

umar4911

Quote from: KuRiMi on Dec 22, 2017, 02:14 AMMake sure it's the same text as used in the ak47.xml.
didn't understand
RT Member | Asian City Scripter | VKs Contributor | European City Contributor | EAD Scripter

!

#12
Try
//
<?phpelse if( cmd == "wep" || cmd == "we" ){   if( !text ) return MessagePlayer( "[#FFDD33]Command Error:[#FFFFFF] /"+cmd+" <wep 1> <wep 2> <...>", player );   else   {      local params = split( text, " " );       local weapons;      for( local i = 0; i <= params.len() - 1; i++ )       {         if( !IsNum( params[i] ) && getWeaponID( params[i] ) != 255 )          {            player.SetWeapon( getWeaponID( params[i] ), 99999 );             if ( !weapons ) weapons = getWeaponName( getWeaponID( params[i] ) );            else weapons = weapons+", "+getWeaponName( getWeaponID( params[i] ) );         }         else if( IsNum( params[i] ) && getWeaponName( params[i].tointeger() ) != "Unknown" )         {            player.SetWeapon( params[i].tointeger(), 99999 );             weapons = getWeaponName( params[i].tointeger() );            if ( !weapons ) weapons = getWeaponName( params[i].tointeger() );            else weapons = weapons+", "+getWeaponName( params[i].tointeger() );         }      }      if ( weapons ) MessagePlayer("[#FFDD33]Information:[#FFFFFF] You received the following weapon: "+weapons+".", player);      else MessagePlayer( "[#FFDD33]Information:[#FFFFFF] Invalid Weapon Name/ID", player );   }}//will return 255 when invalid weapon name is usedfunction getWeaponID( strName ){   if ( strName.len() > 3 ) // make sure to use the correct one here   {      if ( strName.tolower().find( getWeaponName( 102 ).tolower() ) != null )      {         return 102;      }      if ( strName.tolower().find( getWeaponName( 103 ).tolower() ) != null )      {         return 103;      }   }      return GetWeaponID( strName );}//This one by Xmair//will return Unknown when invalid weapon ID is usedfunction getWeaponName( intID ){   switch( intID )   {       case 102:          {            return "AK-47";         }      break;      case 103:         {            return "IV Rocket Launcher";         }      break;      default:         {            return GetWeaponName( intID );         }      break;   }}

Discord: zeus#5155

umar4911

Quote from: ! on Dec 22, 2017, 04:36 PMTry
//
<?phpelse if( cmd == "wep" || cmd == "we" ){   if( !text ) return MessagePlayer( "[#FFDD33]Command Error:[#FFFFFF] /"+cmd+" <wep 1> <wep 2> <...>", player );   else   {      local params = split( text, " " );       local weapons;      for( local i = 0; i <= params.len() - 1; i++ )       {         if( !IsNum( params[i] ) && getWeaponID( params[i] ) != 255 )          {            player.SetWeapon( getWeaponID( params[i] ), 99999 );             if ( !wepons ) weapons = getWeaponName( getWeaponID( params[i] ) );            else weapons = wepons+", "+getWeaponName( getWeaponID( params[i] ) );         }         else if( IsNum( params[i] ) && getWeaponName( params[i].tointeger() ) != "Unknown" )         {            player.SetWeapon( params[i].tointeger(), 99999 );             weapons = getWeaponName( params[i].tointeger() );            if ( !wepons ) weapons = getWeaponName( params[i].tointeger() );            else weapons = wepons+", "+getWeaponName( params[i].tointeger() );         }      }      if ( weapons ) MessagePlayer("[#FFDD33]Information:[#FFFFFF] You received the following weapon: "+weapons+".", player);      else MessagePlayer( "[#FFDD33]Information:[#FFFFFF] Invalid Weapon Name/ID", player );   }}//will return 255 when invalid weapon name is usedfunction getWeaponID( strName ){   if ( strName.len() > 3 ) // make sure to use the correct one here   {      if ( strName.find( getWeaponName( 102 ) ) )      {         return 102;      }      if ( strName.find( getWeaponName( 103 ) ) )      {         return 103;      }            return GetWeaponID( strName );   }      return GetWeaponID( strName );}//This one by Xmair//will return Unknown when invalid weapon ID is usedfunction getWeaponName( intID ){   switch( intID )   {       case 102:          {            return "AK-47";         }      break;      case 103:         {            return "IV Rocket Launcher";         }      break;      default:         {            return GetWeaponName( intID );         }      break;   }}
This works but problem does not solves. if I type /wep 102, it gives me ak but if I typpe /wep ak, it says Invalid weapon. How to fix that
RT Member | Asian City Scripter | VKs Contributor | European City Contributor | EAD Scripter

!

#14
//
<?php   if ( strName.len() > 3 ) // make sure to use the correct one here

Only ak wont work since it checks for 4 words for custom weps

Change it to

//
<?php   if ( strName.len() > 1 ) // make sure to use the correct one here

It's better to limit the search words to 2 or 3 instead of removing it.

Discord: zeus#5155