Vice City: Multiplayer

Server Development => Scripting and Server Management => Topic started by: umar4911 on Oct 23, 2017, 10:18 AM

Title: load custom weps
Post by: umar4911 on Oct 23, 2017, 10:18 AM
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 );
}
}
}
Title: Re: load custom weps
Post by: Xmair on Oct 23, 2017, 10:41 AM
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 )
Title: Re: load custom weps
Post by: DizzasTeR on Oct 23, 2017, 11:19 AM
Quote from: Xmair on Oct 23, 2017, 10:41 AM...

You mean getWeaponName( weaponID )
Title: Re: load custom weps
Post by: Xmair on Oct 23, 2017, 11:22 AM
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.
Title: Re: load custom weps
Post by: umar4911 on Oct 23, 2017, 03:36 PM
You didnot understand. It doesnot compare the Get the ID. If I type /wep ak, it says Invalid wep
Title: Re: load custom weps
Post by: Xmair on Oct 23, 2017, 04:09 PM
I gave you a fully copy pasta function, if you're still unable to do it, stop scripting.
Title: Re: load custom weps
Post by: 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
Title: Re: load custom weps
Post by: 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.
Title: Re: load custom weps
Post by: umar4911 on Oct 25, 2017, 05:08 AM
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
Title: Re: load custom weps
Post by: umar4911 on Dec 21, 2017, 12:28 PM
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
Title: Re: load custom weps
Post by: D4rkR420R on Dec 22, 2017, 02:14 AM
Make sure it's the same text as used in the ak47.xml.
Title: Re: load custom weps
Post by: umar4911 on Dec 22, 2017, 12:30 PM
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
Title: Re: load custom weps
Post by: ! on Dec 22, 2017, 04:36 PM
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 splittext" " ); 
      
local weapons;
      for( 
local i 0<= params.len() - 1i++ ) 
      {
         if( !
IsNumparams[i] ) && getWeaponIDparams[i] ) != 255 
         {
            
player.SetWeapongetWeaponIDparams[i] ), 99999 ); 
            if ( !
weapons weapons getWeaponNamegetWeaponIDparams[i] ) );
            else 
weapons weapons+", "+getWeaponNamegetWeaponIDparams[i] ) );
         }
         else if( 
IsNumparams[i] ) && getWeaponNameparams[i].tointeger() ) != "Unknown" )
         {
            
player.SetWeaponparams[i].tointeger(), 99999 ); 
            
weapons getWeaponNameparams[i].tointeger() );
            if ( !
weapons weapons getWeaponNameparams[i].tointeger() );
            else 
weapons weapons+", "+getWeaponNameparams[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 getWeaponIDstrName )
{
   if ( 
strName.len() > // make sure to use the correct one here
   
{
      if ( 
strName.tolower().findgetWeaponName102 ).tolower() ) != null )
      {
         return 
102;
      }
      if ( 
strName.tolower().findgetWeaponName103 ).tolower() ) != null )
      {
         return 
103;
      }
   }
   
   return 
GetWeaponIDstrName );
}
//This one by Xmair
//will return Unknown when invalid weapon ID is used
function getWeaponNameintID )
{
   switch( 
intID )
   { 
      case 
102
         {
            return 
"AK-47";
         }
      break;
      case 
103:
         {
            return 
"IV Rocket Launcher";
         }
      break;
      default:
         {
            return 
GetWeaponNameintID );
         }
      break;
   }
}
Title: Re: load custom weps
Post by: umar4911 on Dec 24, 2017, 02:33 PM
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 splittext" " ); 
      
local weapons;
      for( 
local i 0<= params.len() - 1i++ ) 
      {
         if( !
IsNumparams[i] ) && getWeaponIDparams[i] ) != 255 
         {
            
player.SetWeapongetWeaponIDparams[i] ), 99999 ); 
            if ( !
wepons weapons getWeaponNamegetWeaponIDparams[i] ) );
            else 
weapons wepons+", "+getWeaponNamegetWeaponIDparams[i] ) );
         }
         else if( 
IsNumparams[i] ) && getWeaponNameparams[i].tointeger() ) != "Unknown" )
         {
            
player.SetWeaponparams[i].tointeger(), 99999 ); 
            
weapons getWeaponNameparams[i].tointeger() );
            if ( !
wepons weapons getWeaponNameparams[i].tointeger() );
            else 
weapons wepons+", "+getWeaponNameparams[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 getWeaponIDstrName )
{
   if ( 
strName.len() > // make sure to use the correct one here
   
{
      if ( 
strName.findgetWeaponName102 ) ) )
      {
         return 
102;
      }
      if ( 
strName.findgetWeaponName103 ) ) )
      {
         return 
103;
      }
      
      return 
GetWeaponIDstrName );
   }
   
   return 
GetWeaponIDstrName );
}
//This one by Xmair
//will return Unknown when invalid weapon ID is used
function getWeaponNameintID )
{
   switch( 
intID )
   { 
      case 
102
         {
            return 
"AK-47";
         }
      break;
      case 
103:
         {
            return 
"IV Rocket Launcher";
         }
      break;
      default:
         {
            return 
GetWeaponNameintID );
         }
      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
Title: Re: load custom weps
Post by: ! on Dec 24, 2017, 02:44 PM
//<?php
   
if ( strName.len() > // 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() > // make sure to use the correct one here

It's better to limit the search words to 2 or 3 instead of removing it.
Title: Re: load custom weps
Post by: umar4911 on Dec 24, 2017, 03:00 PM
Quote from: ! on Dec 24, 2017, 02:44 PM//<?php
   
if ( strName.len() > // 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() > // 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
Title: Re: load custom weps
Post by: ! on Dec 24, 2017, 04:47 PM
Modify the function
/* <?php */
function 
getWeaponIDstrName )
{
   if ( 
strName.len() > // make sure to use the correct one here
   
{
      if ( 
strName.findgetWeaponName102 ) ) )
      {
         return 
102;
      }
      if ( 
strName.findgetWeaponName103 ) ) )
      {
         return 
103;
      }
      
      return 
GetWeaponIDstrName );
   }
   
   return 
