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 );
}
}
}
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 )
Quote from: Doom_Kill3R on Oct 23, 2017, 11:19 AMQuote from: Xmair on Oct 23, 2017, 10:41 AM...
You mean getWeaponName( weaponID )
Yeah, thanks for pointing out the mistake, edited the post.
You didnot understand. It doesnot compare the Get the ID. If I type /wep ak, it says Invalid wep
I gave you a fully copy pasta function, if you're still unable to do it, stop scripting.
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
Quote from: umar4911 on Oct 24, 2017, 07:33 AMQuote 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.
Quote from: Xmair on Oct 24, 2017, 08:49 AMQuote from: umar4911 on Oct 24, 2017, 07:33 AMQuote 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
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
Make sure it's the same text as used in the ak47.xml.
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
Try
//<?php
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] ) != 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 used
function 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 used
function getWeaponName( intID )
{
switch( intID )
{
case 102:
{
return "AK-47";
}
break;
case 103:
{
return "IV Rocket Launcher";
}
break;
default:
{
return GetWeaponName( intID );
}
break;
}
}
Quote from: ! on Dec 22, 2017, 04:36 PMTry
//<?php
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] ) != 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 used
function 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 used
function 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
//<?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.
Quote from: ! on Dec 24, 2017, 02:44 PM//<?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.
Still no
Modify the function
/* <?php */
function 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 );
}
to
/* <?php */
function getWeaponID( strName )
{
if ( strName.len() > 1 ) // make sure to use the correct one here
{
if ( strName.tolower().find( getWeaponName( 102 ).tolower() ) )
{
return 102;
}
if ( strName.tolower().find( getWeaponName( 103 ).tolower() ) )
{
return 103;
}
}
return GetWeaponID( strName );
}
Quote from: ! on Dec 24, 2017, 04:47 PMModify the function
/* <?php */
function 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 );
}
to
/* <?php */
function getWeaponID( strName )
{
if ( strName.len() > 1 ) // make sure to use the correct one here
{
if ( strName.tolower().find( getWeaponName( 102 ).tolower() ) )
{
return 102;
}
if ( strName.tolower().find( getWeaponName( 103 ).tolower() ) )
{
return 103;
}
}
return GetWeaponID( strName );
}
Still Invalid Weapon :(
Quote from: umar4911 on Dec 25, 2017, 09:45 AMStill Invalid Weapon :(
try this once again there was a mistake now its fixed.
http://forum.vc-mp.org/?topic=5237.msg38626#msg38626
Quote from: ! on Dec 22, 2017, 04:36 PMTry
//<?php
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] ) != 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 used
function getWeaponID( strName )
{
if ( strName.len() > 1 ) // 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 used
function getWeaponName( intID )
{
switch( intID )
{
case 102:
{
return "AK-47";
}
break;
case 103:
{
return "IV Rocket Launcher";
}
break;
default:
{
return GetWeaponName( intID );
}
break;
}
}
Quote from: ! on Dec 25, 2017, 11:31 AMQuote from: umar4911 on Dec 25, 2017, 09:45 AMStill Invalid Weapon :(
try this once again there was a mistake now its fixed.
http://forum.vc-mp.org/?topic=5237.msg38626#msg38626
Quote from: ! on Dec 22, 2017, 04:36 PMTry
//<?php
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] ) != 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 used
function getWeaponID( strName )
{
if ( strName.len() > 1 ) // 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 used
function getWeaponName( intID )
{
switch( intID )
{
case 102:
{
return "AK-47";
}
break;
case 103:
{
return "IV Rocket Launcher";
}
break;
default:
{
return GetWeaponName( intID );
}
break;
}
}
Worked.