GetWeaponIDstrName );
}
to
/* <?php */
function 
getWeaponIDstrName )
{
   if ( 
strName.len() > // make sure to use the correct one here
   
{
      if ( 
strName.tolower().findgetWeaponName102 ).tolower() ) )
      {
         return 
102;
      }
      if ( 
strName.tolower().findgetWeaponName103 ).tolower() ) )
      {
         return 
103;
      }
   }
   
   return 
GetWeaponIDstrName );
}
Title: Re: load custom weps
Post by: umar4911 on Dec 25, 2017, 09:45 AM
Quote from: ! on Dec 24, 2017, 04:47 PMModify the function
/* <?php */
function 
getWeaponIDstrName )
{
   if ( 
strName.len() > // make sure to use the correct one here
   
{
      if ( 
strName.findgetWeaponName102 ) ) )
      {
         return 
102;
      }
      if ( 
strName.findgetWeaponName103 ) ) )
      {
         return 
103;
      }
      
      return 
GetWeaponIDstrName );
   }
   
   return 
GetWeaponIDstrName );
}
to
/* <?php */
function 
getWeaponIDstrName )
{
   if ( 
strName.len() > // make sure to use the correct one here
   
{
      if ( 
strName.tolower().findgetWeaponName102 ).tolower() ) )
      {
         return 
102;
      }
      if ( 
strName.tolower().findgetWeaponName103 ).tolower() ) )
      {
         return 
103;
      }
   }
   
   return 
GetWeaponIDstrName );
}
Still Invalid Weapon :(
Title: Re: load custom weps
Post by: ! on Dec 25, 2017, 11:31 AM
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 splittext" " ); 
      
local weapons;
      for( 
local i 0<= params.len() - 1i++ ) 
      {
         if( !
IsNumparams[i] ) && getWeaponIDparams[i] ) != 255 
         {
            
player.SetWeapongetWeaponIDparams[i] ), 99999 ); 
            if ( !
weapons weapons getWeaponNamegetWeaponIDparams[i] ) );
            else 
weapons weapons+", "+getWeaponNamegetWeaponIDparams[i] ) );
         }
         else if( 
IsNumparams[i] ) && getWeaponNameparams[i].tointeger() ) != "Unknown" )
         {
            
player.SetWeaponparams[i].tointeger(), 99999 ); 
            
weapons getWeaponNameparams[i].tointeger() );
            if ( !
weapons weapons getWeaponNameparams[i].tointeger() );
            else 
weapons weapons+", "+getWeaponNameparams[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 getWeaponIDstrName )
{
   if ( 
strName.len() > // make sure to use the correct one here
   
{
      if ( 
strName.tolower().findgetWeaponName102 ).tolower() ) != null )
      {
         return 
102;
      }
      if ( 
strName.tolower().findgetWeaponName103 ).tolower() ) != null )
      {
         return 
103;
      }
   }
   
   return 
GetWeaponIDstrName );
}
//This one by Xmair
//will return Unknown when invalid weapon ID is used
function getWeaponNameintID )
{
   switch( 
intID )
   { 
      case 
102
         {
            return 
"AK-47";
         }
      break;
      case 
103:
         {
            return 
"IV Rocket Launcher";
         }
      break;
      default:
         {
            return 
GetWeaponNameintID );
         }
      break;
   }
}
Title: Re: load custom weps
Post by: umar4911 on Dec 25, 2017, 11:38 AM
Quote from: ! on Dec 25, 2017, 11:31 AM
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 splittext" " ); 
      
local weapons;
      for( 
local i 0<= params.len() - 1i++ ) 
      {
         if( !
IsNumparams[i] ) && getWeaponIDparams[i] ) != 255 
         {
            
player.SetWeapongetWeaponIDparams[i] ), 99999 ); 
            if ( !
weapons weapons getWeaponNamegetWeaponIDparams[i] ) );
            else 
weapons weapons+", "+getWeaponNamegetWeaponIDparams[i] ) );
         }
         else if( 
IsNumparams[i] ) && getWeaponNameparams[i].tointeger() ) != "Unknown" )
         {
            
player.SetWeaponparams[i].tointeger(), 99999 ); 
            
weapons getWeaponNameparams[i].tointeger() );
            if ( !
weapons weapons getWeaponNameparams[i].tointeger() );
            else 
weapons weapons+", "+getWeaponNameparams[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 getWeaponIDstrName )
{
   if ( 
strName.len() > // make sure to use the correct one here
   
{
      if ( 
strName.tolower().findgetWeaponName102 ).tolower() ) != null )
      {
         return 
102;
      }
      if ( 
strName.tolower().findgetWeaponName103 ).tolower() ) != null )
      {
         return 
103;
      }
   }
   
   return 
GetWeaponIDstrName );
}
//This one by Xmair
//will return Unknown when invalid weapon ID is used
function getWeaponNameintID )
{
   switch( 
intID )
   { 
      case 
102
         {
            return 
"AK-47";
         }
      break;
      case 
103:
         {
            return 
"IV Rocket Launcher";
         }
      break;
      default:
         {
            return 
GetWeaponNameintID );
         }
      break;
   }
}
Worked